From 131fe208b0b8917fd3b0102e44a9dc3e72398092 Mon Sep 17 00:00:00 2001 From: Matthias Wirtz Date: Sun, 7 Jul 2024 08:14:14 +0200 Subject: [PATCH 1/2] use lfp_battery setting in dashboards --- grafana/dashboards/battery-health.json | 30 ++--- grafana/dashboards/charge-level.json | 7 +- grafana/dashboards/charging-stats.json | 155 +++++++++++++------------ grafana/dashboards/overview.json | 26 ++++- 4 files changed, 123 insertions(+), 95 deletions(-) diff --git a/grafana/dashboards/battery-health.json b/grafana/dashboards/battery-health.json index a72d8873b1..24905091b6 100644 --- a/grafana/dashboards/battery-health.json +++ b/grafana/dashboards/battery-health.json @@ -17,7 +17,7 @@ "type": "grafana", "id": "grafana", "name": "Grafana", - "version": "11.0.0" + "version": "11.1.0" }, { "type": "datasource", @@ -138,6 +138,7 @@ "graphMode": "none", "justifyMode": "auto", "orientation": "horizontal", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "lastNotNull" @@ -149,7 +150,7 @@ "textMode": "value_and_name", "wideLayout": true }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "targets": [ { "datasource": { @@ -285,6 +286,7 @@ "graphMode": "none", "justifyMode": "auto", "orientation": "horizontal", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "lastNotNull" @@ -296,7 +298,7 @@ "textMode": "value_and_name", "wideLayout": true }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "targets": [ { "datasource": { @@ -370,6 +372,7 @@ "graphMode": "none", "justifyMode": "auto", "orientation": "horizontal", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "lastNotNull" @@ -381,7 +384,7 @@ "textMode": "value_and_name", "wideLayout": true }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "targets": [ { "datasource": { @@ -753,7 +756,7 @@ "showThresholdMarkers": true, "sizing": "auto" }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "targets": [ { "datasource": { @@ -852,7 +855,7 @@ "sizing": "auto", "valueMode": "color" }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "targets": [ { "datasource": { @@ -966,6 +969,7 @@ "graphMode": "none", "justifyMode": "auto", "orientation": "horizontal", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "mean" @@ -977,7 +981,7 @@ "textMode": "value_and_name", "wideLayout": true }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "targets": [ { "datasource": { @@ -1224,7 +1228,7 @@ "text": {}, "valueMode": "color" }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "targets": [ { "datasource": { @@ -1285,7 +1289,7 @@ "format": "table", "hide": false, "rawQuery": true, - "rawSql": "SELECT\r\n 0 as lowest,\r\n 20 as lower,\r\n CASE\r\n WHEN substring(vin, 7, 1) = 'F' or (substring(vin, 0, 3) != 'LRW' and substring(vin, 8, 1) = 'S' and substring(vin, 7, 1) = 'E')\r\n THEN 100\r\n ELSE 81\r\n END as upper\r\nfrom cars ", + "rawSql": "SELECT\r\n 0 as lowest,\r\n 20 as lower,\r\n CASE WHEN lfp_battery THEN 100 ELSE 81 END as upper\r\nfrom cars inner join car_settings on cars.settings_id = car_settings.id\r\nwhere cars.id = $car_id", "refId": "A", "sql": { "columns": [ @@ -1407,6 +1411,7 @@ "graphMode": "none", "justifyMode": "auto", "orientation": "horizontal", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "lastNotNull" @@ -1418,7 +1423,7 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "targets": [ { "datasource": { @@ -1518,7 +1523,7 @@ "text": {}, "valueMode": "color" }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "targets": [ { "datasource": { @@ -1970,13 +1975,12 @@ "from": "now-6h", "to": "now" }, - "timeRangeUpdatedDuringEditOrView": false, "timepicker": { "hidden": true }, "timezone": "browser", "title": "Battery Health", "uid": "jchmRiqUfXgTM", - "version": 7, + "version": 9, "weekStart": "" } \ No newline at end of file diff --git a/grafana/dashboards/charge-level.json b/grafana/dashboards/charge-level.json index 5e6a4e9a14..2165f24cc1 100644 --- a/grafana/dashboards/charge-level.json +++ b/grafana/dashboards/charge-level.json @@ -5,7 +5,7 @@ "type": "grafana", "id": "grafana", "name": "Grafana", - "version": "11.0.0" + "version": "11.1.0" }, { "type": "datasource", @@ -206,7 +206,7 @@ "format": "table", "hide": false, "rawQuery": true, - "rawSql": "SELECT\r\n 20 as lower,\r\n CASE\r\n WHEN substring(vin, 7, 1) = 'F' or (substring(vin, 0, 3) != 'LRW' and substring(vin, 8, 1) = 'S' and substring(vin, 7, 1) = 'E')\r\n THEN 100\r\n ELSE 80\r\n END as upper\r\nfrom cars ", + "rawSql": "SELECT\r\n 20 as lower,\r\n CASE WHEN lfp_battery THEN 100 ELSE 80 END as upper\r\nfrom cars inner join car_settings on cars.settings_id = car_settings.id\r\nwhere cars.id = $car_id", "refId": "B", "sql": { "columns": [ @@ -322,7 +322,6 @@ "from": "now-7d", "to": "now" }, - "timeRangeUpdatedDuringEditOrView": false, "timepicker": { "refresh_intervals": [ "5s", @@ -351,6 +350,6 @@ "timezone": "", "title": "Charge Level", "uid": "WopVO_mgz", - "version": 2, + "version": 5, "weekStart": "" } \ No newline at end of file diff --git a/grafana/dashboards/charging-stats.json b/grafana/dashboards/charging-stats.json index 5d9613a389..420f63c132 100644 --- a/grafana/dashboards/charging-stats.json +++ b/grafana/dashboards/charging-stats.json @@ -11,7 +11,7 @@ "type": "grafana", "id": "grafana", "name": "Grafana", - "version": "11.0.0" + "version": "11.1.0" }, { "type": "datasource", @@ -155,6 +155,7 @@ "graphMode": "none", "justifyMode": "auto", "orientation": "horizontal", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "mean" @@ -166,9 +167,13 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "targets": [ { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "TeslaMate" + }, "format": "table", "group": [], "metricColumn": "none", @@ -194,11 +199,7 @@ "params": [], "type": "macro" } - ], - "datasource": { - "type": "grafana-postgresql-datasource", - "uid": "TeslaMate" - } + ] } ], "title": "Number of Charges", @@ -243,6 +244,7 @@ "graphMode": "none", "justifyMode": "auto", "orientation": "horizontal", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "mean" @@ -254,9 +256,13 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "targets": [ { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "TeslaMate" + }, "format": "table", "group": [], "metricColumn": "none", @@ -282,11 +288,7 @@ "params": [], "type": "macro" } - ], - "datasource": { - "type": "grafana-postgresql-datasource", - "uid": "TeslaMate" - } + ] } ], "title": "Charged in total", @@ -332,6 +334,7 @@ "graphMode": "none", "justifyMode": "auto", "orientation": "horizontal", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "mean" @@ -343,7 +346,7 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "targets": [ { "datasource": { @@ -421,6 +424,7 @@ "graphMode": "none", "justifyMode": "auto", "orientation": "horizontal", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "mean" @@ -432,9 +436,13 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "targets": [ { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "TeslaMate" + }, "format": "table", "group": [], "metricColumn": "none", @@ -460,11 +468,7 @@ "params": [], "type": "macro" } - ], - "datasource": { - "type": "grafana-postgresql-datasource", - "uid": "TeslaMate" - } + ] } ], "title": "Total Charging Cost", @@ -504,6 +508,7 @@ "graphMode": "none", "justifyMode": "auto", "orientation": "auto", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "mean" @@ -515,9 +520,13 @@ "textMode": "auto", "wideLayout": true }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "targets": [ { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "TeslaMate" + }, "format": "table", "group": [], "metricColumn": "none", @@ -543,11 +552,7 @@ "params": [], "type": "macro" } - ], - "datasource": { - "type": "grafana-postgresql-datasource", - "uid": "TeslaMate" - } + ] } ], "title": "Cost per 100 $length_unit", @@ -589,6 +594,7 @@ "graphMode": "none", "justifyMode": "auto", "orientation": "auto", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "mean" @@ -600,9 +606,13 @@ "textMode": "auto", "wideLayout": true }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "targets": [ { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "TeslaMate" + }, "format": "table", "group": [], "metricColumn": "none", @@ -618,11 +628,7 @@ "params": [], "type": "macro" } - ], - "datasource": { - "type": "grafana-postgresql-datasource", - "uid": "TeslaMate" - } + ] } ], "title": "Average Cost per kWh", @@ -664,6 +670,7 @@ "graphMode": "none", "justifyMode": "auto", "orientation": "auto", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "mean" @@ -675,7 +682,7 @@ "textMode": "auto", "wideLayout": true }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "targets": [ { "datasource": { @@ -757,6 +764,7 @@ "graphMode": "none", "justifyMode": "auto", "orientation": "auto", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "mean" @@ -768,7 +776,7 @@ "textMode": "auto", "wideLayout": true }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "targets": [ { "datasource": { @@ -903,10 +911,14 @@ "unit": "short" } }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "reverseYBuckets": false, "targets": [ { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "TeslaMate" + }, "format": "time_series", "group": [], "metricColumn": "none", @@ -932,11 +944,7 @@ "params": [], "type": "macro" } - ], - "datasource": { - "type": "grafana-postgresql-datasource", - "uid": "TeslaMate" - } + ] } ], "timeFrom": "6M", @@ -1119,7 +1127,7 @@ "format": "table", "hide": false, "rawQuery": true, - "rawSql": "SELECT\r\n 20 as lower,\r\n CASE\r\n WHEN substring(vin, 7, 1) = 'F' or (substring(vin, 0, 3) != 'LRW' and substring(vin, 8, 1) = 'S' and substring(vin, 7, 1) = 'E')\r\n THEN 100\r\n ELSE 80\r\n END as upper\r\nfrom cars ", + "rawSql": "SELECT\r\n 20 as lower,\r\n CASE WHEN lfp_battery THEN 100 ELSE 80 END as upper\r\nfrom cars inner join car_settings on cars.settings_id = car_settings.id\r\nwhere cars.id = $car_id", "refId": "B", "sql": { "columns": [ @@ -1268,6 +1276,10 @@ }, "targets": [ { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "TeslaMate" + }, "format": "time_series", "group": [], "metricColumn": "none", @@ -1293,11 +1305,7 @@ "params": [], "type": "macro" } - ], - "datasource": { - "type": "grafana-postgresql-datasource", - "uid": "TeslaMate" - } + ] } ], "title": "AC/DC - kWh", @@ -1446,7 +1454,7 @@ "zoom": 15 } }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "targets": [ { "datasource": { @@ -1594,6 +1602,10 @@ }, "targets": [ { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "TeslaMate" + }, "format": "time_series", "group": [], "metricColumn": "none", @@ -1619,11 +1631,7 @@ "params": [], "type": "macro" } - ], - "datasource": { - "type": "grafana-postgresql-datasource", - "uid": "TeslaMate" - } + ] } ], "title": "AC/DC - Duration", @@ -1932,7 +1940,7 @@ "showHeader": true, "sortBy": [] }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "targets": [ { "datasource": { @@ -1973,7 +1981,7 @@ "format": "table", "hide": false, "rawQuery": true, - "rawSql": "SELECT\r\n CASE\r\n WHEN substring(vin, 7, 1) = 'F' or (substring(vin, 0, 3) != 'LRW' and substring(vin, 8, 1) = 'S' and substring(vin, 7, 1) = 'E')\r\n THEN 100\r\n ELSE 81\r\n END as high,\r\n CASE\r\n WHEN substring(vin, 7, 1) = 'F' or (substring(vin, 0, 3) != 'LRW' and substring(vin, 8, 1) = 'S' and substring(vin, 7, 1) = 'E')\r\n THEN 100\r\n ELSE 91\r\n END as highest\r\nfrom cars ", + "rawSql": "SELECT\r\n CASE WHEN lfp_battery THEN 100 ELSE 81 END as high,\r\n CASE WHEN lfp_battery THEN 100 ELSE 91 END as highest\r\nfrom cars inner join car_settings on cars.settings_id = car_settings.id\r\nwhere cars.id = $car_id", "refId": "B", "sql": { "columns": [ @@ -2145,9 +2153,13 @@ "showHeader": true, "sortBy": [] }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "targets": [ { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "TeslaMate" + }, "format": "table", "group": [], "metricColumn": "none", @@ -2171,11 +2183,7 @@ "params": [], "type": "macro" } - ], - "datasource": { - "type": "grafana-postgresql-datasource", - "uid": "TeslaMate" - } + ] } ], "title": "Discharge Stats", @@ -2264,9 +2272,13 @@ }, "showHeader": true }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "targets": [ { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "TeslaMate" + }, "format": "table", "group": [], "metricColumn": "none", @@ -2290,11 +2302,7 @@ "params": [], "type": "macro" } - ], - "datasource": { - "type": "grafana-postgresql-datasource", - "uid": "TeslaMate" - } + ] } ], "title": "Top Charging Stations (Charged)", @@ -2387,9 +2395,13 @@ }, "showHeader": true }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "targets": [ { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "TeslaMate" + }, "format": "table", "group": [], "metricColumn": "none", @@ -2415,11 +2427,7 @@ "params": [], "type": "macro" } - ], - "datasource": { - "type": "grafana-postgresql-datasource", - "uid": "TeslaMate" - } + ] } ], "title": "Top Charging Stations (Cost)", @@ -2507,7 +2515,6 @@ "from": "now-10y", "to": "now" }, - "timeRangeUpdatedDuringEditOrView": false, "timepicker": { "hidden": false, "refresh_intervals": [ @@ -2537,6 +2544,6 @@ "timezone": "", "title": "Charging Stats", "uid": "-pkIkhmRz", - "version": 5, + "version": 8, "weekStart": "" } \ No newline at end of file diff --git a/grafana/dashboards/overview.json b/grafana/dashboards/overview.json index c3f2881d5f..2aa9ac2c84 100644 --- a/grafana/dashboards/overview.json +++ b/grafana/dashboards/overview.json @@ -155,6 +155,7 @@ "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, + "editorMode": "code", "format": "table", "group": [], "metricColumn": "none", @@ -171,6 +172,23 @@ } ] ], + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + }, "table": "positions", "timeColumn": "date", "timeColumnType": "timestamp", @@ -185,7 +203,7 @@ "format": "table", "hide": false, "rawQuery": true, - "rawSql": "SELECT\r\n 0 as lowest,\r\n 10 as low,\r\n 20 as mid,\r\n CASE\r\n WHEN substring(vin, 7, 1) = 'F' or (substring(vin, 0, 3) != 'LRW' and substring(vin, 8, 1) = 'S' and substring(vin, 7, 1) = 'E')\r\n THEN 100\r\n ELSE 81\r\n END as high,\r\n CASE\r\n WHEN substring(vin, 7, 1) = 'F' or (substring(vin, 0, 3) != 'LRW' and substring(vin, 8, 1) = 'S' and substring(vin, 7, 1) = 'E')\r\n THEN 100\r\n ELSE 91\r\n END as highest\r\nfrom cars ", + "rawSql": "SELECT\r\n 0 as lowest,\r\n 10 as low,\r\n 20 as mid,\r\n CASE WHEN lfp_battery THEN 100 ELSE 81 END as high,\r\n CASE WHEN lfp_battery THEN 100 ELSE 91 END as highest\r\nfrom cars inner join car_settings on cars.settings_id = car_settings.id\r\nwhere cars.id = $car_id", "refId": "B", "sql": { "columns": [ @@ -442,7 +460,7 @@ "format": "table", "hide": false, "rawQuery": true, - "rawSql": "SELECT\r\n CASE\r\n WHEN substring(vin, 7, 1) = 'F' or (substring(vin, 0, 3) != 'LRW' and substring(vin, 8, 1) = 'S' and substring(vin, 7, 1) = 'E')\r\n THEN 170\r\n ELSE 250\r\n END as max_charging_kw\r\nfrom cars ", + "rawSql": "SELECT\r\n CASE WHEN lfp_battery THEN 170 ELSE 250 END as max_charging_kw\r\nfrom cars inner join car_settings on cars.settings_id = car_settings.id\r\nwhere cars.id = $car_id", "refId": "B", "sql": { "columns": [ @@ -1006,7 +1024,7 @@ "x": 0, "y": 8 }, - "id": 14, + "id": 25, "maxDataPoints": 100, "options": { "colorMode": "value", @@ -2149,6 +2167,6 @@ "timezone": "", "title": "Overview", "uid": "kOuP_Fggz", - "version": 11, + "version": 9, "weekStart": "" } \ No newline at end of file From 6fe067e32de96c72188357307b3d88bd5be0d10a Mon Sep 17 00:00:00 2001 From: Matthias Wirtz Date: Sun, 7 Jul 2024 08:22:15 +0200 Subject: [PATCH 2/2] query perf. improvements in updates dashboard --- grafana/dashboards/updates.json | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/grafana/dashboards/updates.json b/grafana/dashboards/updates.json index b63b874c4f..b33016b250 100644 --- a/grafana/dashboards/updates.json +++ b/grafana/dashboards/updates.json @@ -5,7 +5,7 @@ "type": "grafana", "id": "grafana", "name": "Grafana", - "version": "11.0.0" + "version": "11.1.0" }, { "type": "datasource", @@ -117,6 +117,7 @@ "graphMode": "none", "justifyMode": "auto", "orientation": "auto", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "count" @@ -128,7 +129,7 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "targets": [ { "format": "table", @@ -200,6 +201,7 @@ "graphMode": "none", "justifyMode": "auto", "orientation": "auto", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "mean" @@ -211,7 +213,7 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "targets": [ { "format": "table", @@ -513,7 +515,7 @@ } ] }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.0", "scroll": true, "showHeader": true, "sort": { @@ -623,11 +625,12 @@ "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, + "editorMode": "code", "format": "table", "group": [], "metricColumn": "none", "rawQuery": true, - "rawSql": "with u as (\r\n select *, coalesce(lag(start_date) over(order by start_date desc), now()) as next_start_date \r\n from updates\r\n where car_id = $car_id and $__timeFilter(start_date)\r\n),\r\nrng as (\r\n SELECT\r\n\t to_timestamp(floor(extract(epoch from date)/21600)*21600) AS date,\r\n\t (sum([[preferred_range]]_battery_range_km) / nullif(sum(coalesce(usable_battery_level,battery_level)),0) * 100 ) AS \"battery_rng\"\r\n FROM (\r\n select battery_level, usable_battery_level, date, rated_battery_range_km, ideal_battery_range_km\r\n from positions\r\n where car_id = $car_id and $__timeFilter(date) and ideal_battery_range_km is not null\r\n union all\r\n select battery_level, coalesce(usable_battery_level,battery_level) as usable_battery_level, date, rated_battery_range_km, ideal_battery_range_km\r\n from charges c\r\n join charging_processes p ON p.id = c.charging_process_id \r\n where $__timeFilter(date) and p.car_id = $car_id\r\n ) as data\r\n GROUP BY 1\r\n)\r\n\r\nselect\t\r\n u.start_date as time,\r\n\textract(EPOCH FROM u.end_date - u.start_date) AS update_duration,\r\n\textract(EPOCH FROM u.start_date - lag(u.start_date) OVER (ORDER BY u.start_date)) AS since_last_update,\r\n\tsplit_part(u.version, ' ', 1) as version,\r\n\tcount(distinct cp.id) as chg_ct,\r\n\tconvert_km(avg(r.battery_rng), '$length_unit')::numeric(6,2) AS avg_[[preferred_range]]_range_[[length_unit]]\r\nfrom u u\r\nleft join charging_processes cp\r\n\tON u.car_id = cp.car_id\r\n \tand cp.start_date between u.start_date and u.next_start_date\r\nleft join rng r\r\n\tON r.date between u.start_date and u.next_start_date\r\ngroup by u.car_id,\r\n\tu.start_date,\r\n\tu.end_date,\r\n\tnext_start_date,\r\n\tsplit_part(u.version, ' ', 1)", + "rawSql": "with u as (\r\n select *, coalesce(lag(start_date) over(order by start_date desc), now()) as next_start_date \r\n from updates\r\n where car_id = $car_id and $__timeFilter(start_date)\r\n),\r\nrng as (\r\n SELECT\r\n\t date_trunc('hour', date) AS date,\r\n\t (sum([[preferred_range]]_battery_range_km)/ nullif(sum(usable_battery_level),0) * 100 ) AS \"battery_rng\",\r\n\t sum(case when action = 'Charge' then 1 else 0 end) as chg_ct\r\n FROM (\r\n select coalesce(usable_battery_level, battery_level) as usable_battery_level, start_date as date, start_rated_range_km as rated_battery_range_km, start_ideal_range_km as ideal_battery_range_km, 'Drive' as action\r\n from drives d\r\n inner join positions p on d.start_position_id = p.id \r\n where d.car_id = $car_id and $__timeFilter(start_date)\r\n union all\r\n select end_battery_level as usable_battery_level, end_date, end_rated_range_km as rated_battery_range_km, end_ideal_range_km as ideal_battery_range_km, 'Charge' as action\r\n from charging_processes p\r\n where $__timeFilter(end_date) and p.car_id = $car_id\r\n ) as data\r\n GROUP BY 1\r\n)\r\n\r\nselect\t\r\n u.start_date as time,\r\n\textract(EPOCH FROM u.end_date - u.start_date) AS update_duration,\r\n\textract(EPOCH FROM u.start_date - lag(u.start_date) OVER (ORDER BY u.start_date)) AS since_last_update,\r\n\tsplit_part(u.version, ' ', 1) as version,\r\n\tsum(r.chg_ct) as chg_ct,\r\n\tconvert_km(avg(r.battery_rng), '$length_unit')::numeric(6,2) AS avg_[[preferred_range]]_range_[[length_unit]]\r\nfrom u u\r\nleft join rng r\r\n\tON r.date between u.start_date and u.next_start_date\r\ngroup by u.car_id,\r\n\tu.start_date,\r\n\tu.end_date,\r\n\tnext_start_date,\r\n\tsplit_part(u.version, ' ', 1)", "refId": "A", "select": [ [ @@ -639,6 +642,23 @@ } ] ], + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + }, "table": "cars", "timeColumn": "inserted_at", "timeColumnType": "timestamp", @@ -757,7 +777,6 @@ "from": "now-10y", "to": "now" }, - "timeRangeUpdatedDuringEditOrView": false, "timepicker": { "refresh_intervals": [ "10s", @@ -785,6 +804,6 @@ "timezone": "", "title": "Updates", "uid": "IiC07mgWz", - "version": 1, + "version": 2, "weekStart": "" } \ No newline at end of file