-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (44 loc) · 1.5 KB
/
index.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
//mixpanel.track("Video play", {"genre": "hip-hop", "duration in seconds": 42});
const getInitialInternetSpeed = ()=> {
//At a given point, we should increment only 500 UP or down. the lowest is 0.
return parseInt((Math.random()*50000).toFixed());
}
const users = {
'[email protected]': {
email: '[email protected]',
currentSpeed: getInitialInternetSpeed(),
},
// '[email protected]': {
// email: '[email protected]',
// currentSpeed: getInitialInternetSpeed(),
// }
}
mixpanel.identify(Object.keys(users)[0]);
//1 KBPS to 50,000 KBPS
const getFakeInternetSpeed = (currentSpeed)=> {
//At a given point, we should increment only 500 UP or down. the lowest is 0.
//const op = ['Add', 'Sub'][parseInt((Math.random()*1).toFixed())];
//const delta = parseInt((Math.random()*1000).toFixed());
const op = 'Add';
delta = 500
var newSpeed ;
if(op === 'Add'){
newSpeed = currentSpeed + delta;
}
if(op === 'Sub'){
newSpeed = currentSpeed - delta;
}
if(newSpeed >=0 && newSpeed <= 50000){
return newSpeed
}else {
console.log('newspeed is out of bound', newSpeed);
return getInitialInternetSpeed();
}
}
window.setInterval(()=>{
Object.keys(users).forEach((i)=>{
users[i].currentSpeed = getFakeInternetSpeed(users[i].currentSpeed);
console.log(users[i])
mixpanel.track("InternetSpeed", {"email": users[i].email, "speed": users[i].currentSpeed});
});
}, 60000)