From 39f8021ad823ab4cda368422d7f7adff039b3786 Mon Sep 17 00:00:00 2001 From: Dulanic <2948206+Dulanic@users.noreply.github.com> Date: Fri, 24 Apr 2020 11:16:34 -0500 Subject: [PATCH 1/2] Update charging-stats.json Updated to address https://github.com/adriankumpf/teslamate/issues/528# Added case statement to adjust to show kWh at non decimal level and MWh at the 3 decimal point level. Cannot address directly within grafana so used case statement. Removed grafana sorting so can be sorted properly in SQL since not a direct # now for grafana to sort. --- grafana/dashboards/charging-stats.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/grafana/dashboards/charging-stats.json b/grafana/dashboards/charging-stats.json index da04200e27..5bec69cc45 100644 --- a/grafana/dashboards/charging-stats.json +++ b/grafana/dashboards/charging-stats.json @@ -1155,8 +1155,8 @@ "scroll": true, "showHeader": true, "sort": { - "col": 1, - "desc": true + "col": null, + "desc": false }, "styles": [ { @@ -1198,7 +1198,7 @@ "mappingType": 1, "pattern": "charge_energy_added", "thresholds": [], - "type": "number", + "type": "string", "unit": "kwatth" } ], @@ -1208,7 +1208,7 @@ "group": [], "metricColumn": "none", "rawQuery": true, - "rawSql": "SELECT\n\tCOALESCE(geofence.name, CONCAT_WS(', ', COALESCE(address.name, nullif(CONCAT_WS(' ', address.road, address.house_number), '')), address.city)) AS location,\n\tsum(charge_energy_added) as charge_energy_added\nFROM\n\tcharging_processes c\nLEFT JOIN addresses address ON c.address_id = address.id\nLEFT JOIN geofences geofence ON geofence_id = geofence.id\nWHERE\n\t$__timeFilter(end_date)\n\tAND car_id = $car_id\nGROUP BY\n\t1\nORDER BY\n\tcharge_energy_added DESC\nLIMIT 15;", + "rawSql": "SELECT\n\tCOALESCE(geofence.name, CONCAT_WS(', ', COALESCE(address.name, nullif(CONCAT_WS(' ', address.road, address.house_number), '')), address.city)) AS location,\n\tCASE\n WHEN SUM(charge_energy_added) BETWEEN 0 AND 999.999 THEN SUM(charge_energy_added)::NUMERIC(4,0)::VARCHAR || ' kWh' \n WHEN SUM(charge_energy_added) BETWEEN 1000 AND 999999.999 THEN (SUM(charge_energy_added) / 1000)::NUMERIC(9, 3)::VARCHAR || ' mWh' \n WHEN SUM(charge_energy_added) >= 1000000 THEN (SUM(charge_energy_added) / 1000)::NUMERIC(9, 3)::VARCHAR || ' gWh' \n END as charge_energy_added\nFROM\n\tcharging_processes c\nLEFT JOIN addresses address ON c.address_id = address.id\nLEFT JOIN geofences geofence ON geofence_id = geofence.id\nWHERE\n\t$__timeFilter(end_date)\n\tAND car_id = $car_id\nGROUP BY\n\t1\nORDER BY\n\tSUM(charge_energy_added) DESC\nLIMIT 15;", "refId": "A", "select": [ [ From c404aba483c866e8493a890bab5b511dada2dfca Mon Sep 17 00:00:00 2001 From: Dulanic <2948206+Dulanic@users.noreply.github.com> Date: Fri, 24 Apr 2020 11:20:12 -0500 Subject: [PATCH 2/2] Update charging-stats.json Fixed mWh to MWh --- grafana/dashboards/charging-stats.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grafana/dashboards/charging-stats.json b/grafana/dashboards/charging-stats.json index 5bec69cc45..c630829bd9 100644 --- a/grafana/dashboards/charging-stats.json +++ b/grafana/dashboards/charging-stats.json @@ -1208,7 +1208,7 @@ "group": [], "metricColumn": "none", "rawQuery": true, - "rawSql": "SELECT\n\tCOALESCE(geofence.name, CONCAT_WS(', ', COALESCE(address.name, nullif(CONCAT_WS(' ', address.road, address.house_number), '')), address.city)) AS location,\n\tCASE\n WHEN SUM(charge_energy_added) BETWEEN 0 AND 999.999 THEN SUM(charge_energy_added)::NUMERIC(4,0)::VARCHAR || ' kWh' \n WHEN SUM(charge_energy_added) BETWEEN 1000 AND 999999.999 THEN (SUM(charge_energy_added) / 1000)::NUMERIC(9, 3)::VARCHAR || ' mWh' \n WHEN SUM(charge_energy_added) >= 1000000 THEN (SUM(charge_energy_added) / 1000)::NUMERIC(9, 3)::VARCHAR || ' gWh' \n END as charge_energy_added\nFROM\n\tcharging_processes c\nLEFT JOIN addresses address ON c.address_id = address.id\nLEFT JOIN geofences geofence ON geofence_id = geofence.id\nWHERE\n\t$__timeFilter(end_date)\n\tAND car_id = $car_id\nGROUP BY\n\t1\nORDER BY\n\tSUM(charge_energy_added) DESC\nLIMIT 15;", + "rawSql": "SELECT\n\tCOALESCE(geofence.name, CONCAT_WS(', ', COALESCE(address.name, nullif(CONCAT_WS(' ', address.road, address.house_number), '')), address.city)) AS location,\n\tCASE\n WHEN SUM(charge_energy_added) BETWEEN 0 AND 999.999 THEN SUM(charge_energy_added)::NUMERIC(4,0)::VARCHAR || ' kWh' \n WHEN SUM(charge_energy_added) BETWEEN 1000 AND 999999.999 THEN (SUM(charge_energy_added) / 1000)::NUMERIC(9, 3)::VARCHAR || ' MWh' \n WHEN SUM(charge_energy_added) >= 1000000 THEN (SUM(charge_energy_added) / 1000)::NUMERIC(9, 3)::VARCHAR || ' gWh' \n END as charge_energy_added\nFROM\n\tcharging_processes c\nLEFT JOIN addresses address ON c.address_id = address.id\nLEFT JOIN geofences geofence ON geofence_id = geofence.id\nWHERE\n\t$__timeFilter(end_date)\n\tAND car_id = $car_id\nGROUP BY\n\t1\nORDER BY\n\tSUM(charge_energy_added) DESC\nLIMIT 15;", "refId": "A", "select": [ [