Skip to content

Commit

Permalink
Merge pull request #91 from HackDavis/feat/team-ranking
Browse files Browse the repository at this point in the history
Updated ranking and added submission check
  • Loading branch information
brandonw504 authored Apr 26, 2024
2 parents 21931e5 + 50194e3 commit 9481064
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
14 changes: 13 additions & 1 deletion app/(api)/_datalib/submissions/createSubmission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import isBodyEmpty from '@utils/request/isBodyEmpty';
import NoContentError from '@utils/response/NoContentError';
import HttpError from '@utils/response/HttpError';
import parseAndReplace from '@utils/request/parseAndReplace';
import { NotFoundError, DuplicateError } from '@utils/response/Errors';
import {
NotFoundError,
DuplicateError,
BadRequestError,
} from '@utils/response/Errors';

export const CreateSubmission = async (body: {
judge_id: string;
Expand Down Expand Up @@ -44,6 +48,14 @@ export const CreateSubmission = async (body: {
throw new DuplicateError('Submission already exists');
}

const judgeGroupToTeam = await db.collection('judgeGroupToTeams').findOne({
judge_group_id: judge.judge_group_id,
});

if (judgeGroupToTeam.team_id.toString() !== body.team_id.toString()) {
throw new BadRequestError('Judge is not judging this team.');
}

const creationStatus = await db
.collection('submissions')
.insertOne(parsedBody);
Expand Down
10 changes: 5 additions & 5 deletions app/(api)/_utils/scoring/rankTeams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function calculateTrackScore(
) {
const finalScores = chosenTracks.map((chosenTrack) => {
const weights = tracks.find((track) => track.name == chosenTrack)?.weights;
if (weights === undefined) return -1;
if (weights === undefined) return 0;
const score = weights.reduce((sum, weight, i) => {
return sum + weight * scores[i];
}, 0);
Expand All @@ -24,7 +24,7 @@ function calculateTrackScore(
)?.score;

if (correlationWeight === undefined || score === undefined) {
return -1;
return 0;
}

return (score! * correlationWeight!) / 5;
Expand All @@ -34,7 +34,7 @@ function calculateTrackScore(
}

function calculateScores(team: Team, submissions: Submission[]) {
let results: number[] = [];
let results: number[] = [0, 0, 0, 0, 0];

for (const submission of submissions) {
const scores = calculateTrackScore(
Expand All @@ -48,9 +48,9 @@ function calculateScores(team: Team, submissions: Submission[]) {

const finalScores = results.map((res, i) => ({
track: team.tracks[i],
score: res / submissions.length,
score: isNaN(res / submissions.length) ? 0 : res / submissions.length,
}));

console.log(finalScores);
return { team: team.name, scores: finalScores };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function JudgeTeamGrouping() {
{trackResults !== null
? trackResults!.map((result) => (
<>
<h2>{result.track}</h2>
<h4>{result.track}</h4>
{result.topEntries.map((entry) => (
<>
<p>{entry.team}</p>
Expand Down

0 comments on commit 9481064

Please sign in to comment.