feat(dashboard): add recharts data visualizations
- Install recharts - Add WatchActivityChart (AreaChart, movies + episodes/month, year filter) - Add WatchTimeChart (stacked BarChart, hours/month, synced year filter) - Add RatingsChart (BarChart, user ratings distribution 1–10, color ramp) - Add TopGenresChart (horizontal BarChart, top 10 genres, type filter) - Add CouchDayChart (BarChart, watch count by weekday, peak day highlight) - Add GET /statistics/watch-weekday backend endpoint (DAYOFWEEK aggregation) - Extend statisticsApi with getYearlyWatchCount, getYearlyWatchTime, getWatchdayDistribution - Add useYearlyWatchCount, useYearlyWatchTime, useWatchdayDistribution hooks - Wire all charts into DashboardPage with responsive two-column grid layout
This commit is contained in:
1 parent
3648c41cfd
commit
ae67663623
12 files changed
+1216
-2
No files matched your search
@@ -120,6 +120,32 @@ class StatisticsController {
|
||||
}
|
||||
}
|
||||
|
||||
async getWatchdayDistribution(req, res) {
|
||||
try {
|
||||
// DAYOFWEEK: 1=Sunday, 2=Monday ... 7=Saturday
|
||||
const episodeDays = await EpisodeSeen.findAll({
|
||||
attributes: [
|
||||
[sequelize.fn('DAYOFWEEK', sequelize.col('date_seen')), 'day'],
|
||||
[sequelize.fn('COUNT', sequelize.col('*')), 'count']
|
||||
],
|
||||
group: [sequelize.fn('DAYOFWEEK', sequelize.col('date_seen'))]
|
||||
});
|
||||
|
||||
const movieDays = await EntrySeen.findAll({
|
||||
attributes: [
|
||||
[sequelize.fn('DAYOFWEEK', sequelize.col('date_seen')), 'day'],
|
||||
[sequelize.fn('COUNT', sequelize.col('*')), 'count']
|
||||
],
|
||||
group: [sequelize.fn('DAYOFWEEK', sequelize.col('date_seen'))]
|
||||
});
|
||||
|
||||
res.status(200).json({ episodes: episodeDays, movies: movieDays });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = new StatisticsController();
|
||||
@@ -13,4 +13,7 @@ statisticsRouter.get('/watch-time/year/:year', statisticsController.getYearlyWat
|
||||
// * GET - Yearly Watch Count Grouped By Month
|
||||
statisticsRouter.get('/watch-count/year/:year', statisticsController.getYearlyWatchCountGroupByMonth);
|
||||
|
||||
// * GET - Watch Day Distribution (DAYOFWEEK)
|
||||
statisticsRouter.get('/watch-weekday', statisticsController.getWatchdayDistribution);
|
||||
|
||||
module.exports = statisticsRouter;
|
||||
Generated
+374
@@ -22,6 +22,7 @@
|
||||
"react-dom": "^19.2.4",
|
||||
"react-hook-form": "^7.72.0",
|
||||
"react-router-dom": "^7.13.2",
|
||||
"recharts": "^3.8.1",
|
||||
"shadcn": "^4.1.1",
|
||||
"tailwind-merge": "^3.5.0",
|
||||
"tw-animate-css": "^1.4.0",
|
||||
@@ -1311,6 +1312,42 @@
|
||||
"url": "https://github.com/sponsors/Boshen"
|
||||
}
|
||||
},
|
||||
"node_modules/@reduxjs/toolkit": {
|
||||
"version": "2.11.2",
|
||||
"resolved": "https://registry.npmjs.org/@reduxjs/toolkit/-/toolkit-2.11.2.tgz",
|
||||
"integrity": "sha512-Kd6kAHTA6/nUpp8mySPqj3en3dm0tdMIgbttnQ1xFMVpufoj+ADi8pXLBsd4xzTRHQa7t/Jv8W5UnCuW4kuWMQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@standard-schema/spec": "^1.0.0",
|
||||
"@standard-schema/utils": "^0.3.0",
|
||||
"immer": "^11.0.0",
|
||||
"redux": "^5.0.1",
|
||||
"redux-thunk": "^3.1.0",
|
||||
"reselect": "^5.1.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.9.0 || ^17.0.0 || ^18 || ^19",
|
||||
"react-redux": "^7.2.1 || ^8.1.3 || ^9.0.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"react": {
|
||||
"optional": true
|
||||
},
|
||||
"react-redux": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@reduxjs/toolkit/node_modules/immer": {
|
||||
"version": "11.1.4",
|
||||
"resolved": "https://registry.npmjs.org/immer/-/immer-11.1.4.tgz",
|
||||
"integrity": "sha512-XREFCPo6ksxVzP4E0ekD5aMdf8WMwmdNaz6vuvxgI40UaEiu6q3p8X52aU6GdyvLY3XXX/8R7JOTXStz/nBbRw==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/immer"
|
||||
}
|
||||
},
|
||||
"node_modules/@rolldown/binding-android-arm64": {
|
||||
"version": "1.0.0-rc.12",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm64/-/binding-android-arm64-1.0.0-rc.12.tgz",
|
||||
@@ -1591,6 +1628,12 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/@standard-schema/spec": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.1.0.tgz",
|
||||
"integrity": "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@standard-schema/utils": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@standard-schema/utils/-/utils-0.3.0.tgz",
|
||||
@@ -2026,6 +2069,69 @@
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/d3-array": {
|
||||
"version": "3.2.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/d3-array/-/d3-array-3.2.2.tgz",
|
||||
"integrity": "sha512-hOLWVbm7uRza0BYXpIIW5pxfrKe0W+D5lrFiAEYR+pb6w3N2SwSMaJbXdUfSEv+dT4MfHBLtn5js0LAWaO6otw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/d3-color": {
|
||||
"version": "3.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/d3-color/-/d3-color-3.1.3.tgz",
|
||||
"integrity": "sha512-iO90scth9WAbmgv7ogoq57O9YpKmFBbmoEoCHDB2xMBY0+/KVrqAaCDyCE16dUspeOvIxFFRI+0sEtqDqy2b4A==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/d3-ease": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/d3-ease/-/d3-ease-3.0.2.tgz",
|
||||
"integrity": "sha512-NcV1JjO5oDzoK26oMzbILE6HW7uVXOHLQvHshBUW4UMdZGfiY6v5BeQwh9a9tCzv+CeefZQHJt5SRgK154RtiA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/d3-interpolate": {
|
||||
"version": "3.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/d3-interpolate/-/d3-interpolate-3.0.4.tgz",
|
||||
"integrity": "sha512-mgLPETlrpVV1YRJIglr4Ez47g7Yxjl1lj7YKsiMCb27VJH9W8NVM6Bb9d8kkpG/uAQS5AmbA48q2IAolKKo1MA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/d3-color": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/d3-path": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/d3-path/-/d3-path-3.1.1.tgz",
|
||||
"integrity": "sha512-VMZBYyQvbGmWyWVea0EHs/BwLgxc+MKi1zLDCONksozI4YJMcTt8ZEuIR4Sb1MMTE8MMW49v0IwI5+b7RmfWlg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/d3-scale": {
|
||||
"version": "4.0.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/d3-scale/-/d3-scale-4.0.9.tgz",
|
||||
"integrity": "sha512-dLmtwB8zkAeO/juAMfnV+sItKjlsw2lKdZVVy6LRr0cBmegxSABiLEpGVmSJJ8O08i4+sGR6qQtb6WtuwJdvVw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/d3-time": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/d3-shape": {
|
||||
"version": "3.1.8",
|
||||
"resolved": "https://registry.npmjs.org/@types/d3-shape/-/d3-shape-3.1.8.tgz",
|
||||
"integrity": "sha512-lae0iWfcDeR7qt7rA88BNiqdvPS5pFVPpo5OfjElwNaT2yyekbM0C9vK+yqBqEmHr6lDkRnYNoTBYlAgJa7a4w==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/d3-path": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/d3-time": {
|
||||
"version": "3.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/d3-time/-/d3-time-3.0.4.tgz",
|
||||
"integrity": "sha512-yuzZug1nkAAaBlBBikKZTgzCeA+k1uy4ZFwWANOfKw5z5LRhV0gNA7gNkKm7HoK+HRN0wX3EkxGk0fpbWhmB7g==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/d3-timer": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/d3-timer/-/d3-timer-3.0.2.tgz",
|
||||
"integrity": "sha512-Ps3T8E8dZDam6fUyNiMkekK3XUsaUEik+idO9/YjPtfj2qruF8tFBXS7XhtE4iIXBLxhmLjP3SXpLhVf21I9Lw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/estree": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz",
|
||||
@@ -2078,6 +2184,12 @@
|
||||
"integrity": "sha512-xMAgYwceFhRA2zY+XbEA7mxYbA093wdiW8Vu6gZPGWy9cmOyU9XesH1tNcEWsKFd5Vzrqx5T3D38PWx1FIIXkA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/use-sync-external-store": {
|
||||
"version": "0.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@types/use-sync-external-store/-/use-sync-external-store-0.0.6.tgz",
|
||||
"integrity": "sha512-zFDAD+tlpf2r4asuHEj0XH6pY6i0g5NeAHPn+15wk3BV6JA69eERFXC1gyGThDkVa1zCyKr5jox1+2LbV/AMLg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/validate-npm-package-name": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/validate-npm-package-name/-/validate-npm-package-name-4.0.2.tgz",
|
||||
@@ -3101,6 +3213,127 @@
|
||||
"devOptional": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/d3-array": {
|
||||
"version": "3.2.4",
|
||||
"resolved": "https://registry.npmjs.org/d3-array/-/d3-array-3.2.4.tgz",
|
||||
"integrity": "sha512-tdQAmyA18i4J7wprpYq8ClcxZy3SC31QMeByyCFyRt7BVHdREQZ5lpzoe5mFEYZUWe+oq8HBvk9JjpibyEV4Jg==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"internmap": "1 - 2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/d3-color": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/d3-color/-/d3-color-3.1.0.tgz",
|
||||
"integrity": "sha512-zg/chbXyeBtMQ1LbD/WSoW2DpC3I0mpmPdW+ynRTj/x2DAWYrIY7qeZIHidozwV24m4iavr15lNwIwLxRmOxhA==",
|
||||
"license": "ISC",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/d3-ease": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/d3-ease/-/d3-ease-3.0.1.tgz",
|
||||
"integrity": "sha512-wR/XK3D3XcLIZwpbvQwQ5fK+8Ykds1ip7A2Txe0yxncXSdq1L9skcG7blcedkOX+ZcgxGAmLX1FrRGbADwzi0w==",
|
||||
"license": "BSD-3-Clause",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/d3-format": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/d3-format/-/d3-format-3.1.2.tgz",
|
||||
"integrity": "sha512-AJDdYOdnyRDV5b6ArilzCPPwc1ejkHcoyFarqlPqT7zRYjhavcT3uSrqcMvsgh2CgoPbK3RCwyHaVyxYcP2Arg==",
|
||||
"license": "ISC",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/d3-interpolate": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/d3-interpolate/-/d3-interpolate-3.0.1.tgz",
|
||||
"integrity": "sha512-3bYs1rOD33uo8aqJfKP3JWPAibgw8Zm2+L9vBKEHJ2Rg+viTR7o5Mmv5mZcieN+FRYaAOWX5SJATX6k1PWz72g==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"d3-color": "1 - 3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/d3-path": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/d3-path/-/d3-path-3.1.0.tgz",
|
||||
"integrity": "sha512-p3KP5HCf/bvjBSSKuXid6Zqijx7wIfNW+J/maPs+iwR35at5JCbLUT0LzF1cnjbCHWhqzQTIN2Jpe8pRebIEFQ==",
|
||||
"license": "ISC",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/d3-scale": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/d3-scale/-/d3-scale-4.0.2.tgz",
|
||||
"integrity": "sha512-GZW464g1SH7ag3Y7hXjf8RoUuAFIqklOAq3MRl4OaWabTFJY9PN/E1YklhXLh+OQ3fM9yS2nOkCoS+WLZ6kvxQ==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"d3-array": "2.10.0 - 3",
|
||||
"d3-format": "1 - 3",
|
||||
"d3-interpolate": "1.2.0 - 3",
|
||||
"d3-time": "2.1.1 - 3",
|
||||
"d3-time-format": "2 - 4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/d3-shape": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmjs.org/d3-shape/-/d3-shape-3.2.0.tgz",
|
||||
"integrity": "sha512-SaLBuwGm3MOViRq2ABk3eLoxwZELpH6zhl3FbAoJ7Vm1gofKx6El1Ib5z23NUEhF9AsGl7y+dzLe5Cw2AArGTA==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"d3-path": "^3.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/d3-time": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/d3-time/-/d3-time-3.1.0.tgz",
|
||||
"integrity": "sha512-VqKjzBLejbSMT4IgbmVgDjpkYrNWUYJnbCGo874u7MMKIWsILRX+OpX/gTk8MqjpT1A/c6HY2dCA77ZN0lkQ2Q==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"d3-array": "2 - 3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/d3-time-format": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/d3-time-format/-/d3-time-format-4.1.0.tgz",
|
||||
"integrity": "sha512-dJxPBlzC7NugB2PDLwo9Q8JiTR3M3e4/XANkreKSUxF8vvXKqm1Yfq4Q5dl8budlunRVlUUaDUgFt7eA8D6NLg==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"d3-time": "1 - 3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/d3-timer": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/d3-timer/-/d3-timer-3.0.1.tgz",
|
||||
"integrity": "sha512-ndfJ/JxxMd3nw31uyKoY2naivF+r29V+Lc0svZxe1JvvIRmi8hUsrMvdOwgS1o6uBHmiz91geQ0ylPP0aj1VUA==",
|
||||
"license": "ISC",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/data-uri-to-buffer": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz",
|
||||
@@ -3143,6 +3376,12 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/decimal.js-light": {
|
||||
"version": "2.5.1",
|
||||
"resolved": "https://registry.npmjs.org/decimal.js-light/-/decimal.js-light-2.5.1.tgz",
|
||||
"integrity": "sha512-qIMFpTMZmny+MMIitAB6D7iVPEorVw6YQRWkvarTkT4tBeSLLiHzcwj6q0MmYSFCiVpiqPJTJEYIrpcPzVEIvg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/dedent": {
|
||||
"version": "1.7.2",
|
||||
"resolved": "https://registry.npmjs.org/dedent/-/dedent-1.7.2.tgz",
|
||||
@@ -3397,6 +3636,16 @@
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/es-toolkit": {
|
||||
"version": "1.45.1",
|
||||
"resolved": "https://registry.npmjs.org/es-toolkit/-/es-toolkit-1.45.1.tgz",
|
||||
"integrity": "sha512-/jhoOj/Fx+A+IIyDNOvO3TItGmlMKhtX8ISAHKE90c4b/k1tqaqEZ+uUqfpU8DMnW5cgNJv606zS55jGvza0Xw==",
|
||||
"license": "MIT",
|
||||
"workspaces": [
|
||||
"docs",
|
||||
"benchmarks"
|
||||
]
|
||||
},
|
||||
"node_modules/escalade": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz",
|
||||
@@ -3632,6 +3881,12 @@
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/eventemitter3": {
|
||||
"version": "5.0.4",
|
||||
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.4.tgz",
|
||||
"integrity": "sha512-mlsTRyGaPBjPedk6Bvw+aqbsXDtoAyAzm5MO7JgU+yVRyMQ5O8bD4Kcci7BS85f93veegeCPkL8R4GLClnjLFw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/eventsource": {
|
||||
"version": "3.0.7",
|
||||
"resolved": "https://registry.npmjs.org/eventsource/-/eventsource-3.0.7.tgz",
|
||||
@@ -4393,6 +4648,17 @@
|
||||
"node": ">= 4"
|
||||
}
|
||||
},
|
||||
"node_modules/immer": {
|
||||
"version": "10.2.0",
|
||||
"resolved": "https://registry.npmjs.org/immer/-/immer-10.2.0.tgz",
|
||||
"integrity": "sha512-d/+XTN3zfODyjr89gM3mPq1WNX2B8pYsu7eORitdwyA2sBubnTl3laYlBk4sXY5FUa5qTZGBDPJICVbvqzjlbw==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/immer"
|
||||
}
|
||||
},
|
||||
"node_modules/import-fresh": {
|
||||
"version": "3.3.1",
|
||||
"resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.1.tgz",
|
||||
@@ -4425,6 +4691,15 @@
|
||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/internmap": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/internmap/-/internmap-2.0.3.tgz",
|
||||
"integrity": "sha512-5Hh7Y1wQbvY5ooGgPbDaL5iYLAPzMTUrjMulskHLH6wnv/A+1q5rgEaiuqEjB+oxGXIVZs1FF+R/KPN3ZSQYYg==",
|
||||
"license": "ISC",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/ip-address": {
|
||||
"version": "10.1.0",
|
||||
"resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.1.0.tgz",
|
||||
@@ -5973,6 +6248,37 @@
|
||||
"react": "^16.8.0 || ^17 || ^18 || ^19"
|
||||
}
|
||||
},
|
||||
"node_modules/react-is": {
|
||||
"version": "19.2.4",
|
||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-19.2.4.tgz",
|
||||
"integrity": "sha512-W+EWGn2v0ApPKgKKCy/7s7WHXkboGcsrXE+2joLyVxkbyVQfO3MUEaUQDHoSmb8TFFrSKYa9mw64WZHNHSDzYA==",
|
||||
"license": "MIT",
|
||||
"peer": true
|
||||
},
|
||||
"node_modules/react-redux": {
|
||||
"version": "9.2.0",
|
||||
"resolved": "https://registry.npmjs.org/react-redux/-/react-redux-9.2.0.tgz",
|
||||
"integrity": "sha512-ROY9fvHhwOD9ySfrF0wmvu//bKCQ6AeZZq1nJNtbDC+kk5DuSuNX/n6YWYF/SYy7bSba4D4FSz8DJeKY/S/r+g==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@types/use-sync-external-store": "^0.0.6",
|
||||
"use-sync-external-store": "^1.4.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@types/react": "^18.2.25 || ^19",
|
||||
"react": "^18.0 || ^19",
|
||||
"redux": "^5.0.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@types/react": {
|
||||
"optional": true
|
||||
},
|
||||
"redux": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/react-router": {
|
||||
"version": "7.13.2",
|
||||
"resolved": "https://registry.npmjs.org/react-router/-/react-router-7.13.2.tgz",
|
||||
@@ -6027,6 +6333,52 @@
|
||||
"node": ">= 4"
|
||||
}
|
||||
},
|
||||
"node_modules/recharts": {
|
||||
"version": "3.8.1",
|
||||
"resolved": "https://registry.npmjs.org/recharts/-/recharts-3.8.1.tgz",
|
||||
"integrity": "sha512-mwzmO1s9sFL0TduUpwndxCUNoXsBw3u3E/0+A+cLcrSfQitSG62L32N69GhqUrrT5qKcAE3pCGVINC6pqkBBQg==",
|
||||
"license": "MIT",
|
||||
"workspaces": [
|
||||
"www"
|
||||
],
|
||||
"dependencies": {
|
||||
"@reduxjs/toolkit": "^1.9.0 || 2.x.x",
|
||||
"clsx": "^2.1.1",
|
||||
"decimal.js-light": "^2.5.1",
|
||||
"es-toolkit": "^1.39.3",
|
||||
"eventemitter3": "^5.0.1",
|
||||
"immer": "^10.1.1",
|
||||
"react-redux": "8.x.x || 9.x.x",
|
||||
"reselect": "5.1.1",
|
||||
"tiny-invariant": "^1.3.3",
|
||||
"use-sync-external-store": "^1.2.2",
|
||||
"victory-vendor": "^37.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
||||
"react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
||||
"react-is": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/redux": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/redux/-/redux-5.0.1.tgz",
|
||||
"integrity": "sha512-M9/ELqF6fy8FwmkpnF0S3YKOqMyoWJ4+CS5Efg2ct3oY9daQvd/Pc71FpGZsVsbl3Cpb+IIcjBDUnnyBdQbq4w==",
|
||||
"license": "MIT",
|
||||
"peer": true
|
||||
},
|
||||
"node_modules/redux-thunk": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/redux-thunk/-/redux-thunk-3.1.0.tgz",
|
||||
"integrity": "sha512-NW2r5T6ksUKXCabzhL9z+h206HQw/NJkcLm1GPImRQ8IzfXwRGqjVhKJGauHirT0DAuyy6hjdnMZaRoAcy0Klw==",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"redux": "^5.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/require-directory": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
|
||||
@@ -7003,6 +7355,28 @@
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/victory-vendor": {
|
||||
"version": "37.3.6",
|
||||
"resolved": "https://registry.npmjs.org/victory-vendor/-/victory-vendor-37.3.6.tgz",
|
||||
"integrity": "sha512-SbPDPdDBYp+5MJHhBCAyI7wKM3d5ivekigc2Dk2s7pgbZ9wIgIBYGVw4zGHBml/qTFbexrofXW6Gu4noGxrOwQ==",
|
||||
"license": "MIT AND ISC",
|
||||
"dependencies": {
|
||||
"@types/d3-array": "^3.0.3",
|
||||
"@types/d3-ease": "^3.0.0",
|
||||
"@types/d3-interpolate": "^3.0.1",
|
||||
"@types/d3-scale": "^4.0.2",
|
||||
"@types/d3-shape": "^3.1.0",
|
||||
"@types/d3-time": "^3.0.0",
|
||||
"@types/d3-timer": "^3.0.0",
|
||||
"d3-array": "^3.1.6",
|
||||
"d3-ease": "^3.0.1",
|
||||
"d3-interpolate": "^3.0.1",
|
||||
"d3-scale": "^4.0.2",
|
||||
"d3-shape": "^3.1.0",
|
||||
"d3-time": "^3.0.0",
|
||||
"d3-timer": "^3.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/vite": {
|
||||
"version": "8.0.3",
|
||||
"resolved": "https://registry.npmjs.org/vite/-/vite-8.0.3.tgz",
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
"react-dom": "^19.2.4",
|
||||
"react-hook-form": "^7.72.0",
|
||||
"react-router-dom": "^7.13.2",
|
||||
"recharts": "^3.8.1",
|
||||
"shadcn": "^4.1.1",
|
||||
"tailwind-merge": "^3.5.0",
|
||||
"tw-animate-css": "^1.4.0",
|
||||
|
||||
@@ -1,5 +1,41 @@
|
||||
import { api } from '@/lib/api';
|
||||
|
||||
export interface MonthlyCountItem {
|
||||
month: number;
|
||||
count: string;
|
||||
}
|
||||
|
||||
export interface MonthlyWatchTimeItem {
|
||||
month: number;
|
||||
watchTime: string;
|
||||
}
|
||||
|
||||
export interface YearlyWatchCount {
|
||||
series: MonthlyCountItem[];
|
||||
movies: MonthlyCountItem[];
|
||||
}
|
||||
|
||||
export interface YearlyWatchTime {
|
||||
series: MonthlyWatchTimeItem[];
|
||||
movies: MonthlyWatchTimeItem[];
|
||||
}
|
||||
|
||||
export interface WatchdayItem {
|
||||
day: number; // 1=Sun, 2=Mon ... 7=Sat
|
||||
count: string;
|
||||
}
|
||||
|
||||
export interface WatchdayDistribution {
|
||||
episodes: WatchdayItem[];
|
||||
movies: WatchdayItem[];
|
||||
}
|
||||
|
||||
export const statisticsApi = {
|
||||
get: () => api.get('/statistics').then((r) => r.data),
|
||||
getYearlyWatchCount: (year: number) =>
|
||||
api.get<YearlyWatchCount>(`/statistics/watch-count/year/${year}`).then((r) => r.data),
|
||||
getYearlyWatchTime: (year: number) =>
|
||||
api.get<YearlyWatchTime>(`/statistics/watch-time/year/${year}`).then((r) => r.data),
|
||||
getWatchdayDistribution: () =>
|
||||
api.get<WatchdayDistribution>('/statistics/watch-weekday').then((r) => r.data),
|
||||
};
|
||||
@@ -0,0 +1,133 @@
|
||||
import { useMemo } from 'react';
|
||||
import {
|
||||
BarChart,
|
||||
Bar,
|
||||
XAxis,
|
||||
YAxis,
|
||||
CartesianGrid,
|
||||
Tooltip,
|
||||
Cell,
|
||||
ResponsiveContainer,
|
||||
} from 'recharts';
|
||||
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { useWatchdayDistribution } from '@/hooks/useStatistics';
|
||||
import type { WatchdayItem } from '@/api/statistics';
|
||||
|
||||
// DAYOFWEEK: MySQL returns 1=Sun, 2=Mon, 3=Tue, 4=Wed, 5=Thu, 6=Fri, 7=Sat
|
||||
// We display Mon–Sun
|
||||
const DAY_ORDER = [2, 3, 4, 5, 6, 7, 1];
|
||||
const DAY_LABELS: Record<number, string> = {
|
||||
1: 'Sun',
|
||||
2: 'Mon',
|
||||
3: 'Tue',
|
||||
4: 'Wed',
|
||||
5: 'Thu',
|
||||
6: 'Fri',
|
||||
7: 'Sat',
|
||||
};
|
||||
|
||||
function buildChartData(episodes: WatchdayItem[], movies: WatchdayItem[]) {
|
||||
return DAY_ORDER.map((dayNum) => {
|
||||
const ep = episodes.find((x) => Number(x.day) === dayNum);
|
||||
const mv = movies.find((x) => Number(x.day) === dayNum);
|
||||
const total = (ep ? parseInt(ep.count, 10) : 0) + (mv ? parseInt(mv.count, 10) : 0);
|
||||
return { day: DAY_LABELS[dayNum], total, dayNum };
|
||||
});
|
||||
}
|
||||
|
||||
interface CustomTooltipProps {
|
||||
active?: boolean;
|
||||
payload?: { value: number; payload: { day: string; total: number } }[];
|
||||
}
|
||||
|
||||
function CustomTooltip({ active, payload }: CustomTooltipProps) {
|
||||
if (!active || !payload?.length) return null;
|
||||
const { day, total } = payload[0].payload;
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
backgroundColor: 'var(--color-card)',
|
||||
border: '1px solid var(--color-border)',
|
||||
borderRadius: '8px',
|
||||
padding: '8px 12px',
|
||||
fontSize: '13px',
|
||||
color: 'var(--color-card-foreground)',
|
||||
}}
|
||||
>
|
||||
<p style={{ fontWeight: 600 }}>{day}</p>
|
||||
<p style={{ color: 'var(--color-muted-foreground)' }}>{total} {total === 1 ? 'watch' : 'watches'}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function CouchDayChart() {
|
||||
const { data, isLoading } = useWatchdayDistribution();
|
||||
|
||||
const chartData = useMemo(() => {
|
||||
if (!data) return [];
|
||||
return buildChartData(data.episodes, data.movies);
|
||||
}, [data]);
|
||||
|
||||
const peakDay = useMemo(() => {
|
||||
if (!chartData.length) return null;
|
||||
return chartData.reduce((max, d) => (d.total > max.total ? d : max), chartData[0]);
|
||||
}, [chartData]);
|
||||
|
||||
const maxTotal = Math.max(...chartData.map((d) => d.total), 1);
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div className="flex flex-col gap-1">
|
||||
<CardTitle>Your Couch Day</CardTitle>
|
||||
<CardDescription>
|
||||
Which day of the week do you watch most?
|
||||
{peakDay && peakDay.total > 0 && (
|
||||
<span className="ml-1 text-foreground font-medium">
|
||||
Looks like {peakDay.day}.
|
||||
</span>
|
||||
)}
|
||||
</CardDescription>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{isLoading ? (
|
||||
<Skeleton className="h-52 w-full" />
|
||||
) : (
|
||||
<ResponsiveContainer width="100%" height={210}>
|
||||
<BarChart data={chartData} margin={{ top: 4, right: 8, left: -20, bottom: 0 }}>
|
||||
<CartesianGrid strokeDasharray="3 3" stroke="var(--color-border)" vertical={false} />
|
||||
<XAxis
|
||||
dataKey="day"
|
||||
tick={{ fontSize: 12, fill: 'var(--color-muted-foreground)' }}
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
/>
|
||||
<YAxis
|
||||
allowDecimals={false}
|
||||
tick={{ fontSize: 12, fill: 'var(--color-muted-foreground)' }}
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
/>
|
||||
<Tooltip content={<CustomTooltip />} cursor={{ fill: 'var(--color-accent)' }} />
|
||||
<Bar dataKey="total" radius={[4, 4, 0, 0]}>
|
||||
{chartData.map((entry) => (
|
||||
<Cell
|
||||
key={entry.day}
|
||||
fill={
|
||||
entry.total === maxTotal && entry.total > 0
|
||||
? 'var(--color-chart-4)'
|
||||
: 'var(--color-chart-1)'
|
||||
}
|
||||
opacity={entry.total === 0 ? 0.3 : 1}
|
||||
/>
|
||||
))}
|
||||
</Bar>
|
||||
</BarChart>
|
||||
</ResponsiveContainer>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
import { useMemo, useState } from 'react';
|
||||
import {
|
||||
BarChart,
|
||||
Bar,
|
||||
XAxis,
|
||||
YAxis,
|
||||
CartesianGrid,
|
||||
Tooltip,
|
||||
Cell,
|
||||
ResponsiveContainer,
|
||||
} from 'recharts';
|
||||
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card';
|
||||
import { useLibraryEntries } from '@/stores/useLibraryStore';
|
||||
import type { Entry } from '@/types';
|
||||
|
||||
type Filter = 'all' | 'movies' | 'series';
|
||||
|
||||
function buildRatingsData(entries: Entry[]) {
|
||||
const counts: Record<number, number> = {};
|
||||
for (let i = 1; i <= 10; i++) counts[i] = 0;
|
||||
|
||||
for (const entry of entries) {
|
||||
const rating = entry.entryRatings?.user_rating;
|
||||
if (rating != null) {
|
||||
const key = Math.round(rating);
|
||||
if (key >= 1 && key <= 10) counts[key]++;
|
||||
}
|
||||
}
|
||||
|
||||
return Object.entries(counts).map(([score, count]) => ({
|
||||
score: `${score}★`,
|
||||
count,
|
||||
raw: Number(score),
|
||||
}));
|
||||
}
|
||||
|
||||
// Color ramp: low scores red-ish → mid yellow-ish → high scores green/blue
|
||||
const SCORE_COLORS: Record<number, string> = {
|
||||
1: 'var(--color-chart-5)',
|
||||
2: 'var(--color-chart-5)',
|
||||
3: 'var(--color-chart-5)',
|
||||
4: 'var(--color-chart-3)',
|
||||
5: 'var(--color-chart-3)',
|
||||
6: 'var(--color-chart-3)',
|
||||
7: 'var(--color-chart-2)',
|
||||
8: 'var(--color-chart-2)',
|
||||
9: 'var(--color-chart-1)',
|
||||
10: 'var(--color-chart-1)',
|
||||
};
|
||||
|
||||
interface CustomTooltipProps {
|
||||
active?: boolean;
|
||||
payload?: { value: number; payload: { score: string; count: number } }[];
|
||||
}
|
||||
|
||||
function CustomTooltip({ active, payload }: CustomTooltipProps) {
|
||||
if (!active || !payload?.length) return null;
|
||||
const { score, count } = payload[0].payload;
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
backgroundColor: 'var(--color-card)',
|
||||
border: '1px solid var(--color-border)',
|
||||
borderRadius: '8px',
|
||||
padding: '8px 12px',
|
||||
fontSize: '13px',
|
||||
color: 'var(--color-card-foreground)',
|
||||
}}
|
||||
>
|
||||
<p style={{ fontWeight: 600 }}>{score}</p>
|
||||
<p style={{ color: 'var(--color-muted-foreground)' }}>{count} {count === 1 ? 'title' : 'titles'}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function RatingsChart() {
|
||||
const allEntries = useLibraryEntries();
|
||||
const [filter, setFilter] = useState<Filter>('all');
|
||||
|
||||
const filteredEntries = useMemo(() => {
|
||||
const library = allEntries.filter((e) => !e.watchlist);
|
||||
if (filter === 'movies') return library.filter((e) => !e.is_tvseries);
|
||||
if (filter === 'series') return library.filter((e) => e.is_tvseries);
|
||||
return library;
|
||||
}, [allEntries, filter]);
|
||||
|
||||
const chartData = useMemo(() => buildRatingsData(filteredEntries), [filteredEntries]);
|
||||
|
||||
const ratedCount = filteredEntries.filter(
|
||||
(e) => e.entryRatings?.user_rating != null,
|
||||
).length;
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div className="flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between">
|
||||
<div>
|
||||
<CardTitle>My Ratings</CardTitle>
|
||||
<CardDescription className="mt-1">
|
||||
{ratedCount} rated {filter === 'all' ? 'titles' : filter === 'movies' ? 'movies' : 'series'}
|
||||
</CardDescription>
|
||||
</div>
|
||||
<div className="flex rounded-md border border-border overflow-hidden text-xs self-start">
|
||||
{(['all', 'movies', 'series'] as Filter[]).map((f) => (
|
||||
<button
|
||||
key={f}
|
||||
onClick={() => setFilter(f)}
|
||||
className={`px-3 py-1.5 capitalize transition-colors ${
|
||||
filter === f
|
||||
? 'bg-primary text-primary-foreground'
|
||||
: 'text-muted-foreground hover:bg-accent'
|
||||
}`}
|
||||
>
|
||||
{f}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<ResponsiveContainer width="100%" height={220}>
|
||||
<BarChart data={chartData} margin={{ top: 4, right: 8, left: -20, bottom: 0 }}>
|
||||
<CartesianGrid strokeDasharray="3 3" stroke="var(--color-border)" vertical={false} />
|
||||
<XAxis
|
||||
dataKey="score"
|
||||
tick={{ fontSize: 12, fill: 'var(--color-muted-foreground)' }}
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
/>
|
||||
<YAxis
|
||||
allowDecimals={false}
|
||||
tick={{ fontSize: 12, fill: 'var(--color-muted-foreground)' }}
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
/>
|
||||
<Tooltip content={<CustomTooltip />} cursor={{ fill: 'var(--color-accent)' }} />
|
||||
<Bar dataKey="count" radius={[4, 4, 0, 0]}>
|
||||
{chartData.map((entry) => (
|
||||
<Cell
|
||||
key={entry.raw}
|
||||
fill={SCORE_COLORS[entry.raw] ?? 'var(--color-chart-1)'}
|
||||
/>
|
||||
))}
|
||||
</Bar>
|
||||
</BarChart>
|
||||
</ResponsiveContainer>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
import { useMemo, useState } from 'react';
|
||||
import {
|
||||
BarChart,
|
||||
Bar,
|
||||
XAxis,
|
||||
YAxis,
|
||||
CartesianGrid,
|
||||
Tooltip,
|
||||
Cell,
|
||||
ResponsiveContainer,
|
||||
} from 'recharts';
|
||||
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card';
|
||||
import { useLibraryEntries } from '@/stores/useLibraryStore';
|
||||
import type { Entry } from '@/types';
|
||||
|
||||
type Filter = 'all' | 'movies' | 'series';
|
||||
|
||||
const TOP_N = 10;
|
||||
|
||||
// Cycle through chart color vars for variety
|
||||
const COLORS = [
|
||||
'var(--color-chart-1)',
|
||||
'var(--color-chart-2)',
|
||||
'var(--color-chart-3)',
|
||||
'var(--color-chart-4)',
|
||||
'var(--color-chart-5)',
|
||||
];
|
||||
|
||||
function buildGenreData(entries: Entry[]) {
|
||||
const counts: Record<string, number> = {};
|
||||
for (const entry of entries) {
|
||||
if (!entry.genres) continue;
|
||||
for (const genre of entry.genres as unknown as string[]) {
|
||||
counts[genre] = (counts[genre] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
return Object.entries(counts)
|
||||
.sort((a, b) => b[1] - a[1])
|
||||
.slice(0, TOP_N)
|
||||
.map(([genre, count]) => ({ genre, count }));
|
||||
}
|
||||
|
||||
interface CustomTooltipProps {
|
||||
active?: boolean;
|
||||
payload?: { value: number; payload: { genre: string; count: number } }[];
|
||||
}
|
||||
|
||||
function CustomTooltip({ active, payload }: CustomTooltipProps) {
|
||||
if (!active || !payload?.length) return null;
|
||||
const { genre, count } = payload[0].payload;
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
backgroundColor: 'var(--color-card)',
|
||||
border: '1px solid var(--color-border)',
|
||||
borderRadius: '8px',
|
||||
padding: '8px 12px',
|
||||
fontSize: '13px',
|
||||
color: 'var(--color-card-foreground)',
|
||||
}}
|
||||
>
|
||||
<p style={{ fontWeight: 600 }}>{genre}</p>
|
||||
<p style={{ color: 'var(--color-muted-foreground)' }}>{count} {count === 1 ? 'title' : 'titles'}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function TopGenresChart() {
|
||||
const allEntries = useLibraryEntries();
|
||||
const [filter, setFilter] = useState<Filter>('all');
|
||||
|
||||
const filteredEntries = useMemo(() => {
|
||||
const library = allEntries.filter((e) => !e.watchlist);
|
||||
if (filter === 'movies') return library.filter((e) => !e.is_tvseries);
|
||||
if (filter === 'series') return library.filter((e) => e.is_tvseries);
|
||||
return library;
|
||||
}, [allEntries, filter]);
|
||||
|
||||
const chartData = useMemo(() => buildGenreData(filteredEntries), [filteredEntries]);
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div className="flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between">
|
||||
<div>
|
||||
<CardTitle>Top Genres</CardTitle>
|
||||
<CardDescription className="mt-1">
|
||||
Most watched genres in your library
|
||||
</CardDescription>
|
||||
</div>
|
||||
<div className="flex rounded-md border border-border overflow-hidden text-xs self-start">
|
||||
{(['all', 'movies', 'series'] as Filter[]).map((f) => (
|
||||
<button
|
||||
key={f}
|
||||
onClick={() => setFilter(f)}
|
||||
className={`px-3 py-1.5 capitalize transition-colors ${
|
||||
filter === f
|
||||
? 'bg-primary text-primary-foreground'
|
||||
: 'text-muted-foreground hover:bg-accent'
|
||||
}`}
|
||||
>
|
||||
{f}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<ResponsiveContainer width="100%" height={Math.max(chartData.length * 36, 180)}>
|
||||
<BarChart
|
||||
layout="vertical"
|
||||
data={chartData}
|
||||
margin={{ top: 4, right: 24, left: 0, bottom: 0 }}
|
||||
>
|
||||
<CartesianGrid strokeDasharray="3 3" stroke="var(--color-border)" horizontal={false} />
|
||||
<XAxis
|
||||
type="number"
|
||||
allowDecimals={false}
|
||||
tick={{ fontSize: 12, fill: 'var(--color-muted-foreground)' }}
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
/>
|
||||
<YAxis
|
||||
type="category"
|
||||
dataKey="genre"
|
||||
width={90}
|
||||
tick={{ fontSize: 12, fill: 'var(--color-foreground)' }}
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
/>
|
||||
<Tooltip content={<CustomTooltip />} cursor={{ fill: 'var(--color-accent)' }} />
|
||||
<Bar dataKey="count" radius={[0, 4, 4, 0]}>
|
||||
{chartData.map((_, i) => (
|
||||
<Cell key={i} fill={COLORS[i % COLORS.length]} />
|
||||
))}
|
||||
</Bar>
|
||||
</BarChart>
|
||||
</ResponsiveContainer>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
import { useState, useMemo } from 'react';
|
||||
import {
|
||||
AreaChart,
|
||||
Area,
|
||||
XAxis,
|
||||
YAxis,
|
||||
CartesianGrid,
|
||||
Tooltip,
|
||||
Legend,
|
||||
ResponsiveContainer,
|
||||
} from 'recharts';
|
||||
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { useYearlyWatchCount } from '@/hooks/useStatistics';
|
||||
|
||||
const MONTH_LABELS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||
|
||||
type Filter = 'all' | 'movies' | 'episodes';
|
||||
|
||||
function buildChartData(
|
||||
series: { month: number; count: string }[],
|
||||
movies: { month: number; count: string }[],
|
||||
) {
|
||||
return MONTH_LABELS.map((label, i) => {
|
||||
const monthNum = i + 1;
|
||||
const s = series.find((x) => Number(x.month) === monthNum);
|
||||
const m = movies.find((x) => Number(x.month) === monthNum);
|
||||
return {
|
||||
month: label,
|
||||
Episodes: s ? parseInt(s.count, 10) : 0,
|
||||
Movies: m ? parseInt(m.count, 10) : 0,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export function WatchActivityChart() {
|
||||
const currentYear = new Date().getFullYear();
|
||||
const [year, setYear] = useState(currentYear);
|
||||
const [filter, setFilter] = useState<Filter>('all');
|
||||
|
||||
const { data, isLoading } = useYearlyWatchCount(year);
|
||||
|
||||
const chartData = useMemo(() => {
|
||||
if (!data) return [];
|
||||
return buildChartData(data.series, data.movies);
|
||||
}, [data]);
|
||||
|
||||
const years = Array.from({ length: 5 }, (_, i) => currentYear - i);
|
||||
|
||||
const showMovies = filter === 'all' || filter === 'movies';
|
||||
const showEpisodes = filter === 'all' || filter === 'episodes';
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div className="flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between">
|
||||
<div>
|
||||
<CardTitle>Watch Activity</CardTitle>
|
||||
<CardDescription className="mt-1">
|
||||
Movies and episodes watched per month
|
||||
</CardDescription>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
{/* Filter tabs */}
|
||||
<div className="flex rounded-md border border-border overflow-hidden text-xs">
|
||||
{(['all', 'movies', 'episodes'] as Filter[]).map((f) => (
|
||||
<button
|
||||
key={f}
|
||||
onClick={() => setFilter(f)}
|
||||
className={`px-3 py-1.5 capitalize transition-colors ${
|
||||
filter === f
|
||||
? 'bg-primary text-primary-foreground'
|
||||
: 'text-muted-foreground hover:bg-accent'
|
||||
}`}
|
||||
>
|
||||
{f}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{/* Year selector */}
|
||||
<select
|
||||
value={year}
|
||||
onChange={(e) => setYear(Number(e.target.value))}
|
||||
className="rounded-md border border-border bg-card text-foreground text-xs px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-ring"
|
||||
>
|
||||
{years.map((y) => (
|
||||
<option key={y} value={y}>{y}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{isLoading ? (
|
||||
<Skeleton className="h-64 w-full" />
|
||||
) : (
|
||||
<ResponsiveContainer width="100%" height={260}>
|
||||
<AreaChart data={chartData} margin={{ top: 4, right: 8, left: -16, bottom: 0 }}>
|
||||
<defs>
|
||||
<linearGradient id="colorMovies" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="5%" stopColor="var(--color-chart-1)" stopOpacity={0.3} />
|
||||
<stop offset="95%" stopColor="var(--color-chart-1)" stopOpacity={0} />
|
||||
</linearGradient>
|
||||
<linearGradient id="colorEpisodes" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="5%" stopColor="var(--color-chart-2)" stopOpacity={0.3} />
|
||||
<stop offset="95%" stopColor="var(--color-chart-2)" stopOpacity={0} />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<CartesianGrid strokeDasharray="3 3" stroke="var(--color-border)" />
|
||||
<XAxis
|
||||
dataKey="month"
|
||||
tick={{ fontSize: 12, fill: 'var(--color-muted-foreground)' }}
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
/>
|
||||
<YAxis
|
||||
allowDecimals={false}
|
||||
tick={{ fontSize: 12, fill: 'var(--color-muted-foreground)' }}
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
/>
|
||||
<Tooltip
|
||||
contentStyle={{
|
||||
backgroundColor: 'var(--color-card)',
|
||||
border: '1px solid var(--color-border)',
|
||||
borderRadius: '8px',
|
||||
fontSize: '13px',
|
||||
color: 'var(--color-card-foreground)',
|
||||
}}
|
||||
cursor={{ stroke: 'var(--color-border)', strokeWidth: 1 }}
|
||||
/>
|
||||
<Legend
|
||||
formatter={(value) => (
|
||||
<span style={{ fontSize: 12, color: 'var(--color-muted-foreground)' }}>{value}</span>
|
||||
)}
|
||||
/>
|
||||
{showMovies && (
|
||||
<Area
|
||||
type="monotone"
|
||||
dataKey="Movies"
|
||||
stroke="var(--color-chart-1)"
|
||||
strokeWidth={2}
|
||||
fill="url(#colorMovies)"
|
||||
dot={false}
|
||||
activeDot={{ r: 4, strokeWidth: 0, fill: 'var(--color-chart-1)' }}
|
||||
/>
|
||||
)}
|
||||
{showEpisodes && (
|
||||
<Area
|
||||
type="monotone"
|
||||
dataKey="Episodes"
|
||||
stroke="var(--color-chart-2)"
|
||||
strokeWidth={2}
|
||||
fill="url(#colorEpisodes)"
|
||||
dot={false}
|
||||
activeDot={{ r: 4, strokeWidth: 0, fill: 'var(--color-chart-2)' }}
|
||||
/>
|
||||
)}
|
||||
</AreaChart>
|
||||
</ResponsiveContainer>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
import { useMemo } from 'react';
|
||||
import {
|
||||
BarChart,
|
||||
Bar,
|
||||
XAxis,
|
||||
YAxis,
|
||||
CartesianGrid,
|
||||
Tooltip,
|
||||
Legend,
|
||||
ResponsiveContainer,
|
||||
} from 'recharts';
|
||||
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { useYearlyWatchTime } from '@/hooks/useStatistics';
|
||||
|
||||
const MONTH_LABELS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||
|
||||
function minutesToHours(minutes: number) {
|
||||
return Math.round((minutes / 60) * 10) / 10;
|
||||
}
|
||||
|
||||
function buildChartData(
|
||||
series: { month: number; watchTime: string }[],
|
||||
movies: { month: number; watchTime: string }[],
|
||||
) {
|
||||
return MONTH_LABELS.map((label, i) => {
|
||||
const monthNum = i + 1;
|
||||
const s = series.find((x) => Number(x.month) === monthNum);
|
||||
const m = movies.find((x) => Number(x.month) === monthNum);
|
||||
return {
|
||||
month: label,
|
||||
'TV Series': s ? minutesToHours(parseInt(s.watchTime, 10)) : 0,
|
||||
Movies: m ? minutesToHours(parseInt(m.watchTime, 10)) : 0,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
interface CustomTooltipProps {
|
||||
active?: boolean;
|
||||
payload?: { name: string; value: number; color: string }[];
|
||||
label?: string;
|
||||
}
|
||||
|
||||
function CustomTooltip({ active, payload, label }: CustomTooltipProps) {
|
||||
if (!active || !payload?.length) return null;
|
||||
const total = payload.reduce((sum, p) => sum + p.value, 0);
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
backgroundColor: 'var(--color-card)',
|
||||
border: '1px solid var(--color-border)',
|
||||
borderRadius: '8px',
|
||||
padding: '10px 14px',
|
||||
fontSize: '13px',
|
||||
color: 'var(--color-card-foreground)',
|
||||
}}
|
||||
>
|
||||
<p style={{ fontWeight: 600, marginBottom: 6 }}>{label}</p>
|
||||
{payload.map((p) => (
|
||||
<p key={p.name} style={{ color: p.color }}>
|
||||
{p.name}: {p.value}h
|
||||
</p>
|
||||
))}
|
||||
{payload.length > 1 && (
|
||||
<p style={{ color: 'var(--color-muted-foreground)', marginTop: 4, borderTop: '1px solid var(--color-border)', paddingTop: 4 }}>
|
||||
Total: {total}h
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function WatchTimeChart({ year, onYearChange }: { year: number; onYearChange: (y: number) => void }) {
|
||||
const currentYear = new Date().getFullYear();
|
||||
const { data, isLoading } = useYearlyWatchTime(year);
|
||||
|
||||
const chartData = useMemo(() => {
|
||||
if (!data) return [];
|
||||
return buildChartData(data.series, data.movies);
|
||||
}, [data]);
|
||||
|
||||
const years = Array.from({ length: 5 }, (_, i) => currentYear - i);
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div className="flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between">
|
||||
<div>
|
||||
<CardTitle>Hours Watched</CardTitle>
|
||||
<CardDescription className="mt-1">
|
||||
Total watch time per month, split by movies and TV series
|
||||
</CardDescription>
|
||||
</div>
|
||||
<select
|
||||
value={year}
|
||||
onChange={(e) => onYearChange(Number(e.target.value))}
|
||||
className="rounded-md border border-border bg-card text-foreground text-xs px-2 py-1.5 self-start focus:outline-none focus:ring-1 focus:ring-ring"
|
||||
>
|
||||
{years.map((y) => (
|
||||
<option key={y} value={y}>{y}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{isLoading ? (
|
||||
<Skeleton className="h-56 w-full" />
|
||||
) : (
|
||||
<ResponsiveContainer width="100%" height={220}>
|
||||
<BarChart data={chartData} margin={{ top: 4, right: 8, left: -16, bottom: 0 }}>
|
||||
<CartesianGrid strokeDasharray="3 3" stroke="var(--color-border)" vertical={false} />
|
||||
<XAxis
|
||||
dataKey="month"
|
||||
tick={{ fontSize: 12, fill: 'var(--color-muted-foreground)' }}
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
/>
|
||||
<YAxis
|
||||
unit="h"
|
||||
tick={{ fontSize: 12, fill: 'var(--color-muted-foreground)' }}
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
/>
|
||||
<Tooltip content={<CustomTooltip />} cursor={{ fill: 'var(--color-accent)' }} />
|
||||
<Legend
|
||||
formatter={(value) => (
|
||||
<span style={{ fontSize: 12, color: 'var(--color-muted-foreground)' }}>{value}</span>
|
||||
)}
|
||||
/>
|
||||
<Bar
|
||||
dataKey="Movies"
|
||||
stackId="a"
|
||||
fill="var(--color-chart-1)"
|
||||
radius={[0, 0, 0, 0]}
|
||||
/>
|
||||
<Bar
|
||||
dataKey="TV Series"
|
||||
stackId="a"
|
||||
fill="var(--color-chart-2)"
|
||||
radius={[4, 4, 0, 0]}
|
||||
/>
|
||||
</BarChart>
|
||||
</ResponsiveContainer>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -7,3 +7,24 @@ export function useStatistics() {
|
||||
queryFn: statisticsApi.get,
|
||||
});
|
||||
}
|
||||
|
||||
export function useYearlyWatchCount(year: number) {
|
||||
return useQuery({
|
||||
queryKey: ['statistics', 'watch-count', year],
|
||||
queryFn: () => statisticsApi.getYearlyWatchCount(year),
|
||||
});
|
||||
}
|
||||
|
||||
export function useYearlyWatchTime(year: number) {
|
||||
return useQuery({
|
||||
queryKey: ['statistics', 'watch-time', year],
|
||||
queryFn: () => statisticsApi.getYearlyWatchTime(year),
|
||||
});
|
||||
}
|
||||
|
||||
export function useWatchdayDistribution() {
|
||||
return useQuery({
|
||||
queryKey: ['statistics', 'watch-weekday'],
|
||||
queryFn: statisticsApi.getWatchdayDistribution,
|
||||
});
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useMemo, useState } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { useLibrary } from '@/hooks/useEntries';
|
||||
import { useStatistics } from '@/hooks/useStatistics';
|
||||
@@ -7,11 +7,17 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { Film, Tv, Heart, ListVideo, Clock } from 'lucide-react';
|
||||
import { formatRuntime, getPosterUrl } from '@/lib/media-utils';
|
||||
import { WatchActivityChart } from '@/components/dashboard/WatchActivityChart';
|
||||
import { WatchTimeChart } from '@/components/dashboard/WatchTimeChart';
|
||||
import { RatingsChart } from '@/components/dashboard/RatingsChart';
|
||||
import { TopGenresChart } from '@/components/dashboard/TopGenresChart';
|
||||
import { CouchDayChart } from '@/components/dashboard/CouchDayChart';
|
||||
|
||||
export function DashboardPage() {
|
||||
useLibrary();
|
||||
const { data: stats, isLoading: statsLoading } = useStatistics();
|
||||
const allEntries = useLibraryEntries();
|
||||
const [watchYear, setWatchYear] = useState(new Date().getFullYear());
|
||||
|
||||
const movies = useMemo(() => allEntries.filter((e) => !e.is_tvseries && !e.watchlist), [allEntries]);
|
||||
const tvSeries = useMemo(() => allEntries.filter((e) => e.is_tvseries && !e.watchlist), [allEntries]);
|
||||
@@ -78,6 +84,15 @@ export function DashboardPage() {
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Charts */}
|
||||
<WatchActivityChart />
|
||||
<WatchTimeChart year={watchYear} onYearChange={setWatchYear} />
|
||||
<div className="grid gap-4 lg:grid-cols-2">
|
||||
<RatingsChart />
|
||||
<TopGenresChart />
|
||||
</div>
|
||||
<CouchDayChart />
|
||||
|
||||
{/* Recently Watched */}
|
||||
<div className="space-y-4">
|
||||
<h2 className="text-lg font-semibold">Recently Watched</h2>
|
||||
@@ -99,7 +114,7 @@ export function DashboardPage() {
|
||||
<img
|
||||
src={getPosterUrl(entry)}
|
||||
alt={entry.title}
|
||||
className="aspect-[2/3] w-full rounded-lg object-cover"
|
||||
className="aspect-2/3 w-full rounded-lg object-cover"
|
||||
loading="lazy"
|
||||
/>
|
||||
<p className="mt-1 text-xs font-medium truncate">
|
||||
|
||||
Reference in new issue
Block a user