Minor code cleanup
This commit is contained in:
@@ -10,7 +10,6 @@ export class CalculatorUnavailableError extends Error {
|
|||||||
|
|
||||||
export class CalculatorService {
|
export class CalculatorService {
|
||||||
private calculator: LevelCalculator | null = null;
|
private calculator: LevelCalculator | null = null;
|
||||||
private appliedConfigStringified: string | null = null;
|
|
||||||
Standards: StandardsService = new StandardsService();
|
Standards: StandardsService = new StandardsService();
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -26,18 +25,16 @@ export class CalculatorService {
|
|||||||
|
|
||||||
private async refresh(): Promise<void> {
|
private async refresh(): Promise<void> {
|
||||||
const standardsConfig = await this.Standards.Config.get();
|
const standardsConfig = await this.Standards.Config.get();
|
||||||
const standardsConfigStringified = JSON.stringify(standardsConfig);
|
|
||||||
|
|
||||||
if (this.calculator) {
|
if (this.calculator) {
|
||||||
// avoid instatiating a new Standards object if nothing changed
|
// avoid instantiating a new Standards object if nothing changed
|
||||||
if (standardsConfigStringified === this.appliedConfigStringified) return;
|
if (JSON.stringify(standardsConfig) === JSON.stringify(this.calculator.standards.cfg)) return;
|
||||||
|
|
||||||
this.calculator.Standards = new Standards(standardsConfig);
|
this.calculator.standards = new Standards(standardsConfig);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.calculator = new LevelCalculator(new Standards(standardsConfig));
|
this.calculator = new LevelCalculator(new Standards(standardsConfig));
|
||||||
}
|
}
|
||||||
this.appliedConfigStringified = standardsConfigStringified;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,10 +32,10 @@ const metricPriority = (m: NumberMetric) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export class LevelCalculator {
|
export class LevelCalculator {
|
||||||
Standards: Standards;
|
standards: Standards;
|
||||||
|
|
||||||
public constructor(standards: Standards) {
|
public constructor(standards: Standards) {
|
||||||
this.Standards = standards;
|
this.standards = standards;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------------
|
||||||
@@ -97,7 +97,7 @@ export class LevelCalculator {
|
|||||||
(Object.values(Attribute) as Attribute[]).forEach((attribute) => {
|
(Object.values(Attribute) as Attribute[]).forEach((attribute) => {
|
||||||
const attrActivityPerformances = activityPerformances.filter(
|
const attrActivityPerformances = activityPerformances.filter(
|
||||||
(p) =>
|
(p) =>
|
||||||
this.Standards.byActivity(p.activity).getMetadata()
|
this.standards.byActivity(p.activity).getMetadata()
|
||||||
.attribute === attribute,
|
.attribute === attribute,
|
||||||
);
|
);
|
||||||
attrLevels[attribute] = this.calculateAttributeLevel(
|
attrLevels[attribute] = this.calculateAttributeLevel(
|
||||||
@@ -119,7 +119,7 @@ export class LevelCalculator {
|
|||||||
if (
|
if (
|
||||||
activityPerformances.some(
|
activityPerformances.some(
|
||||||
(p) =>
|
(p) =>
|
||||||
this.Standards.byActivity(p.activity).getMetadata()
|
this.standards.byActivity(p.activity).getMetadata()
|
||||||
.attribute !== attribute,
|
.attribute !== attribute,
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
@@ -127,7 +127,7 @@ export class LevelCalculator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// must perform all of an attributes activities
|
// must perform all of an attributes activities
|
||||||
for (const activity of this.Standards.getAttributeActivities(
|
for (const activity of this.standards.getAttributeActivities(
|
||||||
attribute,
|
attribute,
|
||||||
)) {
|
)) {
|
||||||
const filteredActivites = activityPerformances.map(
|
const filteredActivites = activityPerformances.map(
|
||||||
@@ -142,7 +142,7 @@ export class LevelCalculator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const activityLevels = activityPerformances.map((p) => {
|
const activityLevels = activityPerformances.map((p) => {
|
||||||
const interpolatedStandard = this.Standards
|
const interpolatedStandard = this.standards
|
||||||
.byActivity(p.activity)
|
.byActivity(p.activity)
|
||||||
.byMetrics(player.metrics)
|
.byMetrics(player.metrics)
|
||||||
.getOneInterpolated();
|
.getOneInterpolated();
|
||||||
|
|||||||
Reference in New Issue
Block a user