Restructuring default config for standards
This commit is contained in:
@@ -10,11 +10,11 @@ import {
|
||||
type Player,
|
||||
} from "@blade-and-brawn/domain";
|
||||
import { levenbergMarquardt as LM } from "ml-levenberg-marquardt";
|
||||
import defaultConfig from "./default-config.json" with { type: "json" };
|
||||
import defaultStandardsData from "./data/default-standards.json" with { type: "json" };
|
||||
import defaultStandardsParamsJson from "./data/standards/default-params.json" with { type: "json" };
|
||||
import defaultStandardsDataJson from "./data/standards/default-data.json" with { type: "json" };
|
||||
import { getAvgWeight } from "./avg-weights";
|
||||
import { StandardsDataSchema, StandardsParamsSchema, type LevelCalculatorOutput, type Levels, type NumberMetric, type Standard, type StandardsConfig, type StandardsData } from "./models";
|
||||
import { Value } from "@sinclair/typebox/value";
|
||||
import { StandardsParamsSchema, type LevelCalculatorOutput, type Levels, type NumberMetric, type Standard, type StandardsData, type StandardsParams } from "./models";
|
||||
|
||||
// SOURCES
|
||||
// Squat, Bench, Dead Lift:
|
||||
@@ -34,8 +34,12 @@ const metricPriority = (m: NumberMetric) => {
|
||||
return 2;
|
||||
};
|
||||
|
||||
export const DEFAULT_STANDARDS_DATA = defaultStandardsData as StandardsData;
|
||||
export const DEFAULT_STANDARDS_PARAMS = defaultConfig as StandardsParams;
|
||||
Value.Assert(StandardsDataSchema, defaultStandardsDataJson);
|
||||
Value.Assert(StandardsParamsSchema, defaultStandardsParamsJson);
|
||||
export const DEFAULT_STANDARDS_CONFIG: StandardsConfig = {
|
||||
data: defaultStandardsDataJson,
|
||||
params: defaultStandardsParamsJson
|
||||
};
|
||||
|
||||
export class LevelCalculator {
|
||||
Standards: Standards;
|
||||
@@ -185,15 +189,11 @@ export class LevelCalculator {
|
||||
}
|
||||
|
||||
export class Standards {
|
||||
readonly params: StandardsParams;
|
||||
private data: StandardsData;
|
||||
|
||||
constructor(data: StandardsData, params?: Partial<StandardsParams>) {
|
||||
Value.Assert(StandardsParamsSchema, defaultConfig);
|
||||
this.params = Object.assign({}, defaultConfig, params);
|
||||
|
||||
// prepare data
|
||||
this.data = structuredClone(data);
|
||||
constructor(readonly cfg: StandardsConfig) {
|
||||
// prepare internal data for modification
|
||||
this.data = structuredClone(cfg.data);
|
||||
|
||||
// STRETCH
|
||||
for (const activity of Object.values(Activity)) {
|
||||
@@ -203,7 +203,7 @@ export class Standards {
|
||||
return (i: number) => A * Math.exp(-B * i) + C;
|
||||
}
|
||||
|
||||
if (!this.params.activity[activity].enableGeneration) {
|
||||
if (!cfg.params.activity[activity].enableGeneration) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -263,13 +263,13 @@ export class Standards {
|
||||
const newLevels: Levels = {};
|
||||
const newLowerLevelCount = Math.max(
|
||||
Math.round(
|
||||
this.params.activity[activity].stretch.lower,
|
||||
cfg.params.activity[activity].stretch.lower,
|
||||
),
|
||||
0,
|
||||
);
|
||||
const newUpperLevelCount = Math.max(
|
||||
Math.round(
|
||||
this.params.activity[activity].stretch.upper,
|
||||
cfg.params.activity[activity].stretch.upper,
|
||||
),
|
||||
0,
|
||||
);
|
||||
@@ -311,7 +311,7 @@ export class Standards {
|
||||
let i = 1;
|
||||
while (
|
||||
Object.keys(standard.levels).length <
|
||||
this.params.global.maxLevel
|
||||
cfg.params.global.maxLevel
|
||||
) {
|
||||
standard.levels = this.expandLevels(standard.levels, i++);
|
||||
}
|
||||
@@ -319,11 +319,11 @@ export class Standards {
|
||||
// compress
|
||||
if (
|
||||
Object.keys(standard.levels).length >
|
||||
this.params.global.maxLevel
|
||||
cfg.params.global.maxLevel
|
||||
) {
|
||||
standard.levels = this.compressLevels(
|
||||
standard.levels,
|
||||
this.params.global.maxLevel,
|
||||
cfg.params.global.maxLevel,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -331,12 +331,12 @@ export class Standards {
|
||||
for (const level in standard.levels) {
|
||||
standard.levels[level] =
|
||||
standard.levels[level] *
|
||||
(1 + this.params.activity[activity].difficultyModifier);
|
||||
(1 + cfg.params.activity[activity].difficultyModifier);
|
||||
}
|
||||
}
|
||||
|
||||
// generate data
|
||||
const allGenerators = this.params.activity[activity].enableGeneration
|
||||
const allGenerators = cfg.params.activity[activity].enableGeneration
|
||||
? this.data[activity].metadata.generators.sort(
|
||||
(a, b) =>
|
||||
metricPriority(a.metric) - metricPriority(b.metric),
|
||||
@@ -346,7 +346,7 @@ export class Standards {
|
||||
for (const generator of allGenerators) {
|
||||
if (generator.metric === "age") {
|
||||
for (const gender of Object.values(Gender)) {
|
||||
const peakAge = this.params.activity[activity].peakAge;
|
||||
const peakAge = cfg.params.activity[activity].peakAge;
|
||||
const ageStep = 10;
|
||||
|
||||
const minAge = 0;
|
||||
@@ -376,7 +376,7 @@ export class Standards {
|
||||
if (base == null) continue;
|
||||
|
||||
const ageModifier =
|
||||
this.params.activity[activity].ageModifier;
|
||||
cfg.params.activity[activity].ageModifier;
|
||||
|
||||
const leftSpan = peakAge - minAge;
|
||||
const rightSpan = maxAge - peakAge;
|
||||
@@ -464,7 +464,7 @@ export class Standards {
|
||||
continue;
|
||||
|
||||
const scalingExponent =
|
||||
this.params.activity[activity]
|
||||
cfg.params.activity[activity]
|
||||
.weightModifier;
|
||||
const coefficient =
|
||||
currWeight / referenceWeight;
|
||||
|
||||
@@ -67,3 +67,9 @@ export const StandardsParamsSchema = t.Object({
|
||||
}))
|
||||
});
|
||||
export type StandardsParams = Static<typeof StandardsParamsSchema>;
|
||||
|
||||
export const StandardsConfigSchema = t.Object({
|
||||
data: StandardsDataSchema,
|
||||
params: StandardsParamsSchema
|
||||
});
|
||||
export type StandardsConfig = Static<typeof StandardsConfigSchema>;
|
||||
|
||||
Reference in New Issue
Block a user