UNPKG

wise-eyes-core

Version:

Web server to monitor the status of owlcms

204 lines (203 loc) 6.48 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const athlete_1 = __importDefault(require("./athlete")); const clock_1 = __importDefault(require("./clock")); const JURY_DECISION_DURATION = 3_000; class Platform { static platforms = new Map(); athletes = new Map(); athleteClock; breakClock; breakType = null; centerReferee = null; ceremonyType = null; currentAthlete = null; currentSession = null; downSignal = false; fopState = 'INACTIVE'; juryDecision = null; juryReversal = null; leaders = []; leftReferee = null; liftingOrder = []; liftType = null; liftTypeKey = null; mode = 'WAIT'; name; recordKind = 'none'; records = null; rightReferee = null; static getPlatform(name, { noPersist = false, } = {}) { let platform = this.platforms.get(name); if (!platform) { platform = new Platform({ name, }); if (!noPersist) { this.platforms.set(name, platform); } } return platform; } static getPlatforms() { return Array.from(this.platforms.keys()); } constructor({ name, }) { this.athleteClock = new clock_1.default(); this.breakClock = new clock_1.default(); this.name = name; } getAthleteClock() { return this.athleteClock; } getBreakClock() { return this.breakClock; } getCurrentAthlete() { return this.currentAthlete || null; } getLiftingOrder() { return this.liftingOrder.map((startNumber) => { return this.athletes.get(startNumber); }); } getState() { return { athlete: this.currentAthlete?.getState() || null, athleteClock: this.athleteClock.getState(), breakClock: this.breakClock.getState(), breakType: this.breakType, centerReferee: this.centerReferee, ceremonyType: this.ceremonyType, downSignal: this.downSignal, fopState: this.fopState, juryDecision: this.juryDecision, juryReversal: this.juryReversal, leaders: this.leaders.map((leader) => leader.getState()), leftReferee: this.leftReferee, liftType: this.liftType, liftTypeKey: this.liftTypeKey, mode: this.mode, name: this.name, recordKind: this.recordKind, records: this.records, rightReferee: this.rightReferee, sessionDescription: this.currentSession?.description || null, sessionInfo: this.currentSession?.info || null, sessionName: this.currentSession?.name || null, }; } resetDecisions() { this.centerReferee = null; this.downSignal = false; this.leftReferee = null; this.rightReferee = null; } setBreakType(breakType) { this.breakType = breakType; } setCeremonyType(ceremonyType) { this.ceremonyType = ceremonyType; } setCurrentAthlete(startNumber) { this.currentAthlete = this.athletes.get(startNumber) || null; } setDecisions({ centerReferee, leftReferee, rightReferee, }) { this.downSignal = false; this.centerReferee = centerReferee; this.leftReferee = leftReferee; this.rightReferee = rightReferee; } setDownSignal(state) { this.downSignal = state; if (state) { this.centerReferee = null; this.leftReferee = null; this.rightReferee = null; } } setFopState(fopState) { this.fopState = fopState; } setJuryDecision({ decision, reversal, }) { this.juryDecision = decision; this.juryReversal = reversal; setTimeout(() => { this.juryDecision = null; this.juryReversal = null; }, JURY_DECISION_DURATION); } setLeaders(athletes) { const realAthletes = athletes.filter((athlete) => { return !('isSpacer' in athlete); }); this.leaders = realAthletes.map((athleteData) => { return new athlete_1.default(athleteData); }); } setLiftType({ key, name, }) { this.liftTypeKey = key?.toUpperCase() || null; this.liftType = name; } setMode(mode) { this.mode = mode; } setRecordKind(recordKind) { this.recordKind = recordKind || 'none'; } setRecords(records) { if (!records) { this.records = null; return; } const federations = records.recordNames; this.records = { federations, categories: records.recordCategories, records: records.recordTable.map((record) => { return { category: record.cat, data: record.records.map((data, index) => { return { federation: federations[index], snatch: data.SNATCH, clean: data.CLEANJERK, total: data.TOTAL, snatchAttempt: !!data.snatchHighlight, cleanAttempt: !!data.cjHighlight, totalAttempt: !!data.totalHighlight, }; }), }; }), }; } setSession(session) { this.currentSession = session; } updateAthlete(data) { const startNumber = parseInt(data.startNumber); let athlete = this.athletes.get(startNumber); if (!athlete) { athlete = new athlete_1.default(data); } else { athlete.update(data); } this.athletes.set(startNumber, athlete); return athlete; } updateAthletes(athletes) { const realAthletes = athletes.filter((athlete) => { return !('isSpacer' in athlete); }); this.liftingOrder = realAthletes.map((athleteData) => { const athlete = this.updateAthlete(athleteData); return athlete.getState().startNumber; }); } } exports.default = Platform;