Skip to content

Commit a3769fa

Browse files
committed
added more statistics to endpoint Statistics
1 parent 6c1fb13 commit a3769fa

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ Install dependencies with `npm install` and run dev server with `npn run dev`.
5454

5555
## Changelog
5656

57+
### 1.7.1 (2023-11-03)*
58+
59+
- (o0shojo0o) added more statistics to endpoint `Statistics`
60+
5761
### 1.7.0 (2023-11-03)*
5862

5963
- (o0shojo0o) added new api endpoint `Statistics`

libs/pixelItRepo.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,29 @@ async function getUserMapData() {
188188
async function getStatistics() {
189189
const result = {};
190190
try {
191-
result.buildStats = (await connection.query(`SELECT DISTINCT(IF(build_section = '','No_Data',build_section)) AS build, COUNT(*) AS count FROM pixel_it_telemetry where last_change >= CURRENT_DATE - INTERVAL 30 DAY GROUP BY build_section`))[0];
192-
result.versionStats = (await connection.query(`SELECT DISTINCT(version) AS version, COUNT(*) AS count FROM pixel_it_telemetry where last_change >= CURRENT_DATE - INTERVAL 30 DAY GROUP BY version`))[0];
193-
result.countryStats = (await connection.query(`SELECT DISTINCT(JSON_EXTRACT(geoip, '$.country')) AS country, COUNT(*) AS count FROM pixel_it_telemetry where last_change >= CURRENT_DATE - INTERVAL 30 DAY GROUP BY JSON_EXTRACT(geoip, '$.country')`))[0];
191+
result.buildStats = (await connection.query(`SELECT DISTINCT(IF(build_section = '','No_Data',build_section)) AS build, COUNT(*) AS count FROM pixel_it_telemetry where last_change >= CURRENT_DATE - INTERVAL 30 DAY GROUP BY build_section ORDER BY build`))[0];
192+
result.versionStats = (await connection.query(`SELECT DISTINCT(version) AS version, COUNT(*) AS count FROM pixel_it_telemetry where last_change >= CURRENT_DATE - INTERVAL 30 DAY GROUP BY version ORDER BY VERSION desc`))[0];
193+
result.matrixStats = (await connection.query(`SELECT DISTINCT(JSON_EXTRACT(matrix, '$.name')) AS matrix, COUNT(*) AS count FROM pixel_it_telemetry where last_change >= CURRENT_DATE - INTERVAL 30 DAY GROUP BY JSON_EXTRACT(matrix, '$.name') ORDER BY matrix`))[0];
194194

195+
196+
result.countryStats = (await connection.query(`SELECT DISTINCT(JSON_EXTRACT(geoip, '$.country')) AS country, COUNT(*) AS count FROM pixel_it_telemetry where last_change >= CURRENT_DATE - INTERVAL 30 DAY GROUP BY JSON_EXTRACT(geoip, '$.country') ORDER BY COUNT DESC`))[0];
195197
for (const countryStat of result.countryStats) {
196198
countryStat.country = countries.getName(countryStat.country, 'en', { select: 'official' });
197199
}
198200

201+
const sensors = (await connection.query(`SELECT JSON_ARRAYAGG(sensors) as sensors FROM pixel_it_telemetry where last_change >= CURRENT_DATE - INTERVAL 30 DAY`))[0][0].sensors.flat(1);
202+
const sensorsDistinct = [...new Set(sensors)]
203+
result.sensorStats = [];
204+
for (const sensorDistinct of sensorsDistinct.sort()) {
205+
result.sensorStats.push({
206+
sensor: sensorDistinct,
207+
count: sensors.filter(x => x == sensorDistinct).length
208+
})
209+
}
210+
199211
return result
200212
} catch (error) {
201-
log.error('getUserMapData: {error}', { error: error })
213+
log.error('getStatistics: {error}', { error: error })
202214
return null
203215
}
204216
};

0 commit comments

Comments
 (0)