From ebf208d29ec7d88b641e363e571ed0e0037c8a0e Mon Sep 17 00:00:00 2001 From: Nathan Gardiner Date: Sun, 24 Nov 2019 01:13:12 +1100 Subject: [PATCH 1/4] Update charges.json Added cost column to table, fixed column headers for readability --- grafana/dashboards/charges.json | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/grafana/dashboards/charges.json b/grafana/dashboards/charges.json index 1b5c34def5..2ef411c408 100644 --- a/grafana/dashboards/charges.json +++ b/grafana/dashboards/charges.json @@ -93,7 +93,7 @@ "unit": "short" }, { - "alias": "Energy added", + "alias": "Added", "colorMode": null, "colors": [ "rgba(245, 54, 54, 0.9)", @@ -189,7 +189,7 @@ "unit": "m" }, { - "alias": "Temperature", + "alias": "Temp", "colorMode": null, "colors": [ "rgba(245, 54, 54, 0.9)", @@ -204,6 +204,22 @@ "type": "number", "unit": "celsius" }, + { + "alias": "Cost", + "colorMode": null, + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 2, + "mappingType": 1, + "pattern": "cost", + "thresholds": [], + "type": "number", + "unit": "currencyUSD" + }, { "alias": "", "colorMode": null, @@ -257,7 +273,7 @@ "unit": "short" }, { - "alias": "km driven", + "alias": "Driven", "colorMode": null, "colors": [ "rgba(245, 54, 54, 0.9)", @@ -273,7 +289,7 @@ "unit": "lengthkm" }, { - "alias": "consumed", + "alias": "Consumed", "colorMode": null, "colors": [ "rgba(245, 54, 54, 0.9)", @@ -372,7 +388,7 @@ "unit": "lengthmi" }, { - "alias": "Temperature", + "alias": "Temp", "colorMode": null, "colors": [ "rgba(245, 54, 54, 0.9)", @@ -388,7 +404,7 @@ "unit": "farenheit" }, { - "alias": "mi driven", + "alias": "Driven", "colorMode": null, "colors": [ "rgba(245, 54, 54, 0.9)", @@ -452,7 +468,7 @@ "unit": "short" }, { - "alias": "Energy used", + "alias": "Used", "colorMode": null, "colors": [ "rgba(245, 54, 54, 0.9)", @@ -524,7 +540,7 @@ "group": [], "metricColumn": "none", "rawQuery": true, - "rawSql": "WITH data AS (\n SELECT\n (round(extract(epoch FROM start_date)) * 1000) - 5000 AS start_date_ts,\n (round(extract(epoch FROM end_date)) * 1000) + 5000 AS end_date_ts,\n start_date,\n end_date,\n CONCAT_WS(', ', COALESCE(addresses.name, CONCAT_WS(' ', addresses.road, addresses.house_number)), addresses.city) AS address,\n g.name as geofence_name,\n g.id as geofence_id,\n p.latitude,\n p.longitude,\n charge_energy_added,\n charge_energy_used,\n duration_min,\n start_battery_level,\n end_battery_level,\n start_[[preferred_range]]_range_km,\n end_[[preferred_range]]_range_km,\n outside_temp_avg,\n c.id,\n lag(end_[[preferred_range]]_range_km) OVER (ORDER BY start_date) - start_[[preferred_range]]_range_km AS range_loss,\n p.odometer - lag(p.odometer) OVER (ORDER BY start_date) AS distance,\n cars.efficiency\n FROM\n charging_processes c\n LEFT JOIN positions p ON p.id = c.position_id\n LEFT JOIN cars ON cars.id = c.car_id\n LEFT JOIN addresses ON addresses.id = c.address_id\n LEFT JOIN geofences g ON g.id = geofence_id\nWHERE \n c.car_id = $car_id AND\n $__timeFilter(start_date)\nORDER BY\n start_date\n)\nSELECT\n start_date_ts,\n end_date_ts,\n start_date,\n end_date,\n COALESCE(geofence_name, address) as address, \n duration_min,\n charge_energy_added,\n charge_energy_used,\n CASE WHEN charge_energy_used IS NULL THEN NULL ELSE LEAST(charge_energy_added / charge_energy_used, 1.0) END as charging_efficiency,\n charge_energy_added * 60 / NULLIF (duration_min, 0) AS charge_energy_added_per_hour,\n convert_km((end_[[preferred_range]]_range_km - start_[[preferred_range]]_range_km) * 60 / NULLIF (duration_min, 0), '$length_unit') AS range_added_per_hour_$length_unit,\n start_battery_level,\n end_battery_level,\n convert_km(start_[[preferred_range]]_range_km, '$length_unit') AS start_range_$length_unit,\n convert_km(end_[[preferred_range]]_range_km, '$length_unit') AS end_range_$length_unit,\n convert_km(distance, '$length_unit') AS distance_$length_unit,\n range_loss * efficiency AS consumption_kWh,\n range_loss * efficiency / NULLIF (distance, 0) * 100 * \n CASE WHEN '$length_unit' = 'km' THEN 1\n WHEN '$length_unit' = 'mi' THEN 1.60934\n END AS consumption_kWh_100$length_unit,\n id,\n CASE WHEN geofence_id IS NULL THEN CONCAT('new?lat=', latitude, '&lng=', longitude)\n WHEN geofence_id IS NOT NULL THEN CONCAT(geofence_id, '/edit')\n END as path\nFROM\n data\nWHERE\n (distance >= 0 OR distance IS NULL) AND (charge_energy_added IS NULL OR charge_energy_added > 0.1);\n ", + "rawSql": "WITH data AS (\n SELECT\n (round(extract(epoch FROM start_date)) * 1000) - 5000 AS start_date_ts,\n (round(extract(epoch FROM end_date)) * 1000) + 5000 AS end_date_ts,\n start_date,\n end_date,\n CONCAT_WS(', ', COALESCE(addresses.name, CONCAT_WS(' ', addresses.road, addresses.house_number)), addresses.city) AS address,\n g.name as geofence_name,\n g.id as geofence_id,\n p.latitude,\n p.longitude,\n charge_energy_added,\n charge_energy_used,\n duration_min,\n start_battery_level,\n end_battery_level,\n start_[[preferred_range]]_range_km,\n end_[[preferred_range]]_range_km,\n outside_temp_avg,\n c.id,\n lag(end_[[preferred_range]]_range_km) OVER (ORDER BY start_date) - start_[[preferred_range]]_range_km AS range_loss,\n p.odometer - lag(p.odometer) OVER (ORDER BY start_date) AS distance,\n cars.efficiency,\n cost\n FROM\n charging_processes c\n LEFT JOIN positions p ON p.id = c.position_id\n LEFT JOIN cars ON cars.id = c.car_id\n LEFT JOIN addresses ON addresses.id = c.address_id\n LEFT JOIN geofences g ON g.id = geofence_id\nWHERE \n c.car_id = $car_id AND\n $__timeFilter(start_date)\nORDER BY\n start_date\n)\nSELECT\n start_date_ts,\n end_date_ts,\n start_date,\n end_date,\n COALESCE(geofence_name, address) as address, \n duration_min,\n charge_energy_added,\n cost,\n charge_energy_used,\n CASE WHEN charge_energy_used IS NULL THEN NULL ELSE LEAST(charge_energy_added / charge_energy_used, 1.0) END as charging_efficiency,\n charge_energy_added * 60 / NULLIF (duration_min, 0) AS charge_energy_added_per_hour,\n convert_km((end_[[preferred_range]]_range_km - start_[[preferred_range]]_range_km) * 60 / NULLIF (duration_min, 0), '$length_unit') AS range_added_per_hour_$length_unit,\n start_battery_level,\n end_battery_level,\n convert_km(start_[[preferred_range]]_range_km, '$length_unit') AS start_range_$length_unit,\n convert_km(end_[[preferred_range]]_range_km, '$length_unit') AS end_range_$length_unit,\n convert_km(distance, '$length_unit') AS distance_$length_unit,\n range_loss * efficiency AS consumption_kWh,\n range_loss * efficiency / NULLIF (distance, 0) * 100 * \n CASE WHEN '$length_unit' = 'km' THEN 1\n WHEN '$length_unit' = 'mi' THEN 1.60934\n END AS consumption_kWh_100$length_unit,\n id,\n CASE WHEN geofence_id IS NULL THEN CONCAT('new?lat=', latitude, '&lng=', longitude)\n WHEN geofence_id IS NOT NULL THEN CONCAT(geofence_id, '/edit')\n END as path\n FROM\n data\nWHERE\n (distance >= 0 OR distance IS NULL) AND (charge_energy_added IS NULL OR charge_energy_added > 0.1);\n ", "refId": "A", "select": [ [ From 43742cabe7d1c4b3eb76b7d65fb28bab79728bf5 Mon Sep 17 00:00:00 2001 From: Nathan Gardiner Date: Tue, 26 Nov 2019 23:55:32 +1100 Subject: [PATCH 2/4] Update charges.json Update Grafana dashboard with link to charge cost UI --- grafana/dashboards/charges.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/grafana/dashboards/charges.json b/grafana/dashboards/charges.json index 2ef411c408..1bc88c826b 100644 --- a/grafana/dashboards/charges.json +++ b/grafana/dashboards/charges.json @@ -214,6 +214,10 @@ ], "dateFormat": "YYYY-MM-DD HH:mm:ss", "decimals": 2, + "link": true, + "linkTargetBlank": true, + "linkTooltip": "Set Cost", + "linkUrl": "[[base_url:raw]]/charge-cost/${__cell_19:raw}", "mappingType": 1, "pattern": "cost", "thresholds": [], @@ -265,7 +269,7 @@ "link": true, "linkTargetBlank": true, "linkTooltip": "", - "linkUrl": "[[base_url:raw]]/geo-fences/${__cell_19:raw}", + "linkUrl": "[[base_url:raw]]/geo-fences/${__cell_20:raw}", "mappingType": 1, "pattern": "address", "thresholds": [], From 5250e7defe188f813936015cdbafcf027e5353ef Mon Sep 17 00:00:00 2001 From: Nathan Gardiner Date: Wed, 27 Nov 2019 00:13:47 +1100 Subject: [PATCH 3/4] Update charging-stats.json Update charging stats to show total charge cost (and to better fit the dashboard without scrolling on 1280 x 1024 resolution --- grafana/dashboards/charging-stats.json | 118 +++++++++++++++++++++++-- 1 file changed, 113 insertions(+), 5 deletions(-) diff --git a/grafana/dashboards/charging-stats.json b/grafana/dashboards/charging-stats.json index 190e271028..7e0153b83a 100644 --- a/grafana/dashboards/charging-stats.json +++ b/grafana/dashboards/charging-stats.json @@ -57,8 +57,8 @@ "thresholdMarkers": true }, "gridPos": { - "h": 3, - "w": 12, + "h": 2, + "w": 7, "x": 0, "y": 1 }, @@ -170,9 +170,9 @@ "thresholdMarkers": true }, "gridPos": { - "h": 3, - "w": 12, - "x": 12, + "h": 2, + "w": 9, + "x": 7, "y": 1 }, "id": 10, @@ -264,6 +264,114 @@ ], "valueName": "avg" }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorValue": false, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": null, + "decimals": 2, + "format": "currencyUSD", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 2, + "w": 8, + "x": 16, + "y": 0 + }, + "id": 14, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "options": {}, + "postfix": "", + "postfixFontSize": "50%", + "prefix": "", + "prefixFontSize": "50%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": false, + "lineColor": "rgb(31, 120, 193)", + "show": false, + "ymax": null, + "ymin": null + }, + "tableColumn": "", + "targets": [ + { + "format": "table", + "group": [], + "metricColumn": "none", + "rawQuery": true, + "rawSql": "SELECT\n\tsum(cost)\nFROM\n\tcharging_processes\nWHERE\n\tcar_id = $car_id;", + "refId": "A", + "select": [ + [ + { + "params": [ + "latitude" + ], + "type": "column" + } + ] + ], + "table": "addresses", + "timeColumn": "inserted_at", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + } + ] + } + ], + "thresholds": "", + "timeFrom": null, + "timeShift": null, + "title": "Total Charging Cost", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "avg" + }, { "cards": { "cardPadding": null, From 7dcf2f47a91542df22c689b439f887fdf757a1e6 Mon Sep 17 00:00:00 2001 From: Adrian Kumpf Date: Tue, 26 Nov 2019 16:55:44 +0100 Subject: [PATCH 4/4] Update start date link --- grafana/dashboards/charges.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grafana/dashboards/charges.json b/grafana/dashboards/charges.json index 1bc88c826b..72b24bbe92 100644 --- a/grafana/dashboards/charges.json +++ b/grafana/dashboards/charges.json @@ -72,7 +72,7 @@ "dateFormat": "YYYY-MM-DD HH:mm:ss", "link": true, "linkTooltip": "", - "linkUrl": "d/BHhxFeZRz/laden?orgId=1&from=${__cell_0}&to=${__cell_1}&var-charging_process_id=${__cell_18}&var-car_id=$car_id", + "linkUrl": "d/BHhxFeZRz/laden?orgId=1&from=${__cell_0}&to=${__cell_1}&var-charging_process_id=${__cell_19}&var-car_id=$car_id", "pattern": "start_date", "type": "date" }, @@ -544,7 +544,7 @@ "group": [], "metricColumn": "none", "rawQuery": true, - "rawSql": "WITH data AS (\n SELECT\n (round(extract(epoch FROM start_date)) * 1000) - 5000 AS start_date_ts,\n (round(extract(epoch FROM end_date)) * 1000) + 5000 AS end_date_ts,\n start_date,\n end_date,\n CONCAT_WS(', ', COALESCE(addresses.name, CONCAT_WS(' ', addresses.road, addresses.house_number)), addresses.city) AS address,\n g.name as geofence_name,\n g.id as geofence_id,\n p.latitude,\n p.longitude,\n charge_energy_added,\n charge_energy_used,\n duration_min,\n start_battery_level,\n end_battery_level,\n start_[[preferred_range]]_range_km,\n end_[[preferred_range]]_range_km,\n outside_temp_avg,\n c.id,\n lag(end_[[preferred_range]]_range_km) OVER (ORDER BY start_date) - start_[[preferred_range]]_range_km AS range_loss,\n p.odometer - lag(p.odometer) OVER (ORDER BY start_date) AS distance,\n cars.efficiency,\n cost\n FROM\n charging_processes c\n LEFT JOIN positions p ON p.id = c.position_id\n LEFT JOIN cars ON cars.id = c.car_id\n LEFT JOIN addresses ON addresses.id = c.address_id\n LEFT JOIN geofences g ON g.id = geofence_id\nWHERE \n c.car_id = $car_id AND\n $__timeFilter(start_date)\nORDER BY\n start_date\n)\nSELECT\n start_date_ts,\n end_date_ts,\n start_date,\n end_date,\n COALESCE(geofence_name, address) as address, \n duration_min,\n charge_energy_added,\n cost,\n charge_energy_used,\n CASE WHEN charge_energy_used IS NULL THEN NULL ELSE LEAST(charge_energy_added / charge_energy_used, 1.0) END as charging_efficiency,\n charge_energy_added * 60 / NULLIF (duration_min, 0) AS charge_energy_added_per_hour,\n convert_km((end_[[preferred_range]]_range_km - start_[[preferred_range]]_range_km) * 60 / NULLIF (duration_min, 0), '$length_unit') AS range_added_per_hour_$length_unit,\n start_battery_level,\n end_battery_level,\n convert_km(start_[[preferred_range]]_range_km, '$length_unit') AS start_range_$length_unit,\n convert_km(end_[[preferred_range]]_range_km, '$length_unit') AS end_range_$length_unit,\n convert_km(distance, '$length_unit') AS distance_$length_unit,\n range_loss * efficiency AS consumption_kWh,\n range_loss * efficiency / NULLIF (distance, 0) * 100 * \n CASE WHEN '$length_unit' = 'km' THEN 1\n WHEN '$length_unit' = 'mi' THEN 1.60934\n END AS consumption_kWh_100$length_unit,\n id,\n CASE WHEN geofence_id IS NULL THEN CONCAT('new?lat=', latitude, '&lng=', longitude)\n WHEN geofence_id IS NOT NULL THEN CONCAT(geofence_id, '/edit')\n END as path\n FROM\n data\nWHERE\n (distance >= 0 OR distance IS NULL) AND (charge_energy_added IS NULL OR charge_energy_added > 0.1);\n ", + "rawSql": "WITH data AS (\n SELECT\n (round(extract(epoch FROM start_date)) * 1000) - 5000 AS start_date_ts,\n (round(extract(epoch FROM end_date)) * 1000) + 5000 AS end_date_ts,\n start_date,\n end_date,\n CONCAT_WS(', ', COALESCE(addresses.name, CONCAT_WS(' ', addresses.road, addresses.house_number)), addresses.city) AS address,\n g.name as geofence_name,\n g.id as geofence_id,\n p.latitude,\n p.longitude,\n charge_energy_added,\n charge_energy_used,\n duration_min,\n start_battery_level,\n end_battery_level,\n start_[[preferred_range]]_range_km,\n end_[[preferred_range]]_range_km,\n outside_temp_avg,\n c.id,\n lag(end_[[preferred_range]]_range_km) OVER (ORDER BY start_date) - start_[[preferred_range]]_range_km AS range_loss,\n p.odometer - lag(p.odometer) OVER (ORDER BY start_date) AS distance,\n cars.efficiency,\n cost\n FROM\n charging_processes c\n LEFT JOIN positions p ON p.id = c.position_id\n LEFT JOIN cars ON cars.id = c.car_id\n LEFT JOIN addresses ON addresses.id = c.address_id\n LEFT JOIN geofences g ON g.id = geofence_id\nWHERE \n c.car_id = $car_id AND\n $__timeFilter(start_date)\nORDER BY\n start_date\n)\nSELECT\n start_date_ts,\n end_date_ts,\n start_date,\n end_date,\n COALESCE(geofence_name, address) as address, \n duration_min,\n charge_energy_added,\n cost,\n charge_energy_used,\n CASE WHEN charge_energy_used IS NULL THEN NULL ELSE LEAST(charge_energy_added / charge_energy_used, 1.0) END as charging_efficiency,\n charge_energy_added * 60 / NULLIF (duration_min, 0) AS charge_energy_added_per_hour,\n convert_km((end_[[preferred_range]]_range_km - start_[[preferred_range]]_range_km) * 60 / NULLIF (duration_min, 0), '$length_unit') AS range_added_per_hour_$length_unit,\n start_battery_level,\n end_battery_level,\n convert_km(start_[[preferred_range]]_range_km, '$length_unit') AS start_range_$length_unit,\n convert_km(end_[[preferred_range]]_range_km, '$length_unit') AS end_range_$length_unit,\n convert_km(distance, '$length_unit') AS distance_$length_unit,\n range_loss * efficiency AS consumption_kWh,\n range_loss * efficiency / NULLIF (distance, 0) * 100 * \n CASE WHEN '$length_unit' = 'km' THEN 1\n WHEN '$length_unit' = 'mi' THEN 1.60934\n END AS consumption_kWh_100$length_unit,\n id,\n CASE WHEN geofence_id IS NULL THEN CONCAT('new?lat=', latitude, '&lng=', longitude)\n WHEN geofence_id IS NOT NULL THEN CONCAT(geofence_id, '/edit')\n END as path\n FROM\n data\nWHERE\n (distance >= 0 OR distance IS NULL) AND (charge_energy_added IS NULL OR charge_energy_added > 0.1);\n ", "refId": "A", "select": [ [