Spaces:
Configuration error
Configuration error
Download src/queries/analytics/sessions/getSessionDataValues.ts from SreejithSHR/umami: direct link, hf CLI and curl.
- Browser
- Download file 2.09 kB
-
https://huggingface.co/spaces/SreejithSHR/umami/resolve/main/src/queries/analytics/sessions/getSessionDataValues.ts
- Command line
-
hf download hf://spaces/SreejithSHR/umami/src/queries/analytics/sessions/getSessionDataValues.ts
-
curl -L -o getSessionDataValues.ts https://huggingface.co/spaces/SreejithSHR/umami/resolve/main/src/queries/analytics/sessions/getSessionDataValues.ts
2.09 kB
| import prisma from 'lib/prisma'; | |
| import clickhouse from 'lib/clickhouse'; | |
| import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db'; | |
| import { QueryFilters, WebsiteEventData } from 'lib/types'; | |
| export async function getSessionDataValues( | |
| ...args: [websiteId: string, filters: QueryFilters & { propertyName?: string }] | |
| ): Promise<WebsiteEventData[]> { | |
| return runQuery({ | |
| [PRISMA]: () => relationalQuery(...args), | |
| [CLICKHOUSE]: () => clickhouseQuery(...args), | |
| }); | |
| } | |
| async function relationalQuery( | |
| websiteId: string, | |
| filters: QueryFilters & { propertyName?: string }, | |
| ) { | |
| const { rawQuery, parseFilters, getDateSQL } = prisma; | |
| const { filterQuery, params } = await parseFilters(websiteId, filters); | |
| return rawQuery( | |
| ` | |
| select | |
| case | |
| when data_type = 2 then replace(string_value, '.0000', '') | |
| when data_type = 4 then ${getDateSQL('date_value', 'hour')} | |
| else string_value | |
| end as "value", | |
| count(*) as "total" | |
| from session_data | |
| where website_id = {{websiteId::uuid}} | |
| and created_at between {{startDate}} and {{endDate}} | |
| and data_key = {{propertyName}} | |
| ${filterQuery} | |
| group by value | |
| order by 2 desc | |
| limit 100 | |
| `, | |
| params, | |
| ); | |
| } | |
| async function clickhouseQuery( | |
| websiteId: string, | |
| filters: QueryFilters & { propertyName?: string }, | |
| ): Promise<{ propertyName: string; dataType: number; propertyValue: string; total: number }[]> { | |
| const { rawQuery, parseFilters } = clickhouse; | |
| const { filterQuery, params } = await parseFilters(websiteId, filters); | |
| return rawQuery( | |
| ` | |
| select | |
| multiIf(data_type = 2, replaceAll(string_value, '.0000', ''), | |
| data_type = 4, toString(date_trunc('hour', date_value)), | |
| string_value) as "value", | |
| count(*) as "total" | |
| from session_data final | |
| where website_id = {websiteId:UUID} | |
| and created_at between {startDate:DateTime64} and {endDate:DateTime64} | |
| and data_key = {propertyName:String} | |
| ${filterQuery} | |
| group by value | |
| order by 2 desc | |
| limit 100 | |
| `, | |
| params, | |
| ); | |
| } | |