-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStatTools.js
138 lines (134 loc) · 4.17 KB
/
StatTools.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
const { default: SlippiGame } = require('slp-parser-js');
const fs = require('fs');
const path = require('path');
const _ = require('underscore');
module.exports = {
// find most recent replay in path
findLatestReplay: function(dir) {
var files = fs.readdirSync(dir);
return _.max(files, function (f) {
var fullpath = path.join(dir, f);
return fs.statSync(fullpath).ctime;
});
},
// get stats and metadata from a slippi replay
loadReplay: function(file) {
const game = new SlippiGame(file);
const stats = game.getStats();
const metadata = game.getMetadata();
const settings = game.getSettings();
return [stats, metadata, settings];
},
// turns frame_count into min:sec format
convertTime: function(frame_count) {
const duration = frame_count / 60;
const minutes = Math.floor(duration/60).toString();
let seconds = Math.round(duration - (minutes*60)).toString();
if (seconds.length < 2) {
seconds = '0' + seconds;
}
const time = minutes + ":" + seconds;
return time;
},
//split stats up by category and player
playerStats: function(stats) {
const p1_stats = stats.overall[0];
const p1_actions = stats.actionCounts[0];
const p2_stats = stats.overall[1];
const p2_actions = stats.actionCounts[1];
return [p1_stats, p1_actions, p2_stats, p2_actions];
},
// turn conversion raio into percent
ratioPercent: function(ratio) {
let percent = ratio * 100;
percent = percent.toFixed(2);
return percent;
},
//find which ports the players used
assignPlayers: function(metadata) {
for (i = 0; i < 5; i++) {
if (typeof(metadata.players[i]) !== 'undefined') {
const char1 = metadata.players[i];
for (j = i+1; j < 5; j++) {
if (typeof(metadata.players[j]) !== 'undefined') {
const char2 = metadata.players[j];
return [char1, char2];
}
}
}
}
},
// get stage name from stage ID
getStageName: function(stage_id) {
const stage_dict = {2: 'Fountain Of Dreams',
3: 'Pokémon Stadium',
4: 'Princess Peach’s Castle',
5: 'Kongo Jungle',
6: 'Brinstar ',
7: 'Corneria ',
8: 'Yoshi’s Story',
9: 'Onett ',
10: 'Mute City',
11: 'Rainbow Cruise',
12: 'Jungle Japes',
13: 'Great Bay',
14: 'Hyrule Temple',
15: 'Brinstar Depths',
16: 'Yoshi’s Island',
17: 'Green Greens',
18: 'Fourside',
19: 'Mushroom Kingdom I',
20: 'Mushroom Kingdom Ii',
22: 'Venom',
23: 'Poke Floats',
24: 'Big Blue',
25: 'Icicle Mountain',
26: 'Icetop',
27: 'Flat Zone',
28: 'Dream Land',
29: 'Yoshi’s Island N64',
30: 'Kongo Jungle N64',
31: 'Battlefield',
32: 'Final Destination'};
const stage = stage_dict[stage_id];
return stage;
},
// get character name from character ID
getCharName: function(char_id) {
const char_dict = {0: 'Mario',
1: 'Fox',
2: 'Captain Falcon',
3: 'Donkey Kong',
4: 'Kirby',
5: 'Bowser',
6: 'Link',
7: 'Sheik',
8: 'Ness',
9: 'Peach',
10: 'Popo',
11: 'Nana',
12: 'Pikachu',
13: 'Samus',
14: 'Yoshi',
15: 'Jigglypuff',
16: 'Mewtwo',
17: 'Luigi',
18: 'Marth',
19: 'Zelda',
20: 'Young Link',
21: 'Dr Mario',
22: 'Falco',
23: 'Pichu',
24: 'Mr. Game & Watch',
25: 'Ganondorf',
26: 'Roy',
27: 'Master Hand',
28: 'Crazy Hand',
29: 'Wireframe Male',
30: 'Wireframe Female',
31: 'Giga Bowser',
32: 'Sandbag'};
const char = char_dict[char_id];
return char;
}
};