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 http rsr #285

Merged
merged 15 commits into from
Jan 10, 2025
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 26 additions & 6 deletions stats/lib/stats-fetchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export const fetchRetrievalSuccessRate = async (pgPools, filter) => {
// Fetch the "day" (DATE) as a string (TEXT) to prevent node-postgres for converting it into
// a JavaScript Date with a timezone, as that could change the date one day forward or back.
const { rows } = await pgPools.evaluate.query(`
SELECT day::text, SUM(total) as total, SUM(successful) as successful
SELECT
day::text,
SUM(total) as total,
SUM(successful) as successful,
SUM(successful_http) as successful_http
FROM retrieval_stats
WHERE day >= $1 AND day <= $2 ${filter.nonZero === 'true' ? 'AND successful > 0' : ''}
GROUP BY day
Expand All @@ -20,7 +24,10 @@ export const fetchRetrievalSuccessRate = async (pgPools, filter) => {
day: r.day,
total: r.total,
successful: r.successful,
success_rate: r.total > 0 ? r.successful / r.total : null
success_rate: r.total > 0 ? r.successful / r.total : null,
successful_http: r.successful_http ?? null,
// successful_http might be null because the column was added later
success_rate_http: r.total > 0 && r.successful_http !== null ? r.successful_http / r.total : null
}))
return stats
}
Expand Down Expand Up @@ -207,7 +214,11 @@ export const fetchParticipantRewardTransfers = async (pgPools, { from, to }, add
*/
export const fetchMinersRSRSummary = async (pgPools, filter) => {
const { rows } = await pgPools.evaluate.query(`
SELECT miner_id, SUM(total) as total, SUM(successful) as successful
SELECT
miner_id,
SUM(total) as total,
SUM(successful) as successful,
SUM(successful_http) as successful_http
FROM retrieval_stats
WHERE day >= $1 AND day <= $2
GROUP BY miner_id
Expand All @@ -219,7 +230,10 @@ export const fetchMinersRSRSummary = async (pgPools, filter) => {
miner_id: r.miner_id,
total: r.total,
successful: r.successful,
success_rate: r.total > 0 ? r.successful / r.total : null
success_rate: r.total > 0 ? r.successful / r.total : null,
successful_http: r.successful_http ?? null,
// successful_http might be null because the column was added later
success_rate_http: r.total > 0 && r.successful_http !== null ? r.successful_http / r.total : null
}))
return stats
}
Expand All @@ -232,7 +246,10 @@ export const fetchMinersRSRSummary = async (pgPools, filter) => {
*/
export const fetchDailyMinerRSRSummary = async (pgPools, { from, to }, minerId) => {
const { rows } = await pgPools.evaluate.query(`
SELECT day::TEXT, SUM(total) as total, SUM(successful) as successful
SELECT
day::TEXT,
SUM(total) as total, SUM(successful) as successful,
SUM(successful_http) as successful_http
FROM retrieval_stats
WHERE miner_id = $1 AND day >= $2 AND day <= $3
GROUP BY day
Expand All @@ -246,7 +263,10 @@ export const fetchDailyMinerRSRSummary = async (pgPools, { from, to }, minerId)
day: r.day,
total: r.total,
successful: r.successful,
success_rate: r.total > 0 ? r.successful / r.total : null
success_rate: r.total > 0 ? r.successful / r.total : null,
successful_http: r.successful_http ?? null,
// successful_http might be null because the column was added later
success_rate_http: r.total > 0 && r.successful_http !== null ? r.successful_http / r.total : null
}))
return stats
}
Expand Down
Loading
Loading