summaryrefslogtreecommitdiff
path: root/display.py
diff options
context:
space:
mode:
authorhmjsp <hmjsp@liber8bits.com>2026-10-09 13:31:49 +0100
committerhmjsp <hmjsp@liber8bits.com>2026-10-09 13:31:49 +0100
commitf526d2a83e1b3db901f512381a13e00e91e00075 (patch)
treee98945d4e3a6db5b4f134389b377ec316272decd /display.py
parent4b6845618b972153cef5b8c776dd7b018775e444 (diff)
downloadchronologgy-f526d2a83e1b3db901f512381a13e00e91e00075.zip
add per week displayHEADmain
Diffstat (limited to 'display.py')
-rwxr-xr-xdisplay.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/display.py b/display.py
index cfd7041..3369793 100755
--- a/display.py
+++ b/display.py
@@ -8,6 +8,7 @@ import argparse
from collections import OrderedDict
import formatting as f
import os
+import datetime
parser = argparse.ArgumentParser()
parser.add_argument("logfile", help="log file to display chart of",
@@ -24,13 +25,39 @@ except FileExistsError:
except PermissionError:
print("permission denied: unable to create " + config_dir)
+# get first day; find its weekday so that running day_count starts correctly;
+# first_week so that week numbers are correctly output
+first_day = datetime.date.strptime(day_times[0]['date'], "%Y-%m-%d")
+first_week = first_day.isocalendar().week
+day_count = first_day.weekday()
+
+week_times = [{}] # empty list to append to; list of dicts (tags)
+wi = 0 # week index
+
for day in day_times:
chart = pygal.Bar()
pie = pygal.Pie()
for key, value in day.items():
if key == "date":
continue
+ week_times[wi][key] = week_times[wi].get(key, 0) + value # add days to corresponding weeks
chart.add(key, round(value/60/60, 1))
pie.add(key, round(value/60/60, 1))
+ day_count += 1
+ if day_count >= 6:
+ day_count = 0
+ week_times.append({})
+ wi += 1
chart.render_to_file(str(cache_dir + "/" + day["date"]+"-bar.svg"))
pie.render_to_file(str(cache_dir + "/" + day["date"]+"-pie.svg"))
+
+# currently each csv file should only contain one year... should be easy to fix later; TODO
+year = str(first_day.isocalendar().year)
+for week_num, week in enumerate(week_times):
+ chart = pygal.Bar()
+ pie = pygal.Pie()
+ for key, value in week.items():
+ chart.add(key, round(value/60/60, 1))
+ pie.add(key, round(value/60/60, 1))
+ chart.render_to_file(str(cache_dir + "/" + year+"-week"+str(first_week+week_num)+"-bar.svg"))
+ pie.render_to_file(str(cache_dir + "/" + year+"-week"+str(first_week+week_num)+"-pie.svg"))