Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | 1x 10x 10x 10x 10x 2x 2x 2x 2x 2x 2x 2x 10x 10x 7x 7x 7x 7x 7x 7x 10x 10x 1x 3x 3x 3x 3x 7x 5x 7x 7x 5x 5x 3x 3x 3x 1x 3x 3x 3x 3x 3x 8x 8x 5x 5x 5x 3x 3x 3x 1x 5x 5x 1x 6x 4x 4x | /**
* Score calculation utility functions for Nova
*
* This module provides standardized functions for calculating scores
* across the Nova platform to ensure consistency.
*/
export interface ScoreInput {
total_tests?: number | null;
passed_tests?: number | null;
total_criteria?: number | null;
sum_criterion_score?: number | null;
}
/**
* Calculates a standardized score based on test cases and criteria evaluation
*
* The score is calculated as follows:
* 1. If both tests and criteria exist:
* - Test Score = (passed_tests/total_tests) * 10 * 0.5
* - Criteria Score = (sum_criterion_score/(total_criteria*10)) * 10 * 0.5
* 2. If only criteria exist:
* - Criteria Score = (sum_criterion_score/(total_criteria*10)) * 10 * 1.0
* 3. If only tests exist:
* - Test Score = (passed_tests/total_tests) * 10 * 1.0
*
* Each problem has a maximum score of 10 points
*
* @param submission Object containing test and criteria data
* @returns Calculated score (0-10)
*/
export function calculateScore(submission: ScoreInput): number {
const hasCriteria = (submission.total_criteria || 0) > 0;
const hasTests = (submission.total_tests || 0) > 0;
let criteriaScore = 0;
if (hasCriteria) {
const criteriaWeight = hasTests ? 0.5 : 1.0;
criteriaScore =
((submission.sum_criterion_score || 0) /
((submission.total_criteria || 0) * 10)) *
10 *
criteriaWeight;
}
let testScore = 0;
if (hasTests) {
const testWeight = hasCriteria ? 0.5 : 1.0;
testScore =
((submission.passed_tests || 0) / (submission.total_tests || 0)) *
10 *
testWeight;
}
return criteriaScore + testScore;
}
/**
* Calculates scores for multiple problems and returns the best score for each
*
* @param submissions Array of submission objects with problem IDs
* @returns Map of problem ID to best score
*/
export function calculateBestScores(
submissions: Array<ScoreInput & { problem_id: string }>
): Map<string, number> {
const bestScores = new Map<string, number>();
submissions.forEach((submission) => {
if (!submission.problem_id) return;
const score = calculateScore(submission);
const currentBest = bestScores.get(submission.problem_id) || 0;
if (score > currentBest) {
bestScores.set(submission.problem_id, score);
}
});
return bestScores;
}
/**
* Aggregates scores by challenge
*
* @param problemScores Map of problem ID to score
* @param problemChallengeMap Map of problem ID to challenge ID
* @returns Object mapping challenge IDs to their total scores
*/
export function aggregateByChallenge(
problemScores: Map<string, number>,
problemChallengeMap: Map<string, string>
): Record<string, number> {
const challengeScores: Record<string, number> = {};
problemScores.forEach((score, problemId) => {
const challengeId = problemChallengeMap.get(problemId);
if (challengeId) {
challengeScores[challengeId] =
(challengeScores[challengeId] || 0) + score;
}
});
return challengeScores;
}
/**
* Formats a score for display
*
* @param score Raw score number
* @param decimals Number of decimal places (default: 1)
* @returns Formatted score string
*/
export function formatScore(score: number, decimals: number = 1): string {
return score.toFixed(decimals);
}
/**
* Calculates percentage based on score and maximum possible score
*
* @param score Current score
* @param maxScore Maximum possible score
* @returns Percentage (0-100)
*/
export function calculatePercentage(score: number, maxScore: number): number {
if (maxScore <= 0) return 0;
return (score / maxScore) * 100;
}
|