-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate_sample_dist.js
74 lines (59 loc) · 2.22 KB
/
generate_sample_dist.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
const createCsvWriter = require('csv-writer').createObjectCsvWriter;
/***
* This script can be used to generate random data into a CSV
* It was created to populate token distribution lists for testing
* */
// how many lines in the file? How many users in the airdrop?
const line_count = 50000;
const random_handle = (length = 8) => {
// Declare all characters
let chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
// Pick characers randomly
let str = '';
for (let i = 0; i < length; i++) {
str += chars.charAt(Math.floor(Math.random() * chars.length));
}
return str;
};
// create template for CSV
const csvWriter = createCsvWriter({
path: 'new_sample_dist_list.csv',
header: [
{id: 'handle', title: 'handle'},
{id: 'user_id', title: 'user_id'},
{id: 'total_claim', title: 'total_claim'},
{id: 'active_user', title: 'active_user'},
{id: 'kernel', title: 'kernel'},
{id: 'GMV', title: 'GMV'}
]
});
// create full distribution
const full_dist = []
// populate distribution
var i;
for (i = 0; i < line_count; i++) {
const claim_ceiling = 1000;
const random_total_claim = Math.floor((Math.random() * claim_ceiling) + 12) // total claim between 12 and claim_ceiling
const random_active_user = Math.floor((Math.random() * (random_total_claim - 2)) + 2) // active user = random between total claim - 2 and 2
const random_kernel = Math.floor((Math.random() * (random_total_claim - random_active_user)) + 1) //
const random_GMV = random_total_claim - (random_active_user + random_kernel)
if ((random_GMV + random_active_user + random_kernel) != random_total_claim) {
console.error('TOTAL MISMATCH!')
}
const toWei = 1000000000000000000; // lazy move to wei
// create single record
const user_dist = {
handle: random_handle(8),
user_id: i,
total_claim: random_total_claim * toWei,
active_user: random_active_user * toWei,
kernel: random_kernel * toWei,
GMV: random_GMV * toWei
}
// add record to dictionary
full_dist.push(user_dist);
}
// write the CSV
csvWriter
.writeRecords(full_dist)
.then(()=> console.log('sample_distribution_list.csv has been written!'));