summaryrefslogtreecommitdiff
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
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
-rwxr-xr-xdisplay.py8
-rw-r--r--formatting.py3
-rwxr-xr-xmain.py21
-rw-r--r--timers.py6
4 files changed, 22 insertions, 16 deletions
diff --git a/display.py b/display.py
index 1aa7b58..e160c6b 100755
--- a/display.py
+++ b/display.py
@@ -14,12 +14,14 @@ parser.add_argument("logfile", help="log file to display chart of",
args = parser.parse_args()
day_times = f.per_tag_per_day(args.logfile)
-print(day_times)
for day in day_times:
chart = pygal.Bar()
+ pie = pygal.Pie()
for key, value in day.items():
if key == "date":
continue
- chart.add(key, value)
- chart.render_to_file(str(day["date"]+".svg"))
+ chart.add(key, round(value/60, 0))
+ pie.add(key, round(value/60, 0))
+ chart.render_to_file(str(day["date"]+"-bar.svg"))
+ pie.render_to_file(str(day["date"]+"-pie.svg"))
diff --git a/formatting.py b/formatting.py
index 9c8bffa..04f213d 100644
--- a/formatting.py
+++ b/formatting.py
@@ -38,7 +38,8 @@ def per_tag_per_day(file):
date = rows[i]['date']
tag = rows[i]['tag']
if i > 0 and date == rows[i-1]['date']:
- day_times[cur][tag] = day_times[cur].get(tag, 0) + int(rows[i]['elapsed'])
+ if rows[i]['type'] == 'focus':
+ day_times[cur][tag] = day_times[cur].get(tag, 0) + int(rows[i]['elapsed'])
else:
cur += 1
day_times.append({"date": date, tag: int(rows[i]['elapsed'])})
diff --git a/main.py b/main.py
index cbdc9e3..1c3846e 100755
--- a/main.py
+++ b/main.py
@@ -11,7 +11,7 @@ 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
+ratio = 1/3 # default for now
sesh_type = "focus"
print("tag for session? ", end="", flush=True)
@@ -41,11 +41,12 @@ else:
input()
sesh_list = []
-elapsed, rest, start = timers.timer(timer_length, ratio, 0)
+elapsed_total = 0
+elapsed, rest, start = timers.timer(timer_length, ratio)
+session_id = hashlib.sha256(str(start).encode('utf8')).hexdigest()
while rest > 0:
-# print("\nneed to rest " + str(int(rest)))
session = OrderedDict()
- session["id"] = hashlib.sha256(str(start).encode('utf8')).hexdigest()
+ session["id"] = session_id
session["date"] = start.strftime("%Y-%m-%d")
session["start"] = start.strftime("%H:%M:%S")
session["elapsed"] = int(elapsed)
@@ -54,6 +55,7 @@ while rest > 0:
session["timer"] = timer
session["ratio"] = ratio
sesh_list.append(session)
+ elapsed_total += elapsed
sesh_type = "rest"
elapsed, dontcare, start = timers.timer(rest, 0, 0)
@@ -62,7 +64,7 @@ while rest > 0:
else:
rest -= elapsed
session = OrderedDict()
- session["id"] = hashlib.sha256(str(start).encode('utf8')).hexdigest()
+ session["id"] = session_id
session["date"] = start.strftime("%Y-%m-%d")
session["start"] = start.strftime("%H:%M:%S")
session["elapsed"] = int(elapsed)
@@ -73,13 +75,13 @@ while rest > 0:
sesh_list.append(session)
sesh_type = "focus"
- elapsed, rest, start = timers.timer(0, ratio, rest)
+ elapsed, rest, start = timers.timer(0, ratio, rest, elapsed_total)
if rest == 0:
break
print("\nfocus session finished!\nlogging...")
session = OrderedDict()
-session["id"] = hashlib.sha256(str(start).encode('utf8')).hexdigest()
+session["id"] = session_id
session["date"] = start.strftime("%Y-%m-%d")
session["start"] = start.strftime("%H:%M:%S")
session["elapsed"] = int(elapsed)
@@ -90,6 +92,5 @@ session["ratio"] = ratio
sesh_list.append(session)
for session in sesh_list:
- print(session)
-
-#f.sesh_to_log(session, "main.csv")
+# print(session)
+ f.sesh_to_log(session, "main.csv")
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" +