diff --git a/popcorn.py b/popcorn.py index 2a1c68e..e1dd707 100644 --- a/popcorn.py +++ b/popcorn.py @@ -129,20 +129,58 @@ def _(): @app.cell def _(df: pl.DataFrame): - weekly_downloads = ( - df.sort("date") - .group_by_dynamic("date", every="1w") - .agg(pl.col("downloads").sum()) - .sort("date") - ) - ( - lp.ggplot(weekly_downloads, lp.aes("date", "downloads")) - + lp.geom_line() - + lp.geom_smooth(method="loess") - + lp.labs( - title="Weekly downloads", + def _(): + weekly_downloads = ( + df.sort("date") + .group_by_dynamic("date", every="1w") + .agg(pl.col("downloads").sum()) + .sort("date") ) - ) + + return ( + lp.ggplot(weekly_downloads, lp.aes("date", "downloads")) + + lp.geom_line() + + lp.geom_smooth(method="loess") + + lp.labs( + 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 @@ -193,7 +231,6 @@ def _(sizes_df): # further ideas: # # - daily download habits: -# - which weekday has most downloads? # - are we downloading further spread of versions on specific days # - are there 'update' days, where things converge? specific weekday/on holidays/etc? #