mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 01:04:25 +08:00
hide some statistics when the number of transactions is not enough
This commit is contained in:
+25
-22
@@ -120,14 +120,14 @@ export interface InsightsExplorerTransactionStatisticData {
|
||||
averageAmount: number;
|
||||
medianAmount: number;
|
||||
p90Amount: number;
|
||||
top5AmountShare: number;
|
||||
transactionsFor80PercentAmount: number;
|
||||
top5AmountShare?: number;
|
||||
transactionsFor80PercentAmount?: number;
|
||||
minimumAmount: number;
|
||||
maximumAmount: number;
|
||||
range: number;
|
||||
interquartileRange: number;
|
||||
variance: number;
|
||||
standardDeviation: number;
|
||||
variance?: number;
|
||||
standardDeviation?: number;
|
||||
}
|
||||
|
||||
export const useExplorersStore = defineStore('explorers', () => {
|
||||
@@ -607,14 +607,14 @@ export const useExplorersStore = defineStore('explorers', () => {
|
||||
averageAmount: 0,
|
||||
medianAmount: 0,
|
||||
p90Amount: 0,
|
||||
top5AmountShare: 0,
|
||||
transactionsFor80PercentAmount: 0,
|
||||
top5AmountShare: undefined,
|
||||
transactionsFor80PercentAmount: undefined,
|
||||
minimumAmount: Number.MAX_SAFE_INTEGER,
|
||||
maximumAmount: Number.MIN_SAFE_INTEGER,
|
||||
range: 0,
|
||||
interquartileRange: 0,
|
||||
variance: 0,
|
||||
standardDeviation: 0
|
||||
variance: undefined,
|
||||
standardDeviation: undefined
|
||||
};
|
||||
|
||||
const sourceAmounts: number[] = [];
|
||||
@@ -670,26 +670,29 @@ export const useExplorersStore = defineStore('explorers', () => {
|
||||
const top5Count = Math.ceil(sourceAmounts.length * 0.05);
|
||||
const top5AmountSum = sourceAmounts.slice(-top5Count).reduce((sum, amount) => sum + amount, 0);
|
||||
statisticData.top5AmountShare = statisticData.totalAmount > 0 ? 100.0 * top5AmountSum / statisticData.totalAmount : 0;
|
||||
} else {
|
||||
statisticData.top5AmountShare = 100.0;
|
||||
}
|
||||
|
||||
const eightyPercentAmountThreshold: number = 0.8 * statisticData.totalAmount;
|
||||
let cumulativeAmount: number = 0;
|
||||
let cumulativeCount: number = 0;
|
||||
for (const amount of reversed(sourceAmounts)) {
|
||||
cumulativeAmount += amount;
|
||||
cumulativeCount++;
|
||||
if (sourceAmounts.length > 0) {
|
||||
const eightyPercentAmountThreshold: number = 0.8 * statisticData.totalAmount;
|
||||
let cumulativeAmount: number = 0;
|
||||
let cumulativeCount: number = 0;
|
||||
for (const amount of reversed(sourceAmounts)) {
|
||||
cumulativeAmount += amount;
|
||||
cumulativeCount++;
|
||||
|
||||
if (cumulativeAmount >= eightyPercentAmountThreshold) {
|
||||
statisticData.transactionsFor80PercentAmount = 100.0 * cumulativeCount / statisticData.totalCount;
|
||||
break;
|
||||
if (cumulativeAmount >= eightyPercentAmountThreshold) {
|
||||
statisticData.transactionsFor80PercentAmount = 100.0 * cumulativeCount / statisticData.totalCount;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const sumOfSquaredDifferences: number = sourceAmounts.reduce((sum, amount) => sum + Math.pow(amount / 100.0 - statisticData.averageAmount / 100.0, 2), 0);
|
||||
statisticData.variance = sourceAmounts.length > 0 ? sumOfSquaredDifferences / sourceAmounts.length : 0;
|
||||
statisticData.standardDeviation = Math.sqrt(statisticData.variance);
|
||||
if (statisticData.totalCount > 0 && sourceAmounts.length > 0) {
|
||||
const averageAmountForVarianceCalculation: number = statisticData.totalAmount / statisticData.totalCount / 100.0;
|
||||
const sumOfSquaredDifferences: number = sourceAmounts.reduce((sum, amount) => sum + Math.pow(amount / 100.0 - averageAmountForVarianceCalculation, 2), 0);
|
||||
statisticData.variance = sumOfSquaredDifferences / sourceAmounts.length;
|
||||
statisticData.standardDeviation = Math.sqrt(statisticData.variance);
|
||||
}
|
||||
|
||||
return statisticData;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user