From b5d036762d9e4566f81e18708414fd306db6a1bc Mon Sep 17 00:00:00 2001 From: hmj6502 Date: Sun, 28 Dec 2025 13:35:02 +0000 Subject: INCOMPLETE: add stop/start and rest bank to stopwatch - IMPORTANT: added seconds to timestamp in csv as someone could start and rest in the same minute - BROKEN commit, but i need something sane to be able to roll back to - only works for stopwatch atm, haven't even tested timer - doesn't show cumalative time focused in timer, will need a bit of refactoring (hence need for sane commit) - timer now returns seconds for everything except start --- main.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++------- timers.py | 11 ++++++++--- 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index c59ac4c..cbdc9e3 100755 --- a/main.py +++ b/main.py @@ -11,6 +11,9 @@ import formatting as f print("welcome to lock-n-log, the best way to organise and analyse your focus time!") +ratio = 1 # default for now +sesh_type = "focus" + print("tag for session? ", end="", flush=True) tag = input() if tag == "": @@ -37,18 +40,56 @@ else: print("whenever you're ready, press enter to start", end="", flush=True) input() -elapsed, start = timers.timer(timer_length) +sesh_list = [] +elapsed, rest, start = timers.timer(timer_length, ratio, 0) +while rest > 0: +# print("\nneed to rest " + str(int(rest))) + session = OrderedDict() + session["id"] = hashlib.sha256(str(start).encode('utf8')).hexdigest() + session["date"] = start.strftime("%Y-%m-%d") + session["start"] = start.strftime("%H:%M:%S") + session["elapsed"] = int(elapsed) + session["type"] = sesh_type + session["tag"] = tag + session["timer"] = timer + session["ratio"] = ratio + sesh_list.append(session) + + sesh_type = "rest" + elapsed, dontcare, start = timers.timer(rest, 0, 0) + if elapsed >= rest: # if exceeded break bank, then focus session ended + break + else: + rest -= elapsed + session = OrderedDict() + session["id"] = hashlib.sha256(str(start).encode('utf8')).hexdigest() + session["date"] = start.strftime("%Y-%m-%d") + session["start"] = start.strftime("%H:%M:%S") + session["elapsed"] = int(elapsed) + session["type"] = sesh_type + session["tag"] = tag + session["timer"] = timer + session["ratio"] = ratio + sesh_list.append(session) + + sesh_type = "focus" + elapsed, rest, start = timers.timer(0, ratio, rest) + if rest == 0: + break print("\nfocus session finished!\nlogging...") session = OrderedDict() session["id"] = hashlib.sha256(str(start).encode('utf8')).hexdigest() session["date"] = start.strftime("%Y-%m-%d") -session["start"] = start.strftime("%H:%M") -session["elapsed"] = int(elapsed.total_seconds()) -session["type"] = "focus" +session["start"] = start.strftime("%H:%M:%S") +session["elapsed"] = int(elapsed) +session["type"] = sesh_type session["tag"] = tag session["timer"] = timer -session["ratio"] = 0.2 -#print(session) +session["ratio"] = ratio +sesh_list.append(session) + +for session in sesh_list: + print(session) -f.sesh_to_log(session, "lock-n-log.csv") +#f.sesh_to_log(session, "main.csv") diff --git a/timers.py b/timers.py index cf8e91d..5ba51fa 100644 --- a/timers.py +++ b/timers.py @@ -4,7 +4,7 @@ import inputs frequency = 120 # 120Hz refresh -def timer(length=0): +def timer(length=0, ratio = 0.2, rest_accum=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 @@ -16,12 +16,16 @@ def timer(length=0): while True: now = datetime.datetime.now() elapsed = now - start + rest = elapsed * ratio + datetime.timedelta(seconds=rest_accum) time_left = end - now if length > 0 and time_left.total_seconds() <= 0: break ch = inputs.getch_nb(timeout) if ch == 'q': + rest = datetime.timedelta() + break + elif ch == ' ': break if length > 0: @@ -30,11 +34,12 @@ def timer(length=0): time_display = elapsed # see https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797 - print("\x1b[2K\r" + inputs.delta_to_HM(time_display), end="", flush=True) + print("\x1b[2K\r" + inputs.delta_to_HM(time_display) + "\t" + + inputs.delta_to_HM(rest), end="", flush=True) accum += timeout if accum >= 1: accum = 0 termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings) - return (elapsed, start) + return (elapsed.total_seconds(), rest.total_seconds(), start) -- cgit v1.2.3