Skip to content

Commit

Permalink
Added Streamlit
Browse files Browse the repository at this point in the history
  • Loading branch information
entorb committed Dec 14, 2024
1 parent 5d7d782 commit 842dcf2
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .streamlit/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[browser]
gatherUsageStats = false

[server]
port = 8501
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,23 @@ store these info in [rememberthemilk.ini](src/rememberthemilk.ini) (see [remembe
pip install -r requirements.txt
```

optionally:
#### Dev Tools

optionally: ruff and pre-commit

```sh
pip install ruff pre-commit
```

optionally: pytest coverage report

```sh
pip install pytest-cov
pytest --cov
# or
pytest --cov --cov-report=html:coverage_report
```

### Obtain API token

run [auth.py](src/auth.py) once and add the resulting `token` to [rememberthemilk.ini](src/rememberthemilk.ini)
Expand All @@ -51,6 +62,16 @@ run [auth.py](src/auth.py) once and add the resulting `token` to [rememberthemil
* ranked by product of overdue days x priority, to focus on most urgent ones
* display time estimation in minutes to motivate you for solving the minor ones right away

## Streamlit for interactive data analysis

```sh
pip install streamlit watchdog
```

```sh
streamlit run src/app.py
```

## My RTM lifehacks

see original post at <https://www.rememberthemilk.com/forums/tips/31034/>
Expand Down
4 changes: 4 additions & 0 deletions cspell-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
abcbazfegbaryxzfoo
astype
autouse
DataFrame
frob
lifehacks
Menke
noqa
prio
pytest
rememberthemilk
rrule
selectbox
Streamlit
Taschengeld
taskseries
todos
Expand Down
10 changes: 10 additions & 0 deletions src/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Streamlit UI."""

import streamlit as st

from helper import delete_cache

st.set_page_config(page_title="RTM Report", page_icon=None, layout="wide")
st.title("RTM")

delete_cache()
5 changes: 5 additions & 0 deletions src/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
#


def delete_cache() -> None: # noqa: D103
for file_path in CACHE_DIR.glob("*.json"): # pragma: no cover
file_path.unlink()


def dict_to_url_param(d: dict[str, str]) -> str:
"""
Convert a dictionary of parameter to url parameter string.
Expand Down
39 changes: 39 additions & 0 deletions src/pages/Completed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Completed Tasks.""" # noqa: INP001

import altair as alt
import streamlit as st

from tasks_completed import completed_week, get_tasks_completed

st.set_page_config(page_title="RTM Completed", page_icon=None, layout="wide")
st.title("Completed")

df = get_tasks_completed()
st.dataframe(
df,
hide_index=True,
column_config={"url": st.column_config.LinkColumn("url", display_text="url")},
)

st.header("per Week")
df = completed_week(df)
df = df.reset_index()

sel_param = st.selectbox(
label="Parameter",
options=("count", "sum_prio", "sum_overdue_prio", "sum_estimate"),
)

df["completed_week"] = df["completed_week"].astype(str)
chart = (
alt.Chart(df)
.mark_bar()
.encode(
x=alt.X("completed_week:N", title=None),
y=alt.Y(f"{sel_param}:Q", title=None),
color="list:N",
)
)
st.altair_chart(chart, use_container_width=True)

st.dataframe(df, hide_index=True)
43 changes: 43 additions & 0 deletions src/pages/Overdue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Completed Tasks.""" # noqa: INP001

import altair as alt
import streamlit as st

from tasks_overdue import get_tasks_overdue, group_by_list

st.set_page_config(page_title="RTM Overdue", page_icon=None, layout="wide")
st.title("Overdue")

df = get_tasks_overdue().sort_values(by=["overdue"], ascending=[True])
lists = sorted(set(df["list"].to_list()))

sel_list = st.selectbox(label="List", index=None, options=lists)

st.dataframe(
df.query(f"list == '{sel_list}'") if sel_list else df,
hide_index=True,
column_config={"url": st.column_config.LinkColumn("url", display_text="url")},
)

st.header("by List")
df = group_by_list(df)
df = df.reset_index()


sel_list = st.selectbox(
label="Parameter",
options=("count", "sum_prio", "sum_overdue_prio", "sum_estimate"),
)

chart = (
alt.Chart(df)
.mark_bar()
.encode(
x=alt.X("list:N", title=None),
y=alt.Y(f"{sel_list}:Q", title=None),
color="list:N",
)
)
st.altair_chart(chart, use_container_width=True)

st.dataframe(df, hide_index=True)
43 changes: 31 additions & 12 deletions src/tasks_completed.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import datetime as dt

from pandas import DataFrame

from helper import (
DATE_TODAY,
df_name_url_to_html,
Expand All @@ -20,11 +22,8 @@
AND NOT list:Taschengeld"""


if __name__ == "__main__":
def get_tasks_completed() -> DataFrame: # noqa: D103
lists_dict = get_lists_dict()

print("# RTM tasks completed this year")

df = get_tasks_as_df(
my_filter=FILTER_COMPLETED,
lists_dict=lists_dict,
Expand All @@ -34,7 +33,6 @@
)
df = df.reset_index()

df = df_name_url_to_html(df)
cols = [
"name",
"list",
Expand All @@ -46,20 +44,41 @@
"overdue_prio",
"postponed",
"estimate",
"url",
]
df = df[cols]

return df


def completed_week(df: DataFrame) -> 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()

print("# RTM tasks completed this year")

df = df_name_url_to_html(df)

df_to_html(
df[cols],
df,
"out-completed.html",
)
# df.to_excel(output_dir/"out-done-year.xlsx", index=False)

df2 = df.groupby(["completed_week", "list"]).agg(
count=("completed_week", "count"),
sum_prio=("prio", "sum"),
sum_overdue_prio=("overdue_prio", "sum"),
sum_estimate=("estimate", "sum"),
)
df2 = completed_week(df)
print(df2)

df_to_html(df2, "out-completed-week.html", index=True)
33 changes: 28 additions & 5 deletions src/tasks_overdue.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
by Dr. Torben Menke https://entorb.net
"""

from pandas import DataFrame

from helper import (
df_name_url_to_html,
df_to_html,
Expand All @@ -18,9 +20,8 @@
"""


if __name__ == "__main__":
def get_tasks_overdue() -> DataFrame: # noqa: D103
lists_dict = get_lists_dict()
print("# RTM tasks overdue")

df = get_tasks_as_df(
my_filter=FILTER_OVERDUE,
Expand All @@ -29,12 +30,34 @@
df = df.sort_values(by=["overdue_prio"], ascending=False)
df = df.reset_index()

cols = ["name", "list", "due", "overdue", "prio", "overdue_prio", "estimate"]
cols = ["name", "list", "due", "overdue", "prio", "overdue_prio", "estimate", "url"]
df = df[cols]

return df


def group_by_list(df: DataFrame) -> DataFrame: # noqa: D103
df = (
df.groupby(["list"])
.agg(
count=("list", "count"),
sum_prio=("prio", "sum"),
sum_overdue_prio=("overdue_prio", "sum"),
sum_estimate=("estimate", "sum"),
)
.sort_values(by=["list"], ascending=[True])
)
return df


if __name__ == "__main__":
print("# RTM tasks overdue")
df = get_tasks_overdue()

print(df[cols])
print(df)

df = df_name_url_to_html(df)
df_to_html(
df[cols],
df,
"out-overdue.html",
)

0 comments on commit 842dcf2

Please sign in to comment.