-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasktimer.py
More file actions
executable file
·66 lines (61 loc) · 1.66 KB
/
Copy pathtasktimer.py
File metadata and controls
executable file
·66 lines (61 loc) · 1.66 KB
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
#!/usr/bin/python
import os, time, sys
from threading import Thread
import matplotlib.pyplot as plotter
import numpy as np
STOP_THIS = False
TASK_LOG = {}
TOTAL_TIME = 0
def timer(countdown):
global STOP_THIS
global TASK_LOG
global TOTAL_TIME
secs = countdown
task_no = 0
while True:
if STOP_THIS == True:
task_no +=1
task_time = countdown - secs
TASK_LOG[task_no] = task_time
print('task {} time: '.format(task_no)+str(task_time))
TOTAL_TIME += task_time
print('total time: '+str(TOTAL_TIME)+'\n')
secs = countdown
os.system('play -nq -t alsa synth 0.25 sine 440')
STOP_THIS = False
time.sleep(1)
secs -=1
if secs == 0:
os.system('play -nq -t alsa synth 0.25 sine 880')
def stop():
x=input()
global STOP_THIS
global TASK_LOG
if x != 'q':
STOP_THIS = True
elif x == 'q':
print('generating report...')
fig = plotter.figure(figsize=(16,9))
tno = list(TASK_LOG.keys())
ttime = list(TASK_LOG.values())
plotter.bar(tno,ttime)
plotter.savefig('stats.png')
print('done! report saved to stats.png')
sys.exit(0)
if __name__=='__main__':
#get sysargs
if len(sys.argv) == 1:
print('enter countdown time in secs')
sys.exit(1)
else:
try:
countdown = int(sys.argv[1])
except ValueError:
print('invalid argument')
sys.exit(1)
#do stuff
t1 = Thread(target=timer,args=(countdown,))
t1.daemon = True
t1.start()
while True:
stop()