From fd36e1b0a25405abcc90f0957b843b2fb32420e8 Mon Sep 17 00:00:00 2001 From: Anton Roslund Date: Sun, 30 Mar 2025 16:17:51 +0200 Subject: [PATCH] Add position-precision api --- src/stats.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/stats.js b/src/stats.js index 97c1770..3512251 100644 --- a/src/stats.js +++ b/src/stats.js @@ -80,4 +80,39 @@ router.get('/messages-per-hour', async (req, res) => { } }); +router.get('/position-precision', async (req, res) => { + try { + const sevenDaysAgo = new Date(); + sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7); + + const result = await prisma.node.groupBy({ + by: ['position_precision'], + where: { + position_updated_at: { gte: sevenDaysAgo }, + position_precision: { not: null }, + }, + _count: { + position_precision: true, + }, + orderBy: { + _count: { + position_precision: 'desc', + }, + }, + }); + + const formatted = result.map(r => ({ + position_precision: r.position_precision, + count: r._count.position_precision, + })); + + res.set('Cache-Control', 'public, max-age=600'); // 10 min cache + res.json(formatted); + + } catch (error) { + console.error('Error fetching data:', error); + res.status(500).json({ error: 'Internal Server Error' }); + } +}); + module.exports = router; \ No newline at end of file