Standards domain models shuffling and renaming
This commit is contained in:
@@ -213,7 +213,7 @@ export class LevelCalculator {
|
||||
}
|
||||
}
|
||||
|
||||
const StandardsActivityConfigSchema = Type.Object({
|
||||
const StandardsActivityParametersSchema = Type.Object({
|
||||
weightModifier: Type.Number(),
|
||||
weightSkew: Type.Number(),
|
||||
ageModifier: Type.Number(),
|
||||
@@ -226,22 +226,22 @@ const StandardsActivityConfigSchema = Type.Object({
|
||||
}),
|
||||
});
|
||||
|
||||
export const StandardsConfigSchema = Type.Object({
|
||||
export const StandardsParametersSchema = Type.Object({
|
||||
global: Type.Object({
|
||||
maxLevel: Type.Number(),
|
||||
}),
|
||||
activity: Type.Record(Type.Enum(Activity), StandardsActivityConfigSchema),
|
||||
activity: Type.Record(Type.Enum(Activity), StandardsActivityParametersSchema),
|
||||
});
|
||||
|
||||
export type StandardsConfig = Static<typeof StandardsConfigSchema>;
|
||||
export type StandardsParameters = Static<typeof StandardsParametersSchema>;
|
||||
|
||||
export class Standards {
|
||||
readonly cfg: StandardsConfig;
|
||||
readonly params: StandardsParameters;
|
||||
private standardsData: StandardsData;
|
||||
|
||||
constructor(standardsData: StandardsData, cfg?: Partial<StandardsConfig>) {
|
||||
Value.Assert(StandardsConfigSchema, defaultConfig);
|
||||
this.cfg = Object.assign({}, defaultConfig, cfg);
|
||||
constructor(standardsData: StandardsData, params?: Partial<StandardsParameters>) {
|
||||
Value.Assert(StandardsParametersSchema, defaultConfig);
|
||||
this.params = Object.assign({}, defaultConfig, params);
|
||||
|
||||
// prepare data
|
||||
this.standardsData = structuredClone(standardsData);
|
||||
@@ -254,7 +254,7 @@ export class Standards {
|
||||
return (i: number) => A * Math.exp(-B * i) + C;
|
||||
}
|
||||
|
||||
if (!this.cfg.activity[activity].enableGeneration) {
|
||||
if (!this.params.activity[activity].enableGeneration) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -314,13 +314,13 @@ export class Standards {
|
||||
const newLevels: Levels = {};
|
||||
const newLowerLevelCount = Math.max(
|
||||
Math.round(
|
||||
this.cfg.activity[activity].stretch.lower,
|
||||
this.params.activity[activity].stretch.lower,
|
||||
),
|
||||
0,
|
||||
);
|
||||
const newUpperLevelCount = Math.max(
|
||||
Math.round(
|
||||
this.cfg.activity[activity].stretch.upper,
|
||||
this.params.activity[activity].stretch.upper,
|
||||
),
|
||||
0,
|
||||
);
|
||||
@@ -362,7 +362,7 @@ export class Standards {
|
||||
let i = 1;
|
||||
while (
|
||||
Object.keys(standard.levels).length <
|
||||
this.cfg.global.maxLevel
|
||||
this.params.global.maxLevel
|
||||
) {
|
||||
standard.levels = this.expandLevels(standard.levels, i++);
|
||||
}
|
||||
@@ -370,11 +370,11 @@ export class Standards {
|
||||
// compress
|
||||
if (
|
||||
Object.keys(standard.levels).length >
|
||||
this.cfg.global.maxLevel
|
||||
this.params.global.maxLevel
|
||||
) {
|
||||
standard.levels = this.compressLevels(
|
||||
standard.levels,
|
||||
this.cfg.global.maxLevel,
|
||||
this.params.global.maxLevel,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -382,12 +382,12 @@ export class Standards {
|
||||
for (const level in standard.levels) {
|
||||
standard.levels[level] =
|
||||
standard.levels[level] *
|
||||
(1 + this.cfg.activity[activity].difficultyModifier);
|
||||
(1 + this.params.activity[activity].difficultyModifier);
|
||||
}
|
||||
}
|
||||
|
||||
// generate data
|
||||
const allGenerators = this.cfg.activity[activity].enableGeneration
|
||||
const allGenerators = this.params.activity[activity].enableGeneration
|
||||
? this.standardsData[activity].metadata.generators.sort(
|
||||
(a, b) =>
|
||||
metricPriority(a.metric) - metricPriority(b.metric),
|
||||
@@ -397,7 +397,7 @@ export class Standards {
|
||||
for (const generator of allGenerators) {
|
||||
if (generator.metric === "age") {
|
||||
for (const gender of Object.values(Gender)) {
|
||||
const peakAge = this.cfg.activity[activity].peakAge;
|
||||
const peakAge = this.params.activity[activity].peakAge;
|
||||
const ageStep = 10;
|
||||
|
||||
const minAge = 0;
|
||||
@@ -427,7 +427,7 @@ export class Standards {
|
||||
if (base == null) continue;
|
||||
|
||||
const ageModifier =
|
||||
this.cfg.activity[activity].ageModifier;
|
||||
this.params.activity[activity].ageModifier;
|
||||
|
||||
const leftSpan = peakAge - minAge;
|
||||
const rightSpan = maxAge - peakAge;
|
||||
@@ -515,7 +515,7 @@ export class Standards {
|
||||
continue;
|
||||
|
||||
const scalingExponent =
|
||||
this.cfg.activity[activity]
|
||||
this.params.activity[activity]
|
||||
.weightModifier;
|
||||
const coefficient =
|
||||
currWeight / referenceWeight;
|
||||
|
||||
Reference in New Issue
Block a user