More generator work

This commit is contained in:
Dominic Ferrando
2025-09-16 02:07:05 -04:00
parent c6107074ac
commit d09465616a
2 changed files with 33 additions and 27 deletions
+32 -26
View File
@@ -1,4 +1,4 @@
import { Activity, Attribute, Player, Gender, ActivityPerformance, lbToKg, clampToLevel } from "./util"; import { Activity, Attribute, Player, Gender, ActivityPerformance, lbToKg } from "./util";
// SOURCES // SOURCES
// Squat, Bench, Dead Lift: // Squat, Bench, Dead Lift:
@@ -197,47 +197,53 @@ export class Standards {
const ageGenerators = allGenerators.filter(g => g.metric === "age"); const ageGenerators = allGenerators.filter(g => g.metric === "age");
for (const ageGenerator of ageGenerators) { for (const ageGenerator of ageGenerators) {
// TODO
} }
const weightGenerators = allGenerators.filter(g => g.metric === "weight"); const weightGenerators = allGenerators.filter(g => g.metric === "weight");
for (const weightGenerator of weightGenerators) { for (const weightGenerator of weightGenerators) {
for (const gender of Object.values(Gender)) { 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 standardsByGender = this.byActivity(activity).byGender(gender).getAll();
const ages = [...new Set(standardsByGender.map(s => s.metrics.age))]; const ages = [...new Set(standardsByGender.map(s => s.metrics.age))];
for (const age of ages) { for (const age of ages) {
const referenceStandard = this const referenceWeight = gender === Gender.Male ?
.byActivity(activity) lbToKg(170) :
.byMetrics({ weight: referenceWeight, gender: gender, age: age }) lbToKg(137);
.getInterpolated(); const minWeight = referenceWeight - (weightGenerator.step * weightGenerator.spread);
const maxWeight = referenceWeight + (weightGenerator.step * weightGenerator.spread);
const minWeight = referenceWeight - (referenceWeight * weightGenerator.spread);
const maxWeight = referenceWeight + (referenceWeight * weightGenerator.spread);
let currWeight = minWeight; let currWeight = minWeight;
while (currWeight <= maxWeight) { while (currWeight <= maxWeight) {
// apply allometric scaling const newStandard: Standard = {
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: { metrics: {
weight: currWeight, weight: currWeight,
age: age, age: age,
gender: gender gender: gender
}, },
levels: newStandardLevels levels: {}
}); };
// apply allometric scaling to generate levels
const referenceStandard = this
.byActivity(activity)
.byMetrics({ weight: referenceWeight, gender: gender, age: age })
.getInterpolated();
for (const lvl in referenceStandard.levels) {
const scalingExponent = .125;
const coefficient = weightGenerator.ratio === "inverse" ?
referenceWeight / currWeight :
currWeight / referenceWeight;
newStandard.levels[lvl] = referenceStandard.levels[lvl] * (coefficient ** scalingExponent);
}
// prefer real data over generated data
const overlappingStandard = this
.byActivity(activity)
.byMetrics(newStandard.metrics)
.getOne();
if (!overlappingStandard)
this.activityStandards[activity].standards.push(newStandard);
currWeight += weightGenerator.step; currWeight += weightGenerator.step;
} }
@@ -268,7 +274,7 @@ export class Standards {
filtered = filtered.filter((s) => s.metrics.weight === state.weight); filtered = filtered.filter((s) => s.metrics.weight === state.weight);
return filtered; return filtered;
}, },
getOne: function(): Standard { getOne: function(): Standard | undefined {
return execMethods.exact.getAll()[0]; return execMethods.exact.getAll()[0];
}, },
getNearest(metric: NumberMetric, target: number): { lower: Standard, upper: Standard } { getNearest(metric: NumberMetric, target: number): { lower: Standard, upper: Standard } {
+1 -1
View File
@@ -4733,7 +4733,7 @@
"generators": [ "generators": [
{ {
"metric": "weight", "metric": "weight",
"spread": 0.5, "spread": 4,
"step": 12, "step": 12,
"ratio": "inverse" "ratio": "inverse"
} }