-
Notifications
You must be signed in to change notification settings - Fork 1
/
createtestdata.js
90 lines (77 loc) · 2.13 KB
/
createtestdata.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const fs = require("fs");
const randInt = (min, max) => Math.floor(Math.random() * (max - min + 1) + min);
const randStr = (length) => {
var result = "";
var characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
};
let semver = [0, 0, 0];
const nextSemver = () => {
let [major, minor, patch] = semver;
switch (randInt(0, 20)) {
case 20:
major++;
minor = 0;
patch = 0;
break;
case 19:
case 18:
case 17:
minor++;
patch = 0;
break;
default:
patch++;
break;
}
semver = [major, minor, patch];
return semver.join(".");
};
const lines = [];
for (let i = 0; i < 200; i++) {
const values = {
"add.avg": randInt(3500, 4500),
"update.avg": randInt(2300, 2800),
"delete.avg": randInt(2000, 2500),
"loc.total": randInt(1000, 1250),
"loc.covered": randInt(400, 600),
};
const commitId = randStr(10);
const meta = {
commit: { value: commitId, url: "http://example.org/" + commitId },
date: {
value: new Date(
randInt(Date.now() - 1000 * 60 * 60 * 24 * 365, Date.now())
)
.toISOString()
.slice(0, "2020-02-02".length),
},
};
lines.push(JSON.stringify({ version: nextSemver(), values, meta }));
}
for (let i = 0; i < 200; i++) {
const values = {
"add.avg": randInt(4000, 5000),
"delete.avg": randInt(2000, 2500),
"update.avg": randInt(1000, 2000),
"loc.total": randInt(2000, 2200),
"loc.covered": randInt(1200, 1500),
};
lines.push(JSON.stringify({ version: nextSemver(), values }));
}
for (let i = 0; i < 200; i++) {
const values = {
"add.avg": randInt(800, 900),
"delete.avg": randInt(1000, 1400),
"update.avg": randInt(2000, 2500),
"loc.total": randInt(3000, 3300),
"loc.covered": randInt(2800, 3200),
};
lines.push(JSON.stringify({ version: nextSemver(), values }));
}
fs.writeFileSync("data/ff.v1.jsonl", lines.join("\n"), { encoding: "utf8" });