add most active nodes stats
This commit is contained in:
parent
984771925f
commit
6e9d425bda
1 changed files with 24 additions and 0 deletions
24
src/stats.js
24
src/stats.js
|
|
@ -117,4 +117,28 @@ router.get('/position-precision', async (req, res) => {
|
|||
}
|
||||
});
|
||||
|
||||
router.get('/most-active-nodes', async (req, res) => {
|
||||
try {
|
||||
const result = await prisma.$queryRaw`
|
||||
SELECT n.long_name, COUNT(*) AS count
|
||||
FROM service_envelopes se
|
||||
JOIN nodes n ON se.from = n.node_id
|
||||
WHERE
|
||||
se.created_at >= NOW() - INTERVAL 1 DAY
|
||||
AND se.mqtt_topic NOT LIKE '%/map/'
|
||||
GROUP BY n.long_name
|
||||
ORDER BY count DESC
|
||||
LIMIT 25;
|
||||
`;
|
||||
|
||||
res.set('Cache-Control', 'public, max-age=600'); // 10 min cache
|
||||
res.json(result);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error fetching data:', error);
|
||||
res.status(500).json({ error: 'Internal Server Error' });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
module.exports = router;
|
||||
Loading…
Add table
Add a link
Reference in a new issue