fix: broken frontend displays after API changes

This commit is contained in:
2026-01-31 18:00:26 +00:00
parent 657bd37cdd
commit cb01de1f79
3 changed files with 19 additions and 15 deletions

View File

@@ -28,17 +28,15 @@ const StatPage = () => {
useEffect(() => { useEffect(() => {
Promise.all([ Promise.all([
axios.get("http://localhost:5000/stats/events_per_day"), axios.get("http://localhost:5000/stats/time"),
axios.get("http://localhost:5000/stats/heatmap"),
axios.get("http://localhost:5000/stats/word_frequencies"), axios.get("http://localhost:5000/stats/word_frequencies"),
]) ])
.then(([eventsRes, heatmapRes, wordsRes]) => { .then(([timeRes, wordsRes]) => {
setPostsPerDay( setPostsPerDay(timeRes.data["events_per_day"].filter(
eventsRes.data.filter( (d: any) => new Date(d.date) >= new Date('2026-01-10')
(d: any) => new Date(d.date) >= new Date("2026-01-10") ))
) setHeatmapData(timeRes.data["weekday_hour_heatmap"])
);
setHeatmapData(heatmapRes.data);
setWordFrequencyData( setWordFrequencyData(
wordsRes.data.map((d: BackendWord) => ({ wordsRes.data.map((d: BackendWord) => ({
text: d.word, text: d.word,
@@ -76,8 +74,8 @@ const StatPage = () => {
<Tooltip /> <Tooltip />
<Line <Line
type="monotone" type="monotone"
dataKey="posts_count" dataKey="count"
name="Posts" name="Events"
/> />
</LineChart> </LineChart>
</ResponsiveContainer> </ResponsiveContainer>

View File

@@ -1,6 +1,6 @@
import { ResponsiveHeatMap } from "@nivo/heatmap"; import { ResponsiveHeatMap } from "@nivo/heatmap";
type ApiRow = Record<string, number>; type ApiRow = Record<number, number>;
type ActivityHeatmapProps = { type ActivityHeatmapProps = {
data: ApiRow[]; data: ApiRow[];
}; };

View File

@@ -50,21 +50,27 @@ class StatGen:
"Thursday", "Friday", "Saturday", "Sunday" "Thursday", "Friday", "Saturday", "Sunday"
] ]
self.df["weekday"] = pd.Categorical(
self.df["weekday"],
categories=weekday_order,
ordered=True
)
heatmap = ( heatmap = (
self.df self.df
.assign(weekday=pd.Categorical(self.df["weekday"], weekday_order, ordered=True)) .groupby(["weekday", "hour"], observed=True)
.groupby(["weekday", "hour"])
.size() .size()
.unstack(fill_value=0) .unstack(fill_value=0)
.reindex(columns=range(24), fill_value=0) .reindex(columns=range(24), fill_value=0)
) )
heatmap.columns = heatmap.columns.map(str) heatmap.columns = heatmap.columns.map(str)
burst_index = per_day["count"].std() / max(per_day["count"].mean(), 1) burst_index = per_day["count"].std() / max(per_day["count"].mean(), 1)
return { return {
"events_per_day": per_day.to_dict(orient="records"), "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) "burstiness": round(burst_index, 2)
} }