From 04b43a8f8d03e8cc005d9aab79831fa37a42339c Mon Sep 17 00:00:00 2001 From: Trowbridge Date: Fri, 1 Mar 2019 17:39:44 -0500 Subject: [PATCH] clean up scenario package --- index.js | 10 +- ...enario_totals.sql => scenario_package.sql} | 140 +++++++++--------- 2 files changed, 71 insertions(+), 79 deletions(-) rename route_meta/{scenario_totals.sql => scenario_package.sql} (87%) diff --git a/index.js b/index.js index e11e7ed..2a5d4c3 100644 --- a/index.js +++ b/index.js @@ -167,15 +167,11 @@ server.get('/scenario_package', bodyParser.json(), function (req, res) { jsonb_build_object( 'months' ,(SELECT jsonb_agg(row_to_json(months)::jsonb) FROM months) - ) - ,jsonb_build_object( - 'base' + ,'base' ,(SELECT jsonb_agg(row_to_json(base)::jsonb) FROM base) - ) - ,jsonb_build_object( - 'totals' + ,'totals' ,(SELECT jsonb_agg(row_to_json(totals)::jsonb) FROM totals) - )` + ) package` console.log(w); Postgres.FirstRow(w, [], res) //res.json("hi") diff --git a/route_meta/scenario_totals.sql b/route_meta/scenario_package.sql similarity index 87% rename from route_meta/scenario_totals.sql rename to route_meta/scenario_package.sql index e52bd75..33f25b6 100644 --- a/route_meta/scenario_totals.sql +++ b/route_meta/scenario_package.sql @@ -1,72 +1,68 @@ ---\timing ---explain (analyze, buffers) -WITH base AS ( -SELECT - order_season - ,order_month - ,version - ,iter - ,part_descr - ,bill_cust_descr - ,ship_cust_descr - ,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 - ,order_month - ,version - ,iter - ,part_descr - ,bill_cust_descr - ,ship_cust_descr -) -,months AS ( - SELECT - order_season - ,version - ,iter - ,order_month - ,sum(units) units - ,sum(value_usd) value_usd - FROM - base - GROUP BY - order_season - ,version - ,iter - ,order_month -) -,totals AS ( - SELECT - order_season - ,version - ,iter - ,sum(units) units - ,sum(value_usd) value_usd - FROM - months - GROUP BY - order_season - ,version - ,iter -) -SELECT - jsonb_build_object( - 'months' - ,(SELECT jsonb_agg(row_to_json(months)::jsonb) FROM months) - ) - ,jsonb_build_object( - 'base' - ,(SELECT jsonb_agg(row_to_json(base)::jsonb) FROM base) - ) - ,jsonb_build_object( - 'totals' - ,(SELECT jsonb_agg(row_to_json(totals)::jsonb) FROM totals) - ) \ No newline at end of file +\timing +--explain (analyze, buffers) +WITH base AS ( +SELECT + order_season + ,order_month + ,version + ,iter + ,part_descr + ,bill_cust_descr + ,ship_cust_descr + ,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 + ,order_month + ,version + ,iter + ,part_descr + ,bill_cust_descr + ,ship_cust_descr +) +,months AS ( + SELECT + order_season + ,version + ,iter + ,order_month + ,sum(units) units + ,sum(value_usd) value_usd + FROM + base + GROUP BY + order_season + ,version + ,iter + ,order_month +) +,totals AS ( + SELECT + order_season + ,version + ,iter + ,sum(units) units + ,sum(value_usd) value_usd + FROM + months + GROUP BY + order_season + ,version + ,iter +) +SELECT + jsonb_build_object( + 'months' + ,(SELECT jsonb_agg(row_to_json(months)::jsonb) FROM months) + ,'base' + ,(SELECT jsonb_agg(row_to_json(base)::jsonb) FROM base) + ,'totals' + ,(SELECT jsonb_agg(row_to_json(totals)::jsonb) FROM totals) + ) package \ No newline at end of file