Browse Source

Add threshold configuration

pull/3898/head
Thomas Kaul 11 months ago
parent
commit
109b2d0fc4
  1. 6
      apps/api/src/app/portfolio/rules.service.ts
  2. 10
      apps/api/src/models/rule.ts
  3. 11
      apps/api/src/models/rules/account-cluster-risk/current-investment.ts
  4. 4
      apps/api/src/models/rules/account-cluster-risk/single-account.ts
  5. 4
      apps/api/src/models/rules/currency-cluster-risk/base-currency-current-investment.ts
  6. 11
      apps/api/src/models/rules/currency-cluster-risk/current-investment.ts
  7. 4
      apps/api/src/models/rules/emergency-fund/emergency-fund-setup.ts
  8. 11
      apps/api/src/models/rules/fees/fee-ratio-initial-investment.ts
  9. 9
      libs/common/src/lib/interfaces/portfolio-report-rule.interface.ts

6
apps/api/src/app/portfolio/rules.service.ts

@ -6,7 +6,6 @@ import {
} from '@ghostfolio/common/interfaces';
import { Injectable } from '@nestjs/common';
import { isNumber } from 'lodash';
@Injectable()
export class RulesService {
@ -25,10 +24,7 @@ export class RulesService {
return {
evaluation,
value,
configuration: {
thresholdMax: isNumber(settings['thresholdMax']) ? true : false,
thresholdMin: isNumber(settings['thresholdMin']) ? true : false
} as PortfolioReportRule['configuration'],
configuration: rule.getConfiguration(),
isActive: true,
key: rule.getKey(),
name: rule.getName()

10
apps/api/src/models/rule.ts

@ -1,7 +1,11 @@
import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface';
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service';
import { groupBy } from '@ghostfolio/common/helper';
import { PortfolioPosition, UserSettings } from '@ghostfolio/common/interfaces';
import {
PortfolioPosition,
PortfolioReportRule,
UserSettings
} from '@ghostfolio/common/interfaces';
import { Big } from 'big.js';
@ -65,5 +69,9 @@ export abstract class Rule<T extends RuleSettings> implements RuleInterface<T> {
public abstract evaluate(aRuleSettings: T): EvaluationResult;
public abstract getConfiguration(): Partial<
PortfolioReportRule['configuration']
>;
public abstract getSettings(aUserSettings: UserSettings): T;
}

11
apps/api/src/models/rules/account-cluster-risk/current-investment.ts

@ -76,6 +76,17 @@ export class AccountClusterRiskCurrentInvestment extends Rule<Settings> {
};
}
public getConfiguration() {
return {
threshold: {
max: 1,
min: 0,
step: 0.01
},
thresholdMax: true
};
}
public getSettings({ baseCurrency, xRayRules }: UserSettings): Settings {
return {
baseCurrency,

4
apps/api/src/models/rules/account-cluster-risk/single-account.ts

@ -34,6 +34,10 @@ export class AccountClusterRiskSingleAccount extends Rule<RuleSettings> {
};
}
public getConfiguration() {
return {};
}
public getSettings({ xRayRules }: UserSettings): RuleSettings {
return {
isActive: xRayRules?.[this.getKey()].isActive ?? true

4
apps/api/src/models/rules/currency-cluster-risk/base-currency-current-investment.ts

@ -61,6 +61,10 @@ export class CurrencyClusterRiskBaseCurrencyCurrentInvestment extends Rule<Setti
};
}
public getConfiguration() {
return {};
}
public getSettings({ baseCurrency, xRayRules }: UserSettings): Settings {
return {
baseCurrency,

11
apps/api/src/models/rules/currency-cluster-risk/current-investment.ts

@ -61,6 +61,17 @@ export class CurrencyClusterRiskCurrentInvestment extends Rule<Settings> {
};
}
public getConfiguration() {
return {
threshold: {
max: 1,
min: 0,
step: 0.01
},
thresholdMax: true
};
}
public getSettings({ baseCurrency, xRayRules }: UserSettings): Settings {
return {
baseCurrency,

4
apps/api/src/models/rules/emergency-fund/emergency-fund-setup.ts

@ -32,6 +32,10 @@ export class EmergencyFundSetup extends Rule<Settings> {
};
}
public getConfiguration() {
return {};
}
public getSettings({ baseCurrency, xRayRules }: UserSettings): Settings {
return {
baseCurrency,

11
apps/api/src/models/rules/fees/fee-ratio-initial-investment.ts

@ -43,6 +43,17 @@ export class FeeRatioInitialInvestment extends Rule<Settings> {
};
}
public getConfiguration() {
return {
threshold: {
max: 0.1,
min: 0,
step: 0.005
},
thresholdMax: true
};
}
public getSettings({ baseCurrency, xRayRules }: UserSettings): Settings {
return {
baseCurrency,

9
libs/common/src/lib/interfaces/portfolio-report-rule.interface.ts

@ -1,7 +1,12 @@
export interface PortfolioReportRule {
configuration?: {
thresholdMax: boolean;
thresholdMin: boolean;
threshold?: {
max: number;
min: number;
step: number;
};
thresholdMax?: boolean;
thresholdMin?: boolean;
};
evaluation?: string;
isActive: boolean;

Loading…
Cancel
Save