- commit
- 80cd2bbd6858e2bd860a3ff6307f50849efea17a
- parent
- de1fdc0d30ddd783b6214aec20999ef29aab9574
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2022-02-25 13:56
refactor
Diffstat
| M | vtimelog | 20 | +++++++++----------- |
1 files changed, 9 insertions, 11 deletions
diff --git a/vtimelog b/vtimelog
@@ -215,10 +215,9 @@ class ExpectedHoursPer: 215 215 def days(cls, n): 216 216 """interpolation between day and year""" 217 217 from math import exp218 -1 f = lambda x: 2 / (1 + exp(-x / 7) / exp(-1 / 7)) - 1219 218 d1 = cls.day() 220 219 d2 = cls.year() / 365221 -1 fn = f(n)-1 220 fn = 2 / (1 + exp(-n / 7) / exp(-1 / 7)) - 1 222 221 d = (1-fn) * d1 + fn * d2 223 222 return d * n 224 223 @@ -244,10 +243,9 @@ if __name__ == '__main__': 244 243 args = parser.parse_args() 245 244 246 245 # load data from file247 -1 f = open(args.file)248 -1 l = [line.strip() for line in f.readlines() if line.strip()]249 -1 data = LazyTimelog(l)250 -1 f.close()-1 246 with open(args.file) as fh: -1 247 l = [line.strip() for line in fh.readlines() if line.strip()] -1 248 data = LazyTimelog(l) 251 249 252 250 # filter 253 251 q = Query(data) @@ -267,18 +265,18 @@ if __name__ == '__main__': 267 265 expected = ExpectedHoursPer.days( 268 266 (data[-1]['dt'] - data[0]['dt']).total_seconds() / 3600 / 24 269 267 )270 -1 data = q.all()271 268272 -1 ex = Extractor(data)-1 269 extractor = Extractor(q.all()) 273 270 274 271 # output by comment275 -1 by_comment = ex.by_comment()-1 272 by_comment = extractor.by_comment() 276 273 if len(by_comment) > 0: 277 274 l = max(len(k) for k in by_comment.keys()) 278 275 for comment, delta in sorted(by_comment.items(), key=lambda a: a[1]):279 -1 print(comment + (l + 1 - len(comment)) * ' ' + timedelta2str(delta))-1 276 padding = ' ' * (l + 1 - len(comment)) -1 277 print(comment + padding + timedelta2str(delta)) 280 278 print() 281 279 282 280 # output total workhours283 -1 done = int(ex.sum().total_seconds() / 3600)-1 281 done = int(extractor.sum().total_seconds() / 3600) 284 282 print('Total workhours done: %i (%i extra)' % (done, done - expected))