mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-14 06:57:35 +08:00
add mean absolute deviation and median absolute deviation to value metric in insights explorer
This commit is contained in:
@@ -324,6 +324,8 @@ export enum TransactionExplorerValueMetricType {
|
||||
SourceAmountMaximum = 'sourceAmountMaximum',
|
||||
SourceAmountRange = 'sourceAmountRange',
|
||||
SourceAmountInterquartileRange = 'sourceAmountInterquartileRange',
|
||||
SourceAmountMeanAbsoluteDeviation = 'sourceAmountMeanAbsoluteDeviation',
|
||||
SourceAmountMedianAbsoluteDeviation = 'sourceAmountMedianAbsoluteDeviation',
|
||||
SourceAmountVariance = 'sourceAmountVariance',
|
||||
SourceAmountStandardDeviation = 'sourceAmountStandardDeviation',
|
||||
SourceAmountCoefficientOfVariation = 'sourceAmountCoefficientOfVariation',
|
||||
@@ -359,6 +361,8 @@ export class TransactionExplorerValueMetric implements NameValue {
|
||||
public static readonly SourceAmountMaximum = new TransactionExplorerValueMetric('Maximum Amount', TransactionExplorerValueMetricType.SourceAmountMaximum, true, false, true);
|
||||
public static readonly SourceAmountRange = new TransactionExplorerValueMetric('Range (Max - Min)', TransactionExplorerValueMetricType.SourceAmountRange, true, false, true);
|
||||
public static readonly SourceAmountInterquartileRange = new TransactionExplorerValueMetric('Interquartile Range (Q3 - Q1)', TransactionExplorerValueMetricType.SourceAmountInterquartileRange, true, false, true);
|
||||
public static readonly SourceAmountMeanAbsoluteDeviation = new TransactionExplorerValueMetric('Mean Absolute Deviation', TransactionExplorerValueMetricType.SourceAmountMeanAbsoluteDeviation, true, false, false);
|
||||
public static readonly SourceAmountMedianAbsoluteDeviation = new TransactionExplorerValueMetric('Median Absolute Deviation', TransactionExplorerValueMetricType.SourceAmountMedianAbsoluteDeviation, true, false, false);
|
||||
public static readonly SourceAmountVariance = new TransactionExplorerValueMetric('Variance', TransactionExplorerValueMetricType.SourceAmountVariance, false, false, false);
|
||||
public static readonly SourceAmountStandardDeviation = new TransactionExplorerValueMetric('Standard Deviation', TransactionExplorerValueMetricType.SourceAmountStandardDeviation, false, false, false);
|
||||
public static readonly SourceAmountCoefficientOfVariation = new TransactionExplorerValueMetric('Coefficient of Variation', TransactionExplorerValueMetricType.SourceAmountCoefficientOfVariation, false, false, false);
|
||||
|
||||
@@ -83,6 +83,32 @@ export function cumulativePercentage<T>(sortedValues: T[], percentageThreshold:
|
||||
return 0;
|
||||
}
|
||||
|
||||
export function meanAbsoluteDeviation<T>(values: T[], meanValue: number, valueFn: (item: T) => number): number {
|
||||
if (values.length < 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let sumOfAbsoluteDifferences: number = 0;
|
||||
|
||||
for (const item of values) {
|
||||
const difference: number = Math.abs(valueFn(item) - meanValue);
|
||||
sumOfAbsoluteDifferences += difference;
|
||||
}
|
||||
|
||||
return sumOfAbsoluteDifferences / values.length;
|
||||
}
|
||||
|
||||
export function medianAbsoluteDeviation<T>(sortedValues: T[], medianValue: number, valueFn: (item: T) => number): number {
|
||||
if (sortedValues.length < 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const absoluteDeviations: number[] = sortedValues.map(item => Math.abs(valueFn(item) - medianValue));
|
||||
absoluteDeviations.sort((a, b) => a - b);
|
||||
|
||||
return median(absoluteDeviations, x => x);
|
||||
}
|
||||
|
||||
export function varianceAndStandardDeviation<T>(values: T[], meanValue: number, valueFn: (item: T) => number): { variance: number; standardDeviation: number } {
|
||||
if (values.length < 1) {
|
||||
return { variance: 0, standardDeviation: 0 };
|
||||
|
||||
@@ -1823,6 +1823,8 @@
|
||||
"Transactions for 80% of Amount": "Transaktionen für 80% des Betrags",
|
||||
"Range (Max - Min)": "Spanne (Max - Min)",
|
||||
"Interquartile Range (Q3 - Q1)": "Interquartilsabstand (Q3 - Q1)",
|
||||
"Mean Absolute Deviation": "Mean Absolute Deviation",
|
||||
"Median Absolute Deviation": "Median Absolute Deviation",
|
||||
"Variance": "Varianz",
|
||||
"Standard Deviation": "Standardabweichung",
|
||||
"Coefficient of Variation": "Variationskoeffizient",
|
||||
|
||||
@@ -1823,6 +1823,8 @@
|
||||
"Transactions for 80% of Amount": "Transactions for 80% of Amount",
|
||||
"Range (Max - Min)": "Range (Max - Min)",
|
||||
"Interquartile Range (Q3 - Q1)": "Interquartile Range (Q3 - Q1)",
|
||||
"Mean Absolute Deviation": "Mean Absolute Deviation",
|
||||
"Median Absolute Deviation": "Median Absolute Deviation",
|
||||
"Variance": "Variance",
|
||||
"Standard Deviation": "Standard Deviation",
|
||||
"Coefficient of Variation": "Coefficient of Variation",
|
||||
|
||||
@@ -1823,6 +1823,8 @@
|
||||
"Transactions for 80% of Amount": "Transactions for 80% of Amount",
|
||||
"Range (Max - Min)": "Range (Max - Min)",
|
||||
"Interquartile Range (Q3 - Q1)": "Interquartile Range (Q3 - Q1)",
|
||||
"Mean Absolute Deviation": "Mean Absolute Deviation",
|
||||
"Median Absolute Deviation": "Median Absolute Deviation",
|
||||
"Variance": "Variance",
|
||||
"Standard Deviation": "Standard Deviation",
|
||||
"Coefficient of Variation": "Coefficient of Variation",
|
||||
|
||||
@@ -1823,6 +1823,8 @@
|
||||
"Transactions for 80% of Amount": "Transactions for 80% of Amount",
|
||||
"Range (Max - Min)": "Range (Max - Min)",
|
||||
"Interquartile Range (Q3 - Q1)": "Interquartile Range (Q3 - Q1)",
|
||||
"Mean Absolute Deviation": "Mean Absolute Deviation",
|
||||
"Median Absolute Deviation": "Median Absolute Deviation",
|
||||
"Variance": "Variance",
|
||||
"Standard Deviation": "Standard Deviation",
|
||||
"Coefficient of Variation": "Coefficient of Variation",
|
||||
|
||||
@@ -1823,6 +1823,8 @@
|
||||
"Transactions for 80% of Amount": "Transactions for 80% of Amount",
|
||||
"Range (Max - Min)": "Range (Max - Min)",
|
||||
"Interquartile Range (Q3 - Q1)": "Interquartile Range (Q3 - Q1)",
|
||||
"Mean Absolute Deviation": "Mean Absolute Deviation",
|
||||
"Median Absolute Deviation": "Median Absolute Deviation",
|
||||
"Variance": "Variance",
|
||||
"Standard Deviation": "Standard Deviation",
|
||||
"Coefficient of Variation": "Coefficient of Variation",
|
||||
|
||||
@@ -1823,6 +1823,8 @@
|
||||
"Transactions for 80% of Amount": "Transactions for 80% of Amount",
|
||||
"Range (Max - Min)": "Range (Max - Min)",
|
||||
"Interquartile Range (Q3 - Q1)": "Interquartile Range (Q3 - Q1)",
|
||||
"Mean Absolute Deviation": "Mean Absolute Deviation",
|
||||
"Median Absolute Deviation": "Median Absolute Deviation",
|
||||
"Variance": "Variance",
|
||||
"Standard Deviation": "Standard Deviation",
|
||||
"Coefficient of Variation": "Coefficient of Variation",
|
||||
|
||||
@@ -1823,6 +1823,8 @@
|
||||
"Transactions for 80% of Amount": "Transactions for 80% of Amount",
|
||||
"Range (Max - Min)": "Range (Max - Min)",
|
||||
"Interquartile Range (Q3 - Q1)": "Interquartile Range (Q3 - Q1)",
|
||||
"Mean Absolute Deviation": "Mean Absolute Deviation",
|
||||
"Median Absolute Deviation": "Median Absolute Deviation",
|
||||
"Variance": "Variance",
|
||||
"Standard Deviation": "Standard Deviation",
|
||||
"Coefficient of Variation": "Coefficient of Variation",
|
||||
|
||||
@@ -1823,6 +1823,8 @@
|
||||
"Transactions for 80% of Amount": "Transactions for 80% of Amount",
|
||||
"Range (Max - Min)": "Range (Max - Min)",
|
||||
"Interquartile Range (Q3 - Q1)": "Interquartile Range (Q3 - Q1)",
|
||||
"Mean Absolute Deviation": "Mean Absolute Deviation",
|
||||
"Median Absolute Deviation": "Median Absolute Deviation",
|
||||
"Variance": "Variance",
|
||||
"Standard Deviation": "Standard Deviation",
|
||||
"Coefficient of Variation": "Coefficient of Variation",
|
||||
|
||||
@@ -1823,6 +1823,8 @@
|
||||
"Transactions for 80% of Amount": "Transactions for 80% of Amount",
|
||||
"Range (Max - Min)": "Range (Max - Min)",
|
||||
"Interquartile Range (Q3 - Q1)": "Interquartile Range (Q3 - Q1)",
|
||||
"Mean Absolute Deviation": "Mean Absolute Deviation",
|
||||
"Median Absolute Deviation": "Median Absolute Deviation",
|
||||
"Variance": "Variance",
|
||||
"Standard Deviation": "Standard Deviation",
|
||||
"Coefficient of Variation": "Coefficient of Variation",
|
||||
|
||||
@@ -1823,6 +1823,8 @@
|
||||
"Transactions for 80% of Amount": "Transações para 80% do Valor",
|
||||
"Range (Max - Min)": "Amplitude (Máx - Mín)",
|
||||
"Interquartile Range (Q3 - Q1)": "Intervalo Interquartil (Q3 - Q1)",
|
||||
"Mean Absolute Deviation": "Mean Absolute Deviation",
|
||||
"Median Absolute Deviation": "Median Absolute Deviation",
|
||||
"Variance": "Variância",
|
||||
"Standard Deviation": "Desvio Padrão",
|
||||
"Coefficient of Variation": "Coeficiente de Variação",
|
||||
|
||||
@@ -1823,6 +1823,8 @@
|
||||
"Transactions for 80% of Amount": "Transactions for 80% of Amount",
|
||||
"Range (Max - Min)": "Range (Max - Min)",
|
||||
"Interquartile Range (Q3 - Q1)": "Interquartile Range (Q3 - Q1)",
|
||||
"Mean Absolute Deviation": "Mean Absolute Deviation",
|
||||
"Median Absolute Deviation": "Median Absolute Deviation",
|
||||
"Variance": "Variance",
|
||||
"Standard Deviation": "Standard Deviation",
|
||||
"Coefficient of Variation": "Coefficient of Variation",
|
||||
|
||||
@@ -1823,6 +1823,8 @@
|
||||
"Transactions for 80% of Amount": "Transactions for 80% of Amount",
|
||||
"Range (Max - Min)": "Range (Max - Min)",
|
||||
"Interquartile Range (Q3 - Q1)": "Interquartile Range (Q3 - Q1)",
|
||||
"Mean Absolute Deviation": "Mean Absolute Deviation",
|
||||
"Median Absolute Deviation": "Median Absolute Deviation",
|
||||
"Variance": "Variance",
|
||||
"Standard Deviation": "Standard Deviation",
|
||||
"Coefficient of Variation": "Coefficient of Variation",
|
||||
|
||||
@@ -1823,6 +1823,8 @@
|
||||
"Transactions for 80% of Amount": "Transactions for 80% of Amount",
|
||||
"Range (Max - Min)": "Range (Max - Min)",
|
||||
"Interquartile Range (Q3 - Q1)": "Interquartile Range (Q3 - Q1)",
|
||||
"Mean Absolute Deviation": "Mean Absolute Deviation",
|
||||
"Median Absolute Deviation": "Median Absolute Deviation",
|
||||
"Variance": "Variance",
|
||||
"Standard Deviation": "Standard Deviation",
|
||||
"Coefficient of Variation": "Coefficient of Variation",
|
||||
|
||||
@@ -1823,6 +1823,8 @@
|
||||
"Transactions for 80% of Amount": "Transactions for 80% of Amount",
|
||||
"Range (Max - Min)": "Range (Max - Min)",
|
||||
"Interquartile Range (Q3 - Q1)": "Interquartile Range (Q3 - Q1)",
|
||||
"Mean Absolute Deviation": "Mean Absolute Deviation",
|
||||
"Median Absolute Deviation": "Median Absolute Deviation",
|
||||
"Variance": "Variance",
|
||||
"Standard Deviation": "Standard Deviation",
|
||||
"Coefficient of Variation": "Coefficient of Variation",
|
||||
|
||||
@@ -1823,6 +1823,8 @@
|
||||
"Transactions for 80% of Amount": "Transactions for 80% of Amount",
|
||||
"Range (Max - Min)": "Range (Max - Min)",
|
||||
"Interquartile Range (Q3 - Q1)": "Interquartile Range (Q3 - Q1)",
|
||||
"Mean Absolute Deviation": "Mean Absolute Deviation",
|
||||
"Median Absolute Deviation": "Median Absolute Deviation",
|
||||
"Variance": "Variance",
|
||||
"Standard Deviation": "Standard Deviation",
|
||||
"Coefficient of Variation": "Coefficient of Variation",
|
||||
|
||||
@@ -1823,6 +1823,8 @@
|
||||
"Transactions for 80% of Amount": "Transactions for 80% of Amount",
|
||||
"Range (Max - Min)": "Range (Max - Min)",
|
||||
"Interquartile Range (Q3 - Q1)": "Interquartile Range (Q3 - Q1)",
|
||||
"Mean Absolute Deviation": "Mean Absolute Deviation",
|
||||
"Median Absolute Deviation": "Median Absolute Deviation",
|
||||
"Variance": "Variance",
|
||||
"Standard Deviation": "Standard Deviation",
|
||||
"Coefficient of Variation": "Coefficient of Variation",
|
||||
|
||||
@@ -1823,6 +1823,8 @@
|
||||
"Transactions for 80% of Amount": "Transactions for 80% of Amount",
|
||||
"Range (Max - Min)": "Range (Max - Min)",
|
||||
"Interquartile Range (Q3 - Q1)": "Interquartile Range (Q3 - Q1)",
|
||||
"Mean Absolute Deviation": "Mean Absolute Deviation",
|
||||
"Median Absolute Deviation": "Median Absolute Deviation",
|
||||
"Variance": "Variance",
|
||||
"Standard Deviation": "Standard Deviation",
|
||||
"Coefficient of Variation": "Coefficient of Variation",
|
||||
|
||||
@@ -1823,6 +1823,8 @@
|
||||
"Transactions for 80% of Amount": "贡献80%金额的交易占比",
|
||||
"Range (Max - Min)": "极差 (最大值 - 最小值)",
|
||||
"Interquartile Range (Q3 - Q1)": "四分位距 (Q3 - Q1)",
|
||||
"Mean Absolute Deviation": "平均绝对差",
|
||||
"Median Absolute Deviation": "绝对中位差",
|
||||
"Variance": "方差",
|
||||
"Standard Deviation": "标准差",
|
||||
"Coefficient of Variation": "变异系数",
|
||||
|
||||
@@ -1823,6 +1823,8 @@
|
||||
"Transactions for 80% of Amount": "貢獻80%金額的交易占比",
|
||||
"Range (Max - Min)": "極差 (最大值 - 最小值)",
|
||||
"Interquartile Range (Q3 - Q1)": "四分位距 (Q3 - Q1)",
|
||||
"Mean Absolute Deviation": "平均絕對離差",
|
||||
"Median Absolute Deviation": "中位數絕對離差",
|
||||
"Variance": "變異數",
|
||||
"Standard Deviation": "標準差",
|
||||
"Coefficient of Variation": "變異係數",
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user