-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_training_text.js
executable file
·84 lines (76 loc) · 2.03 KB
/
generate_training_text.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
const fs = require('fs');
const yargs = require('yargs');
const dayjs = require('dayjs');
const argv = yargs
.option('type', {
alias: 't',
description: 'Type of data',
type: 'string',
})
.option('output', {
alias: 'o',
description: 'Ouput file',
type: 'string',
})
.help()
.alias('help', 'h').argv;
const actions = {
date(filename) {
// 10 - 80
const b = dayjs().subtract(20, 'year');
let a = b.subtract(30, 'year');
var file = fs.createWriteStream(filename);
file.on('error', function (err) {
/* error handling */
console.error(err);
});
for (; a.isBefore(b); a = a.add(1, 'day')) {
file.write(a.format('DD/MM/YYYY'));
file.write('\n');
}
file.end();
},
idcard(filename) {
var list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
var getPermutations = function (list, maxLen) {
// Copy initial values as arrays
var perm = list.map(function (val) {
return [val];
});
// Our permutation generator
var generate = function (perm, maxLen, currLen) {
// Reached desired length
if (currLen === maxLen) {
return perm;
}
// For each existing permutation
for (var i = 0, len = perm.length; i < len; i++) {
var currPerm = perm.shift();
// Create new permutation
for (var k = 0; k < list.length; k++) {
perm.push(currPerm.concat(list[k]));
}
}
// Recurse
return generate(perm, maxLen, currLen + 1);
};
// Start with size 1 because of initial values
return generate(perm, maxLen, 1);
};
var num = parseInt(process.argv[2]) || 4;
var arr = getPermutations(list, num);
var file = fs.createWriteStream(filename);
file.on('error', function (err) {
/* error handling */
console.error(err);
});
arr.forEach(function (v) {
file.write(v.join(''));
file.write('\n');
});
file.end();
},
};
// trigger
const fn = actions[argv.type];
if (fn) fn(argv.output);