-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
353 additions
and
103 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/assemblies/generators/tournamentRecords/copyTournamentRecord.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { checkRequiredParameters } from '@Helpers/parameters/checkRequiredParameters'; | ||
import { addDays, extractDate } from '@Tools/dateTime'; | ||
import { UUID } from '@Tools/UUID'; | ||
|
||
// Constants | ||
import { SUCCESS } from '@Constants/resultConstants'; | ||
import { Tournament } from '@Types/tournamentTypes'; | ||
|
||
type CopyTournamentRecordArgs = { | ||
tournamentRecord: Tournament; | ||
copyParticipants?: boolean; | ||
tournamentName: string; | ||
startDate: string; | ||
endDate?: string; | ||
}; | ||
|
||
export function copyTournamentRecord(params: CopyTournamentRecordArgs) { | ||
const paramsCheck = checkRequiredParameters(params, [ | ||
{ tournamentRecord: true, startDate: true, endDate: false, tournamentName: true }, | ||
]); | ||
if (paramsCheck.error) return paramsCheck; | ||
|
||
const { startDate, endDate } = params.tournamentRecord; | ||
const dayMilliseconds = 24 * 60 * 60 * 1000; | ||
const tournamentDayMilliseconds = | ||
startDate && endDate ? new Date(extractDate(endDate)).getTime() - new Date(extractDate(startDate)).getTime() : 0; | ||
const tournamentDays = tournamentDayMilliseconds / dayMilliseconds; | ||
const newEndDate = params.endDate || addDays(params.startDate, tournamentDays); | ||
|
||
const copyParticipant = (participant) => { | ||
const { timeItems, ...rest } = participant; | ||
return { ...rest }; | ||
}; | ||
|
||
const copyEvent = (event) => { | ||
const { drawDefinitions, ...rest } = event; | ||
return { ...rest }; | ||
}; | ||
|
||
const tournamentRecord = { | ||
participants: params.copyParticipants ? params.tournamentRecord.participants?.map(copyParticipant) ?? [] : [], | ||
parentOrganisation: { ...params.tournamentRecord.parentOrganisation }, | ||
events: params.tournamentRecord.events?.map(copyEvent) ?? [], | ||
weekdays: { ...params.tournamentRecord.weekdays }, | ||
venues: { ...params.tournamentRecord.venues }, | ||
tournamentName: params.tournamentName, | ||
startDate: params.startDate, | ||
tournamentId: UUID(), | ||
endDate: newEndDate, | ||
}; | ||
|
||
return { ...SUCCESS, tournamentRecord }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { createTournamentRecord } from '@Generators/tournamentRecords/createTournamentRecord'; | ||
export { copyTournamentRecord } from '@Generators/tournamentRecords/copyTournamentRecord'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { checkRequiredParameters } from '@Helpers/parameters/checkRequiredParameters'; | ||
import { allTournamentMatchUps } from '@Query/matchUps/getAllTournamentMatchUps'; | ||
import { parse } from '@Helpers/matchUpFormatCode/parse'; | ||
|
||
// Constants | ||
import { TOURNAMENT_RECORD } from '@Constants/attributeConstants'; | ||
import { SUCCESS } from '@Constants/resultConstants'; | ||
|
||
export function getAggregateTeamResults(params) { | ||
const paramsCheck = checkRequiredParameters(params, [{ [TOURNAMENT_RECORD]: true }]); | ||
if (paramsCheck.error) return paramsCheck; | ||
|
||
const teamResults = {}; | ||
for (const matchUp of allTournamentMatchUps(params)?.matchUps ?? []) { | ||
const { sides, matchUpFormat } = matchUp; | ||
const parsedMatchUpFormat: any = matchUpFormat && parse(matchUpFormat); | ||
|
||
// both sides must be present and must be a timed format | ||
if ( | ||
sides?.length === 2 && | ||
parsedMatchUpFormat.setFormat?.timed && | ||
(!parsedMatchUpFormat.finalSetFormat || parsedMatchUpFormat.finalSetFormat?.timed) | ||
) { | ||
for (const side of sides) { | ||
const individualTeams = side?.participant?.individualParticipants?.map( | ||
(i) => i.teams?.length === 1 && i.teams[0], | ||
); | ||
const teamParticipant = | ||
(side?.participant?.teams?.length === 1 && side?.participant?.teams?.[0]) || | ||
(individualTeams?.[0].participantId === individualTeams?.[1].participantId && individualTeams?.[0]); | ||
const teamParticipantId = teamParticipant?.participantId; | ||
const sideNumber = side.sideNumber; | ||
|
||
if (teamParticipantId && sideNumber) { | ||
if (!teamResults[teamParticipantId]) { | ||
teamResults[teamParticipantId] = { score: 0, diff: 0, teamName: teamParticipant.participantName }; | ||
} | ||
for (const set of matchUp.score?.sets ?? []) { | ||
const opponentPoints = set?.[`side${3 - sideNumber}Score`] || 0; | ||
const points = set?.[`side${sideNumber}Score`] || 0; | ||
const diff = points - opponentPoints; | ||
|
||
teamResults[teamParticipantId].score += points; | ||
teamResults[teamParticipantId].diff += diff; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return { ...SUCCESS, teamResults }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.