Changeset 23:bc0b04a989aa in stamper
- Timestamp:
- Jul 24, 2014, 2:52:30 AM (10 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
.hgignore
r21 r23 6 6 stamper.egg-info/ 7 7 dist/ 8 graphs/ 8 9 -
bin/stamps
r22 r23 17 17 parser.add_argument('-s', '--sum', action="store_true", 18 18 help='Include sum of times') 19 parser.add_argument('-g', '--graph', action="store_true", 20 help='Generate a SVG graph') 19 21 20 22 args = parser.parse_args() … … 22 24 s = Stamper() 23 25 s.load_stamps() 24 s.show_stamps(args.customer, args.filter, args.verbose, args.sum) 26 s.show_stamps(args.customer, args.filter, args.verbose, args.sum, 27 args.graph) -
stamper/stamper.py
r22 r23 2 2 import json 3 3 import re 4 import pygal 4 5 from datetime import datetime, timedelta 5 6 from os.path import expanduser, exists … … 110 111 details = OrderedDict() 111 112 totals = OrderedDict() 113 total_customer = OrderedDict() 112 114 for stamp in self.stamps: 113 115 if stamp['customer']: … … 125 127 'action': stamp['action'] 126 128 }) 129 customer = stamp['customer'] 127 130 totals[start_day] += worktime 131 if start_day not in total_customer: 132 total_customer[start_day] = {} 133 if customer not in total_customer[start_day]: 134 total_customer[start_day][customer] = 0 135 total_customer[start_day][customer] += worktime 128 136 for day in totals: 129 137 totals[day] = str(timedelta(seconds=totals[day])) 130 return details, totals 138 return details, totals, total_customer 131 139 132 140 def details_by_customer(self, customer): … … 153 161 154 162 def show_stamps(self, customer=None, stamp_filter=None, verbose=False, 155 sum=False ):163 sum=False, graph=False): 156 164 if stamp_filter: 157 165 stamp_filter = self.validate_filter(stamp_filter) … … 161 169 if customer: 162 170 seconds=totals.get(customer, 0) 163 total = timedelta(seconds )171 total = timedelta(seconds=totals.get(customer, 0)) 164 172 print(' %(customer)s: %(total)s' % {'customer': customer, 165 173 'total': total}) … … 167 175 for c in totals: 168 176 seconds=totals[c] 169 total = timedelta(seconds )177 total = timedelta(seconds=totals[c]) 170 178 print(' %(customer)s: %(total)s' % {'customer': c, 171 179 'total': total}) … … 175 183 details, totals = self.details_by_customer(customer) 176 184 else: 177 details, totals = self.details()185 details, totals, total_customer = self.details() 178 186 for day in details: 179 187 print('------ %(day)s ------' % {'day': day}) … … 201 209 totalDays, remainingHr, remainingMin, HOURS_DAY 202 210 )) 211 212 if graph: 213 DAYS = 15 214 list_days = [] 215 list_tot = [] 216 stackedbar_chart = pygal.StackedBar() 217 stackedbar_chart.title = 'Worked time per day (in hours)' 218 219 if customer: 220 for day, tot in totals.iteritems(): 221 list_days.append(day) 222 (h, m, s) = tot.split(':') 223 tot_sec = int(h) * 3600 + int(m) * 60 + int(s) 224 tot_h = float(tot_sec / float(60) / float(60)) 225 list_tot.append(tot_h) 226 stackedbar_chart.add(customer, list_tot) 227 stackedbar_chart.x_labels = map(str, list_days) 228 stackedbar_chart.render_to_file('graphs/chart-%s.svg' % customer ) 229 else: 230 all_customers = self.customers() 231 total_per_customer = {} 232 details, totals, total_customer = self.details() 233 chars = 0 234 total_customer_reverse = total_customer.items() 235 total_customer_reverse.reverse() 236 for day, tot in total_customer_reverse: 237 if chars < DAYS: 238 list_days.append(day) 239 for cust in self.customers(): 240 if cust not in tot: 241 tot[cust] = 0 242 for cus, time in tot.iteritems(): 243 tot_h = float(time / float(60) / float(60)) 244 if cus not in total_per_customer: 245 total_per_customer[cus] = [] 246 total_per_customer[cus].append(tot_h) 247 chars = chars + 1 248 for ccus, ctime in total_per_customer.iteritems(): 249 stackedbar_chart.add(ccus, ctime) 250 stackedbar_chart.x_labels = map(str, list_days[-DAYS:]) 251 stackedbar_chart.render_to_file('graphs/chart-all.svg')
Note:
See TracChangeset
for help on using the changeset viewer.