diff --git a/backend/routes/stats.js b/backend/routes/stats.js index a727991..2cfe320 100644 --- a/backend/routes/stats.js +++ b/backend/routes/stats.js @@ -423,6 +423,7 @@ router.get("/getViewsOverTime", async (req, res) => { stats.forEach((item) => { const library = item.Library; const count = item.Count; + const watchTime = item.TotalTime; const date = new Date(item.Date).toLocaleDateString("en-US", { year: "numeric", month: "short", @@ -435,7 +436,7 @@ router.get("/getViewsOverTime", async (req, res) => { }; } - reorganizedData[date] = { ...reorganizedData[date], [library]: count }; + reorganizedData[date] = { ...reorganizedData[date], [library]: { count, watchTime } }; }); const finalData = { libraries: libraries, stats: Object.values(reorganizedData) }; res.send(finalData); diff --git a/public/locales/en-UK/translation.json b/public/locales/en-UK/translation.json index bd048d4..2d38e64 100644 --- a/public/locales/en-UK/translation.json +++ b/public/locales/en-UK/translation.json @@ -167,7 +167,9 @@ "STAT_PAGE": { "STATISTICS": "Statistics", "DAILY_PLAY_PER_LIBRARY": "Daily Play Count Per Library", + "DAILY_TIME_PER_LIBRARY": "Daily Watch Time Per Library", "PLAY_COUNT_BY": "Play Count By", + "PLAY_TIME_BY": "Play Time By", "COUNT_VIEW": "Total Count", "TIME_VIEW": "Total Time" }, diff --git a/src/pages/components/statistics/chart.jsx b/src/pages/components/statistics/chart.jsx index 7204f0b..1ba9762 100644 --- a/src/pages/components/statistics/chart.jsx +++ b/src/pages/components/statistics/chart.jsx @@ -1,6 +1,6 @@ import { ResponsiveContainer, AreaChart, Area, XAxis, YAxis, Tooltip, Legend } from "recharts"; -function Chart({ stats, libraries }) { +function Chart({ stats, libraries, viewName }) { const colors = [ "rgb(54, 162, 235)", // blue "rgb(255, 99, 132)", // pink @@ -24,13 +24,25 @@ function Chart({ stats, libraries }) { "rgb(147, 112, 219)", // medium purple ]; + const flattenedStats = stats.map(item => { + const flatItem = { Key: item.Key }; + for (const [libraryName, data] of Object.entries(item)) { + if (libraryName === "Key") continue; + flatItem[libraryName] = data[viewName] ?? 0; + } + return flatItem; + }); + const CustomTooltip = ({ payload, label, active }) => { if (active) { return (
{label}
{libraries.map((library, index) => ( -{`${library.Name} : ${payload[index].value} Views`}
+ //{`${library.Name} : ${payload[index].value} Views`}
++ {`${library.Name} : ${payload?.find(p => p.dataKey === library.Name).value} ${viewName === "count" ? "Views" : "Minutes"}`} +
))}