aggre based time week, month, year renamed to daily, weekly, monthly

This commit is contained in:
2026-04-06 17:37:45 +05:30
parent 5f0fa91075
commit 8a866566ba
3 changed files with 15 additions and 15 deletions

View File

@@ -96,7 +96,7 @@ export async function fetchAggregatedData(
const normalize = (amt: number) => Math.abs(amt);
// ---------------- WEEK ----------------
const weekBuckets: Record<string, number> = {
const dailyBuckets: Record<string, number> = {
Mon: 0, Tue: 0, Wed: 0, Thu: 0,
Fri: 0, Sat: 0, Sun: 0
};
@@ -105,7 +105,7 @@ export async function fetchAggregatedData(
const weekEnd = endOfDay(new Date(weekStart.getTime() + 6 * 86400000));
// ---------------- MONTH (rolling 5 weeks, MonSun aligned) ----------------
const monthBuckets: {
const weeklyBuckets: {
label: string;
start: Date;
end: Date;
@@ -118,7 +118,7 @@ export async function fetchAggregatedData(
const start = new Date(currentWeekStart.getTime() - i * 7 * 86400000);
const end = endOfDay(new Date(start.getTime() + 6 * 86400000));
monthBuckets.push({
weeklyBuckets.push({
label: `${format(start)} - ${format(end)}`,
start,
end,
@@ -127,7 +127,7 @@ export async function fetchAggregatedData(
}
// ---------------- YEAR (rolling 12 months) ----------------
const yearBuckets: {
const monthlyBuckets: {
label: string;
start: Date;
end: Date;
@@ -149,7 +149,7 @@ export async function fetchAggregatedData(
month: "short"
})}-${String(d.getFullYear()).slice(2)}`;
yearBuckets.push({
monthlyBuckets.push({
label,
start,
end,
@@ -176,20 +176,20 @@ export async function fetchAggregatedData(
// WEEK
if (d >= weekStart && d <= weekEnd) {
const day = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][d.getDay()];
if (weekBuckets[day] !== undefined) {
weekBuckets[day] += amt;
if (dailyBuckets[day] !== undefined) {
dailyBuckets[day] += amt;
}
}
// MONTH (rolling weeks)
for (const b of monthBuckets) {
for (const b of weeklyBuckets) {
if (d >= b.start && d <= b.end) {
b.amount += amt;
}
}
// YEAR (rolling months)
for (const b of yearBuckets) {
for (const b of monthlyBuckets) {
if (d >= b.start && d <= b.end) {
b.amount += amt;
}
@@ -208,9 +208,9 @@ export async function fetchAggregatedData(
}));
const chartData = {
week: toPoints(weekBuckets),
month: toPoints(monthBuckets),
year: toPoints(yearBuckets)
daily: toPoints(dailyBuckets),
weekly: toPoints(weeklyBuckets),
monthly: toPoints(monthlyBuckets)
};
// highlight max