@@ -46,6 +46,8 @@ def print_report(report, days=[], projects=[], overtime=False):
4646 if proj_stats .get ("have_full_day" , False ):
4747 adjust_full_day (proj_stats )
4848 for project , stat in proj_stats ["projects" ].items ():
49+ if stat .get ("ignore" ):
50+ continue
4951 overtime_value = stat ["overtime" ]
5052 if overtime and overtime_value :
5153 # Just want to count the overtime amount
@@ -60,6 +62,8 @@ def print_report(report, days=[], projects=[], overtime=False):
6062 and (not days or date in days )
6163 # not filtering by overtime, or this is an overtime entry
6264 and (not overtime or overtime_value )
65+ # not marked has "ignore"
66+ and (not proj_stats .get ("ignore" , False ))
6367 ):
6468 rows .append ([date , project , total ])
6569 gran_total += total
@@ -72,7 +76,7 @@ def print_report(report, days=[], projects=[], overtime=False):
7276 click .echo (tabulate (rows , headers = headers , tablefmt = "simple" ))
7377
7478
75- def create_report (sheet , sheet_name , data , overtime = False ):
79+ def create_report (sheet , sheet_name , data , overtime = False , filter = None ):
7680 """Create a time consumption report from a sheet."""
7781 headers_id = get_headers (sheet , sheet_name , indexes = True )
7882 overtime_from = get ("OVERTIME_FROM" , default = False )
@@ -138,6 +142,7 @@ def create_report(sheet, sheet_name, data, overtime=False):
138142 "total" : 0 ,
139143 "overtime" : 0 ,
140144 "full_day" : False ,
145+ "ignore" : False ,
141146 },
142147 )
143148 spent = get_col (row , headers_id ["Spent" ])
@@ -160,13 +165,17 @@ def create_report(sheet, sheet_name, data, overtime=False):
160165 date_stats ["have_full_day" ] = True
161166 prog_stats ["full_day" ] = True
162167
168+ # Filter defined, but it doesn't match
169+ if filter and filter not in get_col (row , headers_id ["Activity" ], "" ):
170+ prog_stats ["ignore" ] = True
171+
163172 date_stats ["projects" ][project ] = prog_stats
164173 dates [str (date )] = date_stats
165174
166175 return dates
167176
168177
169- def report (config_dir , sheet_name , days = [], projects = [], overtime = False ):
178+ def report (config_dir , sheet_name , days = [], projects = [], overtime = False , filter = None ):
170179 """Open a sheet, analyze it and extract stats."""
171180 # The ID and range of the controller timesheet
172181 creds = get_credentials (config_dir , SCOPES , "sheets-token.json" )
@@ -205,10 +214,10 @@ def report(config_dir, sheet_name, days=[], projects=[], overtime=False):
205214 click .echo (err .error_details )
206215 sys .exit (1 )
207216
208- report = create_report (
209- sheet = sheet , sheet_name = sheet_name , data = data , overtime = overtime
217+ computed_report = create_report (
218+ sheet = sheet , sheet_name = sheet_name , data = data , overtime = overtime , filter = filter
210219 )
211220
212221 click .echo ("" )
213- print_report (report , days = days , projects = projects , overtime = overtime )
222+ print_report (computed_report , days = days , projects = projects , overtime = overtime )
214223 click .echo ("" )
0 commit comments