diff --git a/backend/controllers/statisticsController.js b/backend/controllers/statisticsController.js index 6177842..6fe7af4 100644 --- a/backend/controllers/statisticsController.js +++ b/backend/controllers/statisticsController.js @@ -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(); diff --git a/backend/routes/statistics.routes.js b/backend/routes/statistics.routes.js index 49adbee..2f1e6fe 100644 --- a/backend/routes/statistics.routes.js +++ b/backend/routes/statistics.routes.js @@ -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; diff --git a/react_frontend/package-lock.json b/react_frontend/package-lock.json index cc75f64..6154dce 100644 --- a/react_frontend/package-lock.json +++ b/react_frontend/package-lock.json @@ -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", diff --git a/react_frontend/package.json b/react_frontend/package.json index 0e30948..a85e342 100644 --- a/react_frontend/package.json +++ b/react_frontend/package.json @@ -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", diff --git a/react_frontend/src/api/statistics.ts b/react_frontend/src/api/statistics.ts index c11af02..00c6505 100644 --- a/react_frontend/src/api/statistics.ts +++ b/react_frontend/src/api/statistics.ts @@ -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(`/statistics/watch-count/year/${year}`).then((r) => r.data), + getYearlyWatchTime: (year: number) => + api.get(`/statistics/watch-time/year/${year}`).then((r) => r.data), + getWatchdayDistribution: () => + api.get('/statistics/watch-weekday').then((r) => r.data), }; diff --git a/react_frontend/src/components/dashboard/CouchDayChart.tsx b/react_frontend/src/components/dashboard/CouchDayChart.tsx new file mode 100644 index 0000000..074a11a --- /dev/null +++ b/react_frontend/src/components/dashboard/CouchDayChart.tsx @@ -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 = { + 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 ( +
+

{day}

+

{total} {total === 1 ? 'watch' : 'watches'}

+
+ ); +} + +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 ( + + +
+ Your Couch Day + + Which day of the week do you watch most? + {peakDay && peakDay.total > 0 && ( + + Looks like {peakDay.day}. + + )} + +
+
+ + {isLoading ? ( + + ) : ( + + + + + + } cursor={{ fill: 'var(--color-accent)' }} /> + + {chartData.map((entry) => ( + 0 + ? 'var(--color-chart-4)' + : 'var(--color-chart-1)' + } + opacity={entry.total === 0 ? 0.3 : 1} + /> + ))} + + + + )} + +
+ ); +} diff --git a/react_frontend/src/components/dashboard/RatingsChart.tsx b/react_frontend/src/components/dashboard/RatingsChart.tsx new file mode 100644 index 0000000..e6844e9 --- /dev/null +++ b/react_frontend/src/components/dashboard/RatingsChart.tsx @@ -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 = {}; + 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 = { + 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 ( +
+

{score}

+

{count} {count === 1 ? 'title' : 'titles'}

+
+ ); +} + +export function RatingsChart() { + const allEntries = useLibraryEntries(); + const [filter, setFilter] = useState('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 ( + + +
+
+ My Ratings + + {ratedCount} rated {filter === 'all' ? 'titles' : filter === 'movies' ? 'movies' : 'series'} + +
+
+ {(['all', 'movies', 'series'] as Filter[]).map((f) => ( + + ))} +
+
+
+ + + + + + + } cursor={{ fill: 'var(--color-accent)' }} /> + + {chartData.map((entry) => ( + + ))} + + + + +
+ ); +} diff --git a/react_frontend/src/components/dashboard/TopGenresChart.tsx b/react_frontend/src/components/dashboard/TopGenresChart.tsx new file mode 100644 index 0000000..8eb4524 --- /dev/null +++ b/react_frontend/src/components/dashboard/TopGenresChart.tsx @@ -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 = {}; + 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 ( +
+

{genre}

+

{count} {count === 1 ? 'title' : 'titles'}

+
+ ); +} + +export function TopGenresChart() { + const allEntries = useLibraryEntries(); + const [filter, setFilter] = useState('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 ( + + +
+
+ Top Genres + + Most watched genres in your library + +
+
+ {(['all', 'movies', 'series'] as Filter[]).map((f) => ( + + ))} +
+
+
+ + + + + + + } cursor={{ fill: 'var(--color-accent)' }} /> + + {chartData.map((_, i) => ( + + ))} + + + + +
+ ); +} diff --git a/react_frontend/src/components/dashboard/WatchActivityChart.tsx b/react_frontend/src/components/dashboard/WatchActivityChart.tsx new file mode 100644 index 0000000..e79d5fb --- /dev/null +++ b/react_frontend/src/components/dashboard/WatchActivityChart.tsx @@ -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('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 ( + + +
+
+ Watch Activity + + Movies and episodes watched per month + +
+
+ {/* Filter tabs */} +
+ {(['all', 'movies', 'episodes'] as Filter[]).map((f) => ( + + ))} +
+ {/* Year selector */} + +
+
+
+ + {isLoading ? ( + + ) : ( + + + + + + + + + + + + + + + + + ( + {value} + )} + /> + {showMovies && ( + + )} + {showEpisodes && ( + + )} + + + )} + +
+ ); +} diff --git a/react_frontend/src/components/dashboard/WatchTimeChart.tsx b/react_frontend/src/components/dashboard/WatchTimeChart.tsx new file mode 100644 index 0000000..2cb0b1b --- /dev/null +++ b/react_frontend/src/components/dashboard/WatchTimeChart.tsx @@ -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 ( +
+

{label}

+ {payload.map((p) => ( +

+ {p.name}: {p.value}h +

+ ))} + {payload.length > 1 && ( +

+ Total: {total}h +

+ )} +
+ ); +} + +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 ( + + +
+
+ Hours Watched + + Total watch time per month, split by movies and TV series + +
+ +
+
+ + {isLoading ? ( + + ) : ( + + + + + + } cursor={{ fill: 'var(--color-accent)' }} /> + ( + {value} + )} + /> + + + + + )} + +
+ ); +} diff --git a/react_frontend/src/hooks/useStatistics.ts b/react_frontend/src/hooks/useStatistics.ts index 585f2c9..a7aa251 100644 --- a/react_frontend/src/hooks/useStatistics.ts +++ b/react_frontend/src/hooks/useStatistics.ts @@ -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, + }); +} diff --git a/react_frontend/src/pages/DashboardPage.tsx b/react_frontend/src/pages/DashboardPage.tsx index 5582733..e4af71f 100644 --- a/react_frontend/src/pages/DashboardPage.tsx +++ b/react_frontend/src/pages/DashboardPage.tsx @@ -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() { ))} + {/* Charts */} + + +
+ + +
+ + {/* Recently Watched */}

Recently Watched

@@ -99,7 +114,7 @@ export function DashboardPage() { {entry.title}