dbmaster-cli
Version:
Tool for converting tables between Fifa Soccer Games
186 lines (185 loc) • 6.58 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BodyGenerator = void 0;
const faker_1 = require("faker");
const Joi = __importStar(require("joi"));
const interfaces_1 = require("../interfaces");
var BmiCategory;
(function (BmiCategory) {
BmiCategory[BmiCategory["Over"] = 0] = "Over";
BmiCategory[BmiCategory["Normal"] = 1] = "Normal";
BmiCategory[BmiCategory["Under"] = 2] = "Under";
})(BmiCategory || (BmiCategory = {}));
class BodyGeneratorConfig {
constructor() {
this.minHeight = 130;
this.maxHeight = 215;
this.minWeight = 30;
this.maxWeight = 115;
this.specificBodyType = false;
}
}
const bodyGeneratorConfigFactory = (opts) => {
const config = new BodyGeneratorConfig();
if (opts.minHeight) {
config.minHeight = opts.minHeight;
}
if (opts.maxHeight) {
config.maxHeight = opts.maxHeight;
}
if (opts.minWeight) {
config.minWeight = opts.minWeight;
}
if (opts.maxWeight) {
config.maxWeight = opts.maxWeight;
}
if (opts.specificBodyType) {
config.specificBodyType = opts.specificBodyType;
}
return config;
};
// tslint:disable-next-line: max-classes-per-file
class BodyGenerator {
constructor(opts) {
this.config = bodyGeneratorConfigFactory(opts);
}
height(weight) {
if (this.isWeightValid(weight)) {
const avg = weight + 100;
const min = avg - 10 >= this.config.minHeight ? avg - 10 : this.config.minHeight;
const max = avg + 10 <= this.config.maxHeight ? avg + 10 : this.config.maxHeight;
return faker_1.random.number({ min, max });
}
return faker_1.random.number({ min: this.config.minHeight, max: this.config.maxHeight });
}
weight(height) {
if (this.isHeightValid(height)) {
const avg = height - 100;
const min = avg - 10 >= this.config.minWeight ? avg - 10 : this.config.minWeight;
const max = avg + 10 <= this.config.maxWeight ? avg + 10 : this.config.maxWeight;
return faker_1.random.number({ min, max });
}
return faker_1.random.number({ min: this.config.minWeight, max: this.config.maxWeight });
}
isHeightValid(height) {
const { error } = Joi.number()
.integer()
.min(this.config.minHeight)
.max(this.config.maxHeight)
.required()
.validate(height);
return !error;
}
isWeightValid(weight) {
const { error } = Joi.number()
.integer()
.min(this.config.minWeight)
.max(this.config.maxWeight)
.required()
.validate(weight);
return !error;
}
bmi(height, weight) {
return height / (weight * weight);
}
bodyTypeCode(height, weight, id) {
if (id && this.config.specificBodyType) {
switch (id) {
case 158023:
return interfaces_1.BodyTypeCode.Messi;
case 156321:
return interfaces_1.BodyTypeCode.Akinfenwa;
case 192119:
return interfaces_1.BodyTypeCode.Courtois;
case 190871:
return interfaces_1.BodyTypeCode.Neymar;
case 193348:
return interfaces_1.BodyTypeCode.Shaqiri;
case 20801:
return interfaces_1.BodyTypeCode.Ronaldo;
case 226316:
return interfaces_1.BodyTypeCode.Leroux;
case 209331:
return interfaces_1.BodyTypeCode.Salah;
case 226301:
return interfaces_1.BodyTypeCode.Morgan;
default:
return this.bodyTypeCodeBmi(height, weight);
}
}
else {
return this.bodyTypeCodeBmi(height, weight);
}
}
bodyTypeCodeBmi(height, weight) {
const category = this.bmiCategory(height, weight);
if (height > 205) {
return interfaces_1.BodyTypeCode.VeryTallAndLean;
}
else if (height < 170) {
if (category === BmiCategory.Under) {
return interfaces_1.BodyTypeCode.ShortAndLean;
}
else if (category === BmiCategory.Over) {
return interfaces_1.BodyTypeCode.ShortAndMuscular;
}
else {
return interfaces_1.BodyTypeCode.Short;
}
}
else if (height > 190) {
if (category === BmiCategory.Under) {
return interfaces_1.BodyTypeCode.TallAndLean;
}
else if (category === BmiCategory.Over) {
return interfaces_1.BodyTypeCode.TallAndMuscular;
}
else {
return interfaces_1.BodyTypeCode.Tall;
}
}
else {
if (category === BmiCategory.Under) {
return interfaces_1.BodyTypeCode.AverageHeightAndLean;
}
else if (category === BmiCategory.Over) {
return interfaces_1.BodyTypeCode.AverageHeightAndMuscular;
}
else {
return interfaces_1.BodyTypeCode.AverageHeight;
}
}
}
bmiCategory(height, weight) {
const bmi = this.bmi(height, weight);
if (bmi < 18.5) {
return BmiCategory.Under;
}
else if (bmi > 25) {
return BmiCategory.Over;
}
else {
return BmiCategory.Normal;
}
}
}
exports.BodyGenerator = BodyGenerator;