mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-09 23:48:36 +01:00
[NOT READY] start change aggregation timeline
This commit is contained in:
@@ -139,7 +139,6 @@ const { snapshotDuration } = useSnapshot();
|
||||
const selectLabels: { label: string, value: Slice }[] = [
|
||||
{ label: 'Hour', value: 'hour' },
|
||||
{ label: 'Day', value: 'day' },
|
||||
// { label: 'Week', value: 'week' },
|
||||
{ label: 'Month', value: 'month' },
|
||||
];
|
||||
|
||||
@@ -159,7 +158,11 @@ const allDatesFull = ref<string[]>([]);
|
||||
|
||||
function transformResponse(input: { _id: string, count: number }[]) {
|
||||
const data = input.map(e => e.count);
|
||||
const labels = input.map(e => DateService.getChartLabelFromISO(e._id, navigator.language, selectedSlice.value));
|
||||
|
||||
console.log('RESPONSE', input);
|
||||
const labels = input.map(e => DateService.getChartLabelFromISO(e._id, new Date().getTimezoneOffset(), selectedSlice.value));
|
||||
console.log('LABELS', input);
|
||||
|
||||
if (input.length > 0) allDatesFull.value = input.map(e => e._id.toString());
|
||||
return { data, labels }
|
||||
}
|
||||
@@ -223,9 +226,6 @@ function onDataReady() {
|
||||
const maxChartY = Math.max(...visitsData.data.value.data, ...sessionsData.data.value.data);
|
||||
const maxEventSize = Math.max(...eventsData.data.value.data)
|
||||
|
||||
|
||||
const currentDateTime = Date.now();
|
||||
|
||||
chartData.value.datasets[0].data = visitsData.data.value.data;
|
||||
chartData.value.datasets[1].data = sessionsData.data.value.data;
|
||||
chartData.value.datasets[2].data = eventsData.data.value.data.map(e => {
|
||||
|
||||
@@ -10,7 +10,7 @@ const { safeSnapshotDates } = useSnapshot()
|
||||
|
||||
function transformResponse(input: { _id: string, count: number }[]) {
|
||||
const data = input.map(e => e.count);
|
||||
const labels = input.map(e => DateService.getChartLabelFromISO(e._id, navigator.language, props.slice));
|
||||
const labels = input.map(e => DateService.getChartLabelFromISO(e._id, new Date().getTimezoneOffset(), props.slice));
|
||||
return { data, labels }
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ function transformResponse(input: { _id: string, count: number }[]) {
|
||||
|
||||
const data = input.map(e => e.count || 0);
|
||||
|
||||
const labels = input.map(e => DateService.getChartLabelFromISO(e._id, navigator.language, chartSlice.value));
|
||||
const labels = input.map(e => DateService.getChartLabelFromISO(e._id, new Date().getTimezoneOffset(), chartSlice.value));
|
||||
|
||||
const pool = [...input.map(e => e.count || 0)];
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ const { safeSnapshotDates } = useSnapshot()
|
||||
|
||||
function transformResponse(input: { _id: string, count: number }[]) {
|
||||
const data = input.map(e => e.count);
|
||||
const labels = input.map(e => DateService.getChartLabelFromISO(e._id, navigator.language, props.slice));
|
||||
const labels = input.map(e => DateService.getChartLabelFromISO(e._id, new Date().getTimezoneOffset(), props.slice));
|
||||
return { data, labels }
|
||||
}
|
||||
|
||||
|
||||
@@ -44,16 +44,16 @@ const selfhosted = useSelfhosted();
|
||||
<BannerLimitsInfo v-if="!selfhosted" :key="refreshKey"></BannerLimitsInfo>
|
||||
<BannerOffer v-if="!selfhosted" :key="refreshKey"></BannerOffer>
|
||||
</div>
|
||||
|
||||
<!--
|
||||
<div>
|
||||
<DashboardTopSection :key="refreshKey"></DashboardTopSection>
|
||||
<DashboardTopCards :key="refreshKey"></DashboardTopCards>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
<div class="mt-6 px-6 flex gap-6 flex-col 2xl:flex-row w-full">
|
||||
<DashboardActionableChart :key="refreshKey"></DashboardActionableChart>
|
||||
</div>
|
||||
|
||||
<!--
|
||||
<div class="flex w-full justify-center mt-6 px-6">
|
||||
<div class="flex w-full gap-6 flex-col xl:flex-row">
|
||||
<div class="flex-1">
|
||||
@@ -85,7 +85,7 @@ const selfhosted = useSelfhosted();
|
||||
<BarCardOperatingSystems :key="refreshKey"></BarCardOperatingSystems>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
@@ -13,17 +13,12 @@ export default defineEventHandler(async event => {
|
||||
const cacheExp = 60;
|
||||
|
||||
return await Redis.useCacheV2(cacheKey, cacheExp, async () => {
|
||||
|
||||
const timelineData = await executeTimelineAggregation({
|
||||
projectId: project_id,
|
||||
model: EventModel,
|
||||
from, to, slice,
|
||||
});
|
||||
|
||||
const timelineFilledMerged = fillAndMergeTimelineAggregationV2(timelineData, slice, from, to);
|
||||
|
||||
return timelineFilledMerged;
|
||||
|
||||
return timelineData;
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -18,9 +18,7 @@ export default defineEventHandler(async event => {
|
||||
model: SessionModel,
|
||||
from, to, slice,
|
||||
});
|
||||
const timelineFilledMerged = fillAndMergeTimelineAggregationV2(timelineData, slice, from, to);
|
||||
return timelineFilledMerged;
|
||||
|
||||
return timelineData;
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -12,18 +12,14 @@ export default defineEventHandler(async event => {
|
||||
const cacheKey = `timeline:visits:${pid}:${slice}:${from}:${to}`;
|
||||
const cacheExp = 60;
|
||||
|
||||
return await Redis.useCacheV2(cacheKey, cacheExp, async () => {
|
||||
|
||||
return await Redis.useCacheV2(cacheKey, cacheExp, async () => {
|
||||
const timelineData = await executeTimelineAggregation({
|
||||
projectId: project_id,
|
||||
model: VisitModel,
|
||||
from, to, slice,
|
||||
from, to, slice
|
||||
});
|
||||
|
||||
const timelineFilledMerged = fillAndMergeTimelineAggregationV2(timelineData, slice, from, to);
|
||||
return timelineFilledMerged;
|
||||
|
||||
});
|
||||
return timelineData;
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ export type TimelineAggregationOptions = {
|
||||
from: string | number,
|
||||
to: string | number,
|
||||
slice: Slice,
|
||||
dateOffset?: number,
|
||||
debug?: boolean
|
||||
}
|
||||
|
||||
@@ -27,9 +28,9 @@ export async function executeAdvancedTimelineAggregation<T = {}>(options: Advanc
|
||||
options.customProjection = options.customProjection || {};
|
||||
options.customIdGroup = options.customIdGroup || {};
|
||||
|
||||
const { group, sort } = DateService.getQueryDateRange(options.slice);
|
||||
const { dateFromParts, granularity } = DateService.getGranularityData(options.slice, '$tmpDate');
|
||||
|
||||
if (!sort) throw Error('Slice is probably not correct');
|
||||
if (!dateFromParts) throw Error('Slice is probably not correct');
|
||||
|
||||
|
||||
const [sliceValid, errorOrDays] = checkSliceValidity(options.from, options.to, options.slice);
|
||||
@@ -40,31 +41,60 @@ export async function executeAdvancedTimelineAggregation<T = {}>(options: Advanc
|
||||
{
|
||||
$match: {
|
||||
project_id: options.projectId,
|
||||
created_at: { $gte: new Date(options.from), $lte: new Date(options.to) },
|
||||
created_at: {
|
||||
$gte: new Date(options.from),
|
||||
$lte: new Date(options.to)
|
||||
},
|
||||
...options.customMatch
|
||||
}
|
||||
},
|
||||
{
|
||||
$addFields: {
|
||||
tmpDate: {
|
||||
$dateSubtract: {
|
||||
startDate: "$created_at",
|
||||
unit: "minute",
|
||||
amount: options.dateOffset || -60
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
$addFields: { isoDate: { $dateFromParts: dateFromParts } }
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: { ...group, ...options.customIdGroup },
|
||||
_id: { isoDate: "$isoDate", ...options.customIdGroup },
|
||||
count: { $sum: 1 },
|
||||
firstDate: { $first: '$created_at' },
|
||||
...options.customGroup
|
||||
}
|
||||
},
|
||||
{ $sort: { firstDate: 1 } },
|
||||
{
|
||||
$sort: { "_id.isoDate": 1 }
|
||||
},
|
||||
{
|
||||
$densify: {
|
||||
field: "_id.isoDate",
|
||||
range: {
|
||||
step: 1,
|
||||
unit: granularity,
|
||||
bounds: "full"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
$addFields: { count: { $ifNull: ["$count", 0] }, }
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
_id: "$firstDate",
|
||||
count: "$count",
|
||||
_id: '$_id.isoDate',
|
||||
count: '$count',
|
||||
...options.customProjection
|
||||
}
|
||||
}
|
||||
] as any;
|
||||
|
||||
if (options.debug === true) {
|
||||
console.log('---------- SORT ----------')
|
||||
console.log(JSON.stringify(sort, null, 2));
|
||||
console.log('---------- AGGREAGATION ----------')
|
||||
console.log(JSON.stringify(aggregation, null, 2));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user