...
 
Commits (2)
var sqlite = require('sqlite3');
var babar = require('babar');
var analyser = {
results: {
ms: null,
hp: null,
dpt: null,
ttk: null,
idealTtk: null,
idealDpt: {
1: 0.31,
2: 0.65,
3: 1.05,
4: 1.65,
5: 2.31,
6: 3.21,
7: 4.81,
8: 5.65,
9: 8.78,
10: 14,
11: 20,
12: 25,
13: 31.39,
14: 40,
15: 49.22,
16: 56,
17: 65,
18: 75,
19: 88.58,
20: 110
}
},
init: function () {
db.getCharacters(this.onGetCharacters.bind(this));
},
onGetCharacters: function (err, res) {
var chars = res.map(function (r) {
var val = JSON.parse(r.value);
val.components.forEach(function (c) {
val[c.type] = c;
});
return val;
});
this.calcMs(chars);
this.calcHp(chars);
this.calcDpt(chars);
this.calcTtk(chars);
this.calcIdealTtk(chars);
this.plot('ms');
this.plot('hp');
this.plot('dpt');
this.plot('ttk');
this.plot('idealTtk');
},
calcMs: function (chars) {
var res = {};
var counts = {};
for (var i = 1; i <= 20; i++) {
res[i] = 0;
counts[i] = 0;
}
chars.forEach(function (c) {
if ((!c.stats) || (c.name == 'Waffle'))
return;
var level = c.stats.values.level;
var s = [0, 0, 0];
c.inventory.items.forEach(function (i) {
if ((!i.eq) || (!i.stats))
return;
s[0] += (i.stats.int || 0);
s[1] += (i.stats.dex || 0);
s[2] += (i.stats.str || 0);
}, 0);
var ms = Math.max(s[0], s[1], s[2]);
res[level] += (ms + level);
counts[level]++;
});
for (var p in res) {
res[p] = ~~(res[p] / counts[p]);
}
this.results.ms = res;
},
calcHp: function (chars) {
var res = {};
var counts = {};
for (var i = 1; i <= 20; i++) {
res[i] = 0;
counts[i] = 0;
}
chars.forEach(function (c) {
if ((!c.stats) || (c.name == 'Waffle'))
return;
var level = c.stats.values.level;
var vit = c.inventory.items.reduce(function (a, b) {
return (b.eq) ? ((b.stats || {}).vit || 0) : 0;
}, 0);
var maxHp = (level * 32.7) + (vit * 10);
res[level] += maxHp;
counts[level]++;
});
for (var p in res) {
res[p] = ~~(res[p] / counts[p]);
}
this.results.hp = res;
},
calcDpt: function (chars) {
var res = {};
var counts = {};
for (var i = 1; i <= 20; i++) {
res[i] = 0;
counts[i] = 0;
}
chars.forEach(function (c) {
if ((!c.stats) || (c.name == 'Waffle'))
return;
var level = c.stats.values.level;
var spells = c.spellbook.spells;
var total = 0;
var count = 0;
spells.forEach(function (s) {
var dmg = s.values.dmg;
if (!dmg)
return;
dmg = parseFloat(dmg.split('/')[0]);
total += dmg;
count++;
});
if (count > 0)
res[level] += (total / count);
counts[level]++;
});
for (var p in res) {
res[p] = (res[p] / counts[p]);
}
this.results.dpt = res;
},
calcTtk: function (chars) {
var res = {};
var mults = {
'1': 0.1,
'2': 0.2,
'3': 0.4,
'4': 0.7,
'5': 0.78,
'6': 0.91,
'7': 1.16,
'8': 1.19,
'9': 1.65,
'10': 2.36,
'11': 3.07,
'12': 3.55,
'13': 4.1,
'14': 4.85,
'15': 5.6,
'16': 5.9,
'17': 6.5,
'18': 7.1,
'19': 7.9,
'20': 12,
};
var dpt = this.results.dpt;
for (var i = 1; i <= 20; i++) {
var hp = (i * 32.7) * (mults[i] || 1);
res[i] = hp / dpt[i];
}
this.results.ttk = res;
},
calcIdealTtk: function (chars) {
var res = {};
var mults = {
'1': 0.1,
'2': 0.2,
'3': 0.4,
'4': 0.7,
'5': 0.78,
'6': 0.91,
'7': 1.16,
'8': 1.19,
'9': 1.65,
'10': 2.36,
'11': 3.07,
'12': 3.55,
'13': 4.1,
'14': 4.85,
'15': 5.6,
'16': 5.9,
'17': 6.5,
'18': 7.1,
'19': 7.9,
'20': 12,
};
var dpt = this.results.idealDpt;
for (var i = 1; i <= 20; i++) {
var hp = (i * 32.7) * (mults[i] || 1);
res[i] = hp / dpt[i];
}
this.results.idealTtk = res;
},
plot: function (field) {
var res = this.results[field];
console.log(' ' + field.toUpperCase());
var print = [];
for (var i = 1; i <= 20; i++) {
print.push([i, res[i]]);
}
console.log(babar(print));
console.log();
}
};
var db = {
db: null,
init: function () {
this.db = new sqlite.Database('../../data/storage.db', analyser.init.bind(analyser));
},
getCharacters: function (cb) {
var query = `SELECT * FROM character`;
this.db.all(query, cb);
}
};
db.init();
{
"version": "0.0.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"babar": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/babar/-/babar-0.2.0.tgz",
"integrity": "sha512-bH01czBTWEbf7Q6qje/4raQEG14jhPTQJmpj1Uxzw92VCr9yQcCWN+SbKTg34aOvWDs6wrhjfr6SGC8AaeSzaA==",
"requires": {
"colors": "0.6.2"
}
},
"colors": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/colors/-/colors-0.6.2.tgz",
"integrity": "sha1-JCP+ZnisDF2uiFLl0OW+CMmXq8w="
},
"extend": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz",
"integrity": "sha1-p1Xqe8Gt/MWjHOfnYtuq3F5jZEQ="
},
"nan": {
"version": "2.9.2",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.9.2.tgz",
"integrity": "sha512-ltW65co7f3PQWBDbqVvaU1WtFJUsNW7sWWm4HINhbMQIyVyzIeyZ8toX5TC5eeooE6piZoaEh4cZkueSKG3KYw=="
},
"sqlite3": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/sqlite3/-/sqlite3-4.0.0.tgz",
"integrity": "sha512-6OlcAQNGaRSBLK1CuaRbKwlMFBb9DEhzmZyQP+fltNRF6XcIMpVIfXCBEcXPe1d4v9LnhkQUYkknDbA5JReqJg==",
"requires": {
"nan": "2.9.2",
"node-pre-gyp": "0.9.0"
},
"dependencies": {
"abbrev": {
"version": "1.1.1",
"bundled": true
},
"ansi-regex": {
"version": "2.1.1",
"bundled": true
},
"aproba": {
"version": "1.2.0",
"bundled": true
},
"are-we-there-yet": {
"version": "1.1.4",
"bundled": true,
"requires": {
"delegates": "1.0.0",
"readable-stream": "2.3.5"
}
},
"balanced-match": {
"version": "1.0.0",
"bundled": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"requires": {
"balanced-match": "1.0.0",
"concat-map": "0.0.1"
}
},
"chownr": {
"version": "1.0.1",
"bundled": true
},
"code-point-at": {
"version": "1.1.0",
"bundled": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true
},
"core-util-is": {
"version": "1.0.2",
"bundled": true
},
"debug": {
"version": "2.6.9",
"bundled": true,
"requires": {
"ms": "2.0.0"
}
},
"deep-extend": {
"version": "0.4.2",
"bundled": true
},
"delegates": {
"version": "1.0.0",
"bundled": true
},
"detect-libc": {
"version": "1.0.3",
"bundled": true
},
"fs-minipass": {
"version": "1.2.5",
"bundled": true,
"requires": {
"minipass": "2.2.1"
}
},
"fs.realpath": {
"version": "1.0.0",
"bundled": true
},
"gauge": {
"version": "2.7.4",
"bundled": true,
"requires": {
"aproba": "1.2.0",
"console-control-strings": "1.1.0",
"has-unicode": "2.0.1",
"object-assign": "4.1.1",
"signal-exit": "3.0.2",
"string-width": "1.0.2",
"strip-ansi": "3.0.1",
"wide-align": "1.1.2"
}
},
"glob": {
"version": "7.1.2",
"bundled": true,
"requires": {
"fs.realpath": "1.0.0",
"inflight": "1.0.6",
"inherits": "2.0.3",
"minimatch": "3.0.4",
"once": "1.4.0",
"path-is-absolute": "1.0.1"
}
},
"has-unicode": {
"version": "2.0.1",
"bundled": true
},
"iconv-lite": {
"version": "0.4.19",
"bundled": true
},
"ignore-walk": {
"version": "3.0.1",
"bundled": true,
"requires": {
"minimatch": "3.0.4"
}
},
"inflight": {
"version": "1.0.6",
"bundled": true,
"requires": {
"once": "1.4.0",
"wrappy": "1.0.2"
}
},
"inherits": {
"version": "2.0.3",
"bundled": true
},
"ini": {
"version": "1.3.5",
"bundled": true
},
"is-fullwidth-code-point": {
"version": "1.0.0",
"bundled": true,
"requires": {
"number-is-nan": "1.0.1"
}
},
"isarray": {
"version": "1.0.0",
"bundled": true
},
"minimatch": {
"version": "3.0.4",
"bundled": true,
"requires": {
"brace-expansion": "1.1.11"
}
},
"minimist": {
"version": "0.0.8",
"bundled": true
},
"minipass": {
"version": "2.2.1",
"bundled": true,
"requires": {
"yallist": "3.0.2"
}
},
"minizlib": {
"version": "1.1.0",
"bundled": true,
"requires": {
"minipass": "2.2.1"
}
},
"mkdirp": {
"version": "0.5.1",
"bundled": true,
"requires": {
"minimist": "0.0.8"
}
},
"ms": {
"version": "2.0.0",
"bundled": true
},
"needle": {
"version": "2.2.0",
"bundled": true,
"requires": {
"debug": "2.6.9",
"iconv-lite": "0.4.19",
"sax": "1.2.4"
}
},
"node-pre-gyp": {
"version": "0.9.0",
"bundled": true,
"requires": {
"detect-libc": "1.0.3",
"mkdirp": "0.5.1",
"needle": "2.2.0",
"nopt": "4.0.1",
"npm-packlist": "1.1.10",
"npmlog": "4.1.2",
"rc": "1.2.6",
"rimraf": "2.6.2",
"semver": "5.5.0",
"tar": "4.4.0"
}
},
"nopt": {
"version": "4.0.1",
"bundled": true,
"requires": {
"abbrev": "1.1.1",
"osenv": "0.1.5"
}
},
"npm-bundled": {
"version": "1.0.3",
"bundled": true
},
"npm-packlist": {
"version": "1.1.10",
"bundled": true,
"requires": {
"ignore-walk": "3.0.1",
"npm-bundled": "1.0.3"
}
},
"npmlog": {
"version": "4.1.2",
"bundled": true,
"requires": {
"are-we-there-yet": "1.1.4",
"console-control-strings": "1.1.0",
"gauge": "2.7.4",
"set-blocking": "2.0.0"
}
},
"number-is-nan": {
"version": "1.0.1",
"bundled": true
},
"object-assign": {
"version": "4.1.1",
"bundled": true
},
"once": {
"version": "1.4.0",
"bundled": true,
"requires": {
"wrappy": "1.0.2"
}
},
"os-homedir": {
"version": "1.0.2",
"bundled": true
},
"os-tmpdir": {
"version": "1.0.2",
"bundled": true
},
"osenv": {
"version": "0.1.5",
"bundled": true,
"requires": {
"os-homedir": "1.0.2",
"os-tmpdir": "1.0.2"
}
},
"path-is-absolute": {
"version": "1.0.1",
"bundled": true
},
"process-nextick-args": {
"version": "2.0.0",
"bundled": true
},
"rc": {
"version": "1.2.6",
"bundled": true,
"requires": {
"deep-extend": "0.4.2",
"ini": "1.3.5",
"minimist": "1.2.0",
"strip-json-comments": "2.0.1"
},
"dependencies": {
"minimist": {
"version": "1.2.0",
"bundled": true
}
}
},
"readable-stream": {
"version": "2.3.5",
"bundled": true,
"requires": {
"core-util-is": "1.0.2",
"inherits": "2.0.3",
"isarray": "1.0.0",
"process-nextick-args": "2.0.0",
"safe-buffer": "5.1.1",
"string_decoder": "1.0.3",
"util-deprecate": "1.0.2"
}
},
"rimraf": {
"version": "2.6.2",
"bundled": true,
"requires": {
"glob": "7.1.2"
}
},
"safe-buffer": {
"version": "5.1.1",
"bundled": true
},
"sax": {
"version": "1.2.4",
"bundled": true
},
"semver": {
"version": "5.5.0",
"bundled": true
},
"set-blocking": {
"version": "2.0.0",
"bundled": true
},
"signal-exit": {
"version": "3.0.2",
"bundled": true
},
"string-width": {
"version": "1.0.2",
"bundled": true,
"requires": {
"code-point-at": "1.1.0",
"is-fullwidth-code-point": "1.0.0",
"strip-ansi": "3.0.1"
}
},
"string_decoder": {
"version": "1.0.3",
"bundled": true,
"requires": {
"safe-buffer": "5.1.1"
}
},
"strip-ansi": {
"version": "3.0.1",
"bundled": true,
"requires": {
"ansi-regex": "2.1.1"
}
},
"strip-json-comments": {
"version": "2.0.1",
"bundled": true
},
"tar": {
"version": "4.4.0",
"bundled": true,
"requires": {
"chownr": "1.0.1",
"fs-minipass": "1.2.5",
"minipass": "2.2.1",
"minizlib": "1.1.0",
"mkdirp": "0.5.1",
"yallist": "3.0.2"
}
},
"util-deprecate": {
"version": "1.0.2",
"bundled": true
},
"wide-align": {
"version": "1.1.2",
"bundled": true,
"requires": {
"string-width": "1.0.2"
}
},
"wrappy": {
"version": "1.0.2",
"bundled": true
},
"yallist": {
"version": "3.0.2",
"bundled": true
}
}
}
}
}
{
"name": "",
"version": "0.0.1",
"description": "",
"dependencies": {
"babar": "^0.2.0",
"extend": "^3.0.1",
"sqlite3": "^4.0.0"
}
}