Changeset 22:43d14913e8fd in stamper for stamper/stamper.py


Ignore:
Timestamp:
Jul 23, 2014, 2:03:55 PM (10 years ago)
Author:
Óscar M. Lage <info@…>
Branch:
default
Phase:
public
Message:

Added -s option to sum all the times and show a resume

File:
1 edited

Legend:

Unmodified
Added
Removed
  • stamper/stamper.py

    r19 r22  
    99STAMPS_FILE = expanduser('~/.workstamps.json')
    1010DATE_FORMAT = '%Y-%m-%d %H:%M'
     11HOURS_DAY = 8
     12SECS_DAY = HOURS_DAY * 60 * 60
    1113
    1214
     
    150152        return details, totals
    151153
    152     def show_stamps(self, customer=None, stamp_filter=None, verbose=False):
     154    def show_stamps(self, customer=None, stamp_filter=None, verbose=False,
     155        sum=False):
    153156        if stamp_filter:
    154157            stamp_filter = self.validate_filter(stamp_filter)
     
    157160
    158161        if customer:
    159             total = timedelta(seconds=totals.get(customer, 0))
     162            seconds=totals.get(customer, 0)
     163            total = timedelta(seconds)
    160164            print(' %(customer)s: %(total)s' % {'customer': customer,
    161165                                                'total': total})
    162166        else:
    163167            for c in totals:
    164                 total = timedelta(seconds=totals[c])
     168                seconds=totals[c]
     169                total = timedelta(seconds)
    165170                print(' %(customer)s: %(total)s' % {'customer': c,
    166171                                                    'total': total})
     
    176181                    print(line)
    177182                print(' Total: %(total)s' % {'total': totals[day]})
     183
     184        if sum:
     185            sum_tot = ''
     186            if totals:
     187                print('------ Totals ------' % {'day': day})
     188                for day, tot in totals.iteritems():
     189                    print(' %(day)s: %(total)s' % {'day': day, 'total': tot})
     190                    sum_tot = "%(total)s %(new)s" % {
     191                        'total': sum_tot,
     192                        'new': total
     193                    }
     194                totalSecs, sec = divmod(seconds, 60)
     195                hr, min = divmod(totalSecs, 60)
     196                totalDays, remaining = divmod(seconds, SECS_DAY)
     197                remainingMin, remainingSec = divmod(remaining, (60))
     198                remainingHr, remainingMin = divmod(remainingMin, (60))
     199                print('----- %d:%02d:%02d -----' % (hr, min, sec))
     200                print('--- %d days, remaining: %d:%02d (%d hours/day) ---' % (
     201                    totalDays, remainingHr, remainingMin, HOURS_DAY
     202                ))
Note: See TracChangeset for help on using the changeset viewer.