-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateMockData.js
70 lines (62 loc) · 2.34 KB
/
generateMockData.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const getRandomInt = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
const generateMockData = () =>
{
return {
activeUsersOverTime: getActiveUsersOverTime(),
topSearchQueries: [
{name: "Home", value: getRandomInt(100, 500)},
{name: "Pricing", value: getRandomInt(50, 300)},
{name: "About", value: getRandomInt(20, 200)},
{name: "Signup", value: getRandomInt(30, 150)},
{name: "Blog", value: getRandomInt(40, 100)},
],
userActivityByRegion: [
getRandomInt(1, 100),
getRandomInt(1, 100),
getRandomInt(1, 100)
],
newSignupsPerDay: Array.from({length: 7}, (_, i) => ({
day: `Day ${i + 1}`,
Signups: getRandomInt(20, 150),
})),
retentionRateOverTime: Array.from({length: 7}, (_, i) => ({
time: `Week ${i + 1}`,
RetentionRate: getRandomInt(50, 90),
})),
mostPopularFeatures: [
{name: "Dark Mode", value: getRandomInt(500, 1500)},
{name: "Push Notifications", value: getRandomInt(400, 1200)},
{name: "Offline Mode", value: getRandomInt(300, 1000)},
],
churnRate: Array.from({length: 7}, (_, i) => ({
time: `Month ${i + 1}`,
ChurnRate: getRandomInt(2, 10),
})),
userDemographics: [
{category: "18-24", age: getRandomInt(100, 500)},
{category: "25-34", age: getRandomInt(200, 700)},
{category: "35-44", age: getRandomInt(100, 400)},
{category: "45-54", age: getRandomInt(50, 200)},
{category: "55+", age: getRandomInt(20, 100)}
],
};
};
function getActiveUsersOverTime()
{
const data = [];
const today = new Date();
for (let i = 0; i < 7; i++)
{
const date = new Date();
date.setDate(today.getDate() - i);
// Format the date as 'MM-DD'
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const formattedDate = `${month}-${day}`;
const activeUsers = getRandomInt(1000, 5000);
data.push({Time: formattedDate, ActiveUsers: activeUsers});
}
// Show the oldest date first.
return data.reverse();
}
module.exports = {generateMockData}