update api to new CH columns

This commit is contained in:
Francis Cao 2022-10-08 16:12:33 -07:00
parent 36edbe2f4c
commit 96add409b6
19 changed files with 74 additions and 48 deletions

View file

@ -41,19 +41,19 @@ async function relationalQuery(website_id, { start_at, end_at, filters = {} }) {
);
}
async function clickhouseQuery(website_id, { start_at, end_at, filters = {} }) {
async function clickhouseQuery(website_uuid, { start_at, end_at, filters = {} }) {
const { rawQuery, getDateQuery, getBetweenDates, parseFilters } = clickhouse;
const params = [website_id];
const params = [website_uuid];
const { pageviewQuery, sessionQuery } = parseFilters(null, filters, params);
return rawQuery(
`select
sum(t.c) as "pageviews",
count(distinct t.session_uuid) as "uniques",
count(distinct t.session_id) as "uniques",
sum(if(t.c = 1, 1, 0)) as "bounces",
sum(if(max_time < min_time + interval 1 hour, max_time-min_time, 0)) as "totaltime"
from (
select session_uuid,
select session_id,
${getDateQuery('created_at', 'day')} time_series,
count(*) c,
min(created_at) min_time,
@ -64,7 +64,7 @@ async function clickhouseQuery(website_id, { start_at, end_at, filters = {} }) {
and ${getBetweenDates('created_at', start_at, end_at)}
${pageviewQuery}
${sessionQuery}
group by session_uuid, time_series
group by session_id, time_series
) t;`,
params,
);