A lot of improvements

- added cookies to store client settings
- missing industry tax calculations
- missing page to edit user settings
This commit is contained in:
José Valdiviesso 2017-11-16 04:13:12 +00:00
parent a65a3d6e6c
commit c6e8cd3fd1
6 changed files with 23185 additions and 1307 deletions

View File

@ -4,11 +4,13 @@ var async = require('async');
var fs = require('fs');
var svurl = "mongodb://localhost:27017/eve-reactor";
var items = require('./items.json');
var systems = require('./systems.json');
var marketUrl = "https://market.fuzzwork.co.uk/aggregates/?region=60003760&types=";
var testMarketUrl = "https://market.fuzzwork.co.uk/aggregates/?region=60003760&types=34,35,36";
//addDaily();
newUpdateItems();
updateCostIndex();
function getItemID(name) {
for (let i = 0; i < items.length; i++) {
@ -34,6 +36,48 @@ function getDate() {
return today;
}
function getSystem(arr, id) {
for (let i = 0; i < arr.length; i++) {
if (arr[i].solar_system_id === id) {
return arr[i];
}
}
}
function updateCostIndex() {
let esiurl = "https://esi.tech.ccp.is/latest/industry/systems/?datasource=tranquility";
request(esiurl, function(err, res, body) {
let esi = JSON.parse(body);
let sys = [];
for (let i = 0; i < systems.length; i++) {
let temp = {
"updateOne": {
"filter": {
"_id": parseInt(systems[i].solarSystemID)
},
"update": {
"_id": systems[i].solarSystemID,
"name": systems[i].solarSystemName,
"index": getSystem(esi, systems[i].solarSystemID).cost_indices[5].cost_index
}
}
}
sys.push(temp);
}
mongo.connect(svurl, function(err, db) {
if (err) {
console.log(err);
} else {
db.collection('systems').bulkWrite(sys, { "ordered": true, "w": 1 }, function(err, result) {
if (err) throw err;
console.log(result.modifiedCount);
console.log("success!!");
db.close();
});
}
});
});
}
function split50() {
let arr = [];
@ -99,8 +143,8 @@ function updateDB(itms) {
if (err) throw err;
console.log(result.modifiedCount);
console.log("success!!");
db.close();
});
db.close();
}
});
}
@ -140,8 +184,8 @@ function addDaily() { //need to re-write this
} else {
db.collection('history').insert(insert, function(err, result) {
console.log("success!!");
db.close();
});
db.close();
}
});
});

21725
db_server/systems.json Normal file

File diff suppressed because it is too large Load Diff

2453
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,23 +1,24 @@
{
"name": "eve-reactions-calculator",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"async": "^2.6.0",
"body-parser": "~1.17.1",
"cluster": "^0.7.7",
"cookie-parser": "~1.4.3",
"debug": "~2.6.3",
"express": "~4.15.2",
"hbs": "~4.0.1",
"mongodb": "^2.2.33",
"mongoose": "^4.13.0",
"morgan": "~1.8.1",
"numeral": "^2.0.6",
"request": "^2.83.0",
"serve-favicon": "~2.4.2"
}
}
"name": "eve-reactions-calculator",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"async": "^2.6.0",
"body-parser": "~1.17.1",
"cluster": "^0.7.7",
"cookie-parser": "^1.4.3",
"debug": "~2.6.3",
"express": "~4.15.2",
"hbs": "~4.0.1",
"mongodb": "^2.2.33",
"mongoose": "^4.13.0",
"morgan": "~1.8.1",
"numeral": "^2.0.6",
"request": "^2.83.0",
"serve-favicon": "~2.4.2",
"xml-js": "^1.5.2"
}
}

View File

@ -3,24 +3,18 @@ var mongo = require('mongodb');
var request = require('request');
var async = require('async');
var numeral = require('numeral');
var cookieParser = require('cookie-parser');
var xmljs = require('xml-js');
var router = express.Router();
var svurl = "mongodb://localhost:27017/eve-reactor";
function getCostIndex(id) {
var esiIndyUrl = "https://esi.tech.ccp.is/latest/industry/systems/?datasource=tranquility"
request(esiIndyUrl, function(err, res, body) {
let data = JSON.parse(body);
for (let i = 0; i < data.length; i++) {
if (data[i].solar_system_id === id) {
for (var ii = 0; ii < 6; ii++) {
if (data[i].cost_indices[ii].activity === "reaction") {
return data[i].cost_indices[ii].cost_index;
}
}
}
function getCostIndex(sys, name) {
for (let i = 0; i < sys.length; i++) {
if (sys[i].name.toUpperCase() === name.toUpperCase()) {
return sys[i].index;
}
});
}
}
function getItem(data, id) {
@ -31,21 +25,51 @@ function getItem(data, id) {
}
}
function getSimplePrice(data, id) {
var tempsell = 0;
var tempbuy = 0;
for (let i = 0; i < data.length; i++) {
if (data[i].id === id) {
for (let ii = 0; ii < data[i].inputs.length; ii++) {
tempsell += data[i].inputs[ii].sell;
tempbuy += data[i].inputs[ii].buy;
}
let exp = {
"sell": tempsell,
"buy": tempbuy
}
return exp;
}
}
}
/* GET comp page. */
router.get('/', function(req, res, next) {
//querry opts
let opt = req.query;
console.log("opt:", opt);
if (opt.i) { var imeth = opt.i; }
if (opt.o) { var ometh = opt.o; }
if (opt.s) { var skill = parseInt(opt.s); }
if (opt.f) { var facility = opt.f; }
if (opt.r) { var rig = parseInt(opt.r); var rige = true; }
if (opt.input) { var imeth = opt.input; }
if (opt.output) { var ometh = opt.output; }
if (opt.skill) { var skill = parseInt(opt.skill); }
if (opt.facility) { var facility = opt.facility; }
if (opt.rig) { var rig = parseInt(opt.rig); var rige = true; }
if (opt.space) { var space = opt.space; }
if (opt.indyTax) { var indyTax = opt.indyTax; }
if (opt.system) { var syst = opt.system; }
var matb = 1;
var time = 180;
var bonus = {};
//set cookies if not found
console.log(req.cookies);
if (!req.cookies.input) { res.cookie('input', 'buy'); }
if (!req.cookies.output) { res.cookie('output', 'sell'); }
if (!req.cookies.skill) { res.cookie('skill', 5); }
if (!req.cookies.facility) { res.cookie('facility', 'large'); }
if (!req.cookies.rig) { res.cookie('rig', 1); }
if (!req.cookies.space) { res.cookie('space', 'null'); }
if (!req.cookies.indyTax) { res.cookie('indyTax', 0); }
if (!req.cookies.system) { res.cookie('system', 'Jita'); }
//calc bonus with opts
//default is Skill (Reactions) 5, Large facility & T1 rig in NullSec
if (skill && facility && rige && space) { // S F R SPACE
@ -370,13 +394,12 @@ router.get('/', function(req, res, next) {
"time": time
}
}
//var cycles = Math.floor(43200 / bonus.time);
var cycles = 1;
var cycles = Math.floor(43200 / bonus.time);
//var cycles = 1;
//vars
let lvid = 30000891;
let costIndex = getCostIndex(lvid);
let querry = ['items', 'bps'];
let querry = ['items', 'bps', 'systems'];
async.map(querry, function(coll, callback) {
mongo.connect(svurl, function(err, db) {
@ -392,34 +415,102 @@ router.get('/', function(req, res, next) {
}, function(err, results) {
let itemData = results[0];
let bpsData = results[1];
let systems = results[2];
//get cost index
var costIndex = getCostIndex(systems, 'l-vxtk');
let calc = [];
let reac = bpsData[0].reaction;
//START build new BP array with prices
for (let i = 0; i < reac.length; i++) {
let tempin = [];
for (let inp = 0; inp < reac[i].inputs.length; inp++) {
let tmpPrc = {
"id": reac[i].inputs[inp].id,
"buy": getItem(itemData, reac[i].inputs[inp].id).buy * reac[i].inputs[inp].qt * cycles,
"sell": getItem(itemData, reac[i].inputs[inp].id).sell * reac[i].inputs[inp].qt * cycles
let tempout = {};
let ttmp = {};
let tmpPrc = {};
if (reac[i].type === "simple") {
for (let inp = 0; inp < reac[i].inputs.length; inp++) {
tmpPrc = {
"id": reac[i].inputs[inp].id,
"buy": getItem(itemData, reac[i].inputs[inp].id).buy * reac[i].inputs[inp].qt * cycles,
"sell": getItem(itemData, reac[i].inputs[inp].id).sell * reac[i].inputs[inp].qt * cycles
}
tempin.push(tmpPrc);
}
tempin.push(tmpPrc);
tempout = {
"id": reac[i].output.id,
"sell": getItem(itemData, reac[i].output.id).sell * reac[i].output.qt * cycles,
"buy": getItem(itemData, reac[i].output.id).buy * reac[i].output.qt * cycles
}
ttmp = {
"id": reac[i].id,
"name": reac[i].name,
"chain": "No",
"inputs": tempin,
"output": tempout
}
calc.push(ttmp);
} else if (reac[i].type === "complex") {
//calc as simple
tempin = [];
tempout = {};
tmpPrc = {};
for (let inp = 0; inp < reac[i].inputs.length; inp++) {
tmpPrc = {
"id": reac[i].inputs[inp].id,
"buy": getItem(itemData, reac[i].inputs[inp].id).buy * reac[i].inputs[inp].qt * cycles,
"sell": getItem(itemData, reac[i].inputs[inp].id).sell * reac[i].inputs[inp].qt * cycles
}
tempin.push(tmpPrc);
}
tempout = {
"id": reac[i].output.id,
"sell": getItem(itemData, reac[i].output.id).sell * reac[i].output.qt * cycles,
"buy": getItem(itemData, reac[i].output.id).buy * reac[i].output.qt * cycles
}
ttmp = {
"id": reac[i].id,
"name": reac[i].name,
"chain": "No",
"inputs": tempin,
"output": tempout
}
calc.push(ttmp);
//calc as chain
tempin = [];
tmpPrc = {};
tempout = {};
for (let inp = 0; inp < reac[i].inputs.length; inp++) {
if (inp === reac[i].inputs.length - 1) { //look for fuel block
tmpPrc = {
"id": reac[i].inputs[inp].id,
"buy": getItem(itemData, reac[i].inputs[inp].id).buy * reac[i].inputs[inp].qt * cycles,
"sell": getItem(itemData, reac[i].inputs[inp].id).sell * reac[i].inputs[inp].qt * cycles
}
} else { //look for input from other reactions
tmpPrc = {
"id": reac[i].inputs[inp].id,
"buy": getSimplePrice(calc, reac[i].inputs[inp].id).buy / 2,
"sell": getSimplePrice(calc, reac[i].inputs[inp].id).sell / 2
}
}
tempin.push(tmpPrc);
}
tempout = {
"id": reac[i].output.id,
"sell": getItem(itemData, reac[i].output.id).sell * reac[i].output.qt * cycles,
"buy": getItem(itemData, reac[i].output.id).buy * reac[i].output.qt * cycles
}
ttmp = {
"id": reac[i].id,
"name": reac[i].name,
"chain": "yes",
"inputs": tempin,
"output": tempout
}
calc.push(ttmp);
}
let tempout = {
"id": reac[i].output.id,
"sell": getItem(itemData, reac[i].output.id).sell * reac[i].output.qt * cycles,
"buy": getItem(itemData, reac[i].output.id).buy * reac[i].output.qt * cycles
}
let ttmp = {
"id": reac[i].id,
"name": reac[i].name,
"chain": "No",
"inputs": tempin,
"output": tempout
}
calc.push(ttmp);
}
//console.log(calc);
//END build new BP array with prices
//START build array with total input cost, output cost & profits
let prof = [];
@ -429,6 +520,7 @@ router.get('/', function(req, res, next) {
let rout = calc[i].output;
let tisell = 0;
let tibuy = 0;
var indexTax = rout.sell * costIndex;
for (let ii = 0; ii < rin.length; ii++) {
tisell += rin[ii].sell;
tibuy += rin[ii].buy;
@ -439,9 +531,10 @@ router.get('/', function(req, res, next) {
"name": calc[i].name,
"chain": calc[i].chain,
"i": numeral(tibuy * bonus.mat).format('0,0.00'),
"tax": numeral(indexTax).format('0,0.00'),
"o": numeral(rout.sell).format('0,0.00'),
"prof": numeral(rout.sell - tibuy * bonus.mat).format('0,0.00'),
"per": numeral(((rout.sell - tibuy * bonus.mat) / rout.sell)).format('0.00%')
"prof": numeral((rout.sell - tibuy * bonus.mat) + indexTax).format('0,0.00'),
"per": numeral((((rout.sell - tibuy * bonus.mat) + indexTax) / rout.sell)).format('0.00%')
}
if (((rout.sell - tibuy * bonus.mat) / rout.sell) > 0) {
temp.pos = true;
@ -454,9 +547,10 @@ router.get('/', function(req, res, next) {
"name": calc[i].name,
"chain": calc[i].chain,
"i": numeral(tibuy * bonus.mat).format('0,0.00'),
"tax": numeral(indexTax).format('0,0.00'),
"o": numeral(rout.buy).format('0,0.00'),
"prof": numeral(rout.buy - tibuy * bonus.mat).format('0,0.00'),
"per": numeral(((rout.buy - tibuy * bonus.mat) / rout.buy)).format('0.00%')
"prof": numeral((rout.buy - tibuy * bonus.mat) + indexTax).format('0,0.00'),
"per": numeral((((rout.buy - tibuy * bonus.mat) + indexTax) / rout.buy)).format('0.00%')
}
if (((rout.buy - tibuy * bonus.mat) / rout.buy) > 0) {
temp.pos = true;
@ -469,9 +563,10 @@ router.get('/', function(req, res, next) {
"name": calc[i].name,
"chain": calc[i].chain,
"i": numeral(tisell * bonus.mat).format('0,0.00'),
"tax": numeral(indexTax).format('0,0.00'),
"o": numeral(rout.sell).format('0,0.00'),
"prof": numeral(rout.sell - tisell * bonus.mat).format('0,0.00'),
"per": numeral(((rout.sell - tisell * bonus.mat) / rout.sell)).format('0.00%')
"prof": numeral((rout.sell - tisell * bonus.mat) + indexTax).format('0,0.00'),
"per": numeral((((rout.sell - tisell * bonus.mat) + indexTax) / rout.sell)).format('0.00%')
}
if (((rout.sell - tisell * bonus.mat) / rout.sell) > 0) {
temp.pos = true;
@ -484,9 +579,10 @@ router.get('/', function(req, res, next) {
"name": calc[i].name,
"chain": calc[i].chain,
"i": numeral(tisell * bonus.mat).format('0,0.00'),
"tax": numeral(indexTax).format('0,0.00'),
"o": numeral(rout.buy).format('0,0.00'),
"prof": numeral(rout.buy - tisell * bonus.mat).format('0,0.00'),
"per": numeral(((rout.buy - tisell * bonus.mat) / rout.buy)).format('0.00%')
"prof": numeral((rout.buy - tisell * bonus.mat) + indexTax).format('0,0.00'),
"per": numeral((((rout.buy - tisell * bonus.mat) + indexTax) / rout.buy)).format('0.00%')
}
if (((rout.buy - tisell * bonus.mat) / rout.buy) > 0) {
temp.pos = true;
@ -499,9 +595,10 @@ router.get('/', function(req, res, next) {
"name": calc[i].name,
"chain": calc[i].chain,
"i": numeral(tibuy * bonus.mat).format('0,0.00'),
"tax": numeral(indexTax).format('0,0.00'),
"o": numeral(rout.buy).format('0,0.00'),
"prof": numeral(rout.buy - tibuy * bonus.mat).format('0,0.00'),
"per": numeral(((rout.buy - tibuy * bonus.mat) / rout.buy)).format('0.00%')
"prof": numeral((rout.buy - tibuy * bonus.mat) + indexTax).format('0,0.00'),
"per": numeral((((rout.buy - tibuy * bonus.mat) + indexTax) / rout.buy)).format('0.00%')
}
if (((rout.buy - tibuy * bonus.mat) / rout.buy) > 0) {
temp.pos = true;
@ -514,9 +611,10 @@ router.get('/', function(req, res, next) {
"name": calc[i].name,
"chain": calc[i].chain,
"i": numeral(tisell * bonus.mat).format('0,0.00'),
"tax": numeral(indexTax).format('0,0.00'),
"o": numeral(rout.sell).format('0,0.00'),
"prof": numeral(rout.sell - tisell * bonus.mat).format('0,0.00'),
"per": numeral(((rout.sell - tisell * bonus.mat) / rout.sell)).format('0.00%')
"prof": numeral((rout.sell - tisell * bonus.mat) + indexTax).format('0,0.00'),
"per": numeral((((rout.sell - tisell * bonus.mat) + indexTax) / rout.sell)).format('0.00%')
}
if (((rout.sell - tisell * bonus.mat) / rout.sell) > 0) {
temp.pos = true;
@ -529,9 +627,10 @@ router.get('/', function(req, res, next) {
"name": calc[i].name,
"chain": calc[i].chain,
"i": numeral(tibuy * bonus.mat).format('0,0.00'),
"tax": numeral(indexTax).format('0,0.00'),
"o": numeral(rout.sell).format('0,0.00'),
"prof": numeral(rout.sell - tibuy * bonus.mat).format('0,0.00'),
"per": numeral(((rout.sell - tibuy * bonus.mat) / rout.sell)).format('0.00%')
"prof": numeral((rout.sell - tibuy * bonus.mat) + indexTax).format('0,0.00'),
"per": numeral((((rout.sell - tibuy * bonus.mat) + indexTax) / rout.sell)).format('0.00%')
}
if (((rout.sell - tibuy * bonus.mat) / rout.sell) > 0) {
temp.pos = true;
@ -542,7 +641,6 @@ router.get('/', function(req, res, next) {
prof.push(temp);
}
//END build array with total input cost, output cost & profits
res.render('comp', { title: 'Composite Reactions', comp: true, table: prof });
});
});

View File

@ -1,15 +1,11 @@
<div class="container">
<div class="row mt-5">
<div class="btn-group">
<button class="btn btn-secondary btn-sm dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Skill 5
</button>
</div>
<table class="table">
<thead>
<th scope="col">Reaction</th>
<th scope="col">Chain ?</th>
<th scope="col">Inputs</th>
<th scope="col">Tax</th>
<th scope="col">Output</th>
<th scope="col">Profit</th>
<th scope="col">% prof</th>
@ -20,6 +16,7 @@
<td>{{name}}</td>
<td>{{chain}}</td>
<td>{{i}}</td>
<td>{{tax}}</td>
<td>{{o}}</td>
<td>{{prof}}</td>
<td>{{per}}</td>