This commit is contained in:
Emily
2024-06-21 17:50:51 +02:00
parent d8445b3f1a
commit 240a9cd633
3 changed files with 39 additions and 2 deletions

View File

@@ -8,7 +8,7 @@ const ready = ref<boolean>(false);
const props = defineProps<{ slice: SliceName }>(); const props = defineProps<{ slice: SliceName }>();
async function loadData() { async function loadData() {
const response = await useTimelineDataRaw('visits', props.slice); const response = await useVisitsTimeline(props.slice);
if (!response) return; if (!response) return;
const fixed = fixMetrics(response, props.slice); const fixed = fixMetrics(response, props.slice);
console.log(fixed); console.log(fixed);

View File

@@ -1,3 +1,5 @@
import type { Slice } from "@services/DateService";
import DateService from "@services/DateService";
import type { MetricsCounts } from "~/server/api/metrics/[project_id]/counts"; import type { MetricsCounts } from "~/server/api/metrics/[project_id]/counts";
import type { VisitsWebsiteAggregated } from "~/server/api/metrics/[project_id]/data/websites"; import type { VisitsWebsiteAggregated } from "~/server/api/metrics/[project_id]/data/websites";
import type { MetricsTimeline } from "~/server/api/metrics/[project_id]/timeline/generic"; import type { MetricsTimeline } from "~/server/api/metrics/[project_id]/timeline/generic";
@@ -14,6 +16,19 @@ export function useFirstInteractionData() {
return metricsInfo; return metricsInfo;
} }
export async function useVisitsTimeline(fromDate: string, toDate: string, slice: Slice) {
const { from, to } = DateService.prepareDateRange(fromDate, toDate, slice);
const activeProject = useActiveProject();
const response = await $fetch(
`/api/metrics/${activeProject.value?._id}/timeline/visits`, {
method: 'POST',
...signHeaders({ 'Content-Type': 'application/json' }),
body: JSON.stringify({ slice, from, to })
});
return response;
}
export async function useTimelineDataRaw(timelineEndpointName: string, slice: SliceName) { export async function useTimelineDataRaw(timelineEndpointName: string, slice: SliceName) {
const activeProject = useActiveProject(); const activeProject = useActiveProject();

View File

@@ -1,10 +1,32 @@
import dayjs from 'dayjs'; import dayjs from 'dayjs';
export type Slice = 'day' | 'hour' | 'month' | 'year'; export type Slice = keyof typeof slicesData;
const slicesData = {
hour: {
fromOffset: 1000 * 60 * 60 * 24
},
day: {
fromOffset: 1000 * 60 * 60 * 24 * 7
},
month: {
fromOffset: 1000 * 60 * 60 * 24 * 30 * 12
},
year: {
fromOffset: 1000 * 60 * 60 * 24 * 30 * 12 * 10
}
}
class DateService { class DateService {
public slicesData = slicesData;
getDefaultRange(slice: Slice, from?: string, to?: string) {
}
getQueryDateRange(slice: Slice) { getQueryDateRange(slice: Slice) {
const group: Record<string, any> = {} const group: Record<string, any> = {}