add mean absolute deviation and median absolute deviation to value metric in insights explorer

This commit is contained in:
MaysWind
2026-04-16 01:24:38 +08:00
parent 8f01469a41
commit 1e4bb73874
22 changed files with 85 additions and 0 deletions
+17
View File
@@ -50,6 +50,8 @@ import {
percentile,
sumMaxN,
cumulativePercentage,
meanAbsoluteDeviation,
medianAbsoluteDeviation,
varianceAndStandardDeviation,
coefficientOfVariation,
skewness,
@@ -980,6 +982,21 @@ export const useExplorersStore = defineStore('explorers', () => {
} else {
value = 0;
}
} else if (valueMetric === TransactionExplorerValueMetric.SourceAmountMeanAbsoluteDeviation) {
if (allSourceAmountsInDefaultCurrency.length > 0) {
const averageSourceAmountInDefaultCurrency = totalSourceAmountSumInDefaultCurrency / allSourceAmountsInDefaultCurrency.length;
value = Math.trunc(meanAbsoluteDeviation(allSourceAmountsInDefaultCurrency, averageSourceAmountInDefaultCurrency, item => item));
} else {
value = 0;
}
} else if (valueMetric === TransactionExplorerValueMetric.SourceAmountMedianAbsoluteDeviation) {
if (allSourceAmountsInDefaultCurrency.length > 0) {
allSourceAmountsInDefaultCurrency.sort((a, b) => a - b);
const medianSourceAmountInDefaultCurrency = median(allSourceAmountsInDefaultCurrency, item => item);
value = Math.trunc(medianAbsoluteDeviation(allSourceAmountsInDefaultCurrency, medianSourceAmountInDefaultCurrency, item => item));
} else {
value = 0;
}
} else if (valueMetric === TransactionExplorerValueMetric.SourceAmountVariance
|| valueMetric === TransactionExplorerValueMetric.SourceAmountStandardDeviation
|| valueMetric === TransactionExplorerValueMetric.SourceAmountCoefficientOfVariation