Calculator UI simplification
This commit is contained in:
@@ -10,22 +10,22 @@ export class CalculatorService {
|
|||||||
private cachedStandardsConfigData: string | null = null;
|
private cachedStandardsConfigData: string | null = null;
|
||||||
private lastRefreshedAt = 0;
|
private lastRefreshedAt = 0;
|
||||||
|
|
||||||
private levelCalculator: LevelCalculator;
|
private calculator: LevelCalculator;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.levelCalculator = new LevelCalculator(new Standards(DEFAULT_STANDARDS_DATA));
|
this.calculator = new LevelCalculator(new Standards(DEFAULT_STANDARDS_DATA));
|
||||||
}
|
}
|
||||||
|
|
||||||
calculate(player: Player, activityPerformances: ActivityPerformance[]) {
|
calculate(player: Player, activityPerformances: ActivityPerformance[]) {
|
||||||
this.refreshConfig({ onlyIfStale: true }).catch((err) => log.error({ err }, "failed to refresh calculator config"));
|
this.refreshConfig({ onlyIfStale: true }).catch((err) => log.error({ err }, "failed to refresh calculator config"));
|
||||||
return this.levelCalculator.calculate(player, activityPerformances);
|
return this.calculator.calculate(player, activityPerformances);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSelectedConfig(opt: { skipCache?: boolean } = {}): Promise<StandardsConfig> {
|
async getSelectedConfig(opt: { skipCache?: boolean } = {}): Promise<StandardsConfig> {
|
||||||
if (!opt.skipCache) return this.levelCalculator.standards.cfg;
|
if (!opt.skipCache) return this.calculator.standards.cfg;
|
||||||
|
|
||||||
await this.refreshConfig();
|
await this.refreshConfig();
|
||||||
return this.levelCalculator.standards.cfg;
|
return this.calculator.standards.cfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
async selectConfig(id: string) {
|
async selectConfig(id: string) {
|
||||||
@@ -72,7 +72,7 @@ export class CalculatorService {
|
|||||||
const standardsConfigData = JSON.stringify(result.standards_config);
|
const standardsConfigData = JSON.stringify(result.standards_config);
|
||||||
if (standardsConfigData === this.cachedStandardsConfigData) return;
|
if (standardsConfigData === this.cachedStandardsConfigData) return;
|
||||||
|
|
||||||
this.levelCalculator = new LevelCalculator(new Standards(DEFAULT_STANDARDS_DATA, result.standards_config));
|
this.calculator = new LevelCalculator(new Standards(DEFAULT_STANDARDS_DATA, result.standards_config));
|
||||||
this.cachedStandardsConfigData = standardsConfigData;
|
this.cachedStandardsConfigData = standardsConfigData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,89 +17,24 @@
|
|||||||
|
|
||||||
const defaultStandards = new Standards(DEFAULT_STANDARDS_DATA);
|
const defaultStandards = new Standards(DEFAULT_STANDARDS_DATA);
|
||||||
|
|
||||||
// TODO: try to clean this up
|
|
||||||
let input = $state({
|
let input = $state({
|
||||||
activity: Activity.BenchPress,
|
activity: Activity.BenchPress,
|
||||||
metrics: {
|
metrics: {
|
||||||
gender: Gender.Male,
|
gender: Gender.Male,
|
||||||
age: "",
|
age: null as number | null,
|
||||||
weight: "",
|
weight: null as number | null, // lb
|
||||||
},
|
|
||||||
cfg: {
|
|
||||||
global: {
|
|
||||||
maxLevel: String(defaultStandards.cfg.global.maxLevel),
|
|
||||||
},
|
|
||||||
activity: Object.fromEntries(
|
|
||||||
Object.values(Activity).map((activity) => {
|
|
||||||
return [
|
|
||||||
activity,
|
|
||||||
{
|
|
||||||
enableGeneration:
|
|
||||||
defaultStandards.cfg.activity[activity]
|
|
||||||
.enableGeneration,
|
|
||||||
weightAdvantage: String(
|
|
||||||
defaultStandards.cfg.activity[activity]
|
|
||||||
.weightModifier,
|
|
||||||
),
|
|
||||||
ageModifier: String(
|
|
||||||
defaultStandards.cfg.activity[activity]
|
|
||||||
.ageModifier,
|
|
||||||
),
|
|
||||||
difficultyModifier: String(
|
|
||||||
defaultStandards.cfg.activity[activity]
|
|
||||||
.difficultyModifier,
|
|
||||||
),
|
|
||||||
peakAge: String(
|
|
||||||
defaultStandards.cfg.activity[activity].peakAge,
|
|
||||||
),
|
|
||||||
stretch: {
|
|
||||||
upper: String(
|
|
||||||
defaultStandards.cfg.activity[activity]
|
|
||||||
.stretch.upper,
|
|
||||||
),
|
|
||||||
lower: String(
|
|
||||||
defaultStandards.cfg.activity[activity]
|
|
||||||
.stretch.lower,
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
|
cfg: structuredClone(defaultStandards.cfg) as StandardsConfig,
|
||||||
});
|
});
|
||||||
|
|
||||||
const selected = $derived({
|
const selected = $derived({
|
||||||
activity: input.activity,
|
activity: input.activity,
|
||||||
metrics: {
|
metrics: {
|
||||||
gender: input.metrics.gender,
|
gender: input.metrics.gender,
|
||||||
age: +input.metrics.age,
|
age: input.metrics.age ?? 0,
|
||||||
weight: lbToKg(+input.metrics.weight),
|
weight: lbToKg(input.metrics.weight ?? 0),
|
||||||
} as Metrics,
|
} as Metrics,
|
||||||
cfg: {
|
cfg: input.cfg,
|
||||||
global: {
|
|
||||||
maxLevel: +input.cfg.global.maxLevel,
|
|
||||||
},
|
|
||||||
activity: Object.fromEntries(
|
|
||||||
Object.values(Activity).map((activity) => [
|
|
||||||
activity,
|
|
||||||
{
|
|
||||||
weightModifier:
|
|
||||||
+input.cfg.activity[activity].weightAdvantage,
|
|
||||||
ageModifier: +input.cfg.activity[activity].ageModifier,
|
|
||||||
enableGeneration:
|
|
||||||
input.cfg.activity[activity].enableGeneration,
|
|
||||||
difficultyModifier:
|
|
||||||
+input.cfg.activity[activity].difficultyModifier,
|
|
||||||
peakAge: +input.cfg.activity[activity].peakAge,
|
|
||||||
stretch: {
|
|
||||||
lower: +input.cfg.activity[activity].stretch.lower,
|
|
||||||
upper: +input.cfg.activity[activity].stretch.upper,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
),
|
|
||||||
} as StandardsConfig,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const allStandards = $derived(
|
const allStandards = $derived(
|
||||||
@@ -184,7 +119,7 @@
|
|||||||
placeholder=".1"
|
placeholder=".1"
|
||||||
bind:value={
|
bind:value={
|
||||||
input.cfg.activity[selected.activity]
|
input.cfg.activity[selected.activity]
|
||||||
.weightAdvantage
|
.weightModifier
|
||||||
}
|
}
|
||||||
disabled={!selected.cfg.activity[selected.activity]
|
disabled={!selected.cfg.activity[selected.activity]
|
||||||
.enableGeneration}
|
.enableGeneration}
|
||||||
|
|||||||
Reference in New Issue
Block a user