From 53702e68d8ce567b6a8c9f182d8a459e144ed1c7 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Wed, 15 Apr 2026 00:28:47 +0800 Subject: [PATCH] add total income / total expense / net income to value metric in insights explorer --- src/core/explorer.ts | 6 ++++++ src/stores/explorer.ts | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/core/explorer.ts b/src/core/explorer.ts index 31f0cdb5..c50baaca 100644 --- a/src/core/explorer.ts +++ b/src/core/explorer.ts @@ -302,6 +302,9 @@ export class TransactionExplorerDataDimension implements NameValue { export enum TransactionExplorerValueMetricType { TransactionCount = 'transactionCount', SourceAmountSum = 'sourceAmountSum', + SourceIncomeAmountSum = 'sourceIncomeAmountSum', + SourceExpenseAmountSum = 'sourceExpenseAmountSum', + SourceNetIncomeAmountSum = 'sourceNetIncomeAmountSum', SourceAmountAverage = 'sourceAmountAverage', SourceAmountMedian = 'sourceAmountMedian', SourceAmountQ1Amount = 'sourceQ1Amount', @@ -325,6 +328,9 @@ export class TransactionExplorerValueMetric implements NameValue { private static readonly allInstancesByValue: Record = {}; public static readonly TransactionCount = new TransactionExplorerValueMetric('Transaction Count', TransactionExplorerValueMetricType.TransactionCount, false, true); + public static readonly SourceIncomeAmountSum = new TransactionExplorerValueMetric('Total Income', TransactionExplorerValueMetricType.SourceIncomeAmountSum, true, true); + public static readonly SourceExpenseAmountSum = new TransactionExplorerValueMetric('Total Expense', TransactionExplorerValueMetricType.SourceExpenseAmountSum, true, true); + public static readonly SourceNetIncomeAmountSum = new TransactionExplorerValueMetric('Net Income', TransactionExplorerValueMetricType.SourceNetIncomeAmountSum, true, true); public static readonly SourceAmountSum = new TransactionExplorerValueMetric('Total Amount', TransactionExplorerValueMetricType.SourceAmountSum, true, true); public static readonly SourceAmountAverage = new TransactionExplorerValueMetric('Average Amount', TransactionExplorerValueMetricType.SourceAmountAverage, true, true); public static readonly SourceAmountMedian = new TransactionExplorerValueMetric('Median Amount', TransactionExplorerValueMetricType.SourceAmountMedian, true, true); diff --git a/src/stores/explorer.ts b/src/stores/explorer.ts index 3ea8a81d..f7b9188a 100644 --- a/src/stores/explorer.ts +++ b/src/stores/explorer.ts @@ -831,6 +831,8 @@ export const useExplorersStore = defineStore('explorers', () => { for (const seriesTransactions of values(allSeriesTransactions)) { const allSourceAmountsInDefaultCurrency: number[] = []; let totalSourceAmountSumInDefaultCurrency: number = 0; + let totalSourceIncomeAmountSumInDefaultCurrency: number = 0; + let totalSourceExpenseAmountSumInDefaultCurrency: number = 0; let minimumSourceAmountInDefaultCurrency: number = Number.MAX_SAFE_INTEGER; let maximumSourceAmountInDefaultCurrency: number = Number.MIN_SAFE_INTEGER; @@ -850,6 +852,12 @@ export const useExplorersStore = defineStore('explorers', () => { allSourceAmountsInDefaultCurrency.push(amountInDefaultCurrency); totalSourceAmountSumInDefaultCurrency += amountInDefaultCurrency; + if (transaction.type === TransactionType.Income) { + totalSourceIncomeAmountSumInDefaultCurrency += amountInDefaultCurrency; + } else if (transaction.type === TransactionType.Expense) { + totalSourceExpenseAmountSumInDefaultCurrency += amountInDefaultCurrency; + } + if (amountInDefaultCurrency >= 0 && amountInDefaultCurrency < minimumSourceAmountInDefaultCurrency) { minimumSourceAmountInDefaultCurrency = amountInDefaultCurrency; } @@ -865,6 +873,12 @@ export const useExplorersStore = defineStore('explorers', () => { value = allSourceAmountsInDefaultCurrency.length; } else if (valueMetric === TransactionExplorerValueMetric.SourceAmountSum) { value = totalSourceAmountSumInDefaultCurrency; + } else if (valueMetric === TransactionExplorerValueMetric.SourceIncomeAmountSum) { + value = totalSourceIncomeAmountSumInDefaultCurrency; + } else if (valueMetric === TransactionExplorerValueMetric.SourceExpenseAmountSum) { + value = totalSourceExpenseAmountSumInDefaultCurrency; + } else if (valueMetric === TransactionExplorerValueMetric.SourceNetIncomeAmountSum) { + value = totalSourceIncomeAmountSumInDefaultCurrency - totalSourceExpenseAmountSumInDefaultCurrency; } else if (valueMetric === TransactionExplorerValueMetric.SourceAmountAverage) { value = allSourceAmountsInDefaultCurrency.length > 0 ? Math.trunc(totalSourceAmountSumInDefaultCurrency / allSourceAmountsInDefaultCurrency.length) : 0; } else if (valueMetric === TransactionExplorerValueMetric.SourceAmountMedian) {