Skip to content

Commit

Permalink
fix monthly and all time charts
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscao633 committed Aug 27, 2024
1 parent a219f5d commit b1caf6e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/components/charts/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function BarChart(props: BarChartProps) {
x: {
type: XAxisType,
stacked: true,
min: minDate,
min: unit === 'minute' ? minDate : '',
max: maxDate,
time: {
unit,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/clickhouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ function getDateStringSQL(data: any, unit: string = 'utc', timezone?: string) {

function getDateSQL(field: string, unit: string, timezone?: string) {
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') {
Expand Down
6 changes: 3 additions & 3 deletions src/queries/analytics/pageviews/getPageviewStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async function clickhouseQuery(
filters: QueryFilters,
): Promise<{ x: string; y: number }[]> {
const { timezone = 'utc', unit = 'day' } = filters;
const { parseFilters, rawQuery } = clickhouse;
const { parseFilters, rawQuery, getDateSQL } = clickhouse;
const { filterQuery, params } = await parseFilters(websiteId, {
...filters,
eventType: EVENT_TYPE.pageView,
Expand All @@ -57,7 +57,7 @@ async function clickhouseQuery(
g.y as y
from (
select
date_trunc('${unit}', created_at, '${timezone}') as t,
${getDateSQL('website_event.created_at', unit, timezone)} as t,
count(*) as y
from website_event
where website_id = {websiteId:UUID}
Expand All @@ -75,7 +75,7 @@ async function clickhouseQuery(
g.y as y
from (
select
date_trunc('${unit}', created_at, '${timezone}') as t,
${getDateSQL('website_event.created_at', unit, timezone)} as t,
sum(views)as y
from website_event_stats_hourly website_event
where website_id = {websiteId:UUID}
Expand Down
10 changes: 5 additions & 5 deletions src/queries/analytics/sessions/getSessionStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async function clickhouseQuery(
filters: QueryFilters,
): Promise<{ x: string; y: number }[]> {
const { timezone = 'utc', unit = 'day' } = filters;
const { parseFilters, rawQuery } = clickhouse;
const { parseFilters, rawQuery, getDateSQL } = clickhouse;
const { filterQuery, params } = await parseFilters(websiteId, {
...filters,
eventType: EVENT_TYPE.pageView,
Expand All @@ -53,11 +53,11 @@ async function clickhouseQuery(
if (EVENT_COLUMNS.some(item => Object.keys(filters).includes(item)) || unit === 'minute') {
sql = `
select
g.t as x,
g.t as x,
g.y as y
from (
select
date_trunc('${unit}', created_at, '${timezone}') as t,
${getDateSQL('website_event.created_at', unit, timezone)} as t,
count(distinct session_id) as y
from website_event
where website_id = {websiteId:UUID}
Expand All @@ -71,11 +71,11 @@ async function clickhouseQuery(
} else {
sql = `
select
g.t as x,
g.t as x,
g.y as y
from (
select
date_trunc('${unit}', created_at, '${timezone}') as t,
${getDateSQL('website_event.created_at', unit, timezone)} as t,
uniq(session_id) as y
from website_event_stats_hourly website_event
where website_id = {websiteId:UUID}
Expand Down

0 comments on commit b1caf6e

Please sign in to comment.