aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-09-06 09:16:59 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-09-06 09:16:59 +0200
commitd0f5249d68a184fa565540bc01e32f1b2433b77a (patch)
treefcee648965d5527f3fdf2f7152dd9132b3886a54
parent7b2d455e8d46069a1f2c6aa6cf4de7f8b1eac9e4 (diff)
add weekly time overview to time report script
-rw-r--r--time.txt1
-rwxr-xr-xtime2tex.py108
2 files changed, 92 insertions, 17 deletions
diff --git a/time.txt b/time.txt
index 3d01dd8..4ef1837 100644
--- a/time.txt
+++ b/time.txt
@@ -9,6 +9,7 @@ loek: 2024-09-04 20m repository scaffolding :: visual studio code cmake configur
loek: 2024-09-05 15m repository scaffolding :: additional latex contributing guidelines
loek: 2024-09-05 1h40m project meeting
loek: 2024-09-05 1h24m time report script
+loek: 2024-09-06 55m time report script
max: 2024-09-04 1h30m installing and configuring latex
max: 2024-09-04 2h reading project info
diff --git a/time2tex.py b/time2tex.py
index 6c8b097..1d0cd90 100755
--- a/time2tex.py
+++ b/time2tex.py
@@ -1,6 +1,6 @@
#!/bin/python3
import sys
-from datetime import datetime
+from datetime import datetime, timedelta
def fmt_duration(sec):
mins = (sec + 59) // 60 # integer divide, round up
@@ -18,7 +18,12 @@ def fmt_duration(sec):
return "\\,".join(out)
+def fmt_percentage(fac):
+ return f"{{\\footnotesize\\itshape({round(fac * 100)}\\%)}}"
+
def fmt_member_overview(times):
+ # calculations
+ out = ""
members = {}
total_time = 0
for time in times:
@@ -26,22 +31,84 @@ def fmt_member_overview(times):
members[time["name"]] = 0
members[time["name"]] += time["duration"]
total_time += time["duration"]
- print("""\\section{Member overview}\n
-\\begin{table}
-\\centering
-\\begin{tabular}{lr}
-\\toprule
-\\textbf{Member} & \\textbf{Tracked}\\\\
-\\midrule""")
+
+ # begin table
+ out += r"\begin{table}\centering"
+ out += r"\begin{tabular}{lr@{~}l}\toprule"
+ out += r"\textbf{Member} & \textbf{Tracked} &\\\midrule{}"
+
+ # member overview
for name, tracked in members.items():
- print(f"{name} & {fmt_duration(tracked)}\\\\")
- print("\\midrule")
- print(f"& sum\\quad {fmt_duration(total_time)}\\\\")
- print("""\\bottomrule
-\\end{tabular}
-\\caption{Tracked time per group member}
-\\label{tab:time-member}
-\\end{table}""")
+ out += f"{name} & {fmt_duration(tracked)} & {fmt_percentage(tracked / total_time)}\\\\"
+ out += r"\midrule{}"
+
+ # sum
+ out += f"&{fmt_duration(total_time)}&\\\\"
+
+ # end table
+ out += r"\bottomrule\end{tabular}"
+ out += r"\caption{Tracked time per group member}\label{tab:time-member}"
+ out += r"\end{table}"
+
+ return out
+
+def fmt_weekly_overview(times):
+ # calculations
+ out = ""
+ weeks = []
+ member_totals = {}
+ total_time = sum(time["duration"] for time in times)
+ members = list(set(time["name"] for time in times))
+ time_start = min(time["date"] for time in times)
+ time_end = max(time["date"] for time in times)
+ week_start = time_start - timedelta(days=time_start.weekday()) # round down to nearest monday
+ week_end = time_end + timedelta(days=7-time_end.weekday())
+
+ week = week_start
+ week_num = 1
+ while week < week_end:
+ week_times = [time for time in times if time["date"] >= week and time["date"] < (week + timedelta(days=7))]
+
+ week_entry = {
+ "num": week_num,
+ "members": {},
+ "total": sum(time["duration"] for time in week_times)
+ }
+
+ for member in members:
+ week_entry["members"][member] = sum(time["duration"] for time in week_times if time["name"] == member)
+
+ weeks.append(week_entry)
+ week_num += 1
+ week += timedelta(days=7)
+ for member in members:
+ member_totals[member] = sum(time["duration"] for time in times if time["name"] == member)
+
+ # begin table
+ out += r"\begin{table}\centering"
+ out += f"\\begin{{tabular}}{{l{'r@{~}l' * len(members)}@{{\\qquad}}r}}\\toprule"
+ out += r"\textbf{Week\#}"
+ for member in members:
+ out += f"&\\textbf{{{member}}}&"
+ out += r"&\textbf{Subtotal}\\\midrule{}"
+
+ for entry in weeks:
+ out += f"{entry['num']}"
+ for member in members:
+ out += f"&{fmt_duration(entry['members'][member])}&{fmt_percentage(entry['members'][member] / entry['total'])}"
+ out += f"&{fmt_duration(entry['total'])}\\\\"
+
+ out += r"\midrule{}"
+ for member in members:
+ out += f"&{fmt_duration(member_totals[member])}&{fmt_percentage(member_totals[member] / total_time)}"
+ out += f"&{fmt_duration(total_time)}\\\\"
+
+ # end table
+ out += r"\bottomrule\end{tabular}"
+ out += r"\caption{Tracked time per week}\label{tab:time-weekly}"
+ out += r"\end{table}"
+
+ return out
def duration2secs(duration):
out = 0 # output (seconds)
@@ -103,7 +170,14 @@ def parse(content):
return out
def fmt(times):
- fmt_member_overview(times)
+ # TODO: Task overview
+ print(f"""
+\\section{{Overviews}}\n
+\\subsection{{Members}}\n
+{fmt_member_overview(times)}
+\\subsection{{Weekly}}\n
+{fmt_weekly_overview(times)}
+""")
def main():
input_file = sys.argv[1]