-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks_completed.py
More file actions
94 lines (75 loc) · 2.15 KB
/
tasks_completed.py
File metadata and controls
94 lines (75 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""RTM tasks completed this year."""
# by Dr. Torben Menke https://entorb.net
# https://github.com/entorb/rememberthemilk
import datetime as dt
from typing import TYPE_CHECKING
from helper import (
DATE_TODAY,
OUTPUT_DIR,
df_name_url_to_html,
df_to_html,
get_lists_dict,
get_tasks_as_df,
)
if TYPE_CHECKING:
import pandas as pd
DATE_START = DATE_TODAY - dt.timedelta(days=365)
FILTER_COMPLETED = f"""
CompletedAfter:{DATE_START.strftime("%d/%m/%Y")}
AND NOT list:Taschengeld"""
FILE_EXPORT = OUTPUT_DIR / "tasks_completed.csv"
def get_tasks_completed() -> pd.DataFrame: # noqa: D103
lists_dict = get_lists_dict()
df = get_tasks_as_df(
my_filter=FILTER_COMPLETED,
lists_dict=lists_dict,
)
df = df.sort_values(
by=["completed", "completed_time", "prio", "name"],
ascending=[False, False, False, True],
)
df = df.reset_index()
cols = [
"name",
"list",
"completed",
"completed_time",
"completed_week",
# "due",
"overdue",
"prio",
"overdue_prio",
"postponed",
"estimate",
"url",
]
df = df[cols]
return df
def completed_week(df: pd.DataFrame) -> pd.DataFrame: # noqa: D103
df = (
df.groupby(["completed_week", "list"])
.agg(
count=("completed_week", "count"),
sum_prio=("prio", "sum"),
sum_overdue_prio=("overdue_prio", "sum"),
sum_estimate=("estimate", "sum"),
)
.sort_values(by=["completed_week", "list"], ascending=[False, True])
)
return df
if __name__ == "__main__":
df = get_tasks_completed()
df["name"] = df["name"].str.replace("\t", " ")
df.sort_values(["completed", "completed_time", "name"]).to_csv(
FILE_EXPORT, index=False, sep="\t", lineterminator="\n"
)
print("# RTM tasks completed this year")
df = df_name_url_to_html(df)
df_to_html(
df,
"out-completed.html",
)
# df.to_excel(output_dir/"out-done-year.xlsx", index=False)
df2 = completed_week(df)
print(df2)
df_to_html(df2, "out-completed-week.html", index=True)