fix monthly and all time charts

This commit is contained in:
Francis Cao 2024-08-27 12:02:23 -07:00
parent a219f5dbe3
commit b1caf6edb7
4 changed files with 11 additions and 11 deletions

View File

@ -36,7 +36,7 @@ export function BarChart(props: BarChartProps) {
x: { x: {
type: XAxisType, type: XAxisType,
stacked: true, stacked: true,
min: minDate, min: unit === 'minute' ? minDate : '',
max: maxDate, max: maxDate,
time: { time: {
unit, unit,

View File

@ -63,9 +63,9 @@ function getDateStringSQL(data: any, unit: string = 'utc', timezone?: string) {
function getDateSQL(field: string, unit: string, timezone?: string) { function getDateSQL(field: string, unit: string, timezone?: string) {
if (timezone) { if (timezone) {
return `date_trunc('${unit}', ${field}, '${timezone}')`; return `toDateTime(date_trunc('${unit}', ${field}, '${timezone}'), '${timezone}')`;
} }
return `date_trunc('${unit}', ${field})`; return `toDateTime(date_trunc('${unit}', ${field}))`;
} }
function mapFilter(column: string, operator: string, name: string, type: string = 'String') { function mapFilter(column: string, operator: string, name: string, type: string = 'String') {

View File

@ -42,7 +42,7 @@ async function clickhouseQuery(
filters: QueryFilters, filters: QueryFilters,
): Promise<{ x: string; y: number }[]> { ): Promise<{ x: string; y: number }[]> {
const { timezone = 'utc', unit = 'day' } = filters; const { timezone = 'utc', unit = 'day' } = filters;
const { parseFilters, rawQuery } = clickhouse; const { parseFilters, rawQuery, getDateSQL } = clickhouse;
const { filterQuery, params } = await parseFilters(websiteId, { const { filterQuery, params } = await parseFilters(websiteId, {
...filters, ...filters,
eventType: EVENT_TYPE.pageView, eventType: EVENT_TYPE.pageView,
@ -57,7 +57,7 @@ async function clickhouseQuery(
g.y as y g.y as y
from ( from (
select select
date_trunc('${unit}', created_at, '${timezone}') as t, ${getDateSQL('website_event.created_at', unit, timezone)} as t,
count(*) as y count(*) as y
from website_event from website_event
where website_id = {websiteId:UUID} where website_id = {websiteId:UUID}
@ -75,7 +75,7 @@ async function clickhouseQuery(
g.y as y g.y as y
from ( from (
select select
date_trunc('${unit}', created_at, '${timezone}') as t, ${getDateSQL('website_event.created_at', unit, timezone)} as t,
sum(views)as y sum(views)as y
from website_event_stats_hourly website_event from website_event_stats_hourly website_event
where website_id = {websiteId:UUID} where website_id = {websiteId:UUID}

View File

@ -42,7 +42,7 @@ async function clickhouseQuery(
filters: QueryFilters, filters: QueryFilters,
): Promise<{ x: string; y: number }[]> { ): Promise<{ x: string; y: number }[]> {
const { timezone = 'utc', unit = 'day' } = filters; const { timezone = 'utc', unit = 'day' } = filters;
const { parseFilters, rawQuery } = clickhouse; const { parseFilters, rawQuery, getDateSQL } = clickhouse;
const { filterQuery, params } = await parseFilters(websiteId, { const { filterQuery, params } = await parseFilters(websiteId, {
...filters, ...filters,
eventType: EVENT_TYPE.pageView, eventType: EVENT_TYPE.pageView,
@ -57,7 +57,7 @@ async function clickhouseQuery(
g.y as y g.y as y
from ( from (
select select
date_trunc('${unit}', created_at, '${timezone}') as t, ${getDateSQL('website_event.created_at', unit, timezone)} as t,
count(distinct session_id) as y count(distinct session_id) as y
from website_event from website_event
where website_id = {websiteId:UUID} where website_id = {websiteId:UUID}
@ -75,7 +75,7 @@ async function clickhouseQuery(
g.y as y g.y as y
from ( from (
select select
date_trunc('${unit}', created_at, '${timezone}') as t, ${getDateSQL('website_event.created_at', unit, timezone)} as t,
uniq(session_id) as y uniq(session_id) as y
from website_event_stats_hourly website_event from website_event_stats_hourly website_event
where website_id = {websiteId:UUID} where website_id = {websiteId:UUID}