diff options
| author | hmjsp <hmjsp@liber8bits.com> | 2026-10-09 13:31:49 +0100 |
|---|---|---|
| committer | hmjsp <hmjsp@liber8bits.com> | 2026-10-09 13:31:49 +0100 |
| commit | f526d2a83e1b3db901f512381a13e00e91e00075 (patch) | |
| tree | e98945d4e3a6db5b4f134389b377ec316272decd | |
| parent | 4b6845618b972153cef5b8c776dd7b018775e444 (diff) | |
| download | chronologgy-f526d2a83e1b3db901f512381a13e00e91e00075.zip | |
| -rwxr-xr-x | display.py | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -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")) |
