diff options
| author | Fuwn <[email protected]> | 2026-01-24 13:09:50 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-01-24 13:09:50 +0000 |
| commit | 396acf3bbbe00a192cb0ea0a9ccf91b1d8d2850b (patch) | |
| tree | b9df4ca6a70db45cfffbae6fdd7252e20fb8e93c /scripts/seed/generators/sessions.ts | |
| download | umami-396acf3bbbe00a192cb0ea0a9ccf91b1d8d2850b.tar.xz umami-396acf3bbbe00a192cb0ea0a9ccf91b1d8d2850b.zip | |
Created from https://vercel.com/new
Diffstat (limited to 'scripts/seed/generators/sessions.ts')
| -rw-r--r-- | scripts/seed/generators/sessions.ts | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/scripts/seed/generators/sessions.ts b/scripts/seed/generators/sessions.ts new file mode 100644 index 0000000..1370511 --- /dev/null +++ b/scripts/seed/generators/sessions.ts @@ -0,0 +1,52 @@ +import { uuid } from '../utils.js'; +import { getRandomDevice } from '../distributions/devices.js'; +import { getRandomGeo, getRandomLanguage } from '../distributions/geographic.js'; +import { generateTimestampForDay } from '../distributions/temporal.js'; + +export interface SessionData { + id: string; + websiteId: string; + browser: string; + os: string; + device: string; + screen: string; + language: string; + country: string; + region: string; + city: string; + createdAt: Date; +} + +export function createSession(websiteId: string, day: Date): SessionData { + const deviceInfo = getRandomDevice(); + const geo = getRandomGeo(); + const language = getRandomLanguage(); + const createdAt = generateTimestampForDay(day); + + return { + id: uuid(), + websiteId, + browser: deviceInfo.browser, + os: deviceInfo.os, + device: deviceInfo.device, + screen: deviceInfo.screen, + language, + country: geo.country, + region: geo.region, + city: geo.city, + createdAt, + }; +} + +export function createSessions(websiteId: string, day: Date, count: number): SessionData[] { + const sessions: SessionData[] = []; + + for (let i = 0; i < count; i++) { + sessions.push(createSession(websiteId, day)); + } + + // Sort by createdAt to maintain chronological order + sessions.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime()); + + return sessions; +} |