From 1e5cd0b3c8b09d600be979121dbb73a0bd1d171b Mon Sep 17 00:00:00 2001 From: liamcottle Date: Wed, 13 Mar 2024 21:02:58 +1300 Subject: [PATCH] implement sidebar to show popular meshtastic devices --- src/index.js | 36 ++++++ src/public/index.html | 294 ++++++++++++++++++++++-------------------- 2 files changed, 192 insertions(+), 138 deletions(-) diff --git a/src/index.js b/src/index.js index f1fdf29..02c77cf 100644 --- a/src/index.js +++ b/src/index.js @@ -84,4 +84,40 @@ app.get('/api/v1/nodes', async (req, res) => { } }); +app.get('/api/v1/stats/hardware-models', async (req, res) => { + try { + + // get nodes from db + const results = await prisma.node.groupBy({ + by: ['hardware_model'], + orderBy: { + _count: { + hardware_model: 'desc', + }, + }, + _count: { + hardware_model: true, + }, + }); + + const hardwareModelStats = results.map((result) => { + return { + count: result._count.hardware_model, + hardware_model: result.hardware_model, + hardware_model_name: HardwareModel.valuesById[result.hardware_model] ?? "UNKNOWN", + }; + }); + + res.json({ + hardware_model_stats: hardwareModelStats, + }); + + } catch(err) { + console.error(err); + res.status(500).json({ + message: "Something went wrong, try again later.", + }); + } +}); + app.listen(8080); diff --git a/src/public/index.html b/src/public/index.html index 67517cf..526a329 100644 --- a/src/public/index.html +++ b/src/public/index.html @@ -24,6 +24,10 @@ + + + +