add total income / total expense / net income to value metric in insights explorer

This commit is contained in:
MaysWind
2026-04-15 00:28:47 +08:00
parent 36d82254d6
commit 53702e68d8
2 changed files with 20 additions and 0 deletions
+6
View File
@@ -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<string, TransactionExplorerValueMetric> = {};
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);
+14
View File
@@ -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) {