diff --git a/grafana/dashboards/drives.json b/grafana/dashboards/drives.json index 018b719fb4..0fcdb29d1a 100644 --- a/grafana/dashboards/drives.json +++ b/grafana/dashboards/drives.json @@ -5,7 +5,7 @@ "type": "grafana", "id": "grafana", "name": "Grafana", - "version": "11.0.0" + "version": "11.0.1" }, { "type": "datasource", @@ -78,116 +78,262 @@ ], "liveNow": false, "panels": [ + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 3, + "panels": [], + "title": "Summary of this period", + "type": "row" + }, { "datasource": { - "type": "grafana-postgresql-datasource", - "uid": "TeslaMate" + "type": "datasource", + "uid": "-- Dashboard --" }, "fieldConfig": { "defaults": { "color": { "mode": "thresholds" }, - "custom": { - "align": "center", - "cellOptions": { - "type": "auto" - }, - "filterable": false, - "inspect": false, - "minWidth": 150 - }, - "mappings": [], + "mappings": [ + { + "options": { + "match": "null", + "result": { + "text": "N/A" + } + }, + "type": "special" + } + ], "thresholds": { "mode": "absolute", "steps": [ { - "color": "green", + "color": "text", "value": null } ] - } + }, + "unit": "kwatth" }, "overrides": [ { "matcher": { "id": "byName", - "options": "start_date" + "options": "consumption_kWh" }, "properties": [ { "id": "displayName", - "value": "Date" - }, - { - "id": "unit", - "value": "dateTimeAsLocal" - }, - { - "id": "links", - "value": [ - { - "targetBlank": false, - "title": "View drive details", - "url": "d/zm7wN6Zgz?from=${__data.fields.start_date_ts.numeric}&to=${__data.fields.end_date_ts.numeric}&var-car_id=${__data.fields.car_id.numeric}&var-drive_id=${__data.fields.drive_id.numeric}" - } - ] - }, - { - "id": "custom.align", - "value": "auto" + "value": "Energy used:" + } + ] + } + ] + }, + "gridPos": { + "h": 2, + "w": 6, + "x": 0, + "y": 1 + }, + "id": 4, + "maxDataPoints": 100, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "center", + "orientation": "horizontal", + "reduceOptions": { + "calcs": [ + "sum" + ], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "11.0.1", + "targets": [ + { + "datasource": { + "type": "datasource", + "uid": "-- Dashboard --" + }, + "panelId": 2, + "refId": "A" + } + ], + "transformations": [ + { + "id": "filterFieldsByName", + "options": { + "include": { + "names": [ + "consumption_kWh" + ] + } + } + } + ], + "transparent": true, + "type": "stat" + }, + { + "datasource": { + "type": "datasource", + "uid": "-- Dashboard --" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "decimals": 0, + "mappings": [ + { + "options": { + "match": "null", + "result": { + "text": "N/A" + } }, + "type": "special" + } + ], + "thresholds": { + "mode": "absolute", + "steps": [ { - "id": "custom.width", - "value": 180 + "color": "text", + "value": null } ] }, + "unit": "m" + }, + "overrides": [ { "matcher": { "id": "byName", - "options": "consumption_kwh_km" + "options": "duration_min" }, "properties": [ { "id": "displayName", - "value": "Consumption" - }, - { - "id": "unit", - "value": "Wh/km" - }, - { - "id": "custom.align", - "value": "center" + "value": "Total Duration:" + } + ] + } + ] + }, + "gridPos": { + "h": 2, + "w": 6, + "x": 6, + "y": 1 + }, + "id": 5, + "maxDataPoints": 100, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "center", + "orientation": "horizontal", + "reduceOptions": { + "calcs": [ + "sum" + ], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "11.0.1", + "targets": [ + { + "datasource": { + "type": "datasource", + "uid": "-- Dashboard --" + }, + "panelId": 2, + "refId": "A" + } + ], + "transformations": [ + { + "id": "filterFieldsByName", + "options": { + "include": { + "names": [ + "duration_min" + ] + } + } + } + ], + "transparent": true, + "type": "stat" + }, + { + "datasource": { + "type": "datasource", + "uid": "-- Dashboard --" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "decimals": 0, + "mappings": [ + { + "options": { + "match": "null", + "result": { + "text": "N/A" + } }, + "type": "special" + } + ], + "thresholds": { + "mode": "absolute", + "steps": [ { - "id": "custom.width", - "value": 150 + "color": "text", + "value": null } ] - }, + } + }, + "overrides": [ { "matcher": { "id": "byName", - "options": "consumption_kwh_mi" + "options": "distance_mi" }, "properties": [ - { - "id": "displayName", - "value": "Consumption" - }, { "id": "unit", - "value": "Wh/mi" - }, - { - "id": "custom.align", - "value": "center" + "value": "none" }, { - "id": "custom.width", - "value": 150 + "id": "displayName", + "value": "Total Distance (mi):" } ] }, @@ -197,98 +343,239 @@ "options": "distance_km" }, "properties": [ - { - "id": "displayName", - "value": "Distance" - }, { "id": "unit", - "value": "lengthkm" + "value": "none" }, { - "id": "decimals", - "value": 1 - }, - { - "id": "custom.align" + "id": "displayName", + "value": "Total Distance (km):" + } + ] + } + ] + }, + "gridPos": { + "h": 2, + "w": 6, + "x": 12, + "y": 1 + }, + "id": 6, + "maxDataPoints": 100, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "center", + "orientation": "horizontal", + "reduceOptions": { + "calcs": [ + "sum" + ], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "11.0.1", + "targets": [ + { + "datasource": { + "type": "datasource", + "uid": "-- Dashboard --" + }, + "panelId": 2, + "refId": "A" + } + ], + "transformations": [ + { + "id": "filterFieldsByName", + "options": { + "include": { + "names": [ + "distance_mi", + "distance_km" + ] + } + } + } + ], + "transparent": true, + "type": "stat" + }, + { + "datasource": { + "type": "datasource", + "uid": "-- Dashboard --" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "decimals": 0, + "mappings": [ + { + "options": { + "match": "null", + "result": { + "text": "N/A" + } }, + "type": "special" + } + ], + "thresholds": { + "mode": "absolute", + "steps": [ { - "id": "custom.width", - "value": 90 + "color": "text", + "value": null } ] - }, + } + }, + "overrides": [ { "matcher": { "id": "byName", - "options": "consumption_kWh" + "options": "consumption_kwh_mi" }, "properties": [ - { - "id": "displayName", - "value": "kWh" - }, { "id": "unit", - "value": "kwatth" - }, - { - "id": "decimals", - "value": 1 - }, - { - "id": "custom.align", - "value": "center" + "value": "Wh/mi" }, { - "id": "custom.cellOptions", - "value": { - "type": "color-text" - } - }, + "id": "displayName", + "value": "Average Consumption:" + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "consumption_kwh_km" + }, + "properties": [ { - "id": "thresholds", - "value": { - "mode": "absolute", - "steps": [ - { - "color": "super-light-green", - "value": null - }, - { - "color": "green", - "value": 20 - }, - { - "color": "dark-green", - "value": 30 - } - ] - } + "id": "unit", + "value": "Wh/km" }, { - "id": "custom.width", - "value": 80 + "id": "displayName", + "value": "Average Consumption:" } ] + } + ] + }, + "gridPos": { + "h": 2, + "w": 6, + "x": 18, + "y": 1 + }, + "id": 7, + "maxDataPoints": 100, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "center", + "orientation": "horizontal", + "reduceOptions": { + "calcs": [ + "mean" + ], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "11.0.1", + "targets": [ + { + "datasource": { + "type": "datasource", + "uid": "-- Dashboard --" + }, + "panelId": 2, + "refId": "A" + } + ], + "transformations": [ + { + "id": "filterFieldsByName", + "options": { + "include": { + "names": [ + "consumption_kwh_mi", + "consumption_kwh_km" + ] + } + } + } + ], + "transparent": true, + "type": "stat" + }, + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "TeslaMate" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "custom": { + "align": "center", + "cellOptions": { + "type": "auto" + }, + "filterable": false, + "inspect": false, + "minWidth": 150 }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green" + } + ] + } + }, + "overrides": [ { "matcher": { "id": "byName", - "options": "start_address" + "options": "start_date" }, "properties": [ { "id": "displayName", - "value": "Start" + "value": "Date" + }, + { + "id": "unit", + "value": "dateTimeAsLocal" }, { "id": "links", "value": [ { - "targetBlank": true, - "title": "Create or edit geo-fence", - "url": "[[base_url:raw]]/geo-fences/${__data.fields.start_path}" + "targetBlank": false, + "title": "View drive details", + "url": "d/zm7wN6Zgz?from=${__data.fields.start_date_ts.numeric}&to=${__data.fields.end_date_ts.numeric}&var-car_id=${__data.fields.car_id.numeric}&var-drive_id=${__data.fields.drive_id.numeric}" } ] }, @@ -297,64 +584,222 @@ "value": "auto" }, { - "id": "custom.width", - "value": 250 + "id": "custom.minWidth", + "value": 180 } ] }, { "matcher": { "id": "byName", - "options": "end_address" + "options": "consumption_kwh_km" }, "properties": [ { "id": "displayName", - "value": "Destination" + "value": "Consumption" }, { - "id": "links", - "value": [ - { - "targetBlank": true, - "title": "Create or edit geo-fence", - "url": "[[base_url:raw]]/geo-fences/${__data.fields.end_path}" - } - ] + "id": "unit", + "value": "Wh/km" }, { "id": "custom.align", - "value": "auto" + "value": "center" }, { - "id": "custom.width", - "value": 250 + "id": "custom.minWidth", + "value": 120 } ] }, { "matcher": { "id": "byName", - "options": "outside_temp_c" + "options": "consumption_kwh_mi" }, "properties": [ { "id": "displayName", - "value": "Temp" + "value": "Consumption" }, { "id": "unit", - "value": "celsius" + "value": "Wh/mi" }, { - "id": "custom.align" + "id": "custom.align", + "value": "center" + }, + { + "id": "custom.minWidth", + "value": 120 + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "distance_km" + }, + "properties": [ + { + "id": "displayName", + "value": "Distance" + }, + { + "id": "unit", + "value": "lengthkm" + }, + { + "id": "decimals", + "value": 1 + }, + { + "id": "custom.align" + }, + { + "id": "custom.minWidth", + "value": 90 + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "consumption_kWh" + }, + "properties": [ + { + "id": "displayName", + "value": "kWh" + }, + { + "id": "unit", + "value": "kwatth" + }, + { + "id": "decimals", + "value": 1 + }, + { + "id": "custom.align", + "value": "center" + }, + { + "id": "custom.cellOptions", + "value": { + "type": "color-text" + } + }, + { + "id": "thresholds", + "value": { + "mode": "absolute", + "steps": [ + { + "color": "super-light-green" + }, + { + "color": "green", + "value": 20 + }, + { + "color": "dark-green", + "value": 30 + } + ] + } + }, + { + "id": "custom.minWidth", + "value": 80 + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "start_address" + }, + "properties": [ + { + "id": "displayName", + "value": "Start" + }, + { + "id": "links", + "value": [ + { + "targetBlank": true, + "title": "Create or edit geo-fence", + "url": "[[base_url:raw]]/geo-fences/${__data.fields.start_path}" + } + ] + }, + { + "id": "custom.align", + "value": "auto" + }, + { + "id": "custom.minWidth", + "value": 200 + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "end_address" + }, + "properties": [ + { + "id": "displayName", + "value": "Destination" + }, + { + "id": "links", + "value": [ + { + "targetBlank": true, + "title": "Create or edit geo-fence", + "url": "[[base_url:raw]]/geo-fences/${__data.fields.end_path}" + } + ] + }, + { + "id": "custom.align", + "value": "auto" + }, + { + "id": "custom.minWidth", + "value": 200 + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "outside_temp_c" + }, + "properties": [ + { + "id": "displayName", + "value": "Temp" + }, + { + "id": "unit", + "value": "celsius" + }, + { + "id": "custom.align" }, { "id": "decimals", "value": 1 }, { - "id": "custom.width", + "id": "custom.minWidth", "value": 70 }, { @@ -369,8 +814,7 @@ "mode": "absolute", "steps": [ { - "color": "super-light-blue", - "value": null + "color": "super-light-blue" }, { "color": "super-light-green", @@ -402,13 +846,13 @@ { "id": "custom.align" }, - { - "id": "custom.width", - "value": 90 - }, { "id": "decimals", "value": 1 + }, + { + "id": "custom.minWidth", + "value": 90 } ] }, @@ -448,8 +892,8 @@ } }, { - "id": "min", - "value": 0 + "id": "custom.minWidth", + "value": 90 } ] }, @@ -498,7 +942,7 @@ "value": 0 }, { - "id": "custom.width", + "id": "custom.minWidth", "value": 90 } ] @@ -548,7 +992,7 @@ "id": "custom.align" }, { - "id": "custom.width", + "id": "custom.minWidth", "value": 90 } ] @@ -575,7 +1019,7 @@ "value": 1 }, { - "id": "custom.width", + "id": "custom.minWidth", "value": 70 }, { @@ -590,8 +1034,7 @@ "mode": "absolute", "steps": [ { - "color": "super-light-blue", - "value": null + "color": "super-light-blue" }, { "color": "super-light-green", @@ -628,7 +1071,7 @@ "value": 0 }, { - "id": "custom.width", + "id": "custom.minWidth", "value": 90 } ] @@ -720,7 +1163,7 @@ "value": 0 }, { - "id": "custom.width", + "id": "custom.minWidth", "value": 76 } ] @@ -737,619 +1180,207 @@ }, { "id": "custom.align" - }, - { - "id": "decimals", - "value": 0 - }, - { - "id": "custom.width", - "value": 65 - } - ] - }, - { - "matcher": { - "id": "byName", - "options": "has_reduced_range" - }, - "properties": [ - { - "id": "displayName", - "value": "❄" - }, - { - "id": "custom.cellOptions", - "value": { - "type": "color-text" - } - }, - { - "id": "custom.align", - "value": "center" - }, - { - "id": "mappings", - "value": [ - { - "options": { - "false": { - "color": "transparent", - "index": 1, - "text": "." - }, - "true": { - "color": "dark-blue", - "index": 0, - "text": "❄" - } - }, - "type": "value" - } - ] - }, - { - "id": "custom.width", - "value": 5 - } - ] - }, - { - "matcher": { - "id": "byName", - "options": "drive_id" - }, - "properties": [ - { - "id": "unit", - "value": "short" - }, - { - "id": "decimals", - "value": 2 - }, - { - "id": "custom.align" - }, - { - "id": "custom.hidden", - "value": true - } - ] - }, - { - "matcher": { - "id": "byName", - "options": "power_max" - }, - "properties": [ - { - "id": "displayName", - "value": "max Power" - }, - { - "id": "unit", - "value": "kwatt" - }, - { - "id": "custom.align" - }, - { - "id": "custom.width", - "value": 90 - } - ] - } - ] - }, - "gridPos": { - "h": 22, - "w": 24, - "x": 0, - "y": 0 - }, - "id": 2, - "options": { - "cellHeight": "sm", - "footer": { - "countRows": false, - "enablePagination": false, - "fields": "", - "reducer": [ - "sum" - ], - "show": false - }, - "showHeader": true, - "sortBy": [] - }, - "pluginVersion": "11.0.0", - "targets": [ - { - "alias": "", - "datasource": { - "type": "grafana-postgresql-datasource", - "uid": "TeslaMate" - }, - "editorMode": "code", - "format": "table", - "group": [], - "metricColumn": "none", - "rawQuery": true, - "rawSql": "WITH data AS (\n SELECT\n round(extract(epoch FROM start_date)) * 1000 AS start_date_ts,\n round(extract(epoch FROM end_date)) * 1000 AS end_date_ts,\n car.id as car_id,\n CASE WHEN start_geofence.id IS NULL THEN CONCAT('new?lat=', start_position.latitude, '&lng=', start_position.longitude)\n WHEN start_geofence.id IS NOT NULL THEN CONCAT(start_geofence.id, '/edit')\n END as start_path,\n CASE WHEN end_geofence.id IS NULL THEN CONCAT('new?lat=', end_position.latitude, '&lng=', end_position.longitude)\n WHEN end_geofence.id IS NOT NULL THEN CONCAT(end_geofence.id, '/edit')\n END as end_path,\n TO_CHAR((duration_min * INTERVAL '1 minute'), 'HH24:MI') as duration_str,\n drives.id as drive_id,\n -- Columns\n start_date,\n COALESCE(start_geofence.name, CONCAT_WS(', ', COALESCE(start_address.name, nullif(CONCAT_WS(' ', start_address.road, start_address.house_number), '')), start_address.city)) AS start_address,\n COALESCE(end_geofence.name, CONCAT_WS(', ', COALESCE(end_address.name, nullif(CONCAT_WS(' ', end_address.road, end_address.house_number), '')), end_address.city)) AS end_address,\n duration_min,\n distance,\n start_position.usable_battery_level as start_usable_battery_level,\n start_position.battery_level as start_battery_level,\n end_position.usable_battery_level as end_usable_battery_level,\n end_position.battery_level as end_battery_level,\n case when (start_position.battery_level != start_position.usable_battery_level OR end_position.battery_level != end_position.usable_battery_level) = true then true else false end as reduced_range,\n duration_min > 1 AND distance > 1 AND ( \n start_position.usable_battery_level IS NULL OR end_position.usable_battery_level IS NULL\tOR\n (end_position.battery_level - end_position.usable_battery_level) = 0 \n ) as is_sufficiently_precise,\n NULLIF(GREATEST(start_[[preferred_range]]_range_km - end_[[preferred_range]]_range_km, 0), 0) as range_diff,\n car.efficiency as car_efficiency,\n outside_temp_avg,\n distance / NULLIF(duration_min, 0) * 60 AS avg_speed,\n power_max\n FROM drives\n LEFT JOIN addresses start_address ON start_address_id = start_address.id\n LEFT JOIN addresses end_address ON end_address_id = end_address.id\n LEFT JOIN positions start_position ON start_position_id = start_position.id\n LEFT JOIN positions end_position ON end_position_id = end_position.id\n LEFT JOIN geofences start_geofence ON start_geofence_id = start_geofence.id\n LEFT JOIN geofences end_geofence ON end_geofence_id = end_geofence.id\n LEFT JOIN cars car ON car.id = drives.car_id\n WHERE $__timeFilter(start_date) AND drives.car_id = $car_id \n AND convert_km(distance::numeric, '$length_unit') >= $min_dist \n AND convert_km(distance::numeric, '$length_unit') / NULLIF(duration_min, 0) * 60 >= $min_speed \n AND ('${geofence:pipe}' = '-1' OR start_geofence.id in ($geofence) OR end_geofence.id in ($geofence)) \n ORDER BY start_date DESC\n)\nSELECT\n start_date_ts,\n end_date_ts,\n car_id,\n start_path,\n end_path,\n duration_str,\n drive_id,\n -- Columns\n start_date,\n start_address,\n end_address,\n duration_min,\n convert_km(distance::numeric, '$length_unit') AS distance_$length_unit,\n start_battery_level as \"% Start\",\n end_battery_level as \"% End\",\n convert_celsius(outside_temp_avg, '$temp_unit') AS outside_temp_$temp_unit,\n convert_km(avg_speed::numeric, '$length_unit') AS speed_avg_$length_unit,\n power_max,\n reduced_range as has_reduced_range,\n CASE WHEN is_sufficiently_precise THEN distance / range_diff\n ELSE NULL\n END AS efficiency,\n range_diff * car_efficiency as \"consumption_kWh\",\n CASE WHEN is_sufficiently_precise THEN range_diff * car_efficiency / distance * 1000 * CASE WHEN '$length_unit' = 'km' THEN 1\n WHEN '$length_unit' = 'mi' THEN 1.60934\n END\n END AS consumption_kWh_$length_unit\nFROM data\nWHERE\n start_address ILIKE '%$location%' OR end_address ILIKE '%$location%';", - "refId": "A", - "select": [ - [ - { - "params": [ - "value" - ], - "type": "column" - } - ] - ], - "sql": { - "columns": [ - { - "parameters": [], - "type": "function" - } - ], - "groupBy": [ - { - "property": { - "type": "string" - }, - "type": "groupBy" - } - ], - "limit": 50 - }, - "timeColumn": "time", - "where": [ - { - "name": "$__timeFilter", - "params": [], - "type": "macro" - } - ] - } - ], - "title": "Drive", - "transformations": [ - { - "id": "merge", - "options": { - "reducers": [] - } - } - ], - "type": "table" - }, - { - "collapsed": false, - "gridPos": { - "h": 1, - "w": 24, - "x": 0, - "y": 22 - }, - "id": 3, - "panels": [], - "title": "Summary of this period", - "type": "row" - }, - { - "datasource": { - "type": "datasource", - "uid": "-- Dashboard --" - }, - "fieldConfig": { - "defaults": { - "color": { - "mode": "thresholds" - }, - "mappings": [ - { - "options": { - "match": "null", - "result": { - "text": "N/A" - } - }, - "type": "special" - } - ], - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "green", - "value": null - }, - { - "color": "red", - "value": 80 - } - ] - }, - "unit": "kwatth" - }, - "overrides": [] - }, - "gridPos": { - "h": 4, - "w": 6, - "x": 0, - "y": 23 - }, - "id": 4, - "maxDataPoints": 100, - "options": { - "colorMode": "none", - "graphMode": "none", - "justifyMode": "auto", - "orientation": "horizontal", - "reduceOptions": { - "calcs": [ - "sum" - ], - "fields": "", - "values": false - }, - "showPercentChange": false, - "textMode": "auto", - "wideLayout": true - }, - "pluginVersion": "11.0.0", - "targets": [ - { - "datasource": { - "type": "datasource", - "uid": "-- Dashboard --" - }, - "panelId": 2, - "refId": "A" - } - ], - "title": "Energy used", - "transformations": [ - { - "id": "filterFieldsByName", - "options": { - "include": { - "names": [ - "consumption_kWh" - ] - } - } - } - ], - "transparent": true, - "type": "stat" - }, - { - "datasource": { - "type": "datasource", - "uid": "-- Dashboard --" - }, - "description": "", - "fieldConfig": { - "defaults": { - "color": { - "mode": "thresholds" - }, - "decimals": 0, - "mappings": [ - { - "options": { - "match": "null", - "result": { - "text": "N/A" - } - }, - "type": "special" - } - ], - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "green", - "value": null - }, - { - "color": "red", - "value": 80 - } - ] - }, - "unit": "m" - }, - "overrides": [] - }, - "gridPos": { - "h": 4, - "w": 6, - "x": 6, - "y": 23 - }, - "id": 5, - "maxDataPoints": 100, - "options": { - "colorMode": "none", - "graphMode": "none", - "justifyMode": "auto", - "orientation": "horizontal", - "reduceOptions": { - "calcs": [ - "sum" - ], - "fields": "", - "values": false - }, - "showPercentChange": false, - "textMode": "auto", - "wideLayout": true - }, - "pluginVersion": "11.0.0", - "targets": [ - { - "datasource": { - "type": "datasource", - "uid": "-- Dashboard --" - }, - "panelId": 2, - "refId": "A" - } - ], - "title": "Total Duration", - "transformations": [ - { - "id": "filterFieldsByName", - "options": { - "include": { - "names": [ - "duration_min" - ] - } - } - } - ], - "transparent": true, - "type": "stat" - }, - { - "datasource": { - "type": "datasource", - "uid": "-- Dashboard --" - }, - "description": "", - "fieldConfig": { - "defaults": { - "color": { - "mode": "thresholds" - }, - "decimals": 0, - "mappings": [ - { - "options": { - "match": "null", - "result": { - "text": "N/A" - } - }, - "type": "special" - } - ], - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "green", - "value": null - }, - { - "color": "red", - "value": 80 - } - ] - } - }, - "overrides": [ - { - "matcher": { - "id": "byName", - "options": "distance_mi" - }, - "properties": [ + }, { - "id": "unit", - "value": "lengthmi" + "id": "decimals", + "value": 0 + }, + { + "id": "custom.minWidth", + "value": 65 } ] }, { "matcher": { "id": "byName", - "options": "distance_km" + "options": "has_reduced_range" }, "properties": [ { - "id": "unit", - "value": "lengthkm" - } - ] - } - ] - }, - "gridPos": { - "h": 4, - "w": 6, - "x": 12, - "y": 23 - }, - "id": 6, - "maxDataPoints": 100, - "options": { - "colorMode": "none", - "graphMode": "none", - "justifyMode": "auto", - "orientation": "horizontal", - "reduceOptions": { - "calcs": [ - "sum" - ], - "fields": "", - "values": false - }, - "showPercentChange": false, - "textMode": "auto", - "wideLayout": true - }, - "pluginVersion": "11.0.0", - "targets": [ - { - "datasource": { - "type": "datasource", - "uid": "-- Dashboard --" - }, - "panelId": 2, - "refId": "A" - } - ], - "title": "Total Distance", - "transformations": [ - { - "id": "filterFieldsByName", - "options": { - "include": { - "names": [ - "distance_mi", - "distance_km" - ] - } - } - } - ], - "transparent": true, - "type": "stat" - }, - { - "datasource": { - "type": "datasource", - "uid": "-- Dashboard --" - }, - "description": "", - "fieldConfig": { - "defaults": { - "color": { - "mode": "thresholds" - }, - "decimals": 0, - "mappings": [ - { - "options": { - "match": "null", - "result": { - "text": "N/A" + "id": "displayName", + "value": "❄" + }, + { + "id": "custom.cellOptions", + "value": { + "type": "color-text" } }, - "type": "special" - } - ], - "thresholds": { - "mode": "absolute", - "steps": [ { - "color": "green", - "value": null + "id": "custom.align", + "value": "center" }, { - "color": "red", - "value": 80 + "id": "mappings", + "value": [ + { + "options": { + "false": { + "color": "transparent", + "index": 1, + "text": "." + }, + "true": { + "color": "dark-blue", + "index": 0, + "text": "❄" + } + }, + "type": "value" + } + ] + }, + { + "id": "custom.minWidth", + "value": 5 } ] - } - }, - "overrides": [ + }, { "matcher": { "id": "byName", - "options": "consumption_kwh_mi" + "options": "drive_id" }, "properties": [ { "id": "unit", - "value": "Wh/mi" + "value": "short" + }, + { + "id": "decimals", + "value": 2 + }, + { + "id": "custom.align" + }, + { + "id": "custom.hidden", + "value": true } ] }, { "matcher": { "id": "byName", - "options": "consumption_kwh_km" + "options": "power_max" }, "properties": [ + { + "id": "displayName", + "value": "max Power" + }, { "id": "unit", - "value": "Wh/km" + "value": "kwatt" + }, + { + "id": "custom.align" + }, + { + "id": "custom.minWidth", + "value": 90 } ] } ] }, "gridPos": { - "h": 4, - "w": 6, - "x": 18, - "y": 23 + "h": 19, + "w": 24, + "x": 0, + "y": 3 }, - "id": 7, - "maxDataPoints": 100, + "id": 2, "options": { - "colorMode": "none", - "graphMode": "none", - "justifyMode": "auto", - "orientation": "horizontal", - "reduceOptions": { - "calcs": [ - "mean" - ], + "cellHeight": "sm", + "footer": { + "countRows": false, + "enablePagination": false, "fields": "", - "values": false + "reducer": [ + "sum" + ], + "show": false }, - "showPercentChange": false, - "textMode": "auto", - "wideLayout": true + "showHeader": true, + "sortBy": [] }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.0.1", "targets": [ { + "alias": "", "datasource": { - "type": "datasource", - "uid": "-- Dashboard --" + "type": "grafana-postgresql-datasource", + "uid": "TeslaMate" }, - "panelId": 2, - "refId": "A" + "editorMode": "code", + "format": "table", + "group": [], + "metricColumn": "none", + "rawQuery": true, + "rawSql": "WITH data AS (\n SELECT\n round(extract(epoch FROM start_date)) * 1000 AS start_date_ts,\n round(extract(epoch FROM end_date)) * 1000 AS end_date_ts,\n car.id as car_id,\n CASE WHEN start_geofence.id IS NULL THEN CONCAT('new?lat=', start_position.latitude, '&lng=', start_position.longitude)\n WHEN start_geofence.id IS NOT NULL THEN CONCAT(start_geofence.id, '/edit')\n END as start_path,\n CASE WHEN end_geofence.id IS NULL THEN CONCAT('new?lat=', end_position.latitude, '&lng=', end_position.longitude)\n WHEN end_geofence.id IS NOT NULL THEN CONCAT(end_geofence.id, '/edit')\n END as end_path,\n TO_CHAR((duration_min * INTERVAL '1 minute'), 'HH24:MI') as duration_str,\n drives.id as drive_id,\n -- Columns\n start_date,\n COALESCE(start_geofence.name, CONCAT_WS(', ', COALESCE(start_address.name, nullif(CONCAT_WS(' ', start_address.road, start_address.house_number), '')), start_address.city)) AS start_address,\n COALESCE(end_geofence.name, CONCAT_WS(', ', COALESCE(end_address.name, nullif(CONCAT_WS(' ', end_address.road, end_address.house_number), '')), end_address.city)) AS end_address,\n duration_min,\n distance,\n start_position.usable_battery_level as start_usable_battery_level,\n start_position.battery_level as start_battery_level,\n end_position.usable_battery_level as end_usable_battery_level,\n end_position.battery_level as end_battery_level,\n case when (start_position.battery_level != start_position.usable_battery_level OR end_position.battery_level != end_position.usable_battery_level) = true then true else false end as reduced_range,\n duration_min > 1 AND distance > 1 AND ( \n start_position.usable_battery_level IS NULL OR end_position.usable_battery_level IS NULL\tOR\n (end_position.battery_level - end_position.usable_battery_level) = 0 \n ) as is_sufficiently_precise,\n NULLIF(GREATEST(start_[[preferred_range]]_range_km - end_[[preferred_range]]_range_km, 0), 0) as range_diff,\n car.efficiency as car_efficiency,\n outside_temp_avg,\n distance / NULLIF(duration_min, 0) * 60 AS avg_speed,\n power_max\n FROM drives\n LEFT JOIN addresses start_address ON start_address_id = start_address.id\n LEFT JOIN addresses end_address ON end_address_id = end_address.id\n LEFT JOIN positions start_position ON start_position_id = start_position.id\n LEFT JOIN positions end_position ON end_position_id = end_position.id\n LEFT JOIN geofences start_geofence ON start_geofence_id = start_geofence.id\n LEFT JOIN geofences end_geofence ON end_geofence_id = end_geofence.id\n LEFT JOIN cars car ON car.id = drives.car_id\n WHERE $__timeFilter(start_date) AND drives.car_id = $car_id \n AND convert_km(distance::numeric, '$length_unit') >= $min_dist \n AND convert_km(distance::numeric, '$length_unit') / NULLIF(duration_min, 0) * 60 >= $min_speed \n AND ('${geofence:pipe}' = '-1' OR start_geofence.id in ($geofence) OR end_geofence.id in ($geofence)) \n ORDER BY start_date DESC\n)\nSELECT\n start_date_ts,\n end_date_ts,\n car_id,\n start_path,\n end_path,\n duration_str,\n drive_id,\n -- Columns\n start_date,\n start_address,\n end_address,\n duration_min,\n convert_km(distance::numeric, '$length_unit') AS distance_$length_unit,\n start_battery_level as \"% Start\",\n end_battery_level as \"% End\",\n convert_celsius(outside_temp_avg, '$temp_unit') AS outside_temp_$temp_unit,\n convert_km(avg_speed::numeric, '$length_unit') AS speed_avg_$length_unit,\n power_max,\n reduced_range as has_reduced_range,\n CASE WHEN is_sufficiently_precise THEN distance / range_diff\n ELSE NULL\n END AS efficiency,\n range_diff * car_efficiency as \"consumption_kWh\",\n CASE WHEN is_sufficiently_precise THEN range_diff * car_efficiency / distance * 1000 * CASE WHEN '$length_unit' = 'km' THEN 1\n WHEN '$length_unit' = 'mi' THEN 1.60934\n END\n END AS consumption_kWh_$length_unit\nFROM data\nWHERE\n start_address ILIKE '%$location%' OR end_address ILIKE '%$location%';", + "refId": "A", + "select": [ + [ + { + "params": [ + "value" + ], + "type": "column" + } + ] + ], + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + }, + "timeColumn": "time", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + } + ] } ], - "title": "Average Consumption", + "title": "Drive", "transformations": [ { - "id": "filterFieldsByName", + "id": "merge", "options": { - "include": { - "names": [ - "consumption_kwh_mi", - "consumption_kwh_km" - ] - } + "reducers": [] } } ], - "transparent": true, - "type": "stat" + "type": "table" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 22 + }, + "id": 10, + "panels": [], + "title": "General information (All drives)", + "type": "row" }, { "datasource": { @@ -1360,7 +1391,7 @@ "h": 2, "w": 24, "x": 0, - "y": 27 + "y": 23 }, "id": 8, "options": { @@ -1372,7 +1403,7 @@ "content": "From here you can check if you have \nincomplete data of **Drives** (drives without ending date)\nIf so, you may follow the official \nguide by Manually fixing data", "mode": "markdown" }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.0.1", "targets": [ { "datasource": { @@ -1445,7 +1476,7 @@ "h": 7, "w": 24, "x": 0, - "y": 29 + "y": 25 }, "id": 9, "options": { @@ -1461,7 +1492,7 @@ }, "showHeader": true }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.0.1", "targets": [ { "alias": "", @@ -1729,6 +1760,6 @@ "timezone": "", "title": "Drives", "uid": "Y8upc6ZRk", - "version": 2, + "version": 3, "weekStart": "" } \ No newline at end of file diff --git a/website/static/screenshots/drives.png b/website/static/screenshots/drives.png index 4f2b5af192..8f800026b0 100755 Binary files a/website/static/screenshots/drives.png and b/website/static/screenshots/drives.png differ