From 78f979d23a9c825cac875691f92e77c9cc80615a Mon Sep 17 00:00:00 2001 From: Emily Date: Sat, 7 Dec 2024 18:24:48 +0100 Subject: [PATCH] [NOT READY] fix granularity --- dashboard/server/api/timeline/events.ts | 2 +- dashboard/server/services/TimelineService.ts | 11 +++++++---- shared/services/DateService.ts | 10 +++++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/dashboard/server/api/timeline/events.ts b/dashboard/server/api/timeline/events.ts index 524dd37..97a7ded 100644 --- a/dashboard/server/api/timeline/events.ts +++ b/dashboard/server/api/timeline/events.ts @@ -16,7 +16,7 @@ export default defineEventHandler(async event => { const timelineData = await executeTimelineAggregation({ projectId: project_id, model: EventModel, - from, to, slice, + from, to, slice }); return timelineData; }); diff --git a/dashboard/server/services/TimelineService.ts b/dashboard/server/services/TimelineService.ts index c1e093a..e3ee818 100644 --- a/dashboard/server/services/TimelineService.ts +++ b/dashboard/server/services/TimelineService.ts @@ -69,19 +69,22 @@ export async function executeAdvancedTimelineAggregation(options: Advanc ...options.customGroup } }, - { - $sort: { "_id.isoDate": 1 } - }, { $densify: { field: "_id.isoDate", range: { step: 1, unit: granularity, - bounds: "full" + bounds: [ + new Date(options.from), + new Date(options.to) + ] } } }, + { + $sort: { "_id.isoDate": 1 } + }, { $addFields: { count: { $ifNull: ["$count", 0] }, } }, diff --git a/shared/services/DateService.ts b/shared/services/DateService.ts index 1b68547..6f58fae 100644 --- a/shared/services/DateService.ts +++ b/shared/services/DateService.ts @@ -75,21 +75,21 @@ class DateService { getGranularityData(slice: Slice, dateField: string) { const dateFromParts: Record = {}; - let granularity = ''; + let granularity; switch (slice) { case 'hour': dateFromParts.hour = { $hour: { date: dateField } } - granularity = 'hour'; + granularity = granularity || 'hour'; case 'day': dateFromParts.day = { $dayOfMonth: { date: dateField } } - granularity = 'day'; + granularity = granularity || 'day'; case 'month': dateFromParts.month = { $month: { date: dateField } } - granularity = 'month'; + granularity = granularity || 'month'; case 'year': dateFromParts.year = { $year: { date: dateField } } - granularity = 'year'; + granularity = granularity || 'year'; } return { dateFromParts, granularity }