mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-08 12:16:12 -05:00
Allow for concluding tournaments happening between seasons Closes #1578
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user