-
Notifications
You must be signed in to change notification settings - Fork 0
/
fillTransactions.js
116 lines (109 loc) · 4.62 KB
/
fillTransactions.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
const moment = require("moment"),
_ = require("lodash"),
random = require("random-js")();
const monthlyTransPatterns = require("./monthly-spendings.json"),
monthlyTransPatterns = require("./monthly-spendings.json"),
startDate = moment("2015-05-01"),
endDate = moment("2017-05-12");
const
examples = {
foreignLang:["English course", "", "język polski", "German course", "French course"],
invPrefix: ["", "", "Customer no ", "Invoice ", "Bill number ", "Invoice "],
firstName: ["Anna", "Jan", "Julia", "Stefan"],
city: ["Bytom", "Katowice", "Sosnowiec", "Warszawa"],
person: ["Jan Ptak", "Anna Korek", "Zbig Kowalski", "Mateusz Kosta"],
street: ["ul. Prosta", "al. Jana Pawła II", "ul. Sokolska", "ul. Warszawska"],
WaterCompany: ["Gotham City Water Supply", "PWIK Katowice", "Welsh Water Co", "Water & Sewer Inc"],
ElectricCompany: ["Tauron Energy", "Edison Electric Company", "Energa S.A.", "Tauron Energy"],
insuranceCompany: ["Prudential Insurance", "WARTA S.A.", "PZU S.A.", "Allianz S.A."],
satTv: ["ITI Neovision SAT", "Cyfrowy Polsat S.A.", "Vectra Cable TV S.A.", "SAT1 Inc"],
langSchool: ["Right Now Language School", "iProfi-Lingua sp. z o.o.",
"#person, #randomAddr", "Sprachschule Berlin GmbH"],
gsmCompany: ["Orange S.A.", "Polkomtel GSM S.A.", "T-Mobile"],
landlord: ["#person, #randomAddr", "#city Apartment Administration",
"Spółdzielnia Mieszkaniowa Hutnik, #city"],
fitness: ["Fitness Center #city", "Swimming Pool #city", "Anna Chobakowska Fitness Center",
"Yoga School, Katowice"],
internetProvider: ["Orange Internet", "Vectra Internet", "Leon Internet Access", "Orange"]
};
var period = startDate.clone(),
m,
generators = {},
user = {city: "Katowice", name: "Adam Kroll" },
patterns, transactions, result;
generators.baby = function (){
return random.pick(examples.firstName) + " " + user.name.match(/\w+ (\w+)/)[1];
}
generators.address = function(){
return random.pick(examples.street)
+ " "
+ random.integer(1,90)
+ ", "
+ random.pick(examples.city)
}
generators.inv = function(){
return random.pick(examples.invPrefix)
+ "#long"
+ random.pick(["/",":","","-"])
+ random.pick(["#long",random.integer(10,1000), "#year"]);
}
function replaceKeys(t){
var m, text = t;
if (text.match(/#name/)){
text = text.replace("#name", user.name);
}
if (text.match(/#nr/)){
text = text.replace("#nr", random.integer(1,50));
}
if (text.match(/#year/)){
text = text.replace("#year", period.format("YYYY"));
}
if (text.match(/#long/)){
text = text.replace("#long", random.integer(1000,500000));
}
if (text.match(/#city/)){
text = text.replace("#city",user.city );
}
m = text.match(/#(\w+)/);
while (m && m[1] && examples[m[1]]) {
text = text.replace("#"+m[1], random.pick(examples[m[1]]));
m = text.match(/#(\w+)/);
}
while (m && m[1] && generators[m[1]]) {
text = text.replace("#"+m[1],generators[m[1]]);
m = text.match(/#(\w+)/);
}
return text;
}
patterns = monthlyTransPatterns.filter(p => true || p.freq > random.integer(0,100));
patterns = patterns.map(p => {
p.amount = random.integer(90, 110) * p.amount / 100;
p.day = random.integer(0, 28);
p.description = replaceKeys(p.description);
p.counterpartyaccountholder = replaceKeys(p.counterpartyaccountholder);
p.counterpartyaccountholder = replaceKeys(p.counterpartyaccountholder);
delete p.field5;
return p;
});
while (period.isBefore(endDate)){
var i = 60 * 6,
day,
daysInMonth = period.daysInMonth();
transactions = patterns.map(_.clone)
.map(t => {
day = t.day || random.integer(0, daysInMonth);
t.date = period.clone().add(day, "day");
i = i + 30;
t.date.add(i, "minute");
delete t.day;
return t;})
.map(t => {
t.amount = t.constAmount || random.integer(90, 110) * t.amount / 100;
t.description = replaceKeys(t.description);
t.description = replaceKeys(t.description);
return t;
})
result = transactions.concat(result);
period = period.add(1, 'month');
}
console.log(result);