|
@@ -2,7 +2,20 @@ SET height = '500';
|
|
SET type = 'line';
|
|
SET type = 'line';
|
|
SET marker = 4;
|
|
SET marker = 4;
|
|
SET max_line_series = 50;
|
|
SET max_line_series = 50;
|
|
-
|
|
|
|
|
|
+SET ":unit" = $unit;
|
|
|
|
+SET ":log_scale" = $log_scale;
|
|
|
|
+SET ":ymin" = (SELECT
|
|
|
|
+ min(price/quantity)
|
|
|
|
+ FROM sqlpage_txn
|
|
|
|
+ WHERE unit = :unit
|
|
|
|
+);
|
|
|
|
+SET ":ymax" = (SELECT
|
|
|
|
+ max(price/quantity)
|
|
|
|
+ FROM sqlpage_txn
|
|
|
|
+ WHERE unit = :unit
|
|
|
|
+);
|
|
|
|
+--SELECT 'debug' AS component;
|
|
|
|
+--SELECT :ymin AS ymin, :ymax AS ymax, :ystep AS ystep;
|
|
|
|
|
|
SELECT 'chart' AS component
|
|
SELECT 'chart' AS component
|
|
, 'Cost per '||$unit AS title
|
|
, 'Cost per '||$unit AS title
|
|
@@ -12,27 +25,23 @@ SELECT 'chart' AS component
|
|
WHEN (
|
|
WHEN (
|
|
SELECT count(DISTINCT product)
|
|
SELECT count(DISTINCT product)
|
|
FROM sqlpage_txn
|
|
FROM sqlpage_txn
|
|
- WHERE unit = $unit
|
|
|
|
|
|
+ WHERE unit = :unit
|
|
) > $max_line_series::numeric
|
|
) > $max_line_series::numeric
|
|
THEN 'scatter' ELSE $type
|
|
THEN 'scatter' ELSE $type
|
|
END AS type
|
|
END AS type
|
|
-, $log_scale = 'true' AS logarithmic
|
|
|
|
|
|
+, :log_scale = 'true' AS logarithmic
|
|
, TRUE AS time
|
|
, TRUE AS time
|
|
-, CASE
|
|
|
|
- WHEN $log_scale = 'true'
|
|
|
|
- THEN 1 ELSE 0
|
|
|
|
|
|
+, 5 AS yticks
|
|
|
|
+, CASE :log_scale
|
|
|
|
+ WHEN 'true' THEN CAST(:ymin AS NUMERIC)/CAST(:ymax AS NUMERIC)
|
|
|
|
+ ELSE 0
|
|
END AS ymin
|
|
END AS ymin
|
|
-, ((
|
|
|
|
- SELECT max(price/quantity)
|
|
|
|
- FROM sqlpage_txn
|
|
|
|
- WHERE unit = $unit
|
|
|
|
- )/10 + 1)::int AS ystep
|
|
|
|
, $marker AS marker
|
|
, $marker AS marker
|
|
;
|
|
;
|
|
SELECT product AS series
|
|
SELECT product AS series
|
|
, ts AS x
|
|
, ts AS x
|
|
, to_char(price/quantity, 'FM999999999.000') AS y
|
|
, to_char(price/quantity, 'FM999999999.000') AS y
|
|
FROM sqlpage_txn
|
|
FROM sqlpage_txn
|
|
-WHERE unit = $unit
|
|
|
|
|
|
+WHERE unit = :unit
|
|
ORDER BY ts
|
|
ORDER BY ts
|
|
;
|
|
;
|