()
| 3 | import { v4 as uuid } from 'uuid'; |
| 4 | |
| 5 | async function main() { |
| 6 | const startDate = new Date('2025-01-01T00:00:00Z'); |
| 7 | const endDate = new Date(); |
| 8 | const eventsPerDay = 25000; |
| 9 | const variance = 3000; |
| 10 | |
| 11 | // Event names to randomly choose from |
| 12 | const eventNames = ['click', 'purchase', 'signup', 'login', 'screen_view']; |
| 13 | |
| 14 | // Loop through each day |
| 15 | for ( |
| 16 | let currentDate = startDate; |
| 17 | currentDate <= endDate; |
| 18 | currentDate.setDate(currentDate.getDate() + 1) |
| 19 | ) { |
| 20 | const events: IClickhouseEvent[] = []; |
| 21 | // Calculate random number of events for this day |
| 22 | const dailyEvents = |
| 23 | eventsPerDay + Math.floor(Math.random() * variance * 2) - variance; |
| 24 | |
| 25 | // Create events for the day |
| 26 | for (let i = 0; i < dailyEvents; i++) { |
| 27 | const eventTime = new Date(currentDate); |
| 28 | // Distribute events throughout the day |
| 29 | eventTime.setHours(Math.floor(Math.random() * 24)); |
| 30 | eventTime.setMinutes(Math.floor(Math.random() * 60)); |
| 31 | eventTime.setSeconds(Math.floor(Math.random() * 60)); |
| 32 | |
| 33 | events.push({ |
| 34 | id: uuid(), |
| 35 | name: eventNames[Math.floor(Math.random() * eventNames.length)]!, |
| 36 | device_id: `device_${Math.floor(Math.random() * 1000)}`, |
| 37 | profile_id: `profile_${Math.floor(Math.random() * 1000)}`, |
| 38 | project_id: 'testing', |
| 39 | session_id: `session_${Math.floor(Math.random() * 10000)}`, |
| 40 | properties: { |
| 41 | hash: 'test-hash', |
| 42 | 'query.utm_source': 'test', |
| 43 | }, |
| 44 | created_at: formatClickhouseDate(eventTime), |
| 45 | country: 'US', |
| 46 | city: 'New York', |
| 47 | region: 'NY', |
| 48 | longitude: -74.006, |
| 49 | latitude: 40.7128, |
| 50 | os: 'macOS', |
| 51 | os_version: '13.0', |
| 52 | browser: 'Chrome', |
| 53 | browser_version: '120.0', |
| 54 | device: 'desktop', |
| 55 | brand: 'Apple', |
| 56 | model: 'MacBook Pro', |
| 57 | duration: Math.floor(Math.random() * 300), |
| 58 | path: `/page-${Math.floor(Math.random() * 20)}`, |
| 59 | origin: 'https://example.com', |
| 60 | referrer: 'https://google.com', |
| 61 | referrer_name: 'Google', |
| 62 | referrer_type: 'search', |
no test coverage detected