Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add endpoint for participants with highest measurement count #164

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions stats/lib/platform-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
fetchDailyStationCount,
fetchMonthlyStationCount,
fetchDailyRewardTransfers,
fetchTopMeasurementStations,
fetchDailyStationAcceptedMeasurementCount
} from './platform-stats-fetchers.js'

Expand Down Expand Up @@ -30,6 +31,8 @@ export const handlePlatformRoutes = async (req, res, pgPools) => {
await respond(pgPools.evaluate, fetchMonthlyStationCount)
} else if (req.method === 'GET' && url === '/measurements/daily') {
await respond(pgPools.evaluate, fetchDailyStationAcceptedMeasurementCount)
} else if (req.method === 'GET' && url === '/stations/top-measurements') {
bajtos marked this conversation as resolved.
Show resolved Hide resolved
await respond(pgPools.evaluate, fetchTopMeasurementStations)
} else if (req.method === 'GET' && url === '/transfers/daily') {
await respond(pgPools.stats, fetchDailyRewardTransfers)
} else {
Expand Down
16 changes: 16 additions & 0 deletions stats/lib/platform-stats-fetchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ export const fetchDailyStationAcceptedMeasurementCount = async (pgPool, filter)
return rows
}

/**
* @param {Queryable} pgPool
* @param {import('./typings.js').DateRangeFilter} filter
*/
export const fetchTopMeasurementStations = async (pgPool, filter) => {
const { rows } = await pgPool.query(`
SELECT station_id, SUM(accepted_measurement_count) as total_accepted_measurement_count
FROM daily_stations
WHERE day >= $1 AND day <= $2
bajtos marked this conversation as resolved.
Show resolved Hide resolved
GROUP BY station_id
ORDER BY total_accepted_measurement_count DESC
bajtos marked this conversation as resolved.
Show resolved Hide resolved
LIMIT 100
bajtos marked this conversation as resolved.
Show resolved Hide resolved
`, [filter.from, filter.to])
PatrickNercessian marked this conversation as resolved.
Show resolved Hide resolved
return rows
}

export const fetchDailyRewardTransfers = async (pgPool, filter) => {
const { rows } = await pgPool.query(`
SELECT day::TEXT, SUM(amount) as amount
Expand Down
Loading