summaryrefslogtreecommitdiff
path: root/timers.py
diff options
context:
space:
mode:
authorhmj6502 <hashim@hmj6502.com>2025-12-28 15:38:17 +0000
committerhmj6502 <hashim@hmj6502.com>2025-12-28 20:09:45 +0000
commitd1066e7a26d8da0d1ed2e15997a485879e46611d (patch)
tree1fea05df5fd2d5205388827cc92f196fd3f44db1 /timers.py
parentb5d036762d9e4566f81e18708414fd306db6a1bc (diff)
downloadlock-n-log-d1066e7a26d8da0d1ed2e15997a485879e46611d.tar.gz
lock-n-log-d1066e7a26d8da0d1ed2e15997a485879e46611d.tar.bz2
lock-n-log-d1066e7a26d8da0d1ed2e15997a485879e46611d.zip
stop/start & rest bank complete on stopwatch
- cumulative time wasn't too bad to add actually - one id per session added - change formatting.py so that it only counts time that is of type 'focus' as time to put on chart - add pie chart and time in minutes rather than seconds to display.py
Diffstat (limited to 'timers.py')
-rw-r--r--timers.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/timers.py b/timers.py
index 5ba51fa..6bd9088 100644
--- a/timers.py
+++ b/timers.py
@@ -4,18 +4,20 @@ import inputs
frequency = 120 # 120Hz refresh
-def timer(length=0, ratio = 0.2, rest_accum=0):
+def timer(length=0, ratio = 0.2, rest_accum=0, elapsed_total=0):
"""countdown and stopwatch; pass length as 0 for stopwatch"""
start = datetime.datetime.now()
end = start + datetime.timedelta(seconds=length) # change to mins in final
accum = 0
timeout = 1/frequency
+ elapsed_base = datetime.timedelta(seconds=elapsed_total)
old_settings = termios.tcgetattr(sys.stdin)
tty.setcbreak(sys.stdin.fileno())
while True:
now = datetime.datetime.now()
elapsed = now - start
+ elapsed_total = elapsed_base + elapsed
rest = elapsed * ratio + datetime.timedelta(seconds=rest_accum)
time_left = end - now
if length > 0 and time_left.total_seconds() <= 0:
@@ -31,7 +33,7 @@ def timer(length=0, ratio = 0.2, rest_accum=0):
if length > 0:
time_display = time_left
else:
- time_display = elapsed
+ time_display = elapsed_total
# see https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
print("\x1b[2K\r" + inputs.delta_to_HM(time_display) + "\t" +