Generator logic
This commit is contained in:
+72
-33
@@ -1,4 +1,4 @@
|
||||
import { Activity, Attribute, Player, Gender, ActivityPerformance, lbToKg } from "./util";
|
||||
import { Activity, Attribute, Player, Gender, ActivityPerformance, lbToKg, clampToLevel } from "./util";
|
||||
|
||||
// SOURCES
|
||||
// Squat, Bench, Dead Lift:
|
||||
@@ -193,29 +193,60 @@ export class Standards {
|
||||
}
|
||||
|
||||
// generate data
|
||||
// const allGenerators = this.activityStandards[activity].metadata.generators;
|
||||
//
|
||||
// const ageGenerators = allGenerators.filter(g => g.metric === "age");
|
||||
// for (const ageGenerator of ageGenerators) {
|
||||
// }
|
||||
//
|
||||
// const weightGenerators = allGenerators.filter(g => g.metric === "weight");
|
||||
// for (const weightGenerator of weightGenerators) {
|
||||
// for (const gender of Object.values(Gender)) {
|
||||
// const referenceWeight = gender === Gender.Male ?
|
||||
// lbToKg(170) :
|
||||
// lbToKg(137);
|
||||
//
|
||||
// const standardsByGender = this.byActivity(activity).byGender(gender).getAll();
|
||||
// const ages = [...new Set(standardsByGender.map(s => s.metrics.age))];
|
||||
//
|
||||
// for (const age of ages) {
|
||||
// const levelCalculator = new LevelCalculator(this);
|
||||
// const referenceStandard =
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
const allGenerators = this.activityStandards[activity].metadata.generators;
|
||||
|
||||
const ageGenerators = allGenerators.filter(g => g.metric === "age");
|
||||
for (const ageGenerator of ageGenerators) {
|
||||
}
|
||||
|
||||
const weightGenerators = allGenerators.filter(g => g.metric === "weight");
|
||||
for (const weightGenerator of weightGenerators) {
|
||||
for (const gender of Object.values(Gender)) {
|
||||
const referenceWeight = gender === Gender.Male ?
|
||||
lbToKg(170) :
|
||||
lbToKg(137);
|
||||
|
||||
const standardsByGender = this.byActivity(activity).byGender(gender).getAll();
|
||||
const ages = [...new Set(standardsByGender.map(s => s.metrics.age))];
|
||||
|
||||
for (const age of ages) {
|
||||
const referenceStandard = this
|
||||
.byActivity(activity)
|
||||
.byMetrics({ weight: referenceWeight, gender: gender, age: age })
|
||||
.getInterpolated();
|
||||
|
||||
const minWeight = referenceWeight - (referenceWeight * weightGenerator.spread);
|
||||
const maxWeight = referenceWeight + (referenceWeight * weightGenerator.spread);
|
||||
|
||||
let currWeight = minWeight;
|
||||
while (currWeight <= maxWeight) {
|
||||
// apply allometric scaling
|
||||
const newStandardLevels: Levels = {};
|
||||
for (const lvl in referenceStandard.levels) {
|
||||
const scalingExponent = .125;
|
||||
const coefficient = weightGenerator.ratio === "inverse" ?
|
||||
referenceWeight / currWeight :
|
||||
currWeight / referenceWeight;
|
||||
newStandardLevels[lvl] = referenceStandard.levels[lvl] * (coefficient ** scalingExponent);
|
||||
}
|
||||
|
||||
this.activityStandards[activity].standards.push({
|
||||
metrics: {
|
||||
weight: currWeight,
|
||||
age: age,
|
||||
gender: gender
|
||||
},
|
||||
levels: newStandardLevels
|
||||
});
|
||||
|
||||
currWeight += weightGenerator.step;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Bun.write("./newStandards.json", JSON.stringify(this.activityStandards, null, 2));
|
||||
}
|
||||
|
||||
public byActivity(activity: Activity) {
|
||||
@@ -223,7 +254,10 @@ export class Standards {
|
||||
|
||||
const state: Partial<Metrics> = {};
|
||||
|
||||
// EXEC METHODS
|
||||
const execMethods = {
|
||||
exact: {
|
||||
// these will get EXACT matches
|
||||
getAll: function(): Standard[] {
|
||||
let filtered = [...self.activityStandards[activity].standards];
|
||||
if (state.gender)
|
||||
@@ -235,10 +269,10 @@ export class Standards {
|
||||
return filtered;
|
||||
},
|
||||
getOne: function(): Standard {
|
||||
return execMethods.getAll()[0];
|
||||
return execMethods.exact.getAll()[0];
|
||||
},
|
||||
getNearest(metric: NumberMetric, target: number): { lower: Standard, upper: Standard } {
|
||||
const standards = execMethods.getAll();
|
||||
const standards = execMethods.exact.getAll();
|
||||
const lower = [...standards]
|
||||
.sort((a, b) => a.metrics[metric] - b.metrics[metric])
|
||||
.reverse()
|
||||
@@ -248,9 +282,9 @@ export class Standards {
|
||||
.find((s) => s.metrics[metric] >= target) ?? standards.at(-1)!;
|
||||
return { lower, upper };
|
||||
},
|
||||
};
|
||||
|
||||
const getInterpolated = (): Standard => {
|
||||
},
|
||||
interpolated: {
|
||||
getInterpolated: (): Standard => {
|
||||
const metrics: Metrics = state as Metrics;
|
||||
|
||||
const interpolateByWeight = (targetAge: number): Levels => {
|
||||
@@ -292,29 +326,34 @@ export class Standards {
|
||||
metrics,
|
||||
levels: interpolatedLevels
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// QUERY METHODS
|
||||
|
||||
const byGender = (gender: Gender) => {
|
||||
state.gender = gender;
|
||||
return { byAge, ...execMethods };
|
||||
return { byAge, ...execMethods.exact };
|
||||
}
|
||||
|
||||
const byAge = (age: number) => {
|
||||
state.age = age;
|
||||
return { byWeight, ...execMethods };
|
||||
return { byWeight, ...execMethods.exact };
|
||||
}
|
||||
|
||||
const byWeight = (weight: number) => {
|
||||
state.weight = weight;
|
||||
return { ...execMethods, getInterpolated };
|
||||
return { ...execMethods.exact, ...execMethods.interpolated };
|
||||
}
|
||||
|
||||
const byMetrics = (metrics: Metrics) => {
|
||||
Object.assign(state, metrics);
|
||||
return { ...execMethods, getInterpolated };
|
||||
return { ...execMethods.exact, ...execMethods.interpolated };
|
||||
}
|
||||
|
||||
return { byGender, byMetrics, ...execMethods }
|
||||
const initialMethods = { byGender, byMetrics, ...execMethods.exact };
|
||||
return initialMethods;
|
||||
}
|
||||
|
||||
getActivityAttribute(activity: Activity): Attribute {
|
||||
|
||||
+1
-1
@@ -4733,7 +4733,7 @@
|
||||
"generators": [
|
||||
{
|
||||
"metric": "weight",
|
||||
"spread": 50,
|
||||
"spread": 0.5,
|
||||
"step": 12,
|
||||
"ratio": "inverse"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user