Events chart.

This commit is contained in:
Mike Cao 2020-08-27 03:42:24 -07:00
parent 5f47f328be
commit 4618dc7f15
9 changed files with 220 additions and 226 deletions

View file

@ -108,7 +108,7 @@ export function getDateArray(data, startDate, endDate, unit) {
const t = add(startDate, i);
const y = findData(t);
arr.push({ t, y });
arr.push({ ...data[i], t, y });
}
return arr;

View file

@ -401,7 +401,7 @@ export function getActiveVisitors(website_id) {
return Promise.resolve([]);
}
export function getEvents(website_id, start_at, end_at) {
export function getEventRankings(website_id, start_at, end_at) {
const db = getDatabase();
if (db === POSTGRESQL) {
@ -438,3 +438,48 @@ export function getEvents(website_id, start_at, end_at) {
return Promise.resolve([]);
}
export function getEvents(website_id, start_at, end_at, timezone = 'utc', unit = 'day') {
const db = getDatabase();
if (db === POSTGRESQL) {
return prisma.$queryRaw(
`
select
event_value x,
date_trunc('${unit}', created_at at time zone '${timezone}') t,
count(*) y
from event
where website_id=$1
and created_at between $2 and $3
group by 1, 2
order by 2
`,
website_id,
start_at,
end_at,
);
}
if (db === MYSQL) {
const tz = moment.tz(timezone).format('Z');
return prisma.$queryRaw(
`
select
event_value x,
date_trunc('${unit}', convert_tz(created_at,'+00:00','${tz}')) t,
count(*) y
from event
where website_id=?
and created_at between ? and ?
group by 1, 2
order by 2
`,
website_id,
start_at,
end_at,
);
}
return Promise.resolve([]);
}