API Reference
Core Library Reference
This is the TypeScript API reference for the @opprs/core calculation library. For REST API documentation, see the REST API page. This reference is for developers directly using the npm package.
Complete reference for all types and functions exported by @opprs/core.
Types
Player
Represents a player in the ranking system.
interface Player {
id: string;
rating: number;
ranking: number;
isRated: boolean;
ratingDeviation?: number;
eventCount?: number;
}TGPConfig
Configuration for Tournament Grading Percentage calculation.
interface TGPConfig {
qualifying: {
type: 'unlimited' | 'limited' | 'hybrid' | 'none';
meaningfulGames: number;
hours?: number;
fourPlayerGroups?: boolean;
threePlayerGroups?: boolean;
multiMatchplay?: boolean;
};
finals: {
formatType: TournamentFormatType;
meaningfulGames: number;
fourPlayerGroups?: boolean;
threePlayerGroups?: boolean;
};
ballCountAdjustment?: number;
}PlayerResult
Represents a player's finish in a tournament.
interface PlayerResult {
player: Player;
position: number;
optedOut?: boolean;
}PointDistribution
Result of point distribution calculation for a player.
interface PointDistribution {
player: Player;
position: number;
linearPoints: number;
dynamicPoints: number;
totalPoints: number;
}Functions
Base Value
calculateBaseValue
Calculates the base value of a tournament based on the number of rated players.
function calculateBaseValue(players: Player[]): numbercountRatedPlayers
Counts the number of rated players in a list.
function countRatedPlayers(players: Player[]): numberisPlayerRated
Checks if a player is rated based on their event count.
function isPlayerRated(eventCount: number): booleanTVA (Tournament Value Adjustment)
calculateRatingTVA
Calculates the rating-based Tournament Value Adjustment.
function calculateRatingTVA(players: Player[]): numbercalculateRankingTVA
Calculates the ranking-based Tournament Value Adjustment.
function calculateRankingTVA(players: Player[]): numbercalculateTotalTVA
Calculates both TVA components and returns the total.
function calculateTotalTVA(players: Player[]): {
ratingTVA: number;
rankingTVA: number;
totalTVA: number;
}TGP (Tournament Grading Percentage)
calculateTGP
Calculates the overall Tournament Grading Percentage.
function calculateTGP(config: TGPConfig): numbercalculateQualifyingTGP
Calculates the TGP contribution from the qualifying round.
function calculateQualifyingTGP(config: TGPConfig): numbercalculateFinalsTGP
Calculates the TGP contribution from the finals round.
function calculateFinalsTGP(config: TGPConfig): numberEvent Boosters
getEventBoosterMultiplier
Returns the multiplier for a given event booster type.
function getEventBoosterMultiplier(type: EventBoosterType): numberqualifiesForCertified
Checks if a tournament qualifies for Certified status.
function qualifiesForCertified(...): booleanqualifiesForCertifiedPlus
Checks if a tournament qualifies for Certified+ status.
function qualifiesForCertifiedPlus(...): booleanPoint Distribution
distributePoints
Distributes points to all players based on their finishing positions.
function distributePoints(
results: PlayerResult[],
firstPlaceValue: number
): PointDistribution[]calculatePlayerPoints
Calculates points for a single player position.
function calculatePlayerPoints(
position: number,
playerCount: number,
ratedPlayerCount: number,
firstPlaceValue: number
): numberTime Decay
applyTimeDecay
Applies time decay to a point value based on event date.
function applyTimeDecay(points: number, eventDate: Date): numberisEventActive
Checks if an event is still active (within 3 years).
function isEventActive(eventDate: Date): booleangetDecayMultiplier
Returns the decay multiplier for a given age in years.
function getDecayMultiplier(ageInYears: number): numberRating
updateRating
Updates a player's Glicko rating based on match results.
function updateRating(update: RatingUpdate): RatingResultsimulateTournamentMatches
Simulates matches for a tournament based on finishing positions.
function simulateTournamentMatches(
position: number,
results: PlayerResult[]
): MatchResult[]Efficiency
calculateOverallEfficiency
Calculates a player's overall efficiency across events.
function calculateOverallEfficiency(events: PlayerEvent[]): numbergetEfficiencyStats
Returns detailed efficiency statistics for a player.
function getEfficiencyStats(events: PlayerEvent[]): EfficiencyStats