-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtkdo_scores.py
executable file
·84 lines (64 loc) · 2.13 KB
/
tkdo_scores.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
# fuck you python; why make it so hard to cleanly import from parent dir?
from os.path import dirname, abspath
import sys ; sys.path.insert(1, dirname(dirname(abspath(__file__))))
import random
import subprocess
import fuckometer
def main(args):
fuckometer.init()
tkdo = TKDO(period=120, history=30)
tkdo.loop() # run forever
class TKDO(fuckometer.Factor):
"""Average of top items from my TKDO list"""
path = 'tkdo_scores'
def fucks(self):
# smooth out the curve if possible
if self.history:
return max(0.0, sum(self.history) / len(self.history))
else:
return max(0.0, self.raw)
def on_update(self):
if fuckometer.cfg.verbose:
print('%s fucks, %s raw, %s' % (self.fucks(), self.raw, self.text))
def update(self):
"""Take the average of the top 20 TKDO tasks,
with a floor threshold of 50.
Pick a task at random as our summary.
"""
scores = []
items = []
fp = subprocess.check_output(('tkdo', 'list', '-20'))
for line in fp.split('\n'):
line = line.strip()
if not line:
continue
parts = line.split()
# the score is easy
score = float(parts[0])
scores.append(score)
# shorten the line for display purposes,
# by flattening the tasks to leaves only
score_ = parts[0]
shortened = []
parts.reverse()
for p in parts:
if p == '::':
break
shortened.append(p)
shortened.append(score_)
shortened.reverse()
#items.append(line)
items.append(' '.join(shortened))
if not scores:
return
total = sum([x-50 for x in scores])
avg = total / len(scores)
randitem = random.choice(items)
self.raw = avg
#self.text = 'TKDO: %.1f' % (self.raw)
#self.text = randitem
self.text = '\n'.join(items)
if __name__ == "__main__":
import sys
main(sys.argv[1:])