Regoranize generator code
This commit is contained in:
@@ -412,10 +412,8 @@ export class Standards {
|
||||
? this.activityStandards[activity].metadata.generators
|
||||
: [];
|
||||
|
||||
const ageGenerators = allGenerators.filter(
|
||||
(g) => g.metric === "age",
|
||||
);
|
||||
for (const ageGenerator of ageGenerators) {
|
||||
for (const generator of allGenerators) {
|
||||
if (generator.metric === "age") {
|
||||
for (const gender of Object.values(Gender)) {
|
||||
const peakAge = this.cfg.activity[activity].peakAge;
|
||||
const ageStep = 10;
|
||||
@@ -446,7 +444,8 @@ export class Standards {
|
||||
const base = referenceStandard.levels[lvl];
|
||||
if (!base) continue;
|
||||
|
||||
const s = this.cfg.activity[activity].ageModifier;
|
||||
const s =
|
||||
this.cfg.activity[activity].ageModifier;
|
||||
|
||||
const youngFloor0 = 0.5;
|
||||
const oldFloor0 = 0.5;
|
||||
@@ -463,8 +462,10 @@ export class Standards {
|
||||
|
||||
let f =
|
||||
currAge <= peakAge
|
||||
? 1 - cy * Math.pow(peakAge - currAge, 2)
|
||||
: 1 - co * Math.pow(currAge - peakAge, 2);
|
||||
? 1 -
|
||||
cy * Math.pow(peakAge - currAge, 2)
|
||||
: 1 -
|
||||
co * Math.pow(currAge - peakAge, 2);
|
||||
|
||||
const floor = Math.min(youngFloor, oldFloor);
|
||||
const fCurr = Math.max(floor, Math.min(1, f));
|
||||
@@ -473,7 +474,9 @@ export class Standards {
|
||||
}
|
||||
|
||||
// prefer real data over generated data
|
||||
const overlappingStandard = this.byActivity(activity)
|
||||
const overlappingStandard = this.byActivity(
|
||||
activity,
|
||||
)
|
||||
.byMetrics(newStandard.metrics)
|
||||
.getOne();
|
||||
if (!overlappingStandard)
|
||||
@@ -490,12 +493,7 @@ export class Standards {
|
||||
this.activityStandards[activity].standards.filter(
|
||||
(s) => s.metrics.weight,
|
||||
);
|
||||
}
|
||||
|
||||
const weightGenerators = allGenerators.filter(
|
||||
(g) => g.metric === "weight",
|
||||
);
|
||||
for (const weightGenerator of weightGenerators) {
|
||||
} else if (generator.metric === "weight") {
|
||||
for (const gender of Object.values(Gender)) {
|
||||
for (const age of this.agesFor(activity, gender)) {
|
||||
const weightStep = 12;
|
||||
@@ -508,7 +506,11 @@ export class Standards {
|
||||
const maxWeight = referenceWeight + 3 * weightStep;
|
||||
|
||||
const referenceStandard = this.byActivity(activity)
|
||||
.byMetrics({ weight: referenceWeight, gender, age })
|
||||
.byMetrics({
|
||||
weight: referenceWeight,
|
||||
gender,
|
||||
age,
|
||||
})
|
||||
.getOneInterpolated();
|
||||
|
||||
let currWeight = minWeight;
|
||||
@@ -524,10 +526,12 @@ export class Standards {
|
||||
|
||||
// apply allometric scaling to generate levels
|
||||
for (const lvl in referenceStandard.levels) {
|
||||
if (!referenceStandard.levels[lvl]) continue;
|
||||
if (!referenceStandard.levels[lvl])
|
||||
continue;
|
||||
|
||||
const scalingExponent =
|
||||
this.cfg.activity[activity].weightModifier;
|
||||
this.cfg.activity[activity]
|
||||
.weightModifier;
|
||||
const coefficient =
|
||||
currWeight / referenceWeight;
|
||||
|
||||
@@ -543,9 +547,9 @@ export class Standards {
|
||||
.byMetrics(newStandard.metrics)
|
||||
.getOne();
|
||||
if (!overlappingStandard)
|
||||
this.activityStandards[activity].standards.push(
|
||||
newStandard,
|
||||
);
|
||||
this.activityStandards[
|
||||
activity
|
||||
].standards.push(newStandard);
|
||||
|
||||
currWeight += weightStep;
|
||||
}
|
||||
@@ -558,6 +562,7 @@ export class Standards {
|
||||
(s) => s.metrics.weight,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
this.activityStandards[activity].standards = this.activityStandards[
|
||||
activity
|
||||
|
||||
Reference in New Issue
Block a user