wise-eyes-core
Version:
Web server to monitor the status of owlcms
94 lines (93 loc) • 3.92 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Athlete {
static meta = {};
static metaFields = [];
state;
static getMeta(membership) {
const meta = this.meta[membership] || {};
this.metaFields.forEach((field) => {
if (meta[field] == null) {
meta[field] = '';
}
});
return meta;
}
static loadMeta(meta) {
this.metaFields = Object.keys(meta[Object.keys(meta)[0]]);
this.meta = meta;
}
constructor(data) {
this.update(data);
}
getAttemptNumber(data) {
const requestedAttemptIndex = [
...data.sattempts,
...data.cattempts,
].findIndex((attempt) => attempt.liftStatus === 'request');
return requestedAttemptIndex == null
? null
: (requestedAttemptIndex % 3) + 1;
}
getNextWeight(data) {
const requestedAttempt = [
...data.sattempts,
...data.cattempts,
].find((attempt) => attempt.liftStatus === 'request');
return requestedAttempt
? parseInt(requestedAttempt.stringValue)
: null;
}
getNextWeightPounds(data) {
const kilos = this.getNextWeight(data);
return kilos === null ? kilos : Math.round(kilos * 2.204);
}
getState() {
return this.state;
}
parseWeight(weight) {
return parseInt(weight.replace(/\D/g, ''));
}
parseWeightPounds(weight) {
const kilos = this.parseWeight(weight);
return Number.isNaN(kilos) ? kilos : Math.round(kilos * 2.204);
}
update(data) {
this.state = {
attemptNumber: this.getAttemptNumber(data),
bestClean: parseInt(data.bestCleanJerk) || null,
bestSnatch: parseInt(data.bestSnatch) || null,
cleanRank: parseInt(data.cleanJerkRank) || null,
clean1State: data.cattempts[0].liftStatus,
clean1Weight: this.parseWeight(data.cattempts[0].stringValue) || null,
clean1WeightPounds: this.parseWeightPounds(data.cattempts[0].stringValue) || null,
clean2State: data.cattempts[1].liftStatus,
clean2Weight: this.parseWeight(data.cattempts[1].stringValue) || null,
clean2WeightPounds: this.parseWeightPounds(data.cattempts[1].stringValue) || null,
clean3State: data.cattempts[2].liftStatus,
clean3Weight: this.parseWeight(data.cattempts[2].stringValue) || null,
clean3WeightPounds: this.parseWeightPounds(data.cattempts[2].stringValue) || null,
category: data.category,
membership: data.membership || null,
meta: Athlete.getMeta(data.membership),
name: data.fullName,
nextWeight: this.getNextWeight(data),
nextWeightPounds: this.getNextWeightPounds(data),
snatch1State: data.sattempts[0].liftStatus,
snatch1Weight: this.parseWeight(data.sattempts[0].stringValue) || null,
snatch1WeightPounds: this.parseWeightPounds(data.sattempts[0].stringValue) || null,
snatch2State: data.sattempts[1].liftStatus,
snatch2Weight: this.parseWeight(data.sattempts[1].stringValue) || null,
snatch2WeightPounds: this.parseWeightPounds(data.sattempts[1].stringValue) || null,
snatch3State: data.sattempts[2].liftStatus,
snatch3Weight: this.parseWeight(data.sattempts[2].stringValue) || null,
snatch3WeightPounds: this.parseWeightPounds(data.sattempts[2].stringValue) || null,
snatchRank: parseInt(data.snatchRank) || null,
startNumber: parseInt(data.startNumber),
team: data.teamName,
total: parseInt(data.total) || null,
totalRank: parseInt(data.totalRank) || null,
};
}
}
exports.default = Athlete;