From 55cbdb63ba2ca2d54fffac72193cc287d4f85476 Mon Sep 17 00:00:00 2001 From: Anton Roslund Date: Sun, 20 Apr 2025 22:19:07 +0200 Subject: [PATCH] Add channel-utilization-stats --- src/stats.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/stats.js b/src/stats.js index 6c123bf..5c76d94 100644 --- a/src/stats.js +++ b/src/stats.js @@ -184,5 +184,22 @@ router.get('/battery-stats', async (req, res) => { } }); +router.get('/channel-utilization-stats', async (req, res) => { + const days = parseInt(req.query.days || '1', 10); + + try { + const stats = await prisma.$queryRaw` + SELECT recorded_at, avg_channel_utilization + FROM channel_utilization_stats + WHERE recorded_at >= NOW() - INTERVAL ${days} DAY + ORDER BY recorded_at DESC; + `; + + res.json(stats); + } catch (err) { + console.error('Error fetching channel utilization stats:', err); + res.status(500).json({ error: 'Internal server error' }); + } +}); module.exports = router; \ No newline at end of file