add asset trends in statistics & analysis (#314)

This commit is contained in:
MaysWind
2025-11-09 22:51:46 +08:00
parent d3abb279e3
commit 4c8bb5a0b7
52 changed files with 1917 additions and 266 deletions
+21 -19
View File
@@ -28,6 +28,7 @@ export interface DateTime {
getSecond(): number;
getDisplayAMPM(options: DateTimeFormatOptions): string;
getTimezoneUtcOffsetMinutes(): number;
getDateTimeAfterDays(day: number): DateTime;
toGregorianCalendarYearMonthDay(): YearMonthDay;
toGregorianCalendarYear0BasedMonth(): Year0BasedMonth;
format(format: string, options: DateTimeFormatOptions): string;
@@ -584,7 +585,8 @@ export class ShortTimeFormat implements TimeFormat {
export enum DateRangeScene {
Normal = 0,
TrendAnalysis = 1
TrendAnalysis = 1,
AssetTrends = 2
}
export class DateRange implements TypeAndName {
@@ -592,38 +594,38 @@ export class DateRange implements TypeAndName {
private static readonly allInstancesByType: Record<number, DateRange> = {};
// All date range
public static readonly All = new DateRange(0, 'All', false, false, DateRangeScene.Normal, DateRangeScene.TrendAnalysis);
public static readonly All = new DateRange(0, 'All', false, false, DateRangeScene.Normal, DateRangeScene.TrendAnalysis, DateRangeScene.AssetTrends);
// Date ranges for normal scene only
public static readonly Today = new DateRange(1, 'Today', false, false, DateRangeScene.Normal);
public static readonly Yesterday = new DateRange(2, 'Yesterday', false, false, DateRangeScene.Normal);
public static readonly LastSevenDays = new DateRange(3, 'Recent 7 days', false, false, DateRangeScene.Normal);
public static readonly LastThirtyDays = new DateRange(4, 'Recent 30 days', false, false, DateRangeScene.Normal);
public static readonly ThisWeek = new DateRange(5, 'This week', false, false, DateRangeScene.Normal);
public static readonly LastWeek = new DateRange(6, 'Last week', false, false, DateRangeScene.Normal);
public static readonly ThisMonth = new DateRange(7, 'This month', false, false, DateRangeScene.Normal);
public static readonly LastMonth = new DateRange(8, 'Last month', false, false, DateRangeScene.Normal);
public static readonly LastSevenDays = new DateRange(3, 'Recent 7 days', false, false, DateRangeScene.Normal, DateRangeScene.AssetTrends);
public static readonly LastThirtyDays = new DateRange(4, 'Recent 30 days', false, false, DateRangeScene.Normal, DateRangeScene.AssetTrends);
public static readonly ThisWeek = new DateRange(5, 'This week', false, false, DateRangeScene.Normal, DateRangeScene.AssetTrends);
public static readonly LastWeek = new DateRange(6, 'Last week', false, false, DateRangeScene.Normal, DateRangeScene.AssetTrends);
public static readonly ThisMonth = new DateRange(7, 'This month', false, false, DateRangeScene.Normal, DateRangeScene.AssetTrends);
public static readonly LastMonth = new DateRange(8, 'Last month', false, false, DateRangeScene.Normal, DateRangeScene.AssetTrends);
// Date ranges for normal and trend analysis scene
public static readonly ThisYear = new DateRange(9, 'This year', false, false, DateRangeScene.Normal, DateRangeScene.TrendAnalysis);
public static readonly LastYear = new DateRange(10, 'Last year', false, false, DateRangeScene.Normal, DateRangeScene.TrendAnalysis);
public static readonly ThisFiscalYear = new DateRange(11, 'This fiscal year', false, true, DateRangeScene.Normal, DateRangeScene.TrendAnalysis);
public static readonly LastFiscalYear = new DateRange(12, 'Last fiscal year', false, true, DateRangeScene.Normal, DateRangeScene.TrendAnalysis);
public static readonly ThisYear = new DateRange(9, 'This year', false, false, DateRangeScene.Normal, DateRangeScene.TrendAnalysis, DateRangeScene.AssetTrends);
public static readonly LastYear = new DateRange(10, 'Last year', false, false, DateRangeScene.Normal, DateRangeScene.TrendAnalysis, DateRangeScene.AssetTrends);
public static readonly ThisFiscalYear = new DateRange(11, 'This fiscal year', false, true, DateRangeScene.Normal, DateRangeScene.TrendAnalysis, DateRangeScene.AssetTrends);
public static readonly LastFiscalYear = new DateRange(12, 'Last fiscal year', false, true, DateRangeScene.Normal, DateRangeScene.TrendAnalysis, DateRangeScene.AssetTrends);
// Billing cycle date ranges for normal scene only
public static readonly CurrentBillingCycle = new DateRange(51, 'Current Billing Cycle', true, true, DateRangeScene.Normal);
public static readonly PreviousBillingCycle = new DateRange(52, 'Previous Billing Cycle', true, true, DateRangeScene.Normal);
// Date ranges for trend analysis scene only
public static readonly RecentTwelveMonths = new DateRange(101, 'Recent 12 months', false, false, DateRangeScene.TrendAnalysis);
public static readonly RecentTwentyFourMonths = new DateRange(102, 'Recent 24 months', false, false, DateRangeScene.TrendAnalysis);
public static readonly RecentThirtySixMonths = new DateRange(103, 'Recent 36 months', false, false, DateRangeScene.TrendAnalysis);
public static readonly RecentTwoYears = new DateRange(104, 'Recent 2 years', false, false, DateRangeScene.TrendAnalysis);
public static readonly RecentThreeYears = new DateRange(105, 'Recent 3 years', false, false, DateRangeScene.TrendAnalysis);
public static readonly RecentFiveYears = new DateRange(106, 'Recent 5 years', false, false, DateRangeScene.TrendAnalysis);
public static readonly RecentTwelveMonths = new DateRange(101, 'Recent 12 months', false, false, DateRangeScene.TrendAnalysis, DateRangeScene.AssetTrends);
public static readonly RecentTwentyFourMonths = new DateRange(102, 'Recent 24 months', false, false, DateRangeScene.TrendAnalysis, DateRangeScene.AssetTrends);
public static readonly RecentThirtySixMonths = new DateRange(103, 'Recent 36 months', false, false, DateRangeScene.TrendAnalysis, DateRangeScene.AssetTrends);
public static readonly RecentTwoYears = new DateRange(104, 'Recent 2 years', false, false, DateRangeScene.TrendAnalysis, DateRangeScene.AssetTrends);
public static readonly RecentThreeYears = new DateRange(105, 'Recent 3 years', false, false, DateRangeScene.TrendAnalysis, DateRangeScene.AssetTrends);
public static readonly RecentFiveYears = new DateRange(106, 'Recent 5 years', false, false, DateRangeScene.TrendAnalysis, DateRangeScene.AssetTrends);
// Custom date range
public static readonly Custom = new DateRange(255, 'Custom Date', false, true, DateRangeScene.Normal, DateRangeScene.TrendAnalysis);
public static readonly Custom = new DateRange(255, 'Custom Date', false, true, DateRangeScene.Normal, DateRangeScene.TrendAnalysis, DateRangeScene.AssetTrends);
public readonly type: number;
public readonly name: string;
+8 -1
View File
@@ -7,7 +7,8 @@ import {
ChartDataType,
ChartSortingType,
DEFAULT_CATEGORICAL_CHART_DATA_RANGE,
DEFAULT_TREND_CHART_DATA_RANGE
DEFAULT_TREND_CHART_DATA_RANGE,
DEFAULT_ASSET_TRENDS_CHART_DATA_RANGE
} from './statistics.ts';
import { DEFAULT_CURRENCY_CODE } from '@/consts/currency.ts';
@@ -63,6 +64,8 @@ export interface ApplicationSettings extends BaseApplicationSetting {
defaultCategoricalChartDataRangeType: number;
defaultTrendChartType: number;
defaultTrendChartDataRangeType: number;
defaultAssetTrendsChartType: number;
defaultAssetTrendsChartDataRangeType: number;
};
}
@@ -122,6 +125,8 @@ export const ALL_ALLOWED_CLOUD_SYNC_APP_SETTING_KEY_TYPES: Record<string, UserAp
'statistics.defaultCategoricalChartDataRangeType': UserApplicationCloudSettingType.Number,
'statistics.defaultTrendChartType': UserApplicationCloudSettingType.Number,
'statistics.defaultTrendChartDataRangeType': UserApplicationCloudSettingType.Number,
'statistics.defaultAssetTrendsChartType': UserApplicationCloudSettingType.Number,
'statistics.defaultAssetTrendsChartDataRangeType': UserApplicationCloudSettingType.Number,
};
export const DEFAULT_APPLICATION_SETTINGS: ApplicationSettings = {
@@ -168,6 +173,8 @@ export const DEFAULT_APPLICATION_SETTINGS: ApplicationSettings = {
defaultCategoricalChartDataRangeType: DEFAULT_CATEGORICAL_CHART_DATA_RANGE.type,
defaultTrendChartType: TrendChartType.Default.type,
defaultTrendChartDataRangeType: DEFAULT_TREND_CHART_DATA_RANGE.type,
defaultAssetTrendsChartType: TrendChartType.Default.type,
defaultAssetTrendsChartDataRangeType: DEFAULT_ASSET_TRENDS_CHART_DATA_RANGE.type,
}
};
+46 -10
View File
@@ -3,7 +3,13 @@ import { DateRange } from '@/core/datetime.ts';
export enum StatisticsAnalysisType {
CategoricalAnalysis = 0,
TrendAnalysis = 1
TrendAnalysis = 1,
AssetTrends = 2
}
export enum ChartDataAggregationType {
Sum = 0,
Last = 1
}
export class CategoricalChartType implements TypeAndName {
@@ -115,16 +121,18 @@ export class ChartDataType implements TypeAndName {
public static readonly IncomeByAccount = new ChartDataType(3, 'Income By Account', false, false, StatisticsAnalysisType.CategoricalAnalysis, StatisticsAnalysisType.TrendAnalysis);
public static readonly IncomeByPrimaryCategory = new ChartDataType(4, 'Income By Primary Category', false, false, StatisticsAnalysisType.CategoricalAnalysis, StatisticsAnalysisType.TrendAnalysis);
public static readonly IncomeBySecondaryCategory = new ChartDataType(5, 'Income By Secondary Category', false, false, StatisticsAnalysisType.CategoricalAnalysis, StatisticsAnalysisType.TrendAnalysis);
public static readonly AccountTotalAssets = new ChartDataType(6, 'Account Total Assets', false, false, StatisticsAnalysisType.CategoricalAnalysis);
public static readonly AccountTotalLiabilities = new ChartDataType(7, 'Account Total Liabilities', false, false, StatisticsAnalysisType.CategoricalAnalysis);
public static readonly AccountTotalAssets = new ChartDataType(6, 'Account Total Assets', false, false, StatisticsAnalysisType.CategoricalAnalysis, StatisticsAnalysisType.AssetTrends);
public static readonly AccountTotalLiabilities = new ChartDataType(7, 'Account Total Liabilities', false, false, StatisticsAnalysisType.CategoricalAnalysis, StatisticsAnalysisType.AssetTrends);
public static readonly TotalOutflows = new ChartDataType(13, 'Total Outflows', false, false, StatisticsAnalysisType.TrendAnalysis);
public static readonly TotalExpense = new ChartDataType(8, 'Total Expense', false, false, StatisticsAnalysisType.TrendAnalysis);
public static readonly TotalInflows = new ChartDataType(14, 'Total Inflows', false, false, StatisticsAnalysisType.TrendAnalysis);
public static readonly TotalIncome = new ChartDataType(9, 'Total Income', false, false, StatisticsAnalysisType.TrendAnalysis);
public static readonly NetCashFlow = new ChartDataType(15, 'Net Cash Flow', false, false, StatisticsAnalysisType.TrendAnalysis);
public static readonly NetIncome = new ChartDataType(10, 'Net Income', false, false, StatisticsAnalysisType.TrendAnalysis);
public static readonly NetWorth = new ChartDataType(17, 'Net Worth', false, false, StatisticsAnalysisType.AssetTrends);
public static readonly Default = ChartDataType.ExpenseByPrimaryCategory;
public static readonly DefaultForAssetTrends = ChartDataType.NetWorth;
public readonly type: number;
public readonly name: string;
@@ -221,28 +229,55 @@ export class ChartDateAggregationType {
private static readonly allInstances: ChartDateAggregationType[] = [];
private static readonly allInstancesByType: Record<number, ChartDateAggregationType> = {};
public static readonly Month = new ChartDateAggregationType(0, 'Monthly', 'Aggregate by Month');
public static readonly Quarter = new ChartDateAggregationType(1, 'Quarterly', 'Aggregate by Quarter');
public static readonly Year = new ChartDateAggregationType(2, 'Yearly', 'Aggregate by Year');
public static readonly FiscalYear = new ChartDateAggregationType(3, 'FiscalYearly', 'Aggregate by Fiscal Year');
public static readonly Day = new ChartDateAggregationType(4, 'Daily', 'Aggregate by Day', StatisticsAnalysisType.AssetTrends);
public static readonly Month = new ChartDateAggregationType(0, 'Monthly', 'Aggregate by Month', StatisticsAnalysisType.TrendAnalysis, StatisticsAnalysisType.AssetTrends);
public static readonly Quarter = new ChartDateAggregationType(1, 'Quarterly', 'Aggregate by Quarter', StatisticsAnalysisType.TrendAnalysis, StatisticsAnalysisType.AssetTrends);
public static readonly Year = new ChartDateAggregationType(2, 'Yearly', 'Aggregate by Year', StatisticsAnalysisType.TrendAnalysis, StatisticsAnalysisType.AssetTrends);
public static readonly FiscalYear = new ChartDateAggregationType(3, 'FiscalYearly', 'Aggregate by Fiscal Year', StatisticsAnalysisType.TrendAnalysis, StatisticsAnalysisType.AssetTrends);
public static readonly Default = ChartDateAggregationType.Month;
public readonly type: number;
public readonly shortName: string;
public readonly fullName: string;
private readonly availableAnalysisTypes: Record<number, boolean>;
private constructor(type: number, shortName: string, fullName: string) {
private constructor(type: number, shortName: string, fullName: string, ...availableAnalysisTypes: StatisticsAnalysisType[]) {
this.type = type;
this.shortName = shortName;
this.fullName = fullName;
this.availableAnalysisTypes = {};
if (availableAnalysisTypes) {
for (const analysisType of availableAnalysisTypes) {
this.availableAnalysisTypes[analysisType] = true;
}
}
ChartDateAggregationType.allInstances.push(this);
ChartDateAggregationType.allInstancesByType[type] = this;
}
public static values(): ChartDateAggregationType[] {
return ChartDateAggregationType.allInstances;
public isAvailableAnalysisType(analysisType: StatisticsAnalysisType): boolean {
return this.availableAnalysisTypes[analysisType] || false;
}
public static values(analysisType?: StatisticsAnalysisType): ChartDateAggregationType[] {
const availableInstances: ChartDateAggregationType[] = ChartDateAggregationType.allInstances;
if (analysisType === undefined) {
return availableInstances;
}
const ret: ChartDateAggregationType[] = [];
for (const chartDataType of availableInstances) {
if (chartDataType.isAvailableAnalysisType(analysisType)) {
ret.push(chartDataType);
}
}
return ret;
}
public static valueOf(type: number): ChartDateAggregationType | undefined {
@@ -252,3 +287,4 @@ export class ChartDateAggregationType {
export const DEFAULT_CATEGORICAL_CHART_DATA_RANGE: DateRange = DateRange.ThisMonth;
export const DEFAULT_TREND_CHART_DATA_RANGE: DateRange = DateRange.ThisYear;
export const DEFAULT_ASSET_TRENDS_CHART_DATA_RANGE: DateRange = DateRange.ThisYear;