From d5c2980bb18a34e9bc9ce0b88ff11a6e08e48dde Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Tue, 12 Apr 2022 02:09:36 -0400 Subject: [PATCH] isolate price change on no volume adjustment --- routes/scale/gen_scale.sql | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/routes/scale/gen_scale.sql b/routes/scale/gen_scale.sql index 0c42473..1812d9c 100644 --- a/routes/scale/gen_scale.sql +++ b/routes/scale/gen_scale.sql @@ -208,15 +208,30 @@ WHERE SELECT * FROM baseline WHERE (SELECT COUNT(*) FROM volume_only) = 0 ) ,pscale AS ( - ----what if the selection has several value columns, which one to use?----- - SELECT - (SELECT pincr FROM target) AS target_increment - ,sum("Amount") AS value - ,CASE WHEN (SELECT vscale. - ((SELECT pincr FROM target)-(SELECT sum("Amount") FROM volume))/(SELECT sum("Amount") FROM volume) - ,CASE WHEN (SELECT sum("Amount") FROM volume) = 0 THEN 0 ELSE (SELECT pincr FROM target)/sum("Amount") FROM volume END factor - FROM - volume +SELECT + (SELECT pincr FROM target) AS target_increment + ,sum($$||format('%I',_value_col)||') AS value'||$$ + ,CASE WHEN (SELECT sum($$||format('%I',_value_col)||$$) FROM volume) = 0 THEN + --if the base value is -0- scaling will not work, need to generate price, factor goes to -0- + 0 + ELSE + --expects inbound partial adjustment from volume table + --if the volume table does not have enough price added, need to get to goal increment + --multiplying by the raw factor without adding 1 will work since this data set will be added to the volume data set + ((SELECT pincr FROM target)-(SELECT sum($$||format('%I',_value_col)||$$) FROM volume))/(SELECT sum($$||format('%I',_value_col)||$$) FROM volume) + END factor + ,CASE WHEN (SELECT sum($$||format('%I',_value_col)||$$) FROM volume) = 0 THEN + CASE WHEN ((SELECT pincr::numeric FROM target) - (SELECT sum($$||format('%I',_value_col)||$$) FROM volume)) <> 0 THEN + --if the base value is -0- but the target value hasn't been achieved, derive a price to apply + ((SELECT pincr::numeric FROM target) - (SELECT sum($$||format('%I',_value_col)||$$) FROM volume))/(SELECT sum($$||format('%I',_units_col)||$$) FROM volume) + ELSE + 0 + END + ELSE + 0 + END mod_price +FROM + volume ) ,pricing AS ( SELECT @@ -232,7 +247,7 @@ INSERT INTO SELECT * FROM - volume + volume_only UNION ALL SELECT *