update CH rawquery and type

This commit is contained in:
Francis Cao 2023-09-29 11:00:06 -07:00
parent 35d45334df
commit 98b7624e8f
17 changed files with 169 additions and 52 deletions

View file

@ -172,7 +172,7 @@ async function clickhouseQuery(
);
}
return rawQuery<{ level: number; count: number }[]>(
return rawQuery(
`
WITH level0 AS (
select distinct session_id, url_path, referrer_path, created_at
@ -201,7 +201,7 @@ async function clickhouseQuery(
).then(results => {
return urls.map((a, i) => ({
x: a,
y: results[i]?.count || 0,
y: Number(results[i]?.count) || 0,
z: (1 - Number(results[i]?.count) / Number(results[i - 1]?.count)) * 100 || 0, // drop off
}));
});

View file

@ -75,7 +75,7 @@ async function clickhouseQuery(
${parseFields(fields)}
from website_event
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime} and {endDate:DateTime}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
and event_type = {eventType:UInt32}
${filterQuery}
${parseGroupBy(fields)}

View file

@ -172,5 +172,15 @@ async function clickhouseQuery(
startDate,
endDate,
},
);
).then(a => {
return Object.values(a).map(a => {
return {
date: a.date,
day: Number(a.day),
visitors: Number(a.visitors),
returnVisitors: Number(a.returnVisitors),
percentage: Number(a.percentage),
};
});
});
}