From a42aefc653e26b96e65506fa38cb70c3b0c146f9 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Thu, 28 Feb 2019 01:48:42 -0500 Subject: [PATCH] add scenario totals_route --- index.js | 53 ++++++++++++++++++++++++++++++++++ route_meta/scenario_totals.sql | 17 +++++++++++ 2 files changed, 70 insertions(+) create mode 100644 route_meta/scenario_totals.sql diff --git a/index.js b/index.js index 89d08b0..99d47d7 100644 --- a/index.js +++ b/index.js @@ -85,6 +85,59 @@ server.get('/monthly_orders', bodyParser.json(), function (req,res) { //res.json("hi") }) + +server.get('/scenario_totals', bodyParser.json(), function (req,res) { + + var w = ""; + var c = 1; + var args = []; + for (var i in req.body) { + //console.log(i); + ///console.log(req.body[i]); + if (c > 1) { + w = w + + ` + AND ` + } + w = w + i + " = '" + req.body[i] + "'"; + args.push(req.body[i]); + c = c + 1; + }; + if (c == 1) { + res.send("no body was sent"); + return; + } + //console.log(w); + //console.log(args); + w = + ` + WITH + ini AS ( + SELECT + order_season + ,version + ,iter + ,SUM(units) units + ,SUM(value_usd) value_usd + FROM + rlarp.osm_fcpool + WHERE + ` + w + + ` + GROUP BY + order_season + ,version + ,iter + ) + SELECT + jsonb_agg(row_to_json(ini)::jsonb) x + FROM + ini` + console.log(w); + Postgres.FirstRow(w,[],res) + //res.json("hi") +}) + server.get('/get_pool', bodyParser.json(), function (req,res) { var args = [req.body.quota_rep]; diff --git a/route_meta/scenario_totals.sql b/route_meta/scenario_totals.sql new file mode 100644 index 0000000..b636ff4 --- /dev/null +++ b/route_meta/scenario_totals.sql @@ -0,0 +1,17 @@ +SELECT + order_season + ,version + ,iter + ,SUM(units) units + ,SUM(value_usd) value_usd +FROM + rlarp.osm_fcpool +WHERE + quota_rep_descr = '90005 - MARK WILKINSON' + AND segm = 'Retail' + AND mod_chan = 'MASS' + AND order_month = 'May' +GROUP BY + order_season + ,version + ,iter \ No newline at end of file