From e312bc1abd1112c9ab855c9fc51798a5ac2ec6d7 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Wed, 3 Apr 2019 08:56:01 -0500 Subject: [PATCH] add log file routes and queries --- .gitignore | 3 +- index.js | 5 ++- route_sql/build/list_changes_table.sql | 2 + route_sql/build/rep_totals.sql | 46 ++++++++++++++++++++ route_sql/build/totals.report | 58 ++++++++++++++++++++++++++ route_sql/build/~ | 46 ++++++++++++++++++++ 6 files changed, 157 insertions(+), 3 deletions(-) create mode 100644 route_sql/build/rep_totals.sql create mode 100644 route_sql/build/totals.report create mode 100644 route_sql/build/~ diff --git a/.gitignore b/.gitignore index 590eb27..59d7be7 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,4 @@ npm-debug.log logs.html stat.html *.pem -node.log -changes.html +*.log diff --git a/index.js b/index.js index 1d78d7e..d7851d9 100644 --- a/index.js +++ b/index.js @@ -49,8 +49,11 @@ server.get('/', (req, res) => res.send('node.js express is up and running')) server.get('/login', (req, res) => res.sendFile(process.env.wd + 'msauth.html')) -server.get('/logs', (req, res) => res.sendFile(process.env.wd + 'logs.html')) +server.get('/logs', (req, res) => res.sendFile(process.env.wd + 'changes.log')) +server.get('/pgbadger', (req, res) => res.sendFile(process.env.wd + 'logs.html')) + +server.get('/totals', (req, res) => res.sendFile(process.env.wd + 'totals.log')) server.get('/test_sql', function(req, res){ var path = './route_meta/scenario_package.sql' diff --git a/route_sql/build/list_changes_table.sql b/route_sql/build/list_changes_table.sql index a6b7bfa..dba97da 100644 --- a/route_sql/build/list_changes_table.sql +++ b/route_sql/build/list_changes_table.sql @@ -1,5 +1,6 @@ SELECT iterdef->>'user' "user", + quota_rep_descr, (iterdef->>'stamp')::timestamptz "stamp", iterdef->>'type' "type", round(SUM(fb_val_loc * r_rate)::numeric,2) sales, @@ -10,6 +11,7 @@ WHERE iterdef IS NOT NULL GROUP BY iterdef->>'user', + quota_rep_descr, iterdef->>'stamp', iterdef->>'type', iterdef diff --git a/route_sql/build/rep_totals.sql b/route_sql/build/rep_totals.sql new file mode 100644 index 0000000..f0846db --- /dev/null +++ b/route_sql/build/rep_totals.sql @@ -0,0 +1,46 @@ +WITH +preagg AS ( +SELECT + director_descr + ,quota_rep_descr + ,part + ,bill_cust + ,ship_cust + ,order_month + ,iterdef + ,sum(fb_val_loc * r_rate) FILTER (WHERE iter = 'copy') sales + ,sum(fb_cst_loc * c_rate) FILTER (WHERE iter = 'copy') scogs + ,sum(fb_val_loc * r_rate) FILTER (WHERE iter <> 'copy') sales_adj + ,sum(fb_cst_loc * c_rate) FILTER (WHERE iter <> 'copy') scogs_adj +FROM + rlarp.osm_fcpool +WHERE + order_season = 2020 +GROUP BY + director_descr + ,quota_rep_descr + ,part + ,bill_cust + ,ship_cust + ,order_month + ,iterdef +) +SELECT + director_descr + ,quota_rep_descr + ,to_char(sum(sales),'999,999,999') sales + ,to_char(sum(sales - scogs),'999,999,999') margin + ,to_char(sum(sales_adj),'999,999,999') sales_adj + ,to_char(sum(sales_adj - scogs_adj),'999,999,999') margin_adj + ,count(iterdef) "# of changes" +FROM + preagg +GROUP BY + GROUPING SETS ( + (director_descr,quota_rep_descr), + (director_descr), + () + ) +ORDER BY + director_descr + ,quota_rep_descr diff --git a/route_sql/build/totals.report b/route_sql/build/totals.report new file mode 100644 index 0000000..3167742 --- /dev/null +++ b/route_sql/build/totals.report @@ -0,0 +1,58 @@ + director_descr | quota_rep_descr | sales | margin | sales_adj | margin_adj +----------------+--------------------------------------+--------------+--------------+--------------+-------------- + | | 60 | -6,140 | | + | | 60 | -6,140 | | + Baggetta | 10026 - BRYCE ANDERSON | 9,158,837 | 2,956,217 | -121,103 | -18,166 + Baggetta | 10032 - BRYAN HILL | 22,314,163 | 4,377,559 | -872,713 | 1,082 + Baggetta | 30033 - ROBERT NELSON | 6,286,592 | 1,772,799 | 37,715 | 36,190 + Baggetta | 90050 - BFG HOUSE ACCOUNT | 3,830,304 | 1,735,809 | -1,643 | 833 + Baggetta | | 41,589,897 | 10,842,384 | -957,744 | 19,939 + Hapke | 12023 - RON OLSEN | 4,858,476 | 1,678,699 | | + Hapke | 13026 - ROY SIEMENS | 14,102,808 | 2,004,554 | | + Hapke | 30035 - RODNEY RIOS | 9,359,837 | 2,081,359 | | + Hapke | 30052 - TOM BREWER | 6,265,284 | 1,556,434 | -32,175 | -7,114 + Hapke | | 34,586,406 | 7,321,047 | -32,175 | -7,114 + Other | 10024 - DNU-RICHARD LUTHER | 205 | 149 | | + Other | 50105 - GLENKIRK ASSOCIATES INC | 41,691 | 17,675 | | + Other | 50201 - THE SULLIVAN COMPANY | 649 | 403 | | + Other | 50202 - PUJOL AND JAMES | 6,924 | 2,691 | | + Other | 50204 - LINDCO INC | 6,293 | 3,253 | | + Other | 50205 - JV FOLSOM CO | 2,069 | 1,057 | | + Other | 50207 - DL MARKETING & SALES | 1,137 | 702 | | + Other | 50208 - BRISBIN & ASSOCIATES | 12,626 | 6,156 | | + Other | 50209 - BUFFALO HORTICULTURE SALES | 16,540 | 4,640 | | + Other | 50302 - HORNWOOD AGENCIES INC | 496 | 337 | | + Other | 50303 - DIRECT SOURCE MANAGEMENT | 29,948 | 13,454 | | + Other | 50801 - MARK WILKINSON | 585 | -125 | | + Other | 90002 - ANDRE GRAVEL | 1,423 | 602 | | + Other | 90099 - HOUSE ACCOUNT | 1,346 | 275 | | + Other | # - (BLANK) | 379 | 254 | | + Other | OTH - OTHER ACCOUNTS - REP UNDEFINED | 1,363 | -150 | | + Other | | 123,674 | 51,373 | | + Pierre | 10029 - MICHAEL LAZERICK | 4,444,330 | 1,402,050 | | + Pierre | 10035 - MATTHEW STAAL | 6,395,965 | 1,773,710 | 157 | 157 + Pierre | 13025 - JAMES REGER | 11,789,491 | 1,119,508 | -3,097,151 | -61,806 + Pierre | 13027 - STEVE RUSTEBERG | 6,632,452 | 2,434,854 | -52,604 | -25,192 + Pierre | | 29,262,238 | 6,730,122 | -3,149,598 | -86,841 + PW | PW | 3,578,690 | 1,128,465 | | + PW | | 3,578,690 | 1,128,465 | | + Soltis | 12010 - CHRIS SOLTIS | 647,048 | 151,371 | -1,832 | 264 + Soltis | 12024 - JORDAN BUKOWSKI | 9,389,774 | 2,527,624 | -1,108,068 | -61,001 + Soltis | 12026 - JAMEY SCHIESSWOHL | 4,644,560 | 1,595,567 | -254,393 | -53,500 + Soltis | 13028 - RICHARD MEULE | 10,069,936 | 2,358,350 | -1,066,275 | -24,612 + Soltis | 30032 - MARK ALLWEIN | 5,023,707 | 1,364,509 | -82,191 | -636 + Soltis | 90051 - GRIFFIN HOUSE ACCOUNT | 8,055,838 | 3,820,258 | -6,200 | -79,171 + Soltis | | 37,830,863 | 11,817,678 | -2,518,958 | -218,657 + Vander Deen | 30036 - MARC DESROSIERS | 4,855,705 | 1,325,553 | | + Vander Deen | 40035 - CURT MCNEIL | 5,623,584 | 1,176,684 | | + Vander Deen | 40039 - DAVE BODO | 4,347,210 | 1,161,304 | | + Vander Deen | 40040 - TINA PETTIGREW | 3,962,742 | 1,252,842 | | + Vander Deen | | 18,789,241 | 4,916,384 | | + Wilkinson | 50200 - DORAN MARABLE | 5,973,576 | 2,749,888 | | + Wilkinson | 50300 - RACHEL BOWMAN | 2,048,844 | 722,785 | | + Wilkinson | 50600 - DAN NAUERT | 106 | 65 | | + Wilkinson | 90005 - MARK WILKINSON | 6,633,125 | 697,639 | | + Wilkinson | | 14,655,652 | 4,170,377 | | + | | 180,416,720 | 46,971,690 | -6,658,475 | -292,672 +(54 rows) + diff --git a/route_sql/build/~ b/route_sql/build/~ new file mode 100644 index 0000000..cc3ea53 --- /dev/null +++ b/route_sql/build/~ @@ -0,0 +1,46 @@ +iITH +preagg AS ( +SELECT + director_descr + ,quota_rep_descr + ,part + ,bill_cust + ,ship_cust + ,order_month + ,iterdef + ,sum(fb_val_loc * r_rate) FILTER (WHERE iter = 'copy') sales + ,sum(fb_cst_loc * c_rate) FILTER (WHERE iter = 'copy') scogs + ,sum(fb_val_loc * r_rate) FILTER (WHERE iter <> 'copy') sales_adj + ,sum(fb_cst_loc * c_rate) FILTER (WHERE iter <> 'copy') scogs_adj +FROM + rlarp.osm_fcpool +WHERE + order_season = 2020 +GROUP BY + director_descr + ,quota_rep_descr + ,part + ,bill_cust + ,ship_cust + ,order_month + ,iterdef +) +SELECT + director_descr + ,quota_rep_descr + ,to_char(sum(sales),'999,999,999') sales + ,to_char(sum(sales - scogs) ,'999,999,999') margin + ,to_char(sum(sales_adj),'999,999,999') sales_adj + ,to_char(sum(sales_adj - scogs_adj),'999,999,999') margin_adj + ,count(iterdef) +FROM + preagg +GROUP BY + GROUPING SETS ( + (director_descr,quota_rep_descr), + (director_descr), + () + ) +ORDER BY + director_descr + ,quota_rep_descr