From b1441928191fc950b713bed38e1908b845e60a8f Mon Sep 17 00:00:00 2001 From: Oliver Graff Date: Sun, 29 Mar 2020 22:18:47 -0700 Subject: [PATCH] Display vampire drain range loss per hour in the correct units. Closes #542. --- grafana/dashboards/vampire-drain.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grafana/dashboards/vampire-drain.json b/grafana/dashboards/vampire-drain.json index 37b43c274c..cd2438f9ec 100644 --- a/grafana/dashboards/vampire-drain.json +++ b/grafana/dashboards/vampire-drain.json @@ -358,7 +358,7 @@ "group": [], "metricColumn": "none", "rawQuery": true, - "rawSql": "with v0 as (\n SELECT\n lag(t.end_date) OVER w AS start_date,\n t.start_date AS end_date,\n lag(t.end_[[preferred_range]]_range_km) OVER w AS start_range,\n t.start_[[preferred_range]]_range_km AS end_range,\n lag(t.end_rated_range_km) OVER w AS start_rated_range,\n t.start_rated_range_km AS end_rated_range,\n lag(t.end_km) OVER w AS start_km,\n t.start_km AS end_km,\n EXTRACT(EPOCH FROM age(t.start_date, lag(t.end_date) OVER w)) AS duration,\n lag(t.end_position_id) OVER w AS start_position_id,\n t.start_position_id AS end_position_id\n FROM drives t\n WHERE car_id = $car_id AND $__timeFilter(start_date)\n WINDOW w AS (ORDER BY t.id ASC)\n ORDER BY id DESC\n),\nv as (\n SELECT\n *,\n start_position.battery_level AS start_soc,\n end_position.battery_level AS end_soc,\n start_position.usable_battery_level AS start_usable_soc,\n end_position.usable_battery_level AS end_usable_soc,\n greatest(start_position.battery_level - end_position.battery_level, 0) AS soc_diff,\n\t\tend_position.battery_level > end_position.usable_battery_level AS has_reduced_range\n FROM v0\n JOIN positions start_position ON start_position_id = start_position.id\n JOIN positions end_position ON end_position_id = end_position.id\n),\nc as (\n select efficiency from cars\n)\n\nSELECT\n round(extract(epoch FROM v.start_date)) * 1000 AS start_date_ts,\n round(extract(epoch FROM v.end_date)) * 1000 AS end_date_ts,\n -- Columns\n v.start_date as start_date_[[length_unit]],\n v.end_date as end_date_[[length_unit]],\n v.duration,\n (coalesce(s_asleep.sleep, 0) + coalesce(s_offline.sleep, 0)) / v.duration as standby,\n\t-soc_diff as soc_diff,\n\tCASE WHEN has_reduced_range THEN 1 ELSE 0 END as has_reduced_range,\n\tconvert_km(CASE WHEN has_reduced_range THEN NULL ELSE (v.start_range - v.end_range) END, '$length_unit') AS range_diff_$length_unit,\n CASE WHEN has_reduced_range THEN NULL ELSE (v.start_range - v.end_range) * c.efficiency END AS consumption,\n CASE WHEN has_reduced_range THEN NULL ELSE ((v.start_range - v.end_range) * c.efficiency) / (v.duration / 3600) * 1000 END as avg_power,\n convert_km(CASE WHEN has_reduced_range THEN NULL ELSE (v.start_range - v.end_range) / (v.duration / 3600) END, '$length_unit') AS range_lost_per_hour_km\nFROM v, c,\n LATERAL (\n SELECT EXTRACT(EPOCH FROM sum(age(s.end_date, s.start_date))) as sleep\n FROM states s\n WHERE\n state = 'asleep' AND\n v.start_date <= s.start_date AND s.end_date <= v.end_date AND\n s.car_id = $car_id\n ) s_asleep,\n LATERAL (\n SELECT EXTRACT(EPOCH FROM sum(age(s.end_date, s.start_date))) as sleep\n FROM states s\n WHERE\n state = 'offline' AND\n v.start_date <= s.start_date AND s.end_date <= v.end_date AND\n s.car_id = $car_id\n ) s_offline\nWHERE\n v.duration > ($duration * 60 * 60)\n AND v.start_range - v.end_range >= 0\n AND v.end_km - v.start_km < 1;\n", + "rawSql": "with v0 as (\n SELECT\n lag(t.end_date) OVER w AS start_date,\n t.start_date AS end_date,\n lag(t.end_[[preferred_range]]_range_km) OVER w AS start_range,\n t.start_[[preferred_range]]_range_km AS end_range,\n lag(t.end_rated_range_km) OVER w AS start_rated_range,\n t.start_rated_range_km AS end_rated_range,\n lag(t.end_km) OVER w AS start_km,\n t.start_km AS end_km,\n EXTRACT(EPOCH FROM age(t.start_date, lag(t.end_date) OVER w)) AS duration,\n lag(t.end_position_id) OVER w AS start_position_id,\n t.start_position_id AS end_position_id\n FROM drives t\n WHERE car_id = $car_id AND $__timeFilter(start_date)\n WINDOW w AS (ORDER BY t.id ASC)\n ORDER BY id DESC\n),\nv as (\n SELECT\n *,\n start_position.battery_level AS start_soc,\n end_position.battery_level AS end_soc,\n start_position.usable_battery_level AS start_usable_soc,\n end_position.usable_battery_level AS end_usable_soc,\n greatest(start_position.battery_level - end_position.battery_level, 0) AS soc_diff,\n\t\tend_position.battery_level > end_position.usable_battery_level AS has_reduced_range\n FROM v0\n JOIN positions start_position ON start_position_id = start_position.id\n JOIN positions end_position ON end_position_id = end_position.id\n),\nc as (\n select efficiency from cars\n)\n\nSELECT\n round(extract(epoch FROM v.start_date)) * 1000 AS start_date_ts,\n round(extract(epoch FROM v.end_date)) * 1000 AS end_date_ts,\n -- Columns\n v.start_date as start_date_[[length_unit]],\n v.end_date as end_date_[[length_unit]],\n v.duration,\n (coalesce(s_asleep.sleep, 0) + coalesce(s_offline.sleep, 0)) / v.duration as standby,\n\t-soc_diff as soc_diff,\n\tCASE WHEN has_reduced_range THEN 1 ELSE 0 END as has_reduced_range,\n\tconvert_km(CASE WHEN has_reduced_range THEN NULL ELSE (v.start_range - v.end_range) END, '$length_unit') AS range_diff_$length_unit,\n CASE WHEN has_reduced_range THEN NULL ELSE (v.start_range - v.end_range) * c.efficiency END AS consumption,\n CASE WHEN has_reduced_range THEN NULL ELSE ((v.start_range - v.end_range) * c.efficiency) / (v.duration / 3600) * 1000 END as avg_power,\n convert_km(CASE WHEN has_reduced_range THEN NULL ELSE (v.start_range - v.end_range) / (v.duration / 3600) END, '$length_unit') AS range_lost_per_hour_[[length_unit]]\nFROM v, c,\n LATERAL (\n SELECT EXTRACT(EPOCH FROM sum(age(s.end_date, s.start_date))) as sleep\n FROM states s\n WHERE\n state = 'asleep' AND\n v.start_date <= s.start_date AND s.end_date <= v.end_date AND\n s.car_id = $car_id\n ) s_asleep,\n LATERAL (\n SELECT EXTRACT(EPOCH FROM sum(age(s.end_date, s.start_date))) as sleep\n FROM states s\n WHERE\n state = 'offline' AND\n v.start_date <= s.start_date AND s.end_date <= v.end_date AND\n s.car_id = $car_id\n ) s_offline\nWHERE\n v.duration > ($duration * 60 * 60)\n AND v.start_range - v.end_range >= 0\n AND v.end_km - v.start_km < 1;\n", "refId": "A", "select": [ [