Draws Governor
import { drawsGovernor } from 'tods-competition-factory';
addAdHocMatchUps
Adds matchUps generated by generateAdHocMatchUps to specified structure within an AD_HOC drawDefinition.
engine.addAdHocMatchUps({
structureId, // optional if there is only one structure in drawDefinition
matchUps,
drawId,
});
addDrawDefinitionTimeItem
Adds a time item to a drawDefinition.
engine.addDrawDefinitionTimeItem({
drawId, // required
timeItem, // required - time item object
itemType, // required - time item type
});
Purpose: Attach time-based metadata to draws.
addFinishingRounds
Adds finishing rounds to an existing structure for placement matchUps.
engine.addFinishingRounds({
drawId, // required
structureId, // required
finishingPositions, // required - array of positions to play off
});
Purpose: Add placement matchUps for specific finishing positions.
addGoesTo
Adds a link between structures indicating progression path.
engine.addGoesTo({
drawId, // required
sourceStructureId, // required
targetStructureId, // required
roundNumber, // optional - specific round
});
Purpose: Define progression paths between structures.
adHocPositionSwap
Swaps participant assignments in two unscored matchUps that are part of the same roundNumber in and AD_HOC structure.
This method and one of the two participantIds are returned in validActions by positionActions which calls adHocMatchUpActions, meaning this method is not normally called directly.
engine.adHocPositionSwap({
participantIds,
structureId,
roundNumber,
drawId,
});
addLinkedConsolationStructure
Generates a consolation structure of any draw type and attaches it to an existing draw with LOSER links from specified source rounds. The consolation structure is created using the factory's standard generator pipeline, so it supports all draw types (AD_HOC, SINGLE_ELIMINATION, LUCKY_DRAW, ROUND_ROBIN, FEED_IN, etc.).
engine.addLinkedConsolationStructure({
drawId,
structureId, // optional - main structure to link from; auto-resolved if omitted
structureType, // optional - defaults to AD_HOC; any valid draw type (SINGLE_ELIMINATION, LUCKY_DRAW, ROUND_ROBIN, etc.)
structureName, // optional - defaults to 'Consolation'
drawSize, // optional - defaults to 2
matchUpFormat, // optional - scoring format for consolation matchUps
matchUpType, // optional - SINGLES, DOUBLES, TEAM; defaults to draw's matchUpType
links: [
// required - LOSER link definitions from main to consolation
{ sourceRoundNumber: 1, targetRoundNumber: 1 },
{ sourceRoundNumber: 2, targetRoundNumber: 1 },
{ sourceRoundNumber: 3, targetRoundNumber: 1 },
],
});
Use generateConsolationStructure to generate the consolation structure without attaching it. This is useful in client/server architectures where the structure must be generated locally and attached via an execution queue.
addPlayoffStructures
Adds playoff structures to an existing drawDefinition. This method creates PLAY_OFF structures linked via LOSER links from the specified source structure.
engine.addPlayoffStructures({
drawId,
structureId,
roundNumbers: [3], // required if no playoffPositions - source roundNumbers which will feed target structures, e.g. [1, 2]
roundProfiles, // optional - source roundNumbers as Object.keys with depth as Object.values, e.g. [{ 1: 2}, {2: 1}]
playoffPositions: [3, 4], // required if not provided roundNumbers
playoffAttributes, // optional - mapping of exitProfile or finishingPositionRange to structure names (see Finishing Positions concept)
exitProfileLimit, // limit playoff rounds generated by the attributes present in playoffAttributes
playoffStructureNameBase, // optional - base word for default playoff naming, e.g. 'Playoff'
});
// example use of playoffAttributes - will generated playoff structure from 2nd round with structureName: 'BRONZE'
const playoffAttributes = {
'0-2': { name: 'BRONZE', abbreviation: 'B' },
};
For multi-level playoff trees (e.g., COMPASS topologies), use the withPlayoffs parameter on generateDrawDefinition instead of chaining multiple addPlayoffStructures calls. The withPlayoffs.roundPlayoffs field supports recursive nesting, building the entire tree in a single call. See Custom Playoff Topologies.
addQualifyingStructure
engine.addQualifyingStructure({
targetStructureId, // required: structure for which participants will qualify
qualifyingPositions, // optional: specify the # of qualifyingPositions
qualifyingRoundNumber, // optional: determine qualifyingPositions by # of matchUps in specified round; does not apply to ROUND_ROBIN
structureOptions, // optional: specific to ROUND_ROBIN generation
structureName, // optional
drawSize,
drawType, // optional: defaults to SINGLE_ELIMINATION
drawId, // required: draw within which target structure appears
});
addVoluntaryConsolationStage
Modifies the entryProfile for a draw to allow { entryStage: VOLUNTARY_CONSOLATION }
engine.addVoluntaryConsolationStage({
drawSize,
drawId,
});
addVoluntaryConsolationStructure
Generates a new structure within a drawDefinition if any draw entries are present for { entryStage: VOLUNTARY_CONSOLATION }.
engine.addVoluntaryConsolationStructure({
structureAbbreviation, // optional
structureName, // optional - defaults to 'VOLUNTARY_CONSOLATION'
drawId,
});
allPlayoffPositionsFilled
Checks if all playoff positions for a structure have been filled.
const { allFilled } = engine.allPlayoffPositionsFilled({
drawId, // required
structureId, // required
});
Returns: Boolean indicating if all playoff positions are assigned.
alternateDrawPositionAssignment
Replaces an existing drawPosition assignment with an alternateParticipantId. This method is included in validActions for positionActions
engine.alternateDrawPositionAssignment({
alternateParticipantId,
drawPosition,
structureId,
drawId,
});
assignDrawPosition
Low level function normally called by higher order convenience functions.
engine.assignDrawPosition({
participantId, // optional - if assigning position to a participant
drawPosition,
structureId,
qualifier, // optional boolean, if assigning a space for a qualifier
drawId,
bye, // optional boolean, if assigning a bye
});
assignDrawPositionBye
engine.assignDrawPositionBye({
structureId,
drawId,
});
attachQualifyingStructure
engine.attachQualifyingStructure({
structure, // required: structure object; see `generateQualifyingStructure`
drawId, // required: id of drawDedfinition to which structure will be attached
link, // required
});
automatedPlayoffPositioning
For Round Robin structures, uses Round Robin Tallies to position participants in playoff structure(s).
engine.automatedPlayoffPositioning({
structureId: mainStructure.structureId,
provisionalPositioning, // optional boolean, defaults to false; when true will honor provisionalOrder if no groupOrder is found in tallyResults
applyPositioning, // optional boolean, defaults to true; when false will return positioning but not apply it to playoff structures
drawId,
});