add scenario totals_route
This commit is contained in:
parent
d1630811bb
commit
a42aefc653
53
index.js
53
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];
|
||||
|
17
route_meta/scenario_totals.sql
Normal file
17
route_meta/scenario_totals.sql
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user