Skip to content

Commit

Permalink
added more statistics to endpoint Statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
o0shojo0o committed Nov 3, 2023
1 parent 6c1fb13 commit a3769fa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ Install dependencies with `npm install` and run dev server with `npn run dev`.

## Changelog

### 1.7.1 (2023-11-03)*

- (o0shojo0o) added more statistics to endpoint `Statistics`

### 1.7.0 (2023-11-03)*

- (o0shojo0o) added new api endpoint `Statistics`
Expand Down
20 changes: 16 additions & 4 deletions libs/pixelItRepo.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,29 @@ async function getUserMapData() {
async function getStatistics() {
const result = {};
try {
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];
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];
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];
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];
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];
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];


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];
for (const countryStat of result.countryStats) {
countryStat.country = countries.getName(countryStat.country, 'en', { select: 'official' });
}

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);
const sensorsDistinct = [...new Set(sensors)]
result.sensorStats = [];
for (const sensorDistinct of sensorsDistinct.sort()) {
result.sensorStats.push({
sensor: sensorDistinct,
count: sensors.filter(x => x == sensorDistinct).length
})
}

return result
} catch (error) {
log.error('getUserMapData: {error}', { error: error })
log.error('getStatistics: {error}', { error: error })
return null
}
};
Expand Down

0 comments on commit a3769fa

Please sign in to comment.