Add weekday barplot

This commit is contained in:
Marty Oehme 2025-09-28 21:05:44 +02:00
parent 343b75c9e4
commit 07c45ca205
Signed by: Marty
GPG key ID: 4E535BC19C61886E

View file

@ -129,13 +129,15 @@ def _():
@app.cell @app.cell
def _(df: pl.DataFrame): def _(df: pl.DataFrame):
def _():
weekly_downloads = ( weekly_downloads = (
df.sort("date") df.sort("date")
.group_by_dynamic("date", every="1w") .group_by_dynamic("date", every="1w")
.agg(pl.col("downloads").sum()) .agg(pl.col("downloads").sum())
.sort("date") .sort("date")
) )
(
return (
lp.ggplot(weekly_downloads, lp.aes("date", "downloads")) lp.ggplot(weekly_downloads, lp.aes("date", "downloads"))
+ lp.geom_line() + lp.geom_line()
+ lp.geom_smooth(method="loess") + lp.geom_smooth(method="loess")
@ -143,6 +145,42 @@ def _(df: pl.DataFrame):
title="Weekly downloads", title="Weekly downloads",
) )
) )
_()
return
@app.cell
def _(df: pl.DataFrame):
def _():
weekday_downloads = df.sort("date").with_columns(
pl.col("date")
.dt.weekday()
.sort()
.replace_strict(
{
1: "Mon",
2: "Tue",
3: "Wed",
4: "Thu",
5: "Fri",
6: "Sat",
7: "Sun",
}
)
.alias("weekday")
)
return (
lp.ggplot(weekday_downloads, lp.aes("weekday", "downloads"))
+ lp.geom_bar()
+ lp.labs(
title="Weekday downloads",
caption="Downloads aggregated per day of the week they took place.",
)
)
_()
return return
@ -193,7 +231,6 @@ def _(sizes_df):
# further ideas: # further ideas:
# #
# - daily download habits: # - daily download habits:
# - which weekday has most downloads?
# - are we downloading further spread of versions on specific days # - are we downloading further spread of versions on specific days
# - are there 'update' days, where things converge? specific weekday/on holidays/etc? # - are there 'update' days, where things converge? specific weekday/on holidays/etc?
# #