mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
Updated Clickhouse number handling. Removed number formatting.
This commit is contained in:
parent
caa9da9166
commit
04e0b33622
@ -187,6 +187,7 @@ async function rawQuery<T = unknown>(
|
|||||||
query: query,
|
query: query,
|
||||||
query_params: params,
|
query_params: params,
|
||||||
format: 'JSONEachRow',
|
format: 'JSONEachRow',
|
||||||
|
clickhouse_settings: { output_format_json_quote_64bit_integers: 0 },
|
||||||
});
|
});
|
||||||
|
|
||||||
return (await resultSet.json()) as T;
|
return (await resultSet.json()) as T;
|
||||||
|
@ -85,17 +85,7 @@ async function clickhouseQuery(
|
|||||||
limit 500
|
limit 500
|
||||||
`,
|
`,
|
||||||
params,
|
params,
|
||||||
).then(result => {
|
);
|
||||||
return Object.values(result).map((a: any) => {
|
|
||||||
return {
|
|
||||||
eventName: a.eventName,
|
|
||||||
propertyName: a.propertyName,
|
|
||||||
dataType: Number(a.dataType),
|
|
||||||
propertyValue: a.propertyValue,
|
|
||||||
total: Number(a.total),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rawQuery(
|
return rawQuery(
|
||||||
@ -113,14 +103,5 @@ async function clickhouseQuery(
|
|||||||
limit 500
|
limit 500
|
||||||
`,
|
`,
|
||||||
params,
|
params,
|
||||||
).then(result => {
|
);
|
||||||
return Object.values(result).map((a: any) => {
|
|
||||||
return {
|
|
||||||
eventName: a.eventName,
|
|
||||||
propertyName: a.propertyName,
|
|
||||||
dataType: Number(a.dataType),
|
|
||||||
total: Number(a.total),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
@ -64,13 +64,5 @@ async function clickhouseQuery(
|
|||||||
limit 500
|
limit 500
|
||||||
`,
|
`,
|
||||||
params,
|
params,
|
||||||
).then(result => {
|
);
|
||||||
return Object.values(result).map((a: any) => {
|
|
||||||
return {
|
|
||||||
eventName: a.eventName,
|
|
||||||
propertyName: a.propertyName,
|
|
||||||
total: Number(a.total),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ export async function getEventDataStats(
|
|||||||
return runQuery({
|
return runQuery({
|
||||||
[PRISMA]: () => relationalQuery(...args),
|
[PRISMA]: () => relationalQuery(...args),
|
||||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||||
}).then(results => results[0]);
|
}).then(results => results?.[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
||||||
@ -68,13 +68,5 @@ async function clickhouseQuery(
|
|||||||
) as t
|
) as t
|
||||||
`,
|
`,
|
||||||
params,
|
params,
|
||||||
).then(result => {
|
);
|
||||||
return Object.values(result).map((a: any) => {
|
|
||||||
return {
|
|
||||||
events: Number(a.events),
|
|
||||||
properties: Number(a.properties),
|
|
||||||
records: Number(a.records),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
@ -30,9 +30,5 @@ function clickhouseQuery(
|
|||||||
startDate,
|
startDate,
|
||||||
endDate,
|
endDate,
|
||||||
},
|
},
|
||||||
).then(result => {
|
);
|
||||||
return Object.values(result).map((a: any) => {
|
|
||||||
return { websiteId: a.websiteId, count: Number(a.count) };
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
@ -66,12 +66,5 @@ async function clickhouseQuery(
|
|||||||
limit 100
|
limit 100
|
||||||
`,
|
`,
|
||||||
params,
|
params,
|
||||||
).then(result => {
|
);
|
||||||
return Object.values(result).map((a: any) => {
|
|
||||||
return {
|
|
||||||
...a,
|
|
||||||
total: Number(a.total),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,9 @@ async function relationalQuery(websiteId: string) {
|
|||||||
select count(distinct session_id) x
|
select count(distinct session_id) x
|
||||||
from website_event
|
from website_event
|
||||||
where website_id = {{websiteId::uuid}}
|
where website_id = {{websiteId::uuid}}
|
||||||
and created_at >= {{startAt}}
|
and created_at >= {{startDate}}
|
||||||
`,
|
`,
|
||||||
{ websiteId, startAt: subMinutes(new Date(), 5) },
|
{ websiteId, startDate: subMinutes(new Date(), 5) },
|
||||||
);
|
);
|
||||||
|
|
||||||
return result[0] ?? null;
|
return result[0] ?? null;
|
||||||
@ -35,14 +35,10 @@ async function clickhouseQuery(websiteId: string): Promise<{ x: number }> {
|
|||||||
count(distinct session_id) x
|
count(distinct session_id) x
|
||||||
from website_event
|
from website_event
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at >= {startAt:DateTime64}
|
and created_at >= {startDate:DateTime64}
|
||||||
`,
|
`,
|
||||||
{ websiteId, startAt: subMinutes(new Date(), 5) },
|
{ websiteId, startDate: subMinutes(new Date(), 5) },
|
||||||
).then(a => {
|
);
|
||||||
return Object.values(a).map(a => {
|
|
||||||
return { x: Number(a.x) };
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return result[0] ?? null;
|
return result[0] ?? null;
|
||||||
}
|
}
|
||||||
|
@ -117,15 +117,5 @@ async function clickhouseQuery(
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rawQuery(sql, params).then(result => {
|
return rawQuery(sql, params);
|
||||||
return Object.values(result).map((a: any) => {
|
|
||||||
return {
|
|
||||||
pageviews: Number(a.pageviews),
|
|
||||||
visitors: Number(a.visitors),
|
|
||||||
visits: Number(a.visits),
|
|
||||||
bounces: Number(a.bounces),
|
|
||||||
totaltime: Number(a.totaltime),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
@ -87,9 +87,5 @@ async function clickhouseQuery(
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rawQuery(sql, params).then(result => {
|
return rawQuery(sql, params);
|
||||||
return Object.values(result).map((a: any) => {
|
|
||||||
return { x: a.x, y: Number(a.y) };
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
@ -90,9 +90,7 @@ async function relationalQuery(
|
|||||||
startDate,
|
startDate,
|
||||||
endDate,
|
endDate,
|
||||||
},
|
},
|
||||||
).then(results => {
|
);
|
||||||
return results.map(i => ({ ...i, percentage: Number(i.percentage) || 0 }));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function clickhouseQuery(
|
async function clickhouseQuery(
|
||||||
@ -169,15 +167,5 @@ async function clickhouseQuery(
|
|||||||
startDate,
|
startDate,
|
||||||
endDate,
|
endDate,
|
||||||
},
|
},
|
||||||
).then(result => {
|
);
|
||||||
return Object.values(result).map((a: any) => {
|
|
||||||
return {
|
|
||||||
date: a.date,
|
|
||||||
day: Number(a.day),
|
|
||||||
visitors: Number(a.visitors),
|
|
||||||
returnVisitors: Number(a.returnVisitors),
|
|
||||||
percentage: Number(a.percentage),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
@ -143,17 +143,7 @@ async function clickhouseQuery(
|
|||||||
order by time
|
order by time
|
||||||
`,
|
`,
|
||||||
{ websiteId, startDate, endDate, eventName, revenueProperty, userProperty },
|
{ websiteId, startDate, endDate, eventName, revenueProperty, userProperty },
|
||||||
).then(result => {
|
).then(result => result?.[0]);
|
||||||
return Object.values(result).map((a: any) => {
|
|
||||||
return {
|
|
||||||
time: a.time,
|
|
||||||
sum: Number(a.sum),
|
|
||||||
avg: Number(a.avg),
|
|
||||||
count: Number(a.count),
|
|
||||||
uniqueCount: Number(!a.avg ? 0 : a.uniqueCount),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
const totalRes = await rawQuery<{
|
const totalRes = await rawQuery<{
|
||||||
sum: number;
|
sum: number;
|
||||||
@ -174,16 +164,7 @@ async function clickhouseQuery(
|
|||||||
and data_key in ({revenueProperty:String}, {userProperty:String})
|
and data_key in ({revenueProperty:String}, {userProperty:String})
|
||||||
`,
|
`,
|
||||||
{ websiteId, startDate, endDate, eventName, revenueProperty, userProperty },
|
{ websiteId, startDate, endDate, eventName, revenueProperty, userProperty },
|
||||||
).then(results => {
|
);
|
||||||
const result = results[0];
|
|
||||||
|
|
||||||
return {
|
|
||||||
sum: Number(result.sum),
|
|
||||||
avg: Number(result.avg),
|
|
||||||
count: Number(result.count),
|
|
||||||
uniqueCount: Number(!result.avg ? 0 : result.uniqueCount),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return { chart: chartRes, total: totalRes };
|
return { chart: chartRes, total: totalRes };
|
||||||
}
|
}
|
||||||
|
@ -61,12 +61,5 @@ async function clickhouseQuery(
|
|||||||
limit 500
|
limit 500
|
||||||
`,
|
`,
|
||||||
params,
|
params,
|
||||||
).then(result => {
|
);
|
||||||
return Object.values(result).map((a: any) => {
|
|
||||||
return {
|
|
||||||
propertyName: a.propertyName,
|
|
||||||
total: Number(a.total),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
@ -61,12 +61,5 @@ async function clickhouseQuery(
|
|||||||
limit 100
|
limit 100
|
||||||
`,
|
`,
|
||||||
params,
|
params,
|
||||||
).then(result => {
|
);
|
||||||
return Object.values(result).map((a: any) => {
|
|
||||||
return {
|
|
||||||
...a,
|
|
||||||
total: Number(a.total),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
@ -87,9 +87,5 @@ async function clickhouseQuery(
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rawQuery(sql, params).then(result => {
|
return rawQuery(sql, params);
|
||||||
return Object.values(result).map((a: any) => {
|
|
||||||
return { x: a.x, y: Number(a.y) };
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
@ -68,15 +68,5 @@ async function clickhouseQuery(
|
|||||||
${filterQuery}
|
${filterQuery}
|
||||||
`,
|
`,
|
||||||
params,
|
params,
|
||||||
).then(result => {
|
);
|
||||||
return Object.values(result).map((a: any) => {
|
|
||||||
return {
|
|
||||||
pageviews: Number(a.pageviews),
|
|
||||||
visitors: Number(a.visitors),
|
|
||||||
visits: Number(a.visits),
|
|
||||||
countries: Number(a.countries),
|
|
||||||
events: Number(a.events),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user