add 30 min active user histogram

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-02-13 23:18:24 +01:00
parent 2572da3456
commit f32dc4711a
34 changed files with 570 additions and 457 deletions

View File

@@ -10,7 +10,7 @@ import { round } from '@/utils/math';
import * as mathjs from 'mathjs';
import { sort } from 'ramda';
import { chQuery } from '@mixan/db';
import { chQuery, convertClickhouseDateToJs } from '@mixan/db';
export type GetChartDataResult = Awaited<ReturnType<typeof getChartData>>;
export interface ResultItem {
@@ -73,7 +73,7 @@ function fillEmptySpotsInTimeline(
const getMinute = (date: Date) => date.getUTCMinutes();
const item = items.find((item) => {
const date = new Date(item.date);
const date = convertClickhouseDateToJs(item.date);
if (interval === 'month') {
return (

View File

@@ -10,7 +10,7 @@ import { zChartInput } from '@/utils/validation';
import { flatten, map, pipe, prop, sort, uniq } from 'ramda';
import { z } from 'zod';
import { chQuery } from '@mixan/db';
import { chQuery, createSqlBuilder } from '@mixan/db';
import { getChartData, withFormula } from './chart.helpers';
@@ -117,16 +117,20 @@ export const chartRouter = createTRPCRouter({
})
)
.query(async ({ input: { event, property, projectId } }) => {
const sql = property.startsWith('properties.')
? `SELECT distinct mapValues(mapExtractKeyLike(properties, '${property
.replace(/^properties\./, '')
.replace(
'.*.',
'.%.'
)}')) as values from events where name = '${event}' AND project_id = '${projectId}';`
: `SELECT ${property} as values from events where name = '${event}' AND project_id = '${projectId}';`;
const { sb, getSql } = createSqlBuilder();
sb.where.project_id = `project_id = '${projectId}'`;
if (event !== '*') {
sb.where.event = `name = '${event}'`;
}
if (property.startsWith('properties.')) {
sb.select.values = `distinct mapValues(mapExtractKeyLike(properties, '${property
.replace(/^properties\./, '')
.replace('.*.', '.%.')}')) as values`;
} else {
sb.select.values = `${property} as values`;
}
const events = await chQuery<{ values: string[] }>(sql);
const events = await chQuery<{ values: string[] }>(getSql());
const values = pipe(
(data: typeof events) => map(prop('values'), data),