-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstatics.js
More file actions
53 lines (52 loc) · 2.5 KB
/
statics.js
File metadata and controls
53 lines (52 loc) · 2.5 KB
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
const fs = require('fs');
const db = require('./db');
const systems = db.Database().collection("systems");
const EveService = require('./eveService');
const throttledQueue = require('throttled-queue');
const throttle = throttledQueue(10, 200, true);
const eveService = new EveService();
const CsvReadableStream = require('csv-reader');
module.exports.UpdateStatics = () => {
const wormholeDbFile = fs.createReadStream('./wormhole.db');
const statics = fs.createReadStream('./statics.csv', 'utf8');
const wormholeTypes = [];
wormholeDbFile.on('data', (data) => {
data.toString().split('\n').forEach(line => {
const type = line.search('hi-sec') !== -1 ? 'HS' : line.search('low-sec') !== -1 ? 'LS' : line.search('0.0') !== -1 ? 'NS' : line.search('w-space') !== -1 && line.search('drifter') === -1 ? 'WH' : null;
if (type) {
const wt = {
name: line.match(new RegExp('Wormhole ([A-Z][0-9]+)', 'g'))[0],
code: line.match(new RegExp('([A-Z][0-9]+)', 'g'))[0],
time: parseInt(line.match(new RegExp('[0-9]+ h', 'g'))[0].substr(0, 2)),
goes: type === 'WH' ? 'C' + line.match(new RegExp('Class [0-9]+', 'g'))[0].match(new RegExp('[0-9]+'))[0] : type
};
wormholeTypes.push(wt);
}
});
}).on('end', () => {
statics.pipe(new CsvReadableStream({parseNumbers: true, parseBooleans: true, trim: true, skipHeader: true}))
.on('data', function (row) {
throttle(async () => {
try {
const type = await eveService.getType(row[2]);
const whType = wormholeTypes.find(val => val.name === type.name);
const system = await systems.findOneAndUpdate({
system_id: parseInt(row[1]),
'statics.code': {$ne: whType.code}
}, {
$push: {
'statics': whType
}
}, {
upsert: true,
});
console.log('Updated', parseInt(row[1]));
} catch (ex) {
console.error(ex.message, row[1]);
}
});
})
.on('end', async function (data) {
});
});
};