- commit
- dafd98a3e33c265c45940ca60b1a1b524956b1eb
- parent
- f4d37910a529f9be6d798a2412a8ddde36384abd
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2022-02-25 13:52
add --timesheet
Diffstat
| M | vtimelog | 46 | ++++++++++++++++++++++++++++++++++------------ |
1 files changed, 34 insertions, 12 deletions
diff --git a/vtimelog b/vtimelog
@@ -155,6 +155,17 @@ class Extractor: 155 155 if '**' not in entry['comment'] 156 156 ), start=timedelta()) 157 157 -1 158 def by_date(self): -1 159 dates = {} -1 160 for entry in self.data: -1 161 date = entry['dt'].date() -1 162 if date not in dates: -1 163 dates[date] = [] -1 164 dates[date].append(entry) -1 165 for date, entries in dates.items(): -1 166 e = Extractor(entries) -1 167 yield entries[0]['dt'], entries[-1]['dt'], e.sum() -1 168 158 169 def by_comment(self): 159 170 d = {} 160 171 for prev, entry in pairwise(self.data): @@ -219,6 +230,8 @@ if __name__ == '__main__': 219 230 help='show entries from this year or YEAR years ago') 220 231 parser.add_argument('-c', '--check', action='store_true', 221 232 help='find potential issues') -1 233 parser.add_argument('-s', '--timesheet', action='store_true', -1 234 help='output as timesheet CSV') 222 235 args = parser.parse_args() 223 236 224 237 # load data from file @@ -255,15 +268,24 @@ if __name__ == '__main__': 255 268 else: 256 269 extractor = Extractor(q.all()) 257 270258 -1 # output by comment259 -1 by_comment = extractor.by_comment()260 -1 if len(by_comment) > 0:261 -1 length = max(len(k) for k in by_comment.keys())262 -1 for comment, delta in sorted(by_comment.items(), key=lambda a: a[1]):263 -1 padding = ' ' * (length + 1 - len(comment))264 -1 print(comment + padding + timedelta2str(delta))265 -1 print()266 -1267 -1 # output total workhours268 -1 done = int(extractor.sum().total_seconds() / 3600)269 -1 print('Total workhours done: %i (%i extra)' % (done, done - expected))-1 271 if args.timesheet: -1 272 for start, end, total in extractor.by_date(): -1 273 date = start.strftime('%Y-%m-%d') -1 274 s = start.strftime('%H:%M') -1 275 e = end.strftime('%H:%M') -1 276 _break = ((end - start) - total).total_seconds() -1 277 b = '{:02d}:{:02d}'.format(int(_break / 60 / 60), int(_break / 60 % 60)) -1 278 print('{}\t{}\t{}\t{}'.format(date, s, e, b)) -1 279 else: -1 280 # output by comment -1 281 by_comment = extractor.by_comment() -1 282 if len(by_comment) > 0: -1 283 length = max(len(k) for k in by_comment.keys()) -1 284 for comment, delta in sorted(by_comment.items(), key=lambda a: a[1]): -1 285 padding = ' ' * (length + 1 - len(comment)) -1 286 print(comment + padding + timedelta2str(delta)) -1 287 print() -1 288 -1 289 # output total workhours -1 290 done = int(extractor.sum().total_seconds() / 3600) -1 291 print('Total workhours done: %i (%i extra)' % (done, done - expected))