-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgamesParser.js
54 lines (47 loc) · 1.67 KB
/
gamesParser.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
const fs = require('fs')
let games = require('./data/games.json')
const UNPARSED_GAMES_FOLDER = 'unparsedGames'
var deleteInnerFolderRecursive = function (path) {
if (fs.existsSync(path)) {
fs.readdirSync(path).forEach(function (file, index) {
var curPath = path + "/" + file
if (fs.lstatSync(curPath).isDirectory( )) {
deleteFolderRecursive(curPath)
} else {
fs.unlinkSync(curPath)
}
})
}
}
let files = fs.readdirSync(UNPARSED_GAMES_FOLDER)
let filesCount = files.length
files.forEach(function(fileName, ind) {
let id = fileName.replace('.txt', '')
let game = { }
let content = fs.readFileSync(UNPARSED_GAMES_FOLDER + '/' + fileName, 'utf8')
let lines = content.split('\n')
game.radiantPick = [ ]
game.direPick = [ ]
for (let i = 0; i < 10; i++) {
let split = lines[i].split(':')
let pick = {
hero: parseInt(split[0]),
player: parseInt(split[1])
}
let pickList = (i < 5 ? game.radiantPick : game.direPick)
pickList.push(pick)
}
game.winner = (lines[10] == '0' ? 'radiant' : 'dire')
game.advantage = parseFloat(lines[11])
let intSkill = parseInt(lines[12])
game.skill = (intSkill == 1 ? 'normal' : (intSkill == 2 ? 'high' : 'very high'))
games[id] = game
if (ind % 1000 == 0) {
fs.writeFileSync('data/games.json', JSON.stringify(games))
console.log(ind / filesCount * 100 + '%')
}
}, this)
fs.writeFileSync('data/games.json', JSON.stringify(games))
console.log('deleting unnecessary files...')
deleteInnerFolderRecursive(UNPARSED_GAMES_FOLDER)
console.log('done')