trend analysis supports aggregating amounts by month / quarter / year

This commit is contained in:
MaysWind
2024-11-06 01:35:42 +08:00
parent c3a880e5f5
commit fe35cbae49
9 changed files with 311 additions and 53 deletions
+79 -1
View File
@@ -283,6 +283,22 @@ export function getSpecifiedDayFirstUnixTime(unixTime) {
return moment.unix(unixTime).set({ hour: 0, minute: 0, second: 0, millisecond: 0 }).unix();
}
export function getYearFirstUnixTime(year) {
return moment().set({ year: year, month: 0, date: 1, hour: 0, minute: 0, second: 0, millisecond: 0 }).unix();
}
export function getYearLastUnixTime(year) {
return moment.unix(getYearFirstUnixTime(year)).add(1, 'years').subtract(1, 'seconds').unix();
}
export function getQuarterFirstUnixTime(yearQuarter) {
return moment().set({ year: yearQuarter.year, month: (yearQuarter.quarter - 1) * 3, date: 1, hour: 0, minute: 0, second: 0, millisecond: 0 }).unix();
}
export function getQuarterLastUnixTime(yearQuarter) {
return moment.unix(getQuarterFirstUnixTime(yearQuarter)).add(3, 'months').subtract(1, 'seconds').unix();
}
export function getYearMonthFirstUnixTime(yearMonth) {
if (isString(yearMonth)) {
yearMonth = getYearMonthObjectFromString(yearMonth);
@@ -301,7 +317,69 @@ export function getYearMonthLastUnixTime(yearMonth) {
return moment.unix(getYearMonthFirstUnixTime(yearMonth)).add(1, 'months').subtract(1, 'seconds').unix();
}
export function getAllYearMonthUnixTimesBetweenStartYearMonthAndEndYearMonth(startYearMonth, endYearMonth) {
export function getAllYearsStartAndEndUnixTimes(startYearMonth, endYearMonth) {
if (isString(startYearMonth)) {
startYearMonth = getYearMonthObjectFromString(startYearMonth);
}
if (isString(endYearMonth)) {
endYearMonth = getYearMonthObjectFromString(endYearMonth);
}
const allYearTimes = [];
for (let year = startYearMonth.year; year <= endYearMonth.year; year++) {
const yearTime = {
year: year
};
yearTime.minUnixTime = getYearFirstUnixTime(year);
yearTime.maxUnixTime = getYearLastUnixTime(year);
allYearTimes.push(yearTime);
}
return allYearTimes;
}
export function getAllQuartersStartAndEndUnixTimes(startYearMonth, endYearMonth) {
if (isString(startYearMonth)) {
startYearMonth = getYearMonthObjectFromString(startYearMonth);
}
if (isString(endYearMonth)) {
endYearMonth = getYearMonthObjectFromString(endYearMonth);
}
const allYearQuarterTimes = [];
for (let year = startYearMonth.year, month = startYearMonth.month; year < endYearMonth.year || (year === endYearMonth.year && ((month / 3) <= (endYearMonth.month / 3))); ) {
const yearQuarterTime = {
year: year,
quarter: Math.floor((month / 3)) + 1
};
yearQuarterTime.minUnixTime = getQuarterFirstUnixTime(yearQuarterTime);
yearQuarterTime.maxUnixTime = getQuarterLastUnixTime(yearQuarterTime);
allYearQuarterTimes.push(yearQuarterTime);
if (year === endYearMonth.year && month >= endYearMonth.month) {
break;
}
if (month >= 9) {
year++;
month = 0;
} else {
month += 3;
}
}
return allYearQuarterTimes;
}
export function getAllMonthsStartAndEndUnixTimes(startYearMonth, endYearMonth) {
if (isString(startYearMonth)) {
startYearMonth = getYearMonthObjectFromString(startYearMonth);
}
+32
View File
@@ -451,6 +451,17 @@ function getI18nShortTimeFormat(translateFn, formatTypeValue) {
return getDateTimeFormat(translateFn, datetimeConstants.allShortTimeFormat, datetimeConstants.allShortTimeFormatArray, 'format.shortTime', defaultShortTimeFormatTypeName, datetimeConstants.defaultShortTimeFormat, formatTypeValue);
}
function formatYearQuarter(translateFn, year, quarter) {
if (1 <= quarter && quarter <= 4) {
return translateFn('format.yearQuarter.q' + quarter, {
year: year,
quarter: quarter
});
} else {
return '';
}
}
function isLongTime24HourFormat(translateFn, formatTypeValue) {
const defaultLongTimeFormatTypeName = translateFn('default.longTimeFormat');
const type = getDateTimeFormatType(datetimeConstants.allLongTimeFormat, datetimeConstants.allLongTimeFormatArray, defaultLongTimeFormatTypeName, datetimeConstants.defaultLongTimeFormat, formatTypeValue);
@@ -1142,6 +1153,25 @@ function getAllStatisticsSortingTypes(translateFn) {
return allSortingTypes;
}
function getAllStatisticsDateAggregationTypes(translateFn) {
const aggregationTypes = [];
for (const aggregationTypeField in statisticsConstants.allDateAggregationTypes) {
if (!Object.prototype.hasOwnProperty.call(statisticsConstants.allDateAggregationTypes, aggregationTypeField)) {
continue;
}
const aggregationType = statisticsConstants.allDateAggregationTypes[aggregationTypeField];
aggregationTypes.push({
type: aggregationType.type,
displayName: translateFn(aggregationType.name)
});
}
return aggregationTypes;
}
function getAllTransactionEditScopeTypes(translateFn) {
const allEditScopeTypes = [];
@@ -1632,6 +1662,7 @@ export function i18nFunctions(i18nGlobal) {
formatUnixTimeToShortMonthDay: (userStore, unixTime, utcOffset, currentUtcOffset) => formatUnixTime(unixTime, getI18nShortMonthDayFormat(i18nGlobal.t, userStore.currentUserShortDateFormat), utcOffset, currentUtcOffset),
formatUnixTimeToLongTime: (userStore, unixTime, utcOffset, currentUtcOffset) => formatUnixTime(unixTime, getI18nLongTimeFormat(i18nGlobal.t, userStore.currentUserLongTimeFormat), utcOffset, currentUtcOffset),
formatUnixTimeToShortTime: (userStore, unixTime, utcOffset, currentUtcOffset) => formatUnixTime(unixTime, getI18nShortTimeFormat(i18nGlobal.t, userStore.currentUserShortTimeFormat), utcOffset, currentUtcOffset),
formatYearQuarter: (year, quarter) => formatYearQuarter(i18nGlobal.t, year, quarter),
isLongDateMonthAfterYear: (userStore) => isLongDateMonthAfterYear(i18nGlobal.t, userStore.currentUserLongDateFormat),
isShortDateMonthAfterYear: (userStore) => isShortDateMonthAfterYear(i18nGlobal.t, userStore.currentUserShortDateFormat),
isLongTime24HourFormat: (userStore) => isLongTime24HourFormat(i18nGlobal.t, userStore.currentUserLongTimeFormat),
@@ -1668,6 +1699,7 @@ export function i18nFunctions(i18nGlobal) {
getAllTrendChartTypes: () => getAllTrendChartTypes(i18nGlobal.t),
getAllStatisticsChartDataTypes: (analysisType) => getAllStatisticsChartDataTypes(i18nGlobal.t, analysisType),
getAllStatisticsSortingTypes: () => getAllStatisticsSortingTypes(i18nGlobal.t),
getAllStatisticsDateAggregationTypes: () => getAllStatisticsDateAggregationTypes(i18nGlobal.t),
getAllTransactionEditScopeTypes: () => getAllTransactionEditScopeTypes(i18nGlobal.t),
getAllTransactionScheduledFrequencyTypes: () => getAllTransactionScheduledFrequencyTypes(i18nGlobal.t),
getAllTransactionDefaultCategories: (categoryType, locale) => getAllTransactionDefaultCategories(categoryType, locale, i18nGlobal.t),