diff --git a/routes/comp.js b/routes/comp.js index baf17e7..e492267 100644 --- a/routes/comp.js +++ b/routes/comp.js @@ -541,7 +541,7 @@ router.get('/:id',function(req, res, next){ if (!ck.space) { res.cookie('space', 'null', { maxAge: 31556952000, }); var space = "null"; } if (!ck.indyTax) { res.cookie('indyTax', 0, { maxAge: 31556952000, }); var indyTax = 0; } if (!ck.duration) { res.cookie('duration', 10080, { maxAge: 31556952000, }); var duration = 10080; } - if (!ck.adv-cycles) { res.cookie('adv-cycles', 50, { maxAge: 31556952000, }); var cycles = 50; } + if (!ck.cycles) { res.cookie('cycles', 50, { maxAge: 31556952000, }); var cycles = 50; } if (!ck.system) { res.cookie('system', 'Basgerin', { maxAge: 31556952000, }); var syst = "Basgerin" } //set internal vars to use cookie values @@ -587,8 +587,8 @@ router.get('/:id',function(req, res, next){ } else { var duration = 10080; } - if (ck.adv-cycles >= 1 && ck.adv-cycles <= 300) { - var cycles = ck.adv-cycles + if (ck.cycles >= 1 && ck.cycles <= 300) { + var cycles = ck.cycles } else { var cycles = 50; } @@ -669,6 +669,8 @@ router.get('/:id',function(req, res, next){ let taxtotal = {}; var outArr = []; let outtotal = {}; + var repArr = []; + let reptotal = {}; //START build new BP array with prices var itembp = {}; @@ -687,6 +689,14 @@ router.get('/:id',function(req, res, next){ res.status(404); res.render('error'); }else{ + var advsettings = {}; + advsettings.cycles = Math.round(cycles); + advsettings.ctime = Math.round(cycles * bonus.time); + advsettings.tcycles = Math.floor(ck.duration / advsettings.ctime); + + let prodData = {}; + prodData.name = getItemName(itemData,itembp._id); + prodData.url = req.url; if(itembp.type === "simple"){ //build input array @@ -710,21 +720,286 @@ router.get('/:id',function(req, res, next){ inptotal.qt += elem.qt; inptotal.price += elem.price; }); - inptotal.price = numeral(inptotal.price).format('0,0.00'); + inptotal.pricestr = numeral(inptotal.price).format('0,0.00'); + + //build output array + + let elem = itembp.output; + let outrow = {}; + outrow.id = elem.id; + outrow.name = getItemName(itemData,elem.id); + outrow.qt = Math.ceil(elem.qt * cycles); + outrow.price = outrow.qt * getItem(itemData,elem.id).sell; + outrow.pricestr = numeral(outrow.qt * getItem(itemData,elem.id).sell).format('0,0.00'); + outArr.push(outrow); + + outtotal = { + "name": "TOTAL", + "qt": 0, + "price": 0 + } + outArr.forEach(function(elem){ + outtotal.qt += elem.qt; + outtotal.price += elem.price; + }); + outtotal.pricestr = numeral(outtotal.price).format('0,0.00'); //build tax array - //build output array + let taxrow = {}; + taxrow.name = "Cost Index"; + taxrow.perc = costIndex; + taxrow.price = outtotal.price * costIndex; + taxrow.pricestr = numeral(outtotal.price * costIndex).format('0,0.00'); + taxArr.push(taxrow); + let taxrow2 = {}; + taxrow2.name = "Industrial Tax"; + taxrow2.perc = indyTax; + taxrow2.price = taxrow.price * (indyTax/100); + taxrow2.pricestr = numeral(taxrow.price * (indyTax/100)).format('0,0.00'); + taxArr.push(taxrow2); + + taxtotal = { + "name": "TOTAL", + "price": 0 + } + + taxArr.forEach(function(elem){ + taxtotal.price += elem.price; + }); + taxtotal.pricestr = numeral(taxtotal.price).format('0,0.00'); + + //build report array + + let reprow = {}; + reprow.type = "Input Materials" + reprow.price = -inptotal.price * advsettings.tcycles; + reprow.pricestr = numeral(-inptotal.price * advsettings.tcycles).format('0,0.00'); + repArr.push(reprow); + + reprow = {}; + reprow.type = "Taxes" + reprow.price = -taxtotal.price * advsettings.tcycles; + reprow.pricestr = numeral(-taxtotal.price * advsettings.tcycles).format('0,0.00'); + repArr.push(reprow); + + reprow = {}; + reprow.type = "Output Materials" + reprow.price = outtotal.price * advsettings.tcycles; + reprow.pricestr = numeral(outtotal.price * advsettings.tcycles).format('0,0.00'); + repArr.push(reprow); + + reptotal = { + "type": "TOTAL", + "price": outtotal.price * advsettings.tcycles - inptotal.price * advsettings.tcycles - taxtotal.price * advsettings.tcycles + } + reptotal.pricestr = numeral(reptotal.price).format('0,0.00'); + }else if(itembp.type === "complex"){ + if(req.query.chain){ + prodData.name = "Still working on the chain version of these, sorry :("; + }else{ + //build input array + + itembp.inputs.forEach(function(elem){ + let inrow = {}; + inrow.id = elem.id; + inrow.name = getItemName(itemData,elem.id); + inrow.qt = Math.ceil(elem.qt * cycles * bonus.mat); + inrow.price = inrow.qt * getItem(itemData,elem.id).buy; + inrow.pricestr = numeral(inrow.qt * getItem(itemData,elem.id).buy).format('0,0.00'); + + inpArr.push(inrow); + }); + inptotal = { + "name": "TOTAL", + "qt": 0, + "price": 0 + }; + inpArr.forEach(function(elem){ + inptotal.qt += elem.qt; + inptotal.price += elem.price; + }); + inptotal.pricestr = numeral(inptotal.price).format('0,0.00'); + + //build output array + + let elem = itembp.output; + let outrow = {}; + outrow.id = elem.id; + outrow.name = getItemName(itemData,elem.id); + outrow.qt = Math.ceil(elem.qt * cycles); + outrow.price = outrow.qt * getItem(itemData,elem.id).sell; + outrow.pricestr = numeral(outrow.qt * getItem(itemData,elem.id).sell).format('0,0.00'); + outArr.push(outrow); + + outtotal = { + "name": "TOTAL", + "qt": 0, + "price": 0 + } + outArr.forEach(function(elem){ + outtotal.qt += elem.qt; + outtotal.price += elem.price; + }); + outtotal.pricestr = numeral(outtotal.price).format('0,0.00'); + + //build tax array + + let taxrow = {}; + taxrow.name = "Cost Index"; + taxrow.perc = costIndex; + taxrow.price = outtotal.price * costIndex; + taxrow.pricestr = numeral(outtotal.price * costIndex).format('0,0.00'); + taxArr.push(taxrow); + let taxrow2 = {}; + taxrow2.name = "Industrial Tax"; + taxrow2.perc = indyTax; + taxrow2.price = taxrow.price * (indyTax/100); + taxrow2.pricestr = numeral(taxrow.price * (indyTax/100)).format('0,0.00'); + taxArr.push(taxrow2); + + taxtotal = { + "name": "TOTAL", + "price": 0 + } + + taxArr.forEach(function(elem){ + taxtotal.price += elem.price; + }); + taxtotal.pricestr = numeral(taxtotal.price).format('0,0.00'); + + //build report array + + let reprow = {}; + reprow.type = "Input Materials" + reprow.price = -inptotal.price * advsettings.tcycles; + reprow.pricestr = numeral(-inptotal.price * advsettings.tcycles).format('0,0.00'); + repArr.push(reprow); + + reprow = {}; + reprow.type = "Taxes" + reprow.price = -taxtotal.price * advsettings.tcycles; + reprow.pricestr = numeral(-taxtotal.price * advsettings.tcycles).format('0,0.00'); + repArr.push(reprow); + + reprow = {}; + reprow.type = "Output Materials" + reprow.price = outtotal.price * advsettings.tcycles; + reprow.pricestr = numeral(outtotal.price * advsettings.tcycles).format('0,0.00'); + repArr.push(reprow); + + reptotal = { + "type": "TOTAL", + "price": outtotal.price * advsettings.tcycles - inptotal.price * advsettings.tcycles - taxtotal.price * advsettings.tcycles + } + reptotal.pricestr = numeral(reptotal.price).format('0,0.00'); + + } + + }else if(itembp.type === "unrefined"){ + //build input array + + itembp.inputs.forEach(function(elem){ + let inrow = {}; + inrow.id = elem.id; + inrow.name = getItemName(itemData,elem.id); + inrow.qt = Math.ceil(elem.qt * cycles * bonus.mat); + inrow.price = inrow.qt * getItem(itemData,elem.id).buy; + inrow.pricestr = numeral(inrow.qt * getItem(itemData,elem.id).buy).format('0,0.00'); + + inpArr.push(inrow); + }); + inptotal = { + "name": "TOTAL", + "qt": 0, + "price": 0 + }; + inpArr.forEach(function(elem){ + inptotal.qt += elem.qt; + inptotal.price += elem.price; + }); + inptotal.pricestr = numeral(inptotal.price).format('0,0.00'); + + //build output array + + let elem = itembp.output; + let outrow = {}; + outrow.id = elem.id; + outrow.name = getItemName(itemData,elem.id); + outrow.qt = Math.ceil(elem.qt * cycles); + outrow.price = outrow.qt * getItem(itemData,elem.id).sell; + outrow.pricestr = numeral(outrow.qt * getItem(itemData,elem.id).sell).format('0,0.00'); + outArr.push(outrow); + + outtotal = { + "name": "TOTAL", + "qt": 0, + "price": 0 + } + outArr.forEach(function(elem){ + outtotal.qt += elem.qt; + outtotal.price += elem.price; + }); + outtotal.pricestr = numeral(outtotal.price).format('0,0.00'); + + //build tax array + + let taxrow = {}; + taxrow.name = "Cost Index"; + taxrow.perc = costIndex; + taxrow.price = outtotal.price * costIndex; + taxrow.pricestr = numeral(outtotal.price * costIndex).format('0,0.00'); + taxArr.push(taxrow); + let taxrow2 = {}; + taxrow2.name = "Industrial Tax"; + taxrow2.perc = indyTax; + taxrow2.price = taxrow.price * (indyTax/100); + taxrow2.pricestr = numeral(taxrow.price * (indyTax/100)).format('0,0.00'); + taxArr.push(taxrow2); + + taxtotal = { + "name": "TOTAL", + "price": 0 + } + + taxArr.forEach(function(elem){ + taxtotal.price += elem.price; + }); + taxtotal.pricestr = numeral(taxtotal.price).format('0,0.00'); + + //build report array + + let reprow = {}; + reprow.type = "Input Materials" + reprow.price = -inptotal.price * advsettings.tcycles; + reprow.pricestr = numeral(-inptotal.price * advsettings.tcycles).format('0,0.00'); + repArr.push(reprow); + + reprow = {}; + reprow.type = "Taxes" + reprow.price = -taxtotal.price * advsettings.tcycles; + reprow.pricestr = numeral(-taxtotal.price * advsettings.tcycles).format('0,0.00'); + repArr.push(reprow); + + reprow = {}; + reprow.type = "Output Materials" + reprow.price = outtotal.price * advsettings.tcycles; + reprow.pricestr = numeral(outtotal.price * advsettings.tcycles).format('0,0.00'); + repArr.push(reprow); + + reptotal = { + "type": "TOTAL", + "price": outtotal.price * advsettings.tcycles - inptotal.price * advsettings.tcycles - taxtotal.price * advsettings.tcycles + } + reptotal.pricestr = numeral(reptotal.price).format('0,0.00'); + } - - let prodData = {}; - prodData.name = getItemName(itemData,itembp._id); - res.render('comp-adv', { title: prodData.name + ' Reaction', comp: true, data: prodData, intable: inpArr, intt: inptotal, sett: ck }); + res.render('comp-adv', { title: prodData.name + ' Reaction', comp: true, data: prodData, intable: inpArr, intt: inptotal, outtable: outArr, outtt: outtotal, taxtable: taxArr, taxtt: taxtotal, reptable: repArr, reptt: reptotal, sett: ck, advsett: advsettings }); } }); }); diff --git a/routes/hyb.js b/routes/hyb.js index 9caf65c..6ef2a7e 100644 --- a/routes/hyb.js +++ b/routes/hyb.js @@ -25,6 +25,30 @@ function getItem(data, id) { } } +function isEmpty(obj) { + for(var key in obj) { + if(obj.hasOwnProperty(key)) + return false; + } + return true; +} + +function getItemName(items,id) { + for (let i = 0; i < items.length; i++) { + if (items[i]._id === id) { + return items[i].name; + } + } +} + +function getItemID(items,name) { + for (let i = 0; i < items.length; i++) { + if (items[i].name === name) { + return items[i]._id; + } + } +} + /* GET comp page. */ router.get('/', function(req, res, next) { @@ -364,4 +388,276 @@ router.get('/', function(req, res, next) { }); }); +router.get('/:id',function(req, res, next){ + const reqid = parseInt(req.params.id); + //set cookies if not found + var ck = req.cookies; + //console.log(ck); + if (!ck.input) { res.cookie('input', 'buy', { maxAge: 31556952000, }); var imeth = "buy"; } + if (!ck.output) { res.cookie('output', 'sell', { maxAge: 31556952000, }); var ometh = "sell"; } + if (!ck.skill) { res.cookie('skill', 5, { maxAge: 31556952000, }); var skill = 5; } + if (!ck.facility) { res.cookie('facility', 'large', { maxAge: 31556952000, }); var facility = "large"; } + if (!ck.rig) { res.cookie('rig', 1, { maxAge: 31556952000, }); var rig = 1; var rige = true; } + if (!ck.space) { res.cookie('space', 'null', { maxAge: 31556952000, }); var space = "null"; } + if (!ck.indyTax) { res.cookie('indyTax', 0, { maxAge: 31556952000, }); var indyTax = 0; } + if (!ck.duration) { res.cookie('duration', 10080, { maxAge: 31556952000, }); var duration = 10080; } + if (!ck.cycles) { res.cookie('cycles', 50, { maxAge: 31556952000, }); var cycles = 50; } + if (!ck.system) { res.cookie('system', 'Basgerin', { maxAge: 31556952000, }); var syst = "Basgerin" } + + //set internal vars to use cookie values + if (ck.input.toLowerCase() === "buy" || ck.input.toLowerCase() === "sell") { + var imeth = ck.input.toLowerCase(); + } else { + var imeth = "buy"; + } + if (ck.output.toLowerCase() === "buy" || ck.output.toLowerCase() === "sell") { + var ometh = ck.output.toLowerCase(); + } else { + var ometh = "sell"; + } + if (parseInt(ck.skill) >= 0 && parseInt(ck.skill) <= 5) { + var skill = parseInt(ck.skill); + } else { + var skill = 5; + } + if (ck.facility.toLowerCase() === "med" || ck.facility.toLowerCase() === "large") { + var facility = ck.facility.toLowerCase(); + } else { + var facility = "large"; + } + if (parseInt(ck.rig) >= 0 && parseInt(ck.rig) <= 2) { + var rig = parseInt(ck.rig); + var rige = true; + } else { + var rig = 1; + var rige = true; + } + if (ck.space.toLowerCase() === "low" || ck.space.toLowerCase() === "null") { + var space = ck.space.toLowerCase(); + } else { + var space = "null"; + } + if (ck.indyTax >= 0 && ck.indyTax <= 50) { + var indyTax = ck.indyTax + } else { + var indyTax = 0; + } + if (ck.duration >= 1 && ck.duration <= 43200) { + var duration = ck.duration + } else { + var duration = 10080; + } + if (ck.cycles >= 1 && ck.cycles <= 300) { + var cycles = ck.cycles + } else { + var cycles = 50; + } + if (ck.system) { + var re = /^[a-zA-Z0-9-]+$/; + if (re.test(ck.system)) { + var syst = ck.system; + } else { + var syst = 'Basgerin'; + } + } + + //calc bonus with opts + var matb = 1; + var time = 180; + var bonus = {}; + //default is Skill (Reactions) 5, Large facility & T1 rig in NullSec + //calc material bonus + if (rig === 1 && space === "null") { + matb = 1 - (2 * 1.1) / 100 + } else if (rig === 1 && space === "low") { + matb = 1 - 2 / 100 + } else if (rig === 2 && space === "null") { + matb = 1 - (2.4 * 1.1) / 100 + } else if (rig === 2 && space === "low") { + matb = 1 - 2.4 / 100 + } else { + matb = 1; + } + //calc time bonus + time = 180 * (1 - (4 * skill) / 100); //skill bonus + //facility bonus + if (facility === "med") { + time = time * (1 - 0) + } else if (facility === "large") { + time = time * (1 - (25 / 100)) + } + //rig bonus + if (rig === 1 && space === "null") { + time = time * (1 - (20 * 1.1 / 100)) + } else if (rig === 1 && space === "low") { + time = time * (1 - (20 / 100)) + } else if (rig === 2 && space === "null") { + time = time * (1 - (24 * 1.1 / 100)) + } else if (rig === 2 && space === "low") { + time = time * (1 - (24 / 100)) + } else { + time = time; + } + //final result + bonus = { + "mat": matb, + "time": time + } + + let querry = ['items', 'bp-hybrid', 'systems']; + async.map(querry, function(coll, callback) { + mongo.connect(svurl, function(err, db) { + if (err) { + console.log(err); + } else { + db.collection(coll).find().toArray(function(err, res) { + callback(null, res); + db.close(); + }); + } + }); + }, function(err, results) { + let itemData = results[0]; + let reac = results[1]; + let systems = results[2]; + //get cost index + var costIndex = getCostIndex(systems, syst); + //define vars for information + var inpArr = []; + let inptotal = {}; + var taxArr = []; + let taxtotal = {}; + var outArr = []; + let outtotal = {}; + var repArr = []; + let reptotal = {}; + + //START build new BP array with prices + var itembp = {}; + + for(let i=0;i= 1 && parseInt(ck.cycles) <= 300) { + res.cookie('cycles', parseInt(ck.cycles), { maxAge: 31556952000, }); + } else { + res.cookie('cyckes', 50, { maxAge: 31556952000, }); + } + + let url = "/composite/" + ck.url.substr(1); + + //reply + res.redirect(302, url); + res.end(); +}); + +router.get('/hyb-adv/set', function(req, res, next) { + + let ck = req.query; + + if (parseInt(ck.cycles) >= 1 && parseInt(ck.cycles) <= 300) { + res.cookie('cycles', parseInt(ck.cycles), { maxAge: 31556952000, }); + } else { + res.cookie('cyckes', 50, { maxAge: 31556952000, }); + } + + let url = "/hybrid/" + ck.url.substr(1); + + //reply + res.redirect(302, url); + res.end(); +}); + module.exports = router; \ No newline at end of file diff --git a/views/comp-adv.hbs b/views/comp-adv.hbs index c1a81d6..87fab2b 100644 --- a/views/comp-adv.hbs +++ b/views/comp-adv.hbs @@ -48,6 +48,28 @@ +
+
+ + + + + + + + + + + + + + + + + +
# Runs per cycleCycle timeTotal time# CyclesSave
{{advsett.ctime}} Minutes{{sett.duration}} Minutes{{advsett.tcycles}}
+ +
@@ -73,7 +95,7 @@ {{intt.name}} {{intt.qt}} - {{intt.price}} + {{intt.pricestr}} @@ -82,6 +104,28 @@
TAXES
+ + + + + + + + {{#taxtable}} + + + + + + {{/taxtable}} + + + + + +
NamePercentagePrice
{{name}}{{perc}} %{{pricestr}}
{{taxtt.name}} + {{taxtt.pricestr}} +
@@ -89,9 +133,56 @@
OUTPUTS
+ + + + + + + + {{#outtable}} + + + + + + {{/outtable}} + + + + + +
NameQuantityPrice
{{name}}{{qt}}{{pricestr}}
{{outtt.name}} + {{outtt.qt}} + {{outtt.pricestr}} +
+
+ +
+
+ PROFIT REPORT +
+ + + + + + + {{#reptable}} + + + + + {{/reptable}} + + + + + +
TypePrice
{{type}}{{pricestr}}
{{reptt.type}} + {{reptt.pricestr}} +
- - diff --git a/views/comp.hbs b/views/comp.hbs index 2c00099..ec6b101 100644 --- a/views/comp.hbs +++ b/views/comp.hbs @@ -134,7 +134,7 @@ {{#ctable}} - + {{name}} {{i}} {{tax}} @@ -162,7 +162,7 @@ {{#chtable}} - + {{name}} {{i}} {{tax}} @@ -190,7 +190,7 @@ {{#untable}} - + {{name}} {{i}} {{tax}} diff --git a/views/hyb-adv.hbs b/views/hyb-adv.hbs new file mode 100644 index 0000000..7d319ee --- /dev/null +++ b/views/hyb-adv.hbs @@ -0,0 +1,188 @@ + +
+
+

{{data.name}} Reaction

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
In MethodOut MethodReactionsFacilityRigSpaceSystemIndyTaxBuild Time
{{sett.input}}{{sett.output}}Level {{sett.skill}}{{sett.facility}} RefineryT{{sett.rig}} Rig{{sett.space}}sec{{sett.system}}{{sett.indyTax}}{{sett.duration}} Minutes
+
+
+
+ + + + + + + + + + + + + + + + + +
# Runs per cycleCycle timeTotal time# CyclesSave
{{advsett.ctime}} Minutes{{sett.duration}} Minutes{{advsett.tcycles}}
+ +
+
+
+
+
+ INPUTS +
+ + + + + + + + {{#intable}} + + + + + + {{/intable}} + + + + + +
NameQuantityPrice
{{name}}{{qt}}{{pricestr}}
{{intt.name}} + {{intt.qt}} + {{intt.pricestr}} +
+
+
+
+ TAXES +
+ + + + + + + + {{#taxtable}} + + + + + + {{/taxtable}} + + + + + +
NamePercentagePrice
{{name}}{{perc}} %{{pricestr}}
{{taxtt.name}} + {{taxtt.pricestr}} +
+
+
+
+
+
+ OUTPUTS +
+ + + + + + + + {{#outtable}} + + + + + + {{/outtable}} + + + + + +
NameQuantityPrice
{{name}}{{qt}}{{pricestr}}
{{outtt.name}} + {{outtt.qt}} + {{outtt.pricestr}} +
+
+ +
+
+ PROFIT REPORT +
+ + + + + + + {{#reptable}} + + + + + {{/reptable}} + + + + + +
TypePrice
{{type}}{{pricestr}}
{{reptt.type}} + {{reptt.pricestr}} +
+
+
+
+
diff --git a/views/hyb.hbs b/views/hyb.hbs index 34ccafd..6cbacb8 100644 --- a/views/hyb.hbs +++ b/views/hyb.hbs @@ -14,6 +14,9 @@ null ] } ); + $(".link-row").click(function() { + window.location = $(this).data("href"); + }); });
@@ -61,7 +64,7 @@ {{#htab}} - + {{name}} {{i}} {{tax}}