diff --git a/frontend/src/pages/Stats.tsx b/frontend/src/pages/Stats.tsx
index b88c7da..fc910c6 100644
--- a/frontend/src/pages/Stats.tsx
+++ b/frontend/src/pages/Stats.tsx
@@ -28,17 +28,15 @@ const StatPage = () => {
useEffect(() => {
Promise.all([
- axios.get("http://localhost:5000/stats/events_per_day"),
- axios.get("http://localhost:5000/stats/heatmap"),
+ axios.get("http://localhost:5000/stats/time"),
axios.get("http://localhost:5000/stats/word_frequencies"),
])
- .then(([eventsRes, heatmapRes, wordsRes]) => {
- setPostsPerDay(
- eventsRes.data.filter(
- (d: any) => new Date(d.date) >= new Date("2026-01-10")
- )
- );
- setHeatmapData(heatmapRes.data);
+ .then(([timeRes, wordsRes]) => {
+ setPostsPerDay(timeRes.data["events_per_day"].filter(
+ (d: any) => new Date(d.date) >= new Date('2026-01-10')
+ ))
+ setHeatmapData(timeRes.data["weekday_hour_heatmap"])
+
setWordFrequencyData(
wordsRes.data.map((d: BackendWord) => ({
text: d.word,
@@ -76,8 +74,8 @@ const StatPage = () => {
diff --git a/frontend/src/stats/ActivityHeatmap.tsx b/frontend/src/stats/ActivityHeatmap.tsx
index 903174f..ddc1674 100644
--- a/frontend/src/stats/ActivityHeatmap.tsx
+++ b/frontend/src/stats/ActivityHeatmap.tsx
@@ -1,6 +1,6 @@
import { ResponsiveHeatMap } from "@nivo/heatmap";
-type ApiRow = Record;
+type ApiRow = Record;
type ActivityHeatmapProps = {
data: ApiRow[];
};
diff --git a/server/stat_gen.py b/server/stat_gen.py
index b9311e4..4e25b60 100644
--- a/server/stat_gen.py
+++ b/server/stat_gen.py
@@ -50,21 +50,27 @@ class StatGen:
"Thursday", "Friday", "Saturday", "Sunday"
]
+ self.df["weekday"] = pd.Categorical(
+ self.df["weekday"],
+ categories=weekday_order,
+ ordered=True
+ )
+
heatmap = (
self.df
- .assign(weekday=pd.Categorical(self.df["weekday"], weekday_order, ordered=True))
- .groupby(["weekday", "hour"])
+ .groupby(["weekday", "hour"], observed=True)
.size()
.unstack(fill_value=0)
.reindex(columns=range(24), fill_value=0)
)
+
heatmap.columns = heatmap.columns.map(str)
burst_index = per_day["count"].std() / max(per_day["count"].mean(), 1)
return {
"events_per_day": per_day.to_dict(orient="records"),
- "weekday_hour_heatmap": heatmap.reset_index().to_dict(orient="records"),
+ "weekday_hour_heatmap": heatmap.to_dict(orient="records"),
"burstiness": round(burst_index, 2)
}