-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathreadDatabase.js
198 lines (163 loc) · 5.67 KB
/
readDatabase.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
const fs = require("fs");
const database = JSON.parse(fs.readFileSync("./database.json"));
const chainData = JSON.parse(fs.readFileSync("./src/store/data/data.json"));
let memorialList = chainData.memorialList;
let cowardList = chainData.cowardCount;
let warriorList = chainData.warriors;
let ownerList = chainData.ownerCount;
const golfScores = {};
const golfScoresDead = {};
const arenaScores = {};
const symbolCounts = {};
const symbolCountsDead = {};
loadMetadata();
saveGolfScores();
saveArenaAndScarScores();
saveSymbolCounts();
// getNotEnteredCounts();
function loadMetadata(){
for (let i = 0; i < 26969; i++) {
let json = database[i];
let metadata = JSON.parse(json.replace('data:application/json;ascii,', ''));
// Golf Scores
let golfScore = metadata.attributes.filter( i => i.trait_type === 'Golf Score');
// Symbols
let leftFace = metadata.attributes.filter( i => i.trait_type === 'Left Face')[0].value;
let leftEye = metadata.attributes.filter( i => i.trait_type === 'Left Eye')[0].value;
let mouth = metadata.attributes.filter( i => i.trait_type === 'Mouth')[0].value;
let rightEye = metadata.attributes.filter( i => i.trait_type === 'Right Eye')[0].value;
let rightFace = metadata.attributes.filter( i => i.trait_type === 'Right Face')[0].value;
// Arena Scores
let arenaScore = metadata.attributes.filter( i => i.trait_type === 'Arena Score');
let dead = false;
if(memorialList[i]){
dead = true;
}
if(dead){
if (! golfScoresDead[golfScore[0].value]) {
golfScoresDead[golfScore[0].value] = 0;
}
golfScoresDead[golfScore[0].value]++
if (! symbolCountsDead[leftFace]) {
symbolCountsDead[leftFace] = 0;
}
if (! symbolCountsDead[leftEye]) {
symbolCountsDead[leftEye] = 0;
}
if (! symbolCountsDead[mouth]) {
symbolCountsDead[mouth] = 0;
}
if (! symbolCountsDead[rightEye]) {
symbolCountsDead[rightEye] = 0;
}
if (! symbolCountsDead[rightFace]) {
symbolCountsDead[rightFace] = 0;
}
symbolCountsDead[leftFace]++;
symbolCountsDead[leftEye]++;
symbolCountsDead[mouth]++;
symbolCountsDead[rightEye]++;
symbolCountsDead[rightFace]++;
}
else{
if (! golfScores[golfScore[0].value]) {
golfScores[golfScore[0].value] = 0;
}
golfScores[golfScore[0].value]++
if (! arenaScores[arenaScore[0].value]) {
arenaScores[arenaScore[0].value] = 0;
}
arenaScores[arenaScore[0].value]++
if (! symbolCounts[leftFace]) {
symbolCounts[leftFace] = 0;
}
if (! symbolCounts[leftEye]) {
symbolCounts[leftEye] = 0;
}
if (! symbolCounts[mouth]) {
symbolCounts[mouth] = 0;
}
if (! symbolCounts[rightEye]) {
symbolCounts[rightEye] = 0;
}
if (! symbolCounts[rightFace]) {
symbolCounts[rightFace] = 0;
}
symbolCounts[leftFace]++;
symbolCounts[leftEye]++;
symbolCounts[mouth]++;
symbolCounts[rightEye]++;
symbolCounts[rightFace]++;
}
}
}
function saveGolfScores(){
let golfRows = [];
for (let i in golfScores) {
let v = golfScores[i];
golfRows.push({
score : i,
count: v
})
}
fs.writeFileSync('./src/store/data/golfScores.json', JSON.stringify(golfRows));
console.log('Golf Score JSON file was written successfully');
golfRows = [];
for (let i in golfScoresDead) {
let v = golfScoresDead[i];
golfRows.push({
score : i,
count: v
})
}
fs.writeFileSync('./src/store/data/golfScoresDead.json', JSON.stringify(golfRows));
console.log('Golf Score Dead JSON file was written successfully');
}
function saveArenaAndScarScores(){
// Arena Score
let arenaRows = [];
let scarRows = [];
let scarSum = 0;
let index = 0;
for (let i in arenaScores) {
let v = arenaScores[i];
scarSum += v;
if(i % 10 == 0){
scarRows.push({
score : index++,
count: scarSum
})
scarSum = 0;
}
arenaRows.push({
score : i,
count: v
})
}
fs.writeFileSync('./src/store/data/arenaScores.json', JSON.stringify(arenaRows));
console.log('Arena Score JSON file was written successfully');
fs.writeFileSync('./src/store/data/scarScores.json', JSON.stringify(scarRows));
console.log('Scar Score JSON file was written successfully');
}
function saveSymbolCounts(){
let symbolRows = [];
for (let i in symbolCounts) {
let v = symbolCounts[i];
symbolRows.push({
score : i,
count: v
})
}
fs.writeFileSync('./src/store/data/symbolCounts.json', JSON.stringify(symbolRows));
console.log('Symbol Counts JSON file was written successfully');
symbolRows = [];
for (let i in symbolCountsDead) {
let v = symbolCountsDead[i];
symbolRows.push({
score : i,
count: v
})
}
fs.writeFileSync('./src/store/data/symbolCountsDead.json', JSON.stringify(symbolRows));
console.log('Symbol Counts Dead JSON file was written successfully');
}