mirror of
https://github.com/umami-software/umami.git
synced 2026-02-21 13:05:36 +01:00
Compare commits
No commits in common. "ce1120c3ff595ec827e0d4fbccd5cb59efcdb622" and "27c342811e40a9e40d75d893ff6faa7f00e9a094" have entirely different histories.
ce1120c3ff
...
27c342811e
4 changed files with 18 additions and 22 deletions
|
|
@ -2,7 +2,7 @@ import { z } from 'zod';
|
||||||
import { getQueryFilters, parseRequest } from '@/lib/request';
|
import { getQueryFilters, parseRequest } from '@/lib/request';
|
||||||
import { unauthorized, json } from '@/lib/response';
|
import { unauthorized, json } from '@/lib/response';
|
||||||
import { canViewWebsite } from '@/permissions';
|
import { canViewWebsite } from '@/permissions';
|
||||||
import { filterParams, pagingParams, timezoneParam } from '@/lib/schema';
|
import { pagingParams, timezoneParam } from '@/lib/schema';
|
||||||
import { getWeeklyTraffic } from '@/queries';
|
import { getWeeklyTraffic } from '@/queries';
|
||||||
|
|
||||||
export async function GET(
|
export async function GET(
|
||||||
|
|
@ -13,7 +13,6 @@ export async function GET(
|
||||||
startAt: z.coerce.number().int(),
|
startAt: z.coerce.number().int(),
|
||||||
endAt: z.coerce.number().int(),
|
endAt: z.coerce.number().int(),
|
||||||
timezone: timezoneParam,
|
timezone: timezoneParam,
|
||||||
...filterParams,
|
|
||||||
...pagingParams,
|
...pagingParams,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ export function PageviewsChart({ data, unit, minDate, maxDate, ...props }: Pagev
|
||||||
__id: new Date().getTime(),
|
__id: new Date().getTime(),
|
||||||
datasets: [
|
datasets: [
|
||||||
{
|
{
|
||||||
type: 'bar',
|
type: data.compare ? 'line' : 'bar',
|
||||||
label: formatMessage(labels.visitors),
|
label: formatMessage(labels.visitors),
|
||||||
data: generateTimeSeries(data.sessions, minDate, maxDate, unit, dateLocale),
|
data: generateTimeSeries(data.sessions, minDate, maxDate, unit, dateLocale),
|
||||||
borderWidth: 1,
|
borderWidth: 1,
|
||||||
|
|
@ -41,7 +41,7 @@ export function PageviewsChart({ data, unit, minDate, maxDate, ...props }: Pagev
|
||||||
order: 3,
|
order: 3,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'bar',
|
type: data.compare ? 'line' : 'bar',
|
||||||
label: formatMessage(labels.views),
|
label: formatMessage(labels.views),
|
||||||
data: generateTimeSeries(data.pageviews, minDate, maxDate, unit, dateLocale),
|
data: generateTimeSeries(data.pageviews, minDate, maxDate, unit, dateLocale),
|
||||||
barPercentage: 0.9,
|
barPercentage: 0.9,
|
||||||
|
|
|
||||||
|
|
@ -325,7 +325,7 @@ export function formatDate(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function generateTimeSeries(
|
export function generateTimeSeries(
|
||||||
data: { x: string; y: number; d?: string }[],
|
data: { x: string; y: number }[],
|
||||||
minDate: Date,
|
minDate: Date,
|
||||||
maxDate: Date,
|
maxDate: Date,
|
||||||
unit: string,
|
unit: string,
|
||||||
|
|
@ -345,12 +345,12 @@ export function generateTimeSeries(
|
||||||
current = add(current, 1);
|
current = add(current, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const lookup = new Map(data.map(({ x, y, d }) => [formatDate(x, fmt, locale), { x, y, d }]));
|
const lookup = new Map(data.map(({ x, y }) => [formatDate(x, fmt, locale), { x, y }]));
|
||||||
|
|
||||||
return timeseries.map(t => {
|
return timeseries.map(t => {
|
||||||
const { x, y, d } = lookup.get(t) || {};
|
const { x, y } = lookup.get(t) || {};
|
||||||
|
|
||||||
return { x: t, d: d ?? x, y: y ?? null };
|
return { x: t, d: x, y: y ?? null };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,16 +46,11 @@ async function relationalQuery(
|
||||||
return rawQuery(
|
return rawQuery(
|
||||||
`
|
`
|
||||||
WITH cohort_items AS (
|
WITH cohort_items AS (
|
||||||
select
|
select session_id,
|
||||||
min(${getDateSQL('website_event.created_at', unit, timezone)}) as cohort_date,
|
${getDateSQL('created_at', unit)} as cohort_date
|
||||||
website_event.session_id
|
from session
|
||||||
from website_event
|
where website_id = {{websiteId::uuid}}
|
||||||
${cohortQuery}
|
and created_at between {{startDate}} and {{endDate}}
|
||||||
${joinSessionQuery}
|
|
||||||
where website_event.website_id = {{websiteId::uuid}}
|
|
||||||
and website_event.created_at between {{startDate}} and {{endDate}}
|
|
||||||
${filterQuery}
|
|
||||||
group by website_event.session_id
|
|
||||||
),
|
),
|
||||||
user_activities AS (
|
user_activities AS (
|
||||||
select distinct
|
select distinct
|
||||||
|
|
@ -64,9 +59,11 @@ async function relationalQuery(
|
||||||
from website_event
|
from website_event
|
||||||
join cohort_items
|
join cohort_items
|
||||||
on website_event.session_id = cohort_items.session_id
|
on website_event.session_id = cohort_items.session_id
|
||||||
|
${cohortQuery}
|
||||||
|
${joinSessionQuery}
|
||||||
where website_id = {{websiteId::uuid}}
|
where website_id = {{websiteId::uuid}}
|
||||||
and created_at between {{startDate}} and {{endDate}}
|
and created_at between {{startDate}} and {{endDate}}
|
||||||
|
${filterQuery}
|
||||||
),
|
),
|
||||||
cohort_size as (
|
cohort_size as (
|
||||||
select cohort_date,
|
select cohort_date,
|
||||||
|
|
@ -124,10 +121,8 @@ async function clickhouseQuery(
|
||||||
min(${getDateSQL('created_at', unit, timezone)}) as cohort_date,
|
min(${getDateSQL('created_at', unit, timezone)}) as cohort_date,
|
||||||
session_id
|
session_id
|
||||||
from website_event
|
from website_event
|
||||||
${cohortQuery}
|
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
${filterQuery}
|
|
||||||
group by session_id
|
group by session_id
|
||||||
),
|
),
|
||||||
user_activities AS (
|
user_activities AS (
|
||||||
|
|
@ -137,8 +132,10 @@ async function clickhouseQuery(
|
||||||
from website_event
|
from website_event
|
||||||
join cohort_items
|
join cohort_items
|
||||||
on website_event.session_id = cohort_items.session_id
|
on website_event.session_id = cohort_items.session_id
|
||||||
|
${cohortQuery}
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
|
${filterQuery}
|
||||||
),
|
),
|
||||||
cohort_size as (
|
cohort_size as (
|
||||||
select cohort_date,
|
select cohort_date,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue