Skip to content
Closed
Changes from all commits
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
10 changes: 9 additions & 1 deletion crates/platform-server/src/db/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ pub async fn get_evaluations_for_agent(pool: &Pool, agent_hash: &str) -> Result<
// LEADERBOARD
// ============================================================================

/// Update leaderboard entry for an agent by calculating consensus score from evaluations
///
/// Calculates the average score from all evaluations for the agent and updates the leaderboard.
/// Returns `None` if no evaluations exist for the agent.
pub async fn update_leaderboard(pool: &Pool, agent_hash: &str) -> Result<Option<LeaderboardEntry>> {
let evaluations = get_evaluations_for_agent(pool, agent_hash).await?;
if evaluations.is_empty() {
Expand All @@ -338,7 +342,11 @@ pub async fn update_leaderboard(pool: &Pool, agent_hash: &str) -> Result<Option<
.ok_or_else(|| anyhow!("Submission not found for agent_hash: {}", agent_hash))?;

let scores: Vec<f64> = evaluations.iter().map(|e| e.score).collect();
let consensus_score = scores.iter().sum::<f64>() / scores.len() as f64;
let consensus_score = if scores.is_empty() {
0.0 // Should not happen due to check above, but defensive
} else {
scores.iter().sum::<f64>() / scores.len() as f64
};
let evaluation_count = evaluations.len() as i32;
let first_epoch = submission.epoch as i64;

Expand Down