wise-eyes-core
Version:
Web server to monitor the status of owlcms
97 lines (96 loc) • 4.63 kB
JavaScript
;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
var Athlete = /** @class */ (function () {
function Athlete(data) {
this.update(data);
}
Athlete.getMeta = function (membership) {
var meta = this.meta[membership] || {};
this.metaFields.forEach(function (field) {
if (meta[field] == null) {
meta[field] = '';
}
});
return meta;
};
Athlete.loadMeta = function (meta) {
this.metaFields = Object.keys(meta[Object.keys(meta)[0]]);
this.meta = meta;
};
Athlete.prototype.getAttemptNumber = function (data) {
var requestedAttemptIndex = __spreadArray(__spreadArray([], data.sattempts, true), data.cattempts, true).findIndex(function (attempt) { return attempt.liftStatus === 'request'; });
return requestedAttemptIndex == null
? null
: (requestedAttemptIndex % 3) + 1;
};
Athlete.prototype.getNextWeight = function (data) {
var requestedAttempt = __spreadArray(__spreadArray([], data.sattempts, true), data.cattempts, true).find(function (attempt) { return attempt.liftStatus === 'request'; });
return requestedAttempt
? parseInt(requestedAttempt.stringValue)
: null;
};
Athlete.prototype.getNextWeightPounds = function (data) {
var kilos = this.getNextWeight(data);
return kilos === null ? kilos : Math.round(kilos * 2.204);
};
Athlete.prototype.getState = function () {
return this.state;
};
Athlete.prototype.parseWeight = function (weight) {
return parseInt(weight.replace(/\D/g, ''));
};
Athlete.prototype.parseWeightPounds = function (weight) {
var kilos = this.parseWeight(weight);
return Number.isNaN(kilos) ? kilos : Math.round(kilos * 2.204);
};
Athlete.prototype.update = function (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,
};
};
Athlete.meta = {};
Athlete.metaFields = [];
return Athlete;
}());
exports.default = Athlete;