Skip to content

Commit

Permalink
Grafana Dashboard Integration for Charge Cost (#273)
Browse files Browse the repository at this point in the history
* Update charges.json

Added cost column to table, fixed column headers for readability

* Update charges.json

Update Grafana dashboard with link to charge cost UI

* 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

* Update start date link
  • Loading branch information
ngardiner authored and adriankumpf committed Nov 26, 2019
1 parent 524c094 commit d8eb4e5
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 15 deletions.
40 changes: 30 additions & 10 deletions grafana/dashboards/charges.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -93,7 +93,7 @@
"unit": "short"
},
{
"alias": "Energy added",
"alias": "Added",
"colorMode": null,
"colors": [
"rgba(245, 54, 54, 0.9)",
Expand Down Expand Up @@ -189,7 +189,7 @@
"unit": "m"
},
{
"alias": "Temperature",
"alias": "Temp",
"colorMode": null,
"colors": [
"rgba(245, 54, 54, 0.9)",
Expand All @@ -204,6 +204,26 @@
"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,
"link": true,
"linkTargetBlank": true,
"linkTooltip": "Set Cost",
"linkUrl": "[[base_url:raw]]/charge-cost/${__cell_19:raw}",
"mappingType": 1,
"pattern": "cost",
"thresholds": [],
"type": "number",
"unit": "currencyUSD"
},
{
"alias": "",
"colorMode": null,
Expand Down Expand Up @@ -249,15 +269,15 @@
"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": [],
"type": "string",
"unit": "short"
},
{
"alias": "km driven",
"alias": "Driven",
"colorMode": null,
"colors": [
"rgba(245, 54, 54, 0.9)",
Expand All @@ -273,7 +293,7 @@
"unit": "lengthkm"
},
{
"alias": "consumed",
"alias": "Consumed",
"colorMode": null,
"colors": [
"rgba(245, 54, 54, 0.9)",
Expand Down Expand Up @@ -372,7 +392,7 @@
"unit": "lengthmi"
},
{
"alias": "Temperature",
"alias": "Temp",
"colorMode": null,
"colors": [
"rgba(245, 54, 54, 0.9)",
Expand All @@ -388,7 +408,7 @@
"unit": "farenheit"
},
{
"alias": "mi driven",
"alias": "Driven",
"colorMode": null,
"colors": [
"rgba(245, 54, 54, 0.9)",
Expand Down Expand Up @@ -452,7 +472,7 @@
"unit": "short"
},
{
"alias": "Energy used",
"alias": "Used",
"colorMode": null,
"colors": [
"rgba(245, 54, 54, 0.9)",
Expand Down Expand Up @@ -524,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 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": [
[
Expand Down
118 changes: 113 additions & 5 deletions grafana/dashboards/charging-stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
"thresholdMarkers": true
},
"gridPos": {
"h": 3,
"w": 12,
"h": 2,
"w": 7,
"x": 0,
"y": 1
},
Expand Down Expand Up @@ -170,9 +170,9 @@
"thresholdMarkers": true
},
"gridPos": {
"h": 3,
"w": 12,
"x": 12,
"h": 2,
"w": 9,
"x": 7,
"y": 1
},
"id": 10,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d8eb4e5

Please sign in to comment.