-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivity-fill.js
76 lines (64 loc) · 2.26 KB
/
activity-fill.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
71
72
73
74
75
76
#!/usr/bin/env node
const request = require('request');
const user = process.argv[2];
const pass = process.argv[3];
const domain = process.argv[4] || 'localhost:5984';
const protocol = process.argv[5] || 'http';
const baseUrl = protocol + '://' + user + ':' + pass + '@' + domain;
const userArray = [ 'q', 'w', 'e', 'r', 'a', 's', 'd', 'f' ];
const resourceArray = [
'420aca97613804b8e9fef9c82e00aa5c',
'420aca97613804b8e9fef9c82e00af0c',
'420aca97613804b8e9fef9c82e00b332',
'4393724bb71ab348fd9f7e704b032c7d',
'47b2bf59c96d58704147a870f10c4363'
];
const adminActivityTypes = [ 'login', 'upgrade', 'sync' ];
const newRandomItem = (array) => {
return array[Math.floor(Math.random() * array.length)];
}
const newDate = () => {
return Date.now() - Math.floor(Math.random() * 100000);
}
const loginActivity = () => {
const loginTime = newDate();
return ({
createdOn: 'paul_test.config',
parentCode: 'dev',
user: newRandomItem(userArray),
loginTime,
logoutTime: loginTime + Math.floor(Math.random * 10000),
type: 'login'
});
}
const adminActivity = () => {
return ({
createdOn: 'paul_test.config',
parentCode: 'dev',
user: user,
createdTime: newDate(),
type: newRandomItem(adminActivityTypes)
});
}
const resourceActivity = () => {
return ({
createdOn: 'paul_test.config',
parentCode: 'dev',
user: newRandomItem(userArray),
time: newDate(),
activity: 'visit',
resource: newRandomItem(resourceArray)
});
}
const numberOfActivities = 25000;
const baseArray = Array(numberOfActivities).fill(0);
const addActivities = (docs, db, callback) => {
request.post({ uri: baseUrl + '/' + db + '/_bulk_docs', body: { docs }, json: true }, callback);
}
const logMessageCallback = (message) => (err, response) => console.log(message);
const adminActivities = baseArray.map(() => adminActivity());
const resourceActivities = baseArray.map(() => resourceActivity());
const loginActivities = baseArray.map(() => loginActivity());
addActivities(adminActivities, 'activity_logs', logMessageCallback('Admin activities added'));
addActivities(resourceActivities, 'resource_activities', logMessageCallback('Resource activities added'));
addActivities(loginActivities, 'login_activities', logMessageCallback('Login activities added'));