Allow for concluding tournaments happening between seasons Closes #1578

This commit is contained in:
Kalle
2023-12-09 15:21:47 +02:00
parent ee93c270b8
commit 7f395e9897
3 changed files with 24 additions and 19 deletions

View File

@@ -51,6 +51,7 @@ export function tournamentSummary({
queryCurrentTeamRating,
queryTeamPlayerRatingAverage,
queryCurrentUserRating,
calculateSeasonalStats = true,
}: {
results: AllMatchResult[];
teams: TeamsArg;
@@ -58,19 +59,26 @@ export function tournamentSummary({
queryCurrentTeamRating: (identifier: string) => Rating;
queryTeamPlayerRatingAverage: (identifier: string) => Rating;
queryCurrentUserRating: (userId: number) => Rating;
calculateSeasonalStats?: boolean;
}): TournamentSummary {
const userIdsToTeamId = userIdsToTeamIdRecord(teams);
return {
skills: skills({
results,
userIdsToTeamId,
queryCurrentTeamRating,
queryCurrentUserRating,
queryTeamPlayerRatingAverage,
}),
mapResultDeltas: mapResultDeltas({ results, userIdsToTeamId }),
playerResultDeltas: playerResultDeltas({ results, userIdsToTeamId }),
skills: calculateSeasonalStats
? skills({
results,
userIdsToTeamId,
queryCurrentTeamRating,
queryCurrentUserRating,
queryTeamPlayerRatingAverage,
})
: [],
mapResultDeltas: calculateSeasonalStats
? mapResultDeltas({ results, userIdsToTeamId })
: [],
playerResultDeltas: calculateSeasonalStats
? playerResultDeltas({ results, userIdsToTeamId })
: [],
tournamentResults: tournamentResults({
participantCount: teams.length,
finalStandings,

View File

@@ -111,7 +111,7 @@ export const addSummary = sql.transaction(
}: {
tournamentId: number;
summary: TournamentSummary;
season: number;
season?: number;
}) => {
for (const skill of summary.skills) {
const insertedSkill = addSkillStm.get({

View File

@@ -184,11 +184,9 @@ export const action: ActionFunction = async ({ params, request }) => {
const results = allMatchResultsByTournamentId(tournamentId);
invariant(results.length > 0, "No results found");
// TODO: support tournaments outside of seasons as well as unranked tournaments
const _currentSeason = currentSeason(
const season = currentSeason(
databaseTimestampToDate(tournament.startTime),
);
validate(_currentSeason, "No current season found");
addSummary({
tournamentId,
@@ -196,19 +194,18 @@ export const action: ActionFunction = async ({ params, request }) => {
teams,
finalStandings: _finalStandings,
results,
calculateSeasonalStats: typeof season === "number",
queryCurrentTeamRating: (identifier) =>
queryCurrentTeamRating({ identifier, season: _currentSeason.nth })
.rating,
queryCurrentTeamRating({ identifier, season: season!.nth }).rating,
queryCurrentUserRating: (userId) =>
queryCurrentUserRating({ userId, season: _currentSeason.nth })
.rating,
queryCurrentUserRating({ userId, season: season!.nth }).rating,
queryTeamPlayerRatingAverage: (identifier) =>
queryTeamPlayerRatingAverage({
identifier,
season: _currentSeason.nth,
season: season!.nth,
}),
}),
season: _currentSeason.nth,
season: season?.nth,
});
return null;