turn on sql execution for scale route, but not working

This commit is contained in:
Paul Trowbridge 2022-04-22 00:22:35 -04:00
parent 2531914387
commit d47b00b5cd
3 changed files with 12 additions and 8 deletions

View File

@ -111,6 +111,7 @@ server.get('/scale', bodyParser.json(), function(req, res) {
var app_pincr = req.body.app_pincr; var app_pincr = req.body.app_pincr;
var app_req = JSON.stringify(req.body); var app_req = JSON.stringify(req.body);
var app_vincr = req.body.app_vincr; var app_vincr = req.body.app_vincr;
var app_forecast_name = req.body.app_forecast_name;
var callback = function(arg) { var callback = function(arg) {
sql = arg; sql = arg;
@ -120,19 +121,21 @@ server.get('/scale', bodyParser.json(), function(req, res) {
// res.send("no body was sent"); // res.send("no body was sent");
// return; // return;
//} //}
console.log(new Date().toISOString() + "-------------------------baseline build-----------------------------") console.log(new Date().toISOString() + "-------------------------scale type adjustment----------------------")
console.log(JSON.stringify(req.body)); console.log(JSON.stringify(req.body));
//parse the where clause into the main sql statement //parse the where clause into the main sql statement
//sql = sql.replace(new RegExp("where_clause", 'g'), w) //sql = sql.replace(new RegExp("where_clause", 'g'), w)
//sql = sql.replace(new RegExp("app_pincr", 'g'), app_pincr); //sql = sql.replace(new RegExp("app_pincr", 'g'), app_pincr);
sql = sql.replace(new RegExp("app_req", 'g'), app_req); sql = sql.replace(new RegExp("app_req", 'g'), app_req);
sql = sql.replace(new RegExp("app_forecast_name", 'g'), app_forecast_name);
//sql = sql.replace(new RegExp("app_vincr", 'g'), app_vincr); //sql = sql.replace(new RegExp("app_vincr", 'g'), app_vincr);
sql = sql.replace(new RegExp("app_where", 'g'), w); sql = sql.replace(new RegExp("app_where", 'g'), w);
//execute the sql and send the result //execute the sql and send the result
args.push(req.body.app_baseline_from_date); args.push(req.body.app_baseline_from_date);
console.log(sql); console.log(sql);
res.send(sql); //send only the sql as the result of the route for debug
//Postgres.FirstRow(sql, [], res) //res.send(sql);
Postgres.FirstRow(sql, [], res)
}; };
fs.readFile(path, 'utf8', function(err, data) { fs.readFile(path, 'utf8', function(err, data) {

View File

@ -2,7 +2,7 @@
"app_scenario": { "app_scenario": {
"\"Description\"": "TARGET STOW OH", "\"Description\"": "TARGET STOW OH",
"app_iter": [ "app_iter": [
"baseline" "baseline","scale price"
] ]
}, },
"stamp": "2020-02-19 17:03:38", "stamp": "2020-02-19 17:03:38",
@ -11,7 +11,8 @@
"message": "test json", "message": "test json",
"tag": "standard price", "tag": "standard price",
"version": "dev", "version": "dev",
"app_forecast_name": "dev",
"type": "scale_vp", "type": "scale_vp",
"app_vincr": 0, "app_vincr": 0,
"app_pincr": 2000 "app_pincr": 500
} }

View File

@ -38,10 +38,10 @@ SELECT
,o."Category" ,o."Category"
,o."Party" ,o."Party"
,o."Reason" ,o."Reason"
,sum(o.app_units) AS app_units
,'app_forecast_name' AS app_version ,'app_forecast_name' AS app_version
,'scale' AS app_iter ,'scale' AS app_iter
,0::bigint AS app_logid ,0::bigint AS app_logid
,sum(o.app_units) AS app_units
FROM FROM
tpsv.dcard o tpsv.dcard o
WHERE WHERE
@ -75,10 +75,10 @@ SELECT
,o."Category" ,o."Category"
,o."Party" ,o."Party"
,o."Reason" ,o."Reason"
,round(o.app_units * vscale.factor,5) AS app_units
,'app_forecast_name' AS app_version ,'app_forecast_name' AS app_version
,'scale volume' AS app_iter ,'scale volume' AS app_iter
,(SELECT id FROM ilog) AS app_logid ,(SELECT id FROM ilog) AS app_logid
,round(o.app_units * vscale.factor,5) AS app_units
FROM FROM
basemix o basemix o
CROSS JOIN vscale CROSS JOIN vscale
@ -130,10 +130,10 @@ SELECT
,o."Category" ,o."Category"
,o."Party" ,o."Party"
,o."Reason" ,o."Reason"
,0::numeric AS app_units
,'app_forecast_name' AS app_version ,'app_forecast_name' AS app_version
,'scale price' AS app_iter ,'scale price' AS app_iter
,(SELECT id FROM ilog) AS app_logid ,(SELECT id FROM ilog) AS app_logid
,0::numeric AS app_units
FROM FROM
volume o volume o
CROSS JOIN pscale CROSS JOIN pscale