59 lines
1.9 KiB
TypeScript
59 lines
1.9 KiB
TypeScript
|
|
/**
|
||
|
|
* Simulator Registry
|
||
|
|
*
|
||
|
|
* Maps a sport's simulatorType to the appropriate Simulator implementation.
|
||
|
|
* Set simulatorType on the sport record in the admin UI.
|
||
|
|
* Add new simulators here as new sports are supported.
|
||
|
|
*/
|
||
|
|
|
||
|
|
import type { Simulator } from "./types";
|
||
|
|
import { BracketSimulator } from "./bracket-simulator";
|
||
|
|
import { F1Simulator } from "./f1-simulator";
|
||
|
|
import { GolfSimulator } from "./golf-simulator";
|
||
|
|
|
||
|
|
export type SimulatorType =
|
||
|
|
| "f1_standings"
|
||
|
|
| "indycar_standings"
|
||
|
|
| "golf_qualifying_points"
|
||
|
|
| "playoff_bracket";
|
||
|
|
|
||
|
|
export interface SimulatorInfo {
|
||
|
|
name: string;
|
||
|
|
description: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
const REGISTRY: Record<SimulatorType, { info: SimulatorInfo; create: () => Simulator }> = {
|
||
|
|
f1_standings: {
|
||
|
|
info: { name: "F1 Standings Model", description: "Simulates remaining races using current F1 standings and futures odds" },
|
||
|
|
create: () => new F1Simulator(),
|
||
|
|
},
|
||
|
|
indycar_standings: {
|
||
|
|
info: { name: "IndyCar Standings Model", description: "Simulates remaining races using current IndyCar standings and futures odds" },
|
||
|
|
create: () => new F1Simulator(),
|
||
|
|
},
|
||
|
|
golf_qualifying_points: {
|
||
|
|
info: { name: "Qualifying Points Model", description: "Simulates remaining majors using current QP standings and futures odds" },
|
||
|
|
create: () => new GolfSimulator(),
|
||
|
|
},
|
||
|
|
playoff_bracket: {
|
||
|
|
info: { name: "Bracket Monte Carlo", description: "Simulates playoff bracket outcomes using Elo ratings" },
|
||
|
|
create: () => new BracketSimulator(),
|
||
|
|
},
|
||
|
|
};
|
||
|
|
|
||
|
|
export function getSimulator(simulatorType: SimulatorType): Simulator {
|
||
|
|
const entry = REGISTRY[simulatorType];
|
||
|
|
if (!entry) {
|
||
|
|
throw new Error(
|
||
|
|
`No simulator registered for type: "${simulatorType}". ` +
|
||
|
|
`Add a simulator to app/services/simulations/registry.ts.`
|
||
|
|
);
|
||
|
|
}
|
||
|
|
return entry.create();
|
||
|
|
}
|
||
|
|
|
||
|
|
export function getSimulatorInfo(simulatorType: SimulatorType): SimulatorInfo | null {
|
||
|
|
return REGISTRY[simulatorType]?.info ?? null;
|
||
|
|
}
|
||
|
|
|