-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
72 lines (63 loc) · 2.01 KB
/
index.js
File metadata and controls
72 lines (63 loc) · 2.01 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const FS = require('fs').promises;
const PATH = require('path');
const MOMENT = require('moment');
const DATA_FOLDER = './data';
const ENEMY_NAME_PREFIX = 'L10 Pitboss';
const stringContains = (s, sub) => s.indexOf(sub)!=-1;
/**
* @param {string} line
*/
const parseTimeStamp = (line) => {
if(!line.startsWith('[')){
return null;
}
const startIndex = line.indexOf('[');
const endIndex = line.indexOf(']');
if(startIndex < 0 || endIndex < 0){
return null;
}
const stampStr = line.substring(startIndex+1, endIndex);
return MOMENT.utc(stampStr, "HH:mm:ss");
}
/**
* @param {string} line
* @returns
*/
const parseDamage = (line) => {
if(!stringContains(line, 'damage')){
return 0;
}
const parts = line.split(' > ');
if(parts.length!=3){
return 0;
}
const dmgPart = parts.filter(p=>stringContains(p, 'damage'))[0];
const delimited = dmgPart.split(' ').map(s=>s.trim());
try{
return Number(delimited[0]);
}catch(err){
console.log(err);
}
return 0;
}
const parseBossName = (line) => line.split(' > ').filter(s=>stringContains(s, ENEMY_NAME_PREFIX))[0];
const sumReduce = (previousValue, currentValue) => previousValue + currentValue;
const run = async () => {
let files = await FS.readdir('./data');
files = files.filter(f=>f.endsWith('.log')).map(f=>PATH.join(DATA_FOLDER, f));
for(const f of files){
const data = await FS.readFile(f, "utf8");
const lines = data.split('\n').filter(d=>stringContains(d, ENEMY_NAME_PREFIX));
const bossName = parseBossName(lines[0]);
const startTime = parseTimeStamp(lines[0]);
const endTime = parseTimeStamp(lines[lines.length-1]);
const diff = endTime - startTime;
const dmgSum = lines.map(parseDamage).reduce(sumReduce);
const dps = dmgSum/(diff/1000);
console.log(`DPS OF ${bossName} is ${dps}`);
}
};
run().then(()=>process.exit(0)).catch((err)=>{
console.log(err);
process.exit(1);
});