Changeset 61:8fe64b5932b9 in stamper


Ignore:
Timestamp:
Feb 13, 2015, 5:35:18 PM (10 years ago)
Author:
Borja Lopez <borja@…>
Branch:
default
Phase:
public
Message:

Filter stamps by text in their description/action.

Examples:

  • Returns all stamps for customer A that contain the word "updated":

stamps -t -desc updated A

  • Returns the sum of times for the work on the release of a project for customer B (if you added RELEASE as a text on those stamps):

stamps -vs -desc RELEASE B

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • bin/stamps

    r55 r61  
    2121    # Call the proper methods, based on the given parameters
    2222    if args.timeline:
    23         s.timeline(args.customer, args.filter)
     23        s.timeline(args.customer, args.filter, args.description)
    2424    elif args.delete:
    2525        s.remove_stamps(args.delete)
    2626    elif args.graph:
    27         s.graph_stamps(args.customer, args.filter)
     27        s.graph_stamps(args.customer, args.filter, args.description)
    2828    elif args.import_file:
    2929        s.import_stamps(args.import_file)
    3030    elif args.push:
    31         s.push_stamps(args.customer, args.filter)
     31        s.push_stamps(args.customer, args.filter, args.description)
    3232    else:
    33         s.show_stamps(args.customer, args.filter, args.verbose, args.sum)
     33        s.show_stamps(args.customer, args.filter, args.verbose, args.sum,
     34                      args.description)
  • stamper/cli.py

    r55 r61  
    1717    parser.add_argument('-t', '--timeline', action="store_true",
    1818                        help='Show a timeline of recorded times')
     19    parser.add_argument('-desc', '--description', action="store",
     20                        help='Filter results by the description in the stamp')
    1921    parser.add_argument('-d', '--delete', action="store", type=int,
    2022                        help='Delete up to n recorded stamps')
  • stamper/stamper.py

    r60 r61  
    180180        return customers
    181181
    182     def totals(self, filter_from=None, filter_to=None):
     182    def totals(self, filter_from=None, filter_to=None, filter_descr=None):
    183183        totals = {}
    184184        for stamp in self.stamps:
     
    196196                    # similar for the end date
    197197                    continue
     198                if filter_descr and filter_descr not in stamp['action']:
     199                    continue
    198200                if customer not in totals:
    199201                    totals[customer] = 0
     
    201203        return totals
    202204
    203     def details(self, filter_customer=None, filter_from=None, filter_to=None):
     205    def details(self, filter_customer=None, filter_from=None, filter_to=None,
     206                filter_descr=None):
    204207        details = OrderedDict()
    205208        totals = OrderedDict()
     
    223226                if filter_to and start > filter_to:
    224227                    # similar for the end date
     228                    continue
     229                if filter_descr and filter_descr not in stamp['action']:
    225230                    continue
    226231                # avoid "start" stamps
     
    246251        return details, totals, total_customer
    247252
    248     def timeline(self, customer=None, stamp_filter=None):
     253    def timeline(self, customer=None, stamp_filter=None, filter_descr=None):
    249254        filter_from, filter_to = self.validate_filter(stamp_filter)
    250255        for stamp in self.stamps:
     
    259264                # similar for the end date
    260265                continue
    261 
     266            if filter_descr and stamp['action']:
     267                if filter_descr not in stamp['action']:
     268                    continue
    262269            if not stamp['customer']:
    263270                if customer is None:
     
    272279                                stamp['action']]))
    273280
    274     def graph_stamps(self, customer=None, stamp_filter=None):
     281    def graph_stamps(self, customer=None, stamp_filter=None, filter_descr=None):
    275282        """
    276283        Generate charts with information from the stamps
     
    285292        details, totals, totals_customers = self.details(customer,
    286293                                                         filter_from,
    287                                                          filter_to)
     294                                                         filter_to,
     295                                                         filter_descr)
    288296        days = []
    289297        values = {}
     
    324332
    325333    def show_stamps(self, customer=None, stamp_filter=None, verbose=False,
    326         sum=False):
     334        sum=False, filter_descr=None):
    327335        filter_from, filter_to = self.validate_filter(stamp_filter)
    328336
     
    332340            details, totals, total_customer = self.details(customer,
    333341                                                           filter_from,
    334                                                            filter_to)
     342                                                           filter_to,
     343                                                           filter_descr)
    335344            for day in details:
    336345                print('------ %(day)s ------' % {'day': day})
     
    349358
    350359        # now calculate the totals and show them
    351         totals = self.totals(filter_from, filter_to)
     360        totals = self.totals(filter_from, filter_to, filter_descr)
    352361        if customer:
    353362            seconds=totals.get(customer, 0)
     
    431440        print('[warning] remember to review the resulting stamps file')
    432441
    433     def push_stamps(self, customer=None, stamp_filter=None):
     442    def push_stamps(self, customer=None, stamp_filter=None, filter_descr=None):
    434443        filter_from, filter_to = self.validate_filter(stamp_filter)
    435444
     
    449458                if filter_to and start > filter_to:
    450459                    # similar for the end date
     460                    continue
     461                if filter_descr and filter_descr not in stamp['action']:
    451462                    continue
    452463                stamps.append(stamp)
Note: See TracChangeset for help on using the changeset viewer.