From eee81d2122a3d3b9140236a92c91107ebc0cd586 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Tue, 24 Jun 2025 19:15:57 +0200 Subject: [PATCH] Refactoring --- .../current-investment.ts | 30 +++++++++---------- apps/client/src/app/pages/i18n/i18n-page.html | 8 ++--- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/apps/api/src/models/rules/account-cluster-risk/current-investment.ts b/apps/api/src/models/rules/account-cluster-risk/current-investment.ts index fb2ffac8d..501c9b803 100644 --- a/apps/api/src/models/rules/account-cluster-risk/current-investment.ts +++ b/apps/api/src/models/rules/account-cluster-risk/current-investment.ts @@ -2,11 +2,9 @@ import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.in import { Rule } from '@ghostfolio/api/models/rule'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service'; import { I18nService } from '@ghostfolio/api/services/i18n/i18n.service'; -import { - PortfolioDetails, - PortfolioPosition, - UserSettings -} from '@ghostfolio/common/interfaces'; +import { PortfolioDetails, UserSettings } from '@ghostfolio/common/interfaces'; + +import { Account } from '@prisma/client'; export class AccountClusterRiskCurrentInvestment extends Rule { private accounts: PortfolioDetails['accounts']; @@ -27,36 +25,36 @@ export class AccountClusterRiskCurrentInvestment extends Rule { public evaluate(ruleSettings: Settings) { const accounts: { - [symbol: string]: Pick & { + [symbol: string]: Pick & { investment: number; }; } = {}; for (const [accountId, account] of Object.entries(this.accounts)) { accounts[accountId] = { - name: account.name, - investment: account.valueInBaseCurrency + investment: account.valueInBaseCurrency, + name: account.name }; } - let maxItem: (typeof accounts)[0]; + let maxAccount: (typeof accounts)[0]; let totalInvestment = 0; for (const account of Object.values(accounts)) { - if (!maxItem) { - maxItem = account; + if (!maxAccount) { + maxAccount = account; } // Calculate total investment totalInvestment += account.investment; // Find maximum - if (account.investment > maxItem?.investment) { - maxItem = account; + if (account.investment > maxAccount?.investment) { + maxAccount = account; } } - const maxInvestmentRatio = maxItem?.investment / totalInvestment || 0; + const maxInvestmentRatio = maxAccount?.investment / totalInvestment || 0; if (maxInvestmentRatio > ruleSettings.thresholdMax) { return { @@ -64,8 +62,8 @@ export class AccountClusterRiskCurrentInvestment extends Rule { id: 'rule.accountClusterRiskCurrentInvestment.false', languageCode: this.getLanguageCode(), placeholders: { + maxAccountName: maxAccount.name, maxInvestmentRatio: (maxInvestmentRatio * 100).toPrecision(3), - maxItemName: maxItem.name, thresholdMax: ruleSettings.thresholdMax * 100 } }), @@ -78,8 +76,8 @@ export class AccountClusterRiskCurrentInvestment extends Rule { id: 'rule.accountClusterRiskCurrentInvestment.true', languageCode: this.getLanguageCode(), placeholders: { + maxAccountName: maxAccount.name, maxInvestmentRatio: (maxInvestmentRatio * 100).toPrecision(3), - maxItemName: maxItem.name, thresholdMax: ruleSettings.thresholdMax * 100 } }), diff --git a/apps/client/src/app/pages/i18n/i18n-page.html b/apps/client/src/app/pages/i18n/i18n-page.html index e4445bc01..20fa23f9a 100644 --- a/apps/client/src/app/pages/i18n/i18n-page.html +++ b/apps/client/src/app/pages/i18n/i18n-page.html @@ -14,12 +14,12 @@
  • Investment
  • Over ${thresholdMax}% of your current investment is at - ${maxItemName} (${maxInvestmentRatio}%) + ${maxAccountName} (${maxInvestmentRatio}%)
  • - The major part of your current investment is at ${maxItemName} - (${maxInvestmentRatio}%) and does not exceed - ${thresholdMax}% + The major part of your current investment is at + ${maxAccountName} (${maxInvestmentRatio}%) and does + not exceed ${thresholdMax}%
  • Single Account