From 36936cbc7e79e4eef2f2e49432eeb31e4198e5bd Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Tue, 20 Oct 2020 21:53:57 +0200 Subject: Quick and dirty participation statistics --- admin/index.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'admin/index.js') diff --git a/admin/index.js b/admin/index.js index 407bbcf..99c876a 100644 --- a/admin/index.js +++ b/admin/index.js @@ -52,4 +52,11 @@ app.get("/api/votes", checkAdmin, async (req, res) => { res.json(votes); }); +app.get("/api/participation", checkAdmin, async (req, res) => { + const participation = await db.query( + "SELECT c.name, CAST(COUNT(DISTINCT user_id) AS float) / CAST((SELECT COUNT(*) FROM users WHERE class_id = u.class_id) AS float) * 100 percentage FROM motto_votes INNER JOIN users u ON user_id = u.id INNER JOIN class c ON class_id = c.id GROUP BY class_id", + ); + res.json(participation); +}); + module.exports = app; -- cgit v1.2.3