web: add average per user
This commit is contained in:
@@ -38,7 +38,7 @@ As of today (2023-12-12) I have more then 1.2 million events in PSQL and perform
|
|||||||
- [ ] Area
|
- [ ] Area
|
||||||
- [ ] Support funnels
|
- [ ] Support funnels
|
||||||
- [ ] Support multiple breakdowns
|
- [ ] Support multiple breakdowns
|
||||||
- [ ] Aggregations (sum, average...)
|
- [x] Aggregations (sum, average...)
|
||||||
|
|
||||||
### SDK
|
### SDK
|
||||||
|
|
||||||
|
|||||||
@@ -87,6 +87,10 @@ export function ReportEvents() {
|
|||||||
value: 'user',
|
value: 'user',
|
||||||
label: 'Unique users',
|
label: 'Unique users',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
value: 'user_average',
|
||||||
|
label: 'Unique users (average)',
|
||||||
|
},
|
||||||
]}
|
]}
|
||||||
label="Segment"
|
label="Segment"
|
||||||
>
|
>
|
||||||
@@ -95,6 +99,10 @@ export function ReportEvents() {
|
|||||||
<>
|
<>
|
||||||
<Users size={12} /> Unique users
|
<Users size={12} /> Unique users
|
||||||
</>
|
</>
|
||||||
|
) : event.segment === 'user_average' ? (
|
||||||
|
<>
|
||||||
|
<Users size={12} /> Average per user
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<GanttChart size={12} /> All events
|
<GanttChart size={12} /> All events
|
||||||
|
|||||||
@@ -236,23 +236,27 @@ function getDatesFromRange(range: IChartRange) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isFloat(range)) {
|
if (isFloat(range)) {
|
||||||
const startDate = new Date(Date.now() - 1000 * 60 * (range * 100));
|
const startDate = new Date(
|
||||||
|
Date.now() - 1000 * 60 * (range * 100)
|
||||||
|
).toISOString();
|
||||||
const endDate = new Date().toISOString();
|
const endDate = new Date().toISOString();
|
||||||
|
|
||||||
return {
|
|
||||||
startDate: startDate.toISOString(),
|
|
||||||
endDate: endDate,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const startDate = getDaysOldDate(range).toISOString();
|
|
||||||
const endDate = new Date().toISOString();
|
|
||||||
return {
|
return {
|
||||||
startDate,
|
startDate,
|
||||||
endDate,
|
endDate,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const startDate = getDaysOldDate(range);
|
||||||
|
startDate.setUTCHours(0, 0, 0, 0);
|
||||||
|
const endDate = new Date();
|
||||||
|
endDate.setUTCHours(23, 59, 59, 999);
|
||||||
|
return {
|
||||||
|
startDate: startDate.toISOString(),
|
||||||
|
endDate: endDate.toISOString(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function getChartSql({
|
function getChartSql({
|
||||||
event,
|
event,
|
||||||
chartType,
|
chartType,
|
||||||
@@ -271,6 +275,8 @@ function getChartSql({
|
|||||||
|
|
||||||
if (event.segment === 'event') {
|
if (event.segment === 'event') {
|
||||||
select.push(`count(*)::int as count`);
|
select.push(`count(*)::int as count`);
|
||||||
|
} else if (event.segment === 'user_average') {
|
||||||
|
select.push(`COUNT(*)::float / COUNT(DISTINCT profile_id)::float as count`);
|
||||||
} else {
|
} else {
|
||||||
select.push(`count(DISTINCT profile_id)::int as count`);
|
select.push(`count(DISTINCT profile_id)::int as count`);
|
||||||
}
|
}
|
||||||
@@ -396,6 +402,8 @@ function getChartSql({
|
|||||||
sql.push(`ORDER BY ${orderBy.join(', ')}`);
|
sql.push(`ORDER BY ${orderBy.join(', ')}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('SQL ->', sql.join('\n'));
|
||||||
|
|
||||||
return sql.join('\n');
|
return sql.join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ function objectToZodEnums<K extends string>(obj: Record<K, any>): [K, ...K[]] {
|
|||||||
export const zChartEvent = z.object({
|
export const zChartEvent = z.object({
|
||||||
id: z.string(),
|
id: z.string(),
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
segment: z.enum(['event', 'user']),
|
segment: z.enum(['event', 'user', 'user_average']),
|
||||||
filters: z.array(
|
filters: z.array(
|
||||||
z.object({
|
z.object({
|
||||||
id: z.string(),
|
id: z.string(),
|
||||||
|
|||||||
Reference in New Issue
Block a user