Changeset 30:b8003f616519 in stamper
- Timestamp:
- Aug 9, 2014, 2:59:49 AM (10 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
bin/stamps
r29 r30 36 36 if args.timeline: 37 37 s.timeline() 38 elif args.graph: 39 s.graph_stamps(args.customer, args.filter) 38 40 else: 39 s.show_stamps(args.customer, args.filter, args.verbose, args.sum, 40 args.graph) 41 s.show_stamps(args.customer, args.filter, args.verbose, args.sum) -
stamper/stamper.py
r28 r30 4 4 import pygal 5 5 from datetime import datetime, date, timedelta 6 from os.path import expanduser, exists 6 from os.path import expanduser, exists, islink 7 from os import symlink, remove 7 8 from collections import OrderedDict 8 9 … … 10 11 STAMPS_FILE = expanduser('~/.workstamps.json') 11 12 DATE_FORMAT = '%Y-%m-%d' 13 TIME_FORMAT = '%H:%M:%S' 12 14 DATETIME_FORMAT = '%Y-%m-%d %H:%M' 13 15 HOURS_DAY = 8 … … 128 130 return filter_from, filter_to 129 131 132 @property 130 133 def customers(self): 131 134 customers = [] … … 212 215 stamp['action']])) 213 216 217 def graph_stamps(self, customer=None, stamp_filter=None): 218 """ 219 Generate charts with information from the stamps 220 """ 221 filter_from, filter_to = self.validate_filter(stamp_filter) 222 chart = pygal.Bar(title='Work hours per day', 223 range=(0, HOURS_DAY), 224 x_title='Days', 225 y_title='Work hours', 226 x_label_rotation=45) 227 228 details, totals, totals_customers = self.details(customer, 229 filter_from, 230 filter_to) 231 days = [] 232 values = {} 233 for c in self.customers: 234 values[c] = [] 235 236 found = [] 237 238 for day in details: 239 for c in values: 240 seconds = totals_customers[day].get(c, 0) 241 if seconds and c not in found: 242 found.append(c) 243 human = timedelta(seconds=seconds).__str__() 244 values[c].append({'value': seconds/60.00/60.00, 245 'label': day + ': ' + human}) 246 days.append(day) 247 chart.x_labels = map(str, days) 248 249 if customer: 250 chart.add(customer, values[customer]) 251 else: 252 for c in found: 253 chart.add(c, values[c]) 254 255 chart_name = 'chart-%s.svg' % datetime.today().strftime( 256 '%Y-%m-%d_%H%M%S') 257 chart_symlink = 'chart-latest.svg' 258 chart.render_to_file('graphs/' + chart_name) 259 if islink('graphs/'+ chart_symlink): 260 remove('graphs/'+ chart_symlink) 261 symlink(chart_name, 'graphs/'+ chart_symlink) 262 214 263 def show_stamps(self, customer=None, stamp_filter=None, verbose=False, 215 sum=False, graph=False): 216 264 sum=False): 217 265 filter_from, filter_to = self.validate_filter(stamp_filter) 218 266 … … 263 311 totalDays, remainingHr, remainingMin, HOURS_DAY 264 312 )) 265 266 if graph:267 DAYS = 15268 list_days = []269 list_tot = []270 stackedbar_chart = pygal.StackedBar()271 stackedbar_chart.title = 'Worked time per day (in hours)'272 273 if customer:274 for day, tot in totals.iteritems():275 list_days.append(day)276 (h, m, s) = tot.split(':')277 tot_sec = int(h) * 3600 + int(m) * 60 + int(s)278 tot_h = float(tot_sec / float(60) / float(60))279 list_tot.append(tot_h)280 stackedbar_chart.add(customer, list_tot)281 stackedbar_chart.x_labels = map(str, list_days)282 stackedbar_chart.render_to_file('graphs/chart-%s.svg' % customer )283 else:284 all_customers = self.customers()285 total_per_customer = {}286 details, totals, total_customer = self.details()287 chars = 0288 total_customer_reverse = total_customer.items()289 total_customer_reverse.reverse()290 for day, tot in total_customer_reverse:291 if chars < DAYS:292 list_days.append(day)293 for cust in self.customers():294 if cust not in tot:295 tot[cust] = 0296 for cus, time in tot.iteritems():297 tot_h = float(time / float(60) / float(60))298 if cus not in total_per_customer:299 total_per_customer[cus] = []300 total_per_customer[cus].append(tot_h)301 chars = chars + 1302 for ccus, ctime in total_per_customer.iteritems():303 stackedbar_chart.add(ccus, ctime)304 stackedbar_chart.x_labels = map(str, list_days[-DAYS:])305 stackedbar_chart.render_to_file('graphs/chart-all.svg')
Note:
See TracChangeset
for help on using the changeset viewer.