[NOT READY] fix dates + charts + ui

This commit is contained in:
Emily
2024-12-09 17:57:50 +01:00
parent 78f979d23a
commit 23b8f7229a
18 changed files with 211 additions and 152 deletions

View File

@@ -10,7 +10,7 @@ export type TimelineAggregationOptions = {
from: string | number,
to: string | number,
slice: Slice,
dateOffset?: number,
timeOffset?: number,
debug?: boolean
}
@@ -29,14 +29,13 @@ export async function executeAdvancedTimelineAggregation<T = {}>(options: Advanc
options.customIdGroup = options.customIdGroup || {};
const { dateFromParts, granularity } = DateService.getGranularityData(options.slice, '$tmpDate');
if (!dateFromParts) throw Error('Slice is probably not correct');
const [sliceValid, errorOrDays] = checkSliceValidity(options.from, options.to, options.slice);
if (!sliceValid) throw Error(errorOrDays);
const timeOffset = options.timeOffset || 0;
const aggregation = [
{
$match: {
@@ -54,7 +53,7 @@ export async function executeAdvancedTimelineAggregation<T = {}>(options: Advanc
$dateSubtract: {
startDate: "$created_at",
unit: "minute",
amount: options.dateOffset || -60
amount: timeOffset
}
}
}
@@ -76,8 +75,8 @@ export async function executeAdvancedTimelineAggregation<T = {}>(options: Advanc
step: 1,
unit: granularity,
bounds: [
new Date(options.from),
new Date(options.to)
new Date(new Date(options.from).getTime() - (timeOffset * 1000 * 60)),
new Date(new Date(options.to).getTime() - (timeOffset * 1000 * 60) + 1),
]
}
}