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