From e6be94feedbfe0000ef17c82461b727682e08b7f Mon Sep 17 00:00:00 2001 From: Matthias Wirtz Date: Sat, 2 Nov 2024 17:03:21 +0100 Subject: [PATCH] consistent use of convert_km and date_trunc through all dashboards, minor fixes --- dashboards/AmortizationTracker.json | 67 +++++++---- dashboards/ChargingCostsStats.json | 135 ++++++++++++++++----- dashboards/CurrentDriveView.json | 43 ++++--- dashboards/MileageStats.json | 40 +++++-- dashboards/SpeedRates.json | 174 ++++++++++++++++++++-------- 5 files changed, 333 insertions(+), 126 deletions(-) diff --git a/dashboards/AmortizationTracker.json b/dashboards/AmortizationTracker.json index c883109..bb5d293 100644 --- a/dashboards/AmortizationTracker.json +++ b/dashboards/AmortizationTracker.json @@ -5,7 +5,7 @@ "type": "grafana", "id": "grafana", "name": "Grafana", - "version": "11.1.0" + "version": "11.2.3" }, { "type": "datasource", @@ -115,6 +115,7 @@ "axisLabel": "", "axisPlacement": "auto", "barAlignment": 0, + "barWidthFactor": 0.6, "drawStyle": "line", "fillOpacity": 13, "gradientMode": "none", @@ -203,7 +204,6 @@ }, "xField": "period_number" }, - "pluginVersion": "10.4.0", "targets": [ { "datasource": { @@ -247,14 +247,17 @@ "axisColorMode": "text", "axisLabel": "", "axisPlacement": "auto", + "fillOpacity": 50, "hideFrom": { "legend": false, "tooltip": false, "viz": false }, + "pointShape": "circle", "pointSize": { "fixed": 9 }, + "pointStrokeWidth": 1, "scaleDistribution": { "type": "linear" }, @@ -311,28 +314,50 @@ }, "id": 75, "options": { - "dims": { - "exclude": [ - "months", - "depreciation_time", - "depreciation_mileage" - ] - }, "legend": { "calcs": [], "displayMode": "list", "placement": "bottom", "showLegend": false }, - "series": [], - "seriesMapping": "auto", + "mapping": "auto", + "series": [ + { + "frame": { + "matcher": { + "id": "byIndex", + "options": 0 + } + }, + "x": { + "matcher": { + "id": "byType", + "options": "number" + } + }, + "y": { + "exclude": { + "id": "byNames", + "options": [ + "months", + "depreciation_time", + "depreciation_mileage" + ] + }, + "matcher": { + "id": "byType", + "options": "number" + } + } + } + ], "tooltip": { "maxHeight": 600, "mode": "single", "sort": "none" } }, - "pluginVersion": "10.4.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -342,7 +367,7 @@ "editorMode": "code", "format": "table", "rawQuery": true, - "rawSql": "WITH periodic_mileage AS (\r\n SELECT\r\n DATE_TRUNC('$period', start_date) AS period_start,\r\n convert_km(SUM(end_km - start_km)::numeric, '$length_unit') AS total_mileage\r\n FROM\r\n drives\r\n WHERE\r\n car_id = $car_id \r\n GROUP BY\r\n period_start\r\n),\r\ncum_mileage AS (\r\n SELECT\r\n ROW_NUMBER() OVER () AS period_number,\r\n period_start,\r\n total_mileage,\r\n SUM(total_mileage) OVER (ORDER BY period_start) AS cum_mileage\r\n FROM\r\n periodic_mileage\r\n),\r\nBreakEven AS (\r\nSELECT\r\n cm.period_number,\r\n cm.cum_mileage * (0.20 / CASE WHEN '$length_unit' = 'mi' THEN 1 ELSE 1.60934 END) AS depreciation_mileage,\r\n ($depreciated_value - (cm.period_number - 1) * 5.0 / 12) AS depreciation_time\r\nFROM\r\n cum_mileage cm\r\nLEFT JOIN\r\n periodic_mileage mm ON cm.period_start = mm.period_start\r\nORDER BY\r\n cm.period_number\r\n)\r\nSELECT \r\n period_number,\r\n ($car_cost - depreciation_mileage - (($car_cost - depreciation_mileage) * depreciation_time / 100)) * 100 / $car_cost AS percent_depreciated\r\nFROM BreakEven", + "rawSql": "WITH periodic_mileage AS (\r\n SELECT\r\n DATE_TRUNC('$period', TIMEZONE('UTC', start_date)) AS period_start,\r\n convert_km(SUM(end_km - start_km)::numeric, '$length_unit') AS total_mileage\r\n FROM\r\n drives\r\n WHERE\r\n car_id = $car_id \r\n GROUP BY\r\n period_start\r\n),\r\ncum_mileage AS (\r\n SELECT\r\n ROW_NUMBER() OVER () AS period_number,\r\n period_start,\r\n total_mileage,\r\n SUM(total_mileage) OVER (ORDER BY period_start) AS cum_mileage\r\n FROM\r\n periodic_mileage\r\n),\r\nBreakEven AS (\r\nSELECT\r\n cm.period_number,\r\n cm.cum_mileage * $loss_rate AS depreciation_mileage,\r\n ($depreciated_value - (cm.period_number - 1) * 5.0 / 12) AS depreciation_time\r\nFROM\r\n cum_mileage cm\r\nLEFT JOIN\r\n periodic_mileage mm ON cm.period_start = mm.period_start\r\nORDER BY\r\n cm.period_number\r\n)\r\nSELECT \r\n period_number,\r\n ($car_cost - depreciation_mileage - (($car_cost - depreciation_mileage) * depreciation_time / 100)) * 100 / $car_cost AS percent_depreciated\r\nFROM BreakEven", "refId": "A", "sql": { "columns": [ @@ -630,7 +655,7 @@ }, "showHeader": true }, - "pluginVersion": "11.1.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -640,7 +665,7 @@ "editorMode": "code", "format": "table", "rawQuery": true, - "rawSql": "WITH periodic_mileage AS (\r\n SELECT\r\n DATE_TRUNC('$period', start_date) AS period_start,\r\n convert_km(SUM(end_km - start_km)::numeric, '$length_unit') AS total_mileage\r\n FROM\r\n drives\r\n WHERE\r\n car_id = $car_id \r\n GROUP BY\r\n period_start\r\n),\r\nperiod_cost AS (\r\n SELECT\r\n DATE_TRUNC('$period', start_date) AS period_start,\r\n SUM(cost) AS total_cost\r\n FROM\r\n charging_processes \r\n WHERE\r\n car_id = $car_id \r\n GROUP BY\r\n DATE_TRUNC('$period', start_date)\r\n),\r\ncum_mileage AS (\r\n SELECT\r\n ROW_NUMBER() OVER () AS period_number,\r\n period_start,\r\n total_mileage,\r\n SUM(total_mileage) OVER (ORDER BY period_start) AS cum_mileage\r\n FROM\r\n periodic_mileage\r\n),\r\ncum_cost AS (\r\n SELECT\r\n ROW_NUMBER() OVER () AS period_number,\r\n period_start,\r\n total_cost,\r\n SUM(total_cost) OVER (ORDER BY period_start) AS cum_el_cost\r\n FROM\r\n period_cost\r\n),\r\ncar_current_value AS (\r\n SELECT\r\n $car_cost AS car_current_value\r\n),\r\nBreakEven AS (\r\nSELECT\r\n cm.period_number,\r\n mm.total_mileage AS periodic_mileage,\r\n mc.total_cost AS period_el_cost,\r\n mc.total_cost/mm.total_mileage AS period_cost_per_mileage,\r\n cm.cum_mileage,\r\n cc.cum_el_cost,\r\n cm.cum_mileage * ($loss_rate / CASE WHEN '$length_unit' = 'mi' THEN 1 ELSE 1.60934 END) AS depreciation_mileage,\r\n ($depreciated_value - (cm.period_number - 1) * 5.0 / CASE WHEN '$period' = 'year' THEN 1 ELSE 12 END) AS depreciation_time,\r\n cm.cum_mileage * $fuel_price - cc.cum_el_cost AS cum_el_savings, car_current_value\r\nFROM\r\n cum_mileage cm\r\nLEFT JOIN\r\n cum_cost cc ON cm.period_number = cc.period_number\r\nLEFT JOIN\r\n periodic_mileage mm ON cm.period_start = mm.period_start\r\nLEFT JOIN\r\n period_cost mc ON cm.period_start = mc.period_start\r\nCROSS JOIN\r\n car_current_value\r\nORDER BY\r\n cm.period_number\r\n)\r\nSELECT \r\n period_number, periodic_mileage, period_el_cost, period_cost_per_mileage, cum_mileage, cum_el_cost, depreciation_mileage, depreciation_time, cum_el_savings,\r\n car_current_value - depreciation_mileage - ((car_current_value - depreciation_mileage) * depreciation_time / 100) AS depreciated_car_value,\r\n (car_current_value - depreciation_mileage - ((car_current_value - depreciation_mileage) * depreciation_time / 100)) + (cum_mileage * $fuel_price - cum_el_cost) AS car_value_pls_el_savings\r\nFROM BreakEven", + "rawSql": "WITH periodic_mileage AS (\r\n SELECT\r\n DATE_TRUNC('$period', TIMEZONE('UTC', start_date)) AS period_start,\r\n convert_km(SUM(end_km - start_km)::numeric, '$length_unit') AS total_mileage\r\n FROM\r\n drives\r\n WHERE\r\n car_id = $car_id \r\n GROUP BY\r\n period_start\r\n),\r\nperiod_cost AS (\r\n SELECT\r\n DATE_TRUNC('$period', TIMEZONE('UTC', start_date)) AS period_start,\r\n SUM(cost) AS total_cost\r\n FROM\r\n charging_processes \r\n WHERE\r\n car_id = $car_id \r\n GROUP BY\r\n period_start\r\n),\r\ncum_mileage AS (\r\n SELECT\r\n ROW_NUMBER() OVER () AS period_number,\r\n period_start,\r\n total_mileage,\r\n SUM(total_mileage) OVER (ORDER BY period_start) AS cum_mileage\r\n FROM\r\n periodic_mileage\r\n),\r\ncum_cost AS (\r\n SELECT\r\n ROW_NUMBER() OVER () AS period_number,\r\n period_start,\r\n total_cost,\r\n SUM(total_cost) OVER (ORDER BY period_start) AS cum_el_cost\r\n FROM\r\n period_cost\r\n),\r\ncar_current_value AS (\r\n SELECT\r\n $car_cost AS car_current_value\r\n),\r\nBreakEven AS (\r\nSELECT\r\n cm.period_number,\r\n mm.total_mileage AS periodic_mileage,\r\n mc.total_cost AS period_el_cost,\r\n mc.total_cost/mm.total_mileage AS period_cost_per_mileage,\r\n cm.cum_mileage,\r\n cc.cum_el_cost,\r\n cm.cum_mileage * $loss_rate AS depreciation_mileage,\r\n ($depreciated_value - (cm.period_number - 1) * 5.0 / CASE WHEN '$period' = 'year' THEN 1 ELSE 12 END) AS depreciation_time,\r\n cm.cum_mileage * $fuel_price - cc.cum_el_cost AS cum_el_savings, car_current_value\r\nFROM\r\n cum_mileage cm\r\nLEFT JOIN\r\n cum_cost cc ON cm.period_number = cc.period_number\r\nLEFT JOIN\r\n periodic_mileage mm ON cm.period_start = mm.period_start\r\nLEFT JOIN\r\n period_cost mc ON cm.period_start = mc.period_start\r\nCROSS JOIN\r\n car_current_value\r\nORDER BY\r\n cm.period_number\r\n)\r\nSELECT \r\n period_number, periodic_mileage, period_el_cost, period_cost_per_mileage, cum_mileage, cum_el_cost, depreciation_mileage, depreciation_time, cum_el_savings,\r\n car_current_value - depreciation_mileage - ((car_current_value - depreciation_mileage) * depreciation_time / 100) AS depreciated_car_value,\r\n (car_current_value - depreciation_mileage - ((car_current_value - depreciation_mileage) * depreciation_time / 100)) + (cum_mileage * $fuel_price - cum_el_cost) AS car_value_pls_el_savings\r\nFROM BreakEven", "refId": "A", "sql": { "columns": [ @@ -698,7 +723,7 @@ "content": "# Amortization Tracker\n\nThis dashboard aims to show the depreciation value of the car over time and its journey.\n\nDepreciating a car by its mileage can be done using various methods. A common approach is to use a depreciation rate per mile or to create a depreciation curve based on data. On the other hand, the depreciation of a car due to age can vary depending on several factors such as the make, model, overall condition of the vehicle, and demand in the market.\n\nGenerally, it is estimated that a new car loses approximately 15% to 20% of its value in the first year. From there, the rate of depreciation tends to gradually decrease. Below is a rough estimate of the annual depreciation in the first few years:\n\n- First year: Around 15% to 20%.\n- Second year: Around 10% to 15%.\n- Third year and beyond: Around 5% to 10% annually.\n\nIt is important to remember that these values ​​are approximate and may vary depending on individual circumstances. Also, some car models may hold their value better than others.\n\nAditionally, some studies and experts suggest that a car loses a certain amount of value per mile driven. For instance, here we are using a standard rate 0.20 (use your currency) per mile or kilometer (depending on your prefered length unit)\n\n## Considerations for values ​​in text boxes\n\nIn this panel we have both estimations: **Drepreciation per Mileage** and **Depreciation per Age**\n\nSo fist of all you have to select:\n\n- Period to estimate (yearly or monthly)\n- Cost of your car\n- Depreciation percent % (of the first year). 20% by default as explained before\n- Loss rate per mile of kilometer. 0.2 (your currency) by default as explained before\n- Fuel price per mile of kilometer of your previous car (or a generic on equivalent to your actual Tesla)\n \n To calculate the cost per miles/kilometer of your car, you first need to determine how much it consumes in liters per 100 miles/kilometers. Then you can divide Consumption by mileage.\n\n For example: let's say a car consumes 6 liters per 100km and the fuel costs 1.8€ per liter, we can calculate the actual consumption: 6/100 = 0.06 L/km\n \n Now, to determine the cost per kilometer, we multiply the actual consumption by the price of a liter of fuel (use your currency). For example 0.06L/km × 1.8€/L =0.108€/km (use miles or kms).\n \n Therefore, the cost per kilometer for your car would be approximately 0.108€. That's the value expected on the Fuel price textbox.\n\n## Data shown in the table\n\n- **Period**: Could be 'month' or 'year' dependig what you've selected in the drop down list. So if selected as 'month', its going to be the data accumulated from 1st month at which TeslaMate started logging data, So 1,2,3 will be the month numbers. If \"period\" is selcted as 'year', then its the year numbers.\n- **Mileage**: is the number of kms/miles (depending on your prefered length unit) the car has driven in that period.\n- **Energy Cost**: is the cost spent for electricity in that particular period.\n- **Cost per km or mi** is *energy cost* / *Mileage*\n- **Cumulative Mileage** is the cumulative mileage for that particular period.\n- **Cumulative Cost** is the cumulative cost for electricity for that particular period.\n- **Depreciation per km or mi** is the depreciation by mileage explained at the begining.\n- **Depreciation per age** is the depreciation by time explained at the begining.\n- **Cumulative Savings** is running cost savings for driving an electric car when compared to a fossil fuel car, based on the value enter in the *Fuel price* textbox.\n- **Depreciated Car Value** is the estimated actual price based on the depreciation per age and mileage. \n- **Depreciated Car Value + Savings** is simply adding *Depreciated Car Value* + *Cumulative Savings*. So the expectation is like when one can get the Break-Even for the money we put into buying the car by driving at a cheaper electricity cost when compared to driving a fossil fuel car.\n", "mode": "markdown" }, - "pluginVersion": "11.1.0", + "pluginVersion": "11.2.3", "type": "text" } ], @@ -715,14 +740,14 @@ "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, - "definition": "SELECT name AS __text, id AS __value FROM cars ORDER BY display_priority ASC, name ASC;", + "definition": "SELECT\n id as __value,\n CASE WHEN COUNT(id) OVER (PARTITION BY name) > 1 AND name IS NOT NULL THEN CONCAT(name, ' - ', RIGHT(vin, 6)) ELSE COALESCE(name, RIGHT(vin, 6)) end as __text \nFROM cars\nORDER BY display_priority ASC, name ASC, vin ASC;", "hide": 0, "includeAll": false, "label": "Car", "multi": false, "name": "car_id", "options": [], - "query": "SELECT name AS __text, id AS __value FROM cars ORDER BY display_priority ASC, name ASC;", + "query": "SELECT\n id as __value,\n CASE WHEN COUNT(id) OVER (PARTITION BY name) > 1 AND name IS NOT NULL THEN CONCAT(name, ' - ', RIGHT(vin, 6)) ELSE COALESCE(name, RIGHT(vin, 6)) end as __text \nFROM cars\nORDER BY display_priority ASC, name ASC, vin ASC;", "refresh": 1, "regex": "", "skipUrlSync": false, @@ -782,7 +807,7 @@ "auto_count": 30, "auto_min": "10s", "current": { - "selected": true, + "selected": false, "text": "year", "value": "year" }, @@ -790,12 +815,12 @@ "name": "period", "options": [ { - "selected": true, + "selected": false, "text": "month", "value": "month" }, { - "selected": false, + "selected": true, "text": "year", "value": "year" } diff --git a/dashboards/ChargingCostsStats.json b/dashboards/ChargingCostsStats.json index f9c5d92..5c68e92 100644 --- a/dashboards/ChargingCostsStats.json +++ b/dashboards/ChargingCostsStats.json @@ -11,7 +11,7 @@ "type": "grafana", "id": "grafana", "name": "Grafana", - "version": "11.3.0" + "version": "11.2.3" }, { "type": "datasource", @@ -162,7 +162,7 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "11.3.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -252,7 +252,7 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "11.3.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -342,7 +342,7 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "11.3.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -432,7 +432,7 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "11.3.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -525,7 +525,7 @@ "sizing": "auto", "valueMode": "color" }, - "pluginVersion": "11.3.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -784,7 +784,7 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "11.3.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -900,7 +900,7 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "11.3.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -1016,7 +1016,7 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "11.3.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -1151,7 +1151,7 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "11.3.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -1241,7 +1241,7 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "11.3.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -1331,7 +1331,7 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "11.3.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -1421,7 +1421,7 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "11.3.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -1511,7 +1511,7 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "11.3.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -1596,7 +1596,7 @@ "textMode": "auto", "wideLayout": true }, - "pluginVersion": "11.3.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -1683,7 +1683,7 @@ "textMode": "auto", "wideLayout": true }, - "pluginVersion": "11.3.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -1800,18 +1800,19 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "11.3.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, + "editorMode": "code", "format": "table", "group": [], "metricColumn": "none", "rawQuery": true, - "rawSql": "select \n sum((start_${preferred_range}_range_km - end_${preferred_range}_range_km) * cars.efficiency) / sum(distance) * 1000 * \n CASE WHEN '$length_unit' = 'km' THEN 1\n WHEN '$length_unit' = 'mi' THEN 1.60934\n END AS \"consumption_$length_unit\"\nfrom drives \ninner join cars on cars.id = car_id\nwhere \n distance is not null and\n start_${preferred_range}_range_km - end_${preferred_range}_range_km >= 0.1 and\n car_id = $car_id", + "rawSql": "select \n sum((start_${preferred_range}_range_km - end_${preferred_range}_range_km) * cars.efficiency) / convert_km(sum(distance)::numeric, '$length_unit') * 1000 as \"consumption_$length_unit\"\nfrom drives \ninner join cars on cars.id = car_id\nwhere \n distance is not null and\n start_${preferred_range}_range_km - end_${preferred_range}_range_km >= 0.1 and\n car_id = $car_id", "refId": "A", "select": [ [ @@ -1823,6 +1824,23 @@ } ] ], + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + }, "table": "addresses", "timeColumn": "inserted_at", "timeColumnType": "timestamp", @@ -1917,18 +1935,19 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "11.3.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, + "editorMode": "code", "format": "table", "group": [], "metricColumn": "none", "rawQuery": true, - "rawSql": "WITH d1 AS (\n\tSELECT\n\t\tc.car_id,\n\t\tlag(end_${preferred_range}_range_km) OVER (ORDER BY start_date) - start_${preferred_range}_range_km AS range_loss,\n\t\tp.odometer - lag(p.odometer) OVER (ORDER BY start_date) AS distance\n\tFROM\n\t\tcharging_processes c\n\tLEFT JOIN positions p ON p.id = c.position_id \n\tWHERE\n\t end_date IS NOT NULL AND\n\t c.car_id = $car_id\n\tORDER BY\n\t\tstart_date\n),\nd2 AS (\nSELECT\n\tcar_id,\n\tsum(range_loss) AS range_loss,\n\tsum(distance) AS distance\nFROM\n\td1\nWHERE\n\tdistance >= 0 AND range_loss >= 0\nGROUP BY\n\tcar_id\n)\nSELECT\nrange_loss * c.efficiency / distance * 1000 *\n CASE WHEN '$length_unit' = 'km' THEN 1\n WHEN '$length_unit' = 'mi' THEN 1.60934\n END AS \"consumption_$length_unit\"\nFROM\n\td2\n\tLEFT JOIN cars c ON c.id = car_id", + "rawSql": "WITH d1 AS (\n\tSELECT\n\t\tc.car_id,\n\t\tlag(end_${preferred_range}_range_km) OVER (ORDER BY start_date) - start_${preferred_range}_range_km AS range_loss,\n\t\tp.odometer - lag(p.odometer) OVER (ORDER BY start_date) AS distance\n\tFROM\n\t\tcharging_processes c\n\tLEFT JOIN positions p ON p.id = c.position_id \n\tWHERE\n\t end_date IS NOT NULL AND\n\t c.car_id = $car_id\n\tORDER BY\n\t\tstart_date\n),\nd2 AS (\nSELECT\n\tcar_id,\n\tsum(range_loss) AS range_loss,\n\tsum(distance) AS distance\nFROM\n\td1\nWHERE\n\tdistance >= 0 AND range_loss >= 0\nGROUP BY\n\tcar_id\n)\nSELECT\nrange_loss * c.efficiency / convert_km(distance::numeric, '$length_unit') * 1000 AS \"consumption_$length_unit\"\nFROM\n\td2\n\tLEFT JOIN cars c ON c.id = car_id", "refId": "A", "select": [ [ @@ -1940,6 +1959,23 @@ } ] ], + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + }, "table": "addresses", "timeColumn": "inserted_at", "timeColumnType": "timestamp", @@ -2067,7 +2103,7 @@ }, "showHeader": true }, - "pluginVersion": "11.3.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -2202,7 +2238,7 @@ }, "showHeader": true }, - "pluginVersion": "11.3.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -2337,7 +2373,7 @@ }, "showHeader": true }, - "pluginVersion": "11.3.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -2490,7 +2526,7 @@ }, "showHeader": true }, - "pluginVersion": "11.3.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -3116,7 +3152,7 @@ "showHeader": true, "sortBy": [] }, - "pluginVersion": "11.3.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -3129,7 +3165,7 @@ "hide": false, "metricColumn": "none", "rawQuery": true, - "rawSql": "WITH data AS (\nSELECT\n duration_min > 1 AND\n distance > 1 AND\n ( \n start_position.usable_battery_level IS NULL OR\n (end_position.battery_level - end_position.usable_battery_level) = 0 \n ) AS is_sufficiently_precise,\n NULLIF(GREATEST(start_ideal_range_km - end_ideal_range_km, 0), 0) AS range_diff,\n date_trunc('month', TIMEZONE('UTC', start_date)) as local_period,\n drives.*\nFROM drives\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)\nSELECT\n EXTRACT(EPOCH FROM date_trunc('month', local_period))*1000 AS date_from,\n EXTRACT(EPOCH FROM date_trunc('month', local_period + ('1 ' || 'month')::INTERVAL))*1000 AS date_to,\n CASE 'month'\n WHEN 'month' THEN to_char(local_period, 'YYYY Month')\n WHEN 'year' THEN to_char(local_period, 'YYYY')\n WHEN 'week' THEN 'week ' || to_char(local_period, 'WW') || ' starting ' || to_char(local_period, 'YYYY-MM-DD')\n ELSE to_char(local_period, 'YYYY-MM-DD')\n END AS display,\n local_period AS date,\n convert_km(max(end_km)::integer - min(start_km)::integer, '$length_unit') AS sum_distance_$length_unit,\n convert_celsius(avg(outside_temp_avg), '$temp_unit') AS avg_outside_temp_$temp_unit,\n sum(distance)/sum(range_diff) AS efficiency\nFROM data WHERE\n car_id = $car_id\nGROUP BY date\nORDER BY date DESC", + "rawSql": "WITH data AS (\nSELECT\n duration_min > 1 AND\n distance > 1 AND\n ( \n start_position.usable_battery_level IS NULL OR\n (end_position.battery_level - end_position.usable_battery_level) = 0 \n ) AS is_sufficiently_precise,\n NULLIF(GREATEST(start_ideal_range_km - end_ideal_range_km, 0), 0) AS range_diff,\n date_trunc('month', TIMEZONE('UTC', start_date)) as local_period,\n drives.*\nFROM drives\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)\nSELECT\n EXTRACT(EPOCH FROM local_period)*1000 AS date_from,\n EXTRACT(EPOCH FROM (local_period + interval '1 month'))*1000 AS date_to,\n to_char(local_period, 'YYYY Month') AS display,\n local_period AS date,\n convert_km(max(end_km)::integer - min(start_km)::integer, '$length_unit') AS sum_distance_$length_unit,\n convert_celsius(avg(outside_temp_avg), '$temp_unit') AS avg_outside_temp_$temp_unit,\n sum(distance)/sum(range_diff) AS efficiency\nFROM data WHERE\n car_id = $car_id\nGROUP BY date\nORDER BY date DESC", "refId": "A", "select": [ [ @@ -3180,7 +3216,7 @@ "hide": false, "metricColumn": "none", "rawQuery": true, - "rawSql": "WITH data AS (\n SELECT\n charging_processes.*,\n date_trunc('month', TIMEZONE('UTC', start_date)) as local_period\n FROM charging_processes)\nSELECT\n EXTRACT(EPOCH FROM date_trunc('month', local_period))*1000 AS date_from,\n EXTRACT(EPOCH FROM date_trunc('month', local_period + ('1 ' || 'month')::INTERVAL))*1000 AS date_to,\n CASE 'month'\n WHEN 'month' THEN to_char(local_period, 'YYYY Month')\n WHEN 'year' THEN to_char(local_period, 'YYYY')\n WHEN 'week' THEN 'week ' || to_char(local_period, 'WW') || ' starting ' || to_char(local_period, 'YYYY-MM-DD')\n ELSE to_char(local_period, 'YYYY-MM-DD')\n END AS display,\n local_period AS date,\n sum(greatest(charge_energy_used,charge_energy_used)) AS sum_consumption_kwh,\n sum(greatest(charge_energy_used,charge_energy_used)) / count(*) AS avg_consumption_kwh,\n sum(cost) AS cost_charges,\n count(*) AS cnt_charges\nFROM data WHERE\n car_id = $car_id AND\n (charge_energy_used IS NULL OR charge_energy_used > 0.1)\nGROUP BY date\nORDER BY date", + "rawSql": "WITH data AS (\n SELECT\n charging_processes.*,\n date_trunc('month', TIMEZONE('UTC', start_date)) as local_period\n FROM charging_processes\n)\nSELECT\n EXTRACT(EPOCH FROM local_period)*1000 AS date_from,\n EXTRACT(EPOCH FROM (local_period + interval '1 month'))*1000 AS date_to,\n to_char(local_period, 'YYYY Month') AS display,\n local_period AS date,\n sum(greatest(charge_energy_added,charge_energy_used)) AS sum_consumption_kwh,\n sum(greatest(charge_energy_added,charge_energy_used)) / count(*) AS avg_consumption_kwh,\n sum(cost) AS cost_charges,\n count(*) AS cnt_charges\nFROM data WHERE\n car_id = $car_id AND\n (charge_energy_used IS NULL OR charge_energy_used > 0.1)\nGROUP BY date\nORDER BY date", "refId": "B", "select": [ [ @@ -3229,7 +3265,7 @@ "hide": false, "metricColumn": "none", "rawQuery": true, - "rawSql": "WITH data AS (\n SELECT\n drives.*,\n date_trunc('month', TIMEZONE('UTC', start_date)) as local_period\n FROM drives)\nSELECT\n EXTRACT(EPOCH FROM date_trunc('month', local_period))*1000 AS date_from,\n EXTRACT(EPOCH FROM date_trunc('month', local_period + ('1 ' || 'month')::INTERVAL))*1000 AS date_to,\n CASE 'month'\n WHEN 'month' THEN to_char(local_period, 'YYYY Month')\n WHEN 'year' THEN to_char(local_period, 'YYYY')\n WHEN 'week' THEN 'week ' || to_char(local_period, 'WW') || ' starting ' || to_char(local_period, 'YYYY-MM-DD')\n ELSE to_char(local_period, 'YYYY-MM-DD')\n END AS display,\n local_period AS date,\n sum(GREATEST(start_${preferred_range}_range_km - end_${preferred_range}_range_km, 0) * car.efficiency * 1000) / \n convert_km(sum(distance)::numeric, '$length_unit') as efficiency_net_$length_unit\nFROM data\nJOIN cars car ON car.id = car_id\nWHERE\n car_id = $car_id\nGROUP BY date\nORDER BY date", + "rawSql": "WITH data AS (\n SELECT\n drives.*,\n date_trunc('month', TIMEZONE('UTC', start_date)) as local_period\n FROM drives\n)\nSELECT\n EXTRACT(EPOCH FROM local_period)*1000 AS date_from,\n EXTRACT(EPOCH FROM (local_period + interval '1 month'))*1000 AS date_to,\n to_char(local_period, 'YYYY Month') AS display,\n local_period AS date,\n sum(GREATEST(start_${preferred_range}_range_km - end_${preferred_range}_range_km, 0) * car.efficiency * 1000) / \n convert_km(sum(distance)::numeric, '$length_unit') as efficiency_net_$length_unit\nFROM data\nJOIN cars car ON car.id = car_id\nWHERE\n car_id = $car_id\nGROUP BY date\nORDER BY date", "refId": "C", "select": [ [ @@ -3398,7 +3434,7 @@ } ], "refresh": "", - "schemaVersion": 40, + "schemaVersion": 39, "tags": [ "TeslamateCustomDashboards" ], @@ -3410,14 +3446,18 @@ "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, - "definition": "SELECT name AS __text, id AS __value FROM cars ORDER BY display_priority ASC, name ASC;", + "definition": "SELECT\n id as __value,\n CASE WHEN COUNT(id) OVER (PARTITION BY name) > 1 AND name IS NOT NULL THEN CONCAT(name, ' - ', RIGHT(vin, 6)) ELSE COALESCE(name, RIGHT(vin, 6)) end as __text \nFROM cars\nORDER BY display_priority ASC, name ASC, vin ASC;", + "hide": 0, "includeAll": false, "label": "Car", + "multi": false, "name": "car_id", "options": [], - "query": "SELECT name AS __text, id AS __value FROM cars ORDER BY display_priority ASC, name ASC;", + "query": "SELECT\n id as __value,\n CASE WHEN COUNT(id) OVER (PARTITION BY name) > 1 AND name IS NOT NULL THEN CONCAT(name, ' - ', RIGHT(vin, 6)) ELSE COALESCE(name, RIGHT(vin, 6)) end as __text \nFROM cars\nORDER BY display_priority ASC, name ASC, vin ASC;", "refresh": 1, "regex": "", + "skipUrlSync": false, + "sort": 0, "type": "query" }, { @@ -3429,11 +3469,14 @@ "definition": "select base_url from settings limit 1;", "hide": 2, "includeAll": false, + "multi": false, "name": "base_url", "options": [], "query": "select base_url from settings limit 1;", "refresh": 1, "regex": "", + "skipUrlSync": false, + "sort": 0, "type": "query" }, { @@ -3445,11 +3488,14 @@ "definition": "select unit_of_length from settings limit 1;", "hide": 2, "includeAll": false, + "multi": false, "name": "length_unit", "options": [], "query": "select unit_of_length from settings limit 1;", "refresh": 1, "regex": "", + "skipUrlSync": false, + "sort": 0, "type": "query" }, { @@ -3461,11 +3507,14 @@ "definition": "SELECT\n\tcoalesce(sum(cost), 0)\nFROM\n\tcharging_processes\nWHERE\n\t$__timeFilter(end_date)\n\tAND car_id = $car_id;\n\t", "hide": 2, "includeAll": false, + "multi": false, "name": "TotalCost", "options": [], "query": "SELECT\n\tcoalesce(sum(cost), 0)\nFROM\n\tcharging_processes\nWHERE\n\t$__timeFilter(end_date)\n\tAND car_id = $car_id;\n\t", "refresh": 2, "regex": "", + "skipUrlSync": false, + "sort": 0, "type": "query" }, { @@ -3477,11 +3526,14 @@ "definition": "WITH data AS (\n\tSELECT c.charging_process_id \n\tFROM charges c\n\tLEFT JOIN charging_processes cp ON cp.id = c.charging_process_id\n\tLEFT JOIN addresses addr ON addr.id = cp.address_id\n\tLEFT JOIN geofences geo ON geo.id = geofence_id\n\tWHERE \n\t cp.car_id = $car_id AND c.fast_charger_present\n\t\tAND (COALESCE(geo.name, CONCAT_WS(', ', COALESCE(addr.name, nullif(CONCAT_WS(' ', addr.display_name), '')))) ILIKE '%supercharger%' OR c.fast_charger_brand = 'Tesla')\n\tGROUP BY 1\n)\nSELECT\n coalesce(sum(cp.cost), 0)\nFROM\n\tcharging_processes cp, data\nWHERE\n $__timeFilter(end_date)\n AND cp.id IN (data.charging_process_id);", "hide": 2, "includeAll": false, + "multi": false, "name": "SucCost", "options": [], "query": "WITH data AS (\n\tSELECT c.charging_process_id \n\tFROM charges c\n\tLEFT JOIN charging_processes cp ON cp.id = c.charging_process_id\n\tLEFT JOIN addresses addr ON addr.id = cp.address_id\n\tLEFT JOIN geofences geo ON geo.id = geofence_id\n\tWHERE \n\t cp.car_id = $car_id AND c.fast_charger_present\n\t\tAND (COALESCE(geo.name, CONCAT_WS(', ', COALESCE(addr.name, nullif(CONCAT_WS(' ', addr.display_name), '')))) ILIKE '%supercharger%' OR c.fast_charger_brand = 'Tesla')\n\tGROUP BY 1\n)\nSELECT\n coalesce(sum(cp.cost), 0)\nFROM\n\tcharging_processes cp, data\nWHERE\n $__timeFilter(end_date)\n AND cp.id IN (data.charging_process_id);", "refresh": 2, "regex": "", + "skipUrlSync": false, + "sort": 0, "type": "query" }, { @@ -3493,11 +3545,14 @@ "definition": "WITH data AS (\n\tSELECT c.charging_process_id \n\tFROM charges c\n\tLEFT JOIN charging_processes cp ON cp.id = c.charging_process_id\n\tWHERE \n cp.car_id = $car_id AND c.fast_charger_present\n\tGROUP BY 1\n)\nSELECT\n coalesce(sum(cp.cost) - $SucCost , 0)\t\nFROM\n\tcharging_processes cp, data\nWHERE\n $__timeFilter(end_date)\n AND cp.id IN (data.charging_process_id);", "hide": 2, "includeAll": false, + "multi": false, "name": "DCCost", "options": [], "query": "WITH data AS (\n\tSELECT c.charging_process_id \n\tFROM charges c\n\tLEFT JOIN charging_processes cp ON cp.id = c.charging_process_id\n\tWHERE \n cp.car_id = $car_id AND c.fast_charger_present\n\tGROUP BY 1\n)\nSELECT\n coalesce(sum(cp.cost) - $SucCost , 0)\t\nFROM\n\tcharging_processes cp, data\nWHERE\n $__timeFilter(end_date)\n AND cp.id IN (data.charging_process_id);", "refresh": 2, "regex": "", + "skipUrlSync": false, + "sort": 0, "type": "query" }, { @@ -3509,11 +3564,14 @@ "definition": "WITH data AS (\n\tSELECT c.charging_process_id \n\tFROM charges c\n\tLEFT JOIN charging_processes cp ON cp.id = c.charging_process_id\n\tWHERE \n\t\tcp.car_id = $car_id AND c.charger_voltage != 2\n AND c.fast_charger_present IS NOT true\n GROUP BY 1\n)\nSELECT\n coalesce(sum(cp.cost) , 0)\nFROM\n\tcharging_processes cp, data\nWHERE\n $__timeFilter(end_date)\n AND cp.cost IS NOT NULL\n AND cp.id IN (data.charging_process_id);", "hide": 2, "includeAll": false, + "multi": false, "name": "ACCost", "options": [], "query": "WITH data AS (\n\tSELECT c.charging_process_id \n\tFROM charges c\n\tLEFT JOIN charging_processes cp ON cp.id = c.charging_process_id\n\tWHERE \n\t\tcp.car_id = $car_id AND c.charger_voltage != 2\n AND c.fast_charger_present IS NOT true\n GROUP BY 1\n)\nSELECT\n coalesce(sum(cp.cost) , 0)\nFROM\n\tcharging_processes cp, data\nWHERE\n $__timeFilter(end_date)\n AND cp.cost IS NOT NULL\n AND cp.id IN (data.charging_process_id);", "refresh": 2, "regex": "", + "skipUrlSync": false, + "sort": 0, "type": "query" }, { @@ -3525,11 +3583,14 @@ "definition": "SELECT ROUND(convert_km((max(end_km) - min(start_km))::numeric, '$length_unit'),0) as \"Mileage\"\nFROM drives WHERE car_id = $car_id AND $__timeFilter(end_date)", "hide": 2, "includeAll": false, + "multi": false, "name": "distance_driven", "options": [], "query": "SELECT ROUND(convert_km((max(end_km) - min(start_km))::numeric, '$length_unit'),0) as \"Mileage\"\nFROM drives WHERE car_id = $car_id AND $__timeFilter(end_date)", "refresh": 2, "regex": "", + "skipUrlSync": false, + "sort": 0, "type": "query" }, { @@ -3541,11 +3602,14 @@ "definition": "select unit_of_temperature from settings limit 1;", "hide": 2, "includeAll": false, + "multi": false, "name": "temp_unit", "options": [], "query": "select unit_of_temperature from settings limit 1;", "refresh": 1, "regex": "", + "skipUrlSync": false, + "sort": 0, "type": "query" }, { @@ -3557,11 +3621,14 @@ "definition": "select preferred_range from settings limit 1;", "hide": 2, "includeAll": false, + "multi": false, "name": "preferred_range", "options": [], "query": "select preferred_range from settings limit 1;", "refresh": 1, "regex": "", + "skipUrlSync": false, + "sort": 0, "type": "query" }, { @@ -3572,13 +3639,17 @@ }, "definition": "SELECT name FROM geofences ORDER BY id", "description": "Geofence to display energy added at", + "hide": 0, "includeAll": false, "label": "Geofence", + "multi": false, "name": "geofence", "options": [], "query": "SELECT name FROM geofences ORDER BY id", "refresh": 1, "regex": "", + "skipUrlSync": false, + "sort": 0, "type": "query" } ] @@ -3593,6 +3664,6 @@ "timezone": "", "title": "Charging Costs Stats", "uid": "jchmDdLe5uFVk", - "version": 9, + "version": 1, "weekStart": "" } \ No newline at end of file diff --git a/dashboards/CurrentDriveView.json b/dashboards/CurrentDriveView.json index 76057ac..19f3d90 100644 --- a/dashboards/CurrentDriveView.json +++ b/dashboards/CurrentDriveView.json @@ -17,7 +17,7 @@ "type": "grafana", "id": "grafana", "name": "Grafana", - "version": "10.4.0" + "version": "11.2.3" }, { "type": "datasource", @@ -63,6 +63,7 @@ "editable": true, "fiscalYearStartMonth": 0, "graphTooltip": 1, + "id": null, "links": [ { "asDropdown": true, @@ -120,6 +121,7 @@ "axisLabel": "", "axisPlacement": "auto", "barAlignment": 0, + "barWidthFactor": 0.6, "drawStyle": "line", "fillOpacity": 5, "gradientMode": "hue", @@ -331,7 +333,6 @@ "sort": "none" } }, - "pluginVersion": "8.5.4", "targets": [ { "alias": "", @@ -534,7 +535,7 @@ "zoom": 15 } }, - "pluginVersion": "10.4.0", + "pluginVersion": "11.2.3", "targets": [ { "alias": "", @@ -687,6 +688,7 @@ "graphMode": "none", "justifyMode": "auto", "orientation": "auto", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "lastNotNull" @@ -698,7 +700,7 @@ "textMode": "auto", "wideLayout": true }, - "pluginVersion": "10.4.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -711,7 +713,7 @@ "hide": false, "metricColumn": "none", "rawQuery": true, - "rawSql": "SELECT\n\t(CASE WHEN '$length_unit' = 'km' THEN $efficiency\n\t WHEN '$length_unit' = 'mi' THEN $efficiency * 1.60934\n\tEND) * 10 as \"efficiency_$length_unit\"", + "rawSql": "SELECT $efficiency * 10 / convert_km(1, '$length_unit') as \"efficiency_$length_unit\"", "refId": "A", "select": [ [ @@ -812,6 +814,7 @@ "graphMode": "none", "justifyMode": "auto", "orientation": "auto", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "mean" @@ -823,7 +826,7 @@ "textMode": "auto", "wideLayout": true }, - "pluginVersion": "10.4.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -961,6 +964,7 @@ "graphMode": "area", "justifyMode": "center", "orientation": "auto", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "mean" @@ -973,7 +977,7 @@ "textMode": "auto", "wideLayout": true }, - "pluginVersion": "10.4.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -1160,6 +1164,7 @@ "graphMode": "none", "justifyMode": "auto", "orientation": "auto", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "sum" @@ -1172,7 +1177,7 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "10.4.0", + "pluginVersion": "11.2.3", "targets": [ { "alias": "Elapsed Time", @@ -1321,6 +1326,7 @@ "graphMode": "none", "justifyMode": "auto", "orientation": "horizontal", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "lastNotNull" @@ -1332,7 +1338,7 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "10.4.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -1461,6 +1467,7 @@ "graphMode": "none", "justifyMode": "auto", "orientation": "horizontal", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "mean" @@ -1472,7 +1479,7 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "10.4.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -1598,6 +1605,7 @@ "graphMode": "none", "justifyMode": "auto", "orientation": "horizontal", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "mean" @@ -1609,7 +1617,7 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "10.4.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -1704,6 +1712,7 @@ "graphMode": "area", "justifyMode": "center", "orientation": "vertical", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "lastNotNull" @@ -1715,7 +1724,7 @@ "textMode": "value", "wideLayout": true }, - "pluginVersion": "10.4.0", + "pluginVersion": "11.2.3", "targets": [ { "alias": "kWh Added", @@ -1838,7 +1847,7 @@ "text": {}, "valueMode": "color" }, - "pluginVersion": "10.4.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -1958,7 +1967,7 @@ "text": {}, "valueMode": "color" }, - "pluginVersion": "10.4.0", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { @@ -2026,14 +2035,14 @@ "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, - "definition": "SELECT name AS __text, id AS __value FROM cars ORDER BY display_priority ASC, name ASC;", + "definition": "SELECT\n id as __value,\n CASE WHEN COUNT(id) OVER (PARTITION BY name) > 1 AND name IS NOT NULL THEN CONCAT(name, ' - ', RIGHT(vin, 6)) ELSE COALESCE(name, RIGHT(vin, 6)) end as __text \nFROM cars\nORDER BY display_priority ASC, name ASC, vin ASC;", "hide": 0, "includeAll": false, "label": "Car", "multi": false, "name": "car_id", "options": [], - "query": "SELECT name AS __text, id AS __value FROM cars ORDER BY display_priority ASC, name ASC;", + "query": "SELECT\n id as __value,\n CASE WHEN COUNT(id) OVER (PARTITION BY name) > 1 AND name IS NOT NULL THEN CONCAT(name, ' - ', RIGHT(vin, 6)) ELSE COALESCE(name, RIGHT(vin, 6)) end as __text \nFROM cars\nORDER BY display_priority ASC, name ASC, vin ASC;", "refresh": 1, "regex": "", "skipUrlSync": false, @@ -2259,6 +2268,6 @@ "timezone": "", "title": "Current Drive View", "uid": "jchmkOuP_Fggz", - "version": 11, + "version": 1, "weekStart": "" } \ No newline at end of file diff --git a/dashboards/MileageStats.json b/dashboards/MileageStats.json index 16281ad..6e36042 100644 --- a/dashboards/MileageStats.json +++ b/dashboards/MileageStats.json @@ -11,7 +11,7 @@ "type": "grafana", "id": "grafana", "name": "Grafana", - "version": "10.4.0" + "version": "11.2.3" }, { "type": "datasource", @@ -156,7 +156,11 @@ }, { "id": "decimals", - "value": 2 + "value": 1 + }, + { + "id": "custom.width", + "value": 180 } ] }, @@ -168,7 +172,7 @@ "properties": [ { "id": "custom.width", - "value": 200 + "value": 160 }, { "id": "links", @@ -335,7 +339,7 @@ } ] }, - "pluginVersion": "10.4.0", + "pluginVersion": "11.2.3", "repeatDirection": "h", "targets": [ { @@ -343,11 +347,12 @@ "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, + "editorMode": "code", "format": "table", "group": [], "metricColumn": "none", "rawQuery": true, - "rawSql": "WITH data AS (\nSELECT\n duration_min > 1 AND\n distance > 1 AND\n ( \n start_position.usable_battery_level IS NULL OR\n (end_position.battery_level - end_position.usable_battery_level) = 0 \n ) AS is_sufficiently_precise,\n NULLIF(GREATEST(start_ideal_range_km - end_ideal_range_km, 0), 0) AS range_diff,\n date_trunc('$period', start_date::TIMESTAMP) as local_period,\n drives.*\nFROM drives\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)\nSELECT\n EXTRACT(EPOCH FROM date_trunc('$period', local_period))*1000 AS date_from,\n EXTRACT(EPOCH FROM date_trunc('$period', local_period + ('1 ' || '$period')::INTERVAL))*1000 AS date_to,\n CASE '$period'\n WHEN 'month' THEN to_char(local_period, 'YYYY Month')\n WHEN 'year' THEN to_char(local_period, 'YYYY')\n WHEN 'week' THEN 'week ' || to_char(local_period, 'WW') || ' starting ' || to_char(local_period, 'YYYY-MM-DD')\n ELSE to_char(local_period, 'YYYY-MM-DD')\n END AS display,\n local_period AS date,\n sum(duration_min)*60 AS sum_duration_h, \n convert_km(max(end_km)::integer - min(start_km)::integer, '$length_unit') AS sum_distance_$length_unit,\n count(*) AS cnt,\n sum(distance)/sum(range_diff) AS efficiency\nFROM data WHERE\n car_id = $car_id AND\n $__timeFilter(start_date)\nGROUP BY date\nORDER BY date", + "rawSql": "WITH data AS (\nSELECT\n duration_min > 1 AND\n distance > 1 AND\n ( \n start_position.usable_battery_level IS NULL OR\n (end_position.battery_level - end_position.usable_battery_level) = 0 \n ) AS is_sufficiently_precise,\n NULLIF(GREATEST(start_ideal_range_km - end_ideal_range_km, 0), 0) AS range_diff,\n date_trunc('$period', TIMEZONE('UTC', start_date)) as local_period,\n drives.*\nFROM drives\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)\nSELECT\n EXTRACT(EPOCH FROM local_period)*1000 AS date_from,\n EXTRACT(EPOCH FROM (local_period + interval '1 $period'))*1000 AS date_to,\n CASE '$period'\n WHEN 'month' THEN to_char(local_period, 'YYYY Month')\n WHEN 'year' THEN to_char(local_period, 'YYYY')\n WHEN 'week' THEN 'week ' || to_char(local_period, 'WW') || ' starting ' || to_char(local_period, 'YYYY-MM-DD')\n ELSE to_char(local_period, 'YYYY-MM-DD')\n END AS display,\n local_period AS date,\n sum(duration_min)*60 AS sum_duration_h, \n convert_km(max(end_km)::integer - min(start_km)::integer, '$length_unit') AS sum_distance_$length_unit,\n count(*) AS cnt,\n sum(distance)/sum(range_diff) AS efficiency\nFROM data WHERE\n car_id = $car_id AND\n $__timeFilter(start_date)\nGROUP BY date\nORDER BY date", "refId": "A", "select": [ [ @@ -359,6 +364,23 @@ } ] ], + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + }, "table": "drives", "timeColumn": "start_date", "timeColumnType": "timestamp", @@ -641,7 +663,7 @@ "group": [], "metricColumn": "none", "rawQuery": true, - "rawSql": "WITH data AS (\nSELECT\n duration_min > 1 AND\n distance > 1 AND\n ( \n start_position.usable_battery_level IS NULL OR\n (end_position.battery_level - end_position.usable_battery_level) = 0 \n ) AS is_sufficiently_precise,\n NULLIF(GREATEST(start_ideal_range_km - end_ideal_range_km, 0), 0) AS range_diff,\n date_trunc('$period', start_date::TIMESTAMP) as local_period,\n drives.*\nFROM drives\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)\nSELECT\n EXTRACT(EPOCH FROM date_trunc('$period', local_period))*1000 AS date_from,\n EXTRACT(EPOCH FROM date_trunc('$period', local_period + ('1 ' || '$period')::INTERVAL))*1000 AS date_to,\n CASE '$period'\n WHEN 'month' THEN to_char(local_period, 'YYYY Month')\n WHEN 'year' THEN to_char(local_period, 'YYYY')\n WHEN 'week' THEN 'week ' || to_char(local_period, 'WW') || ' starting ' || to_char(local_period, 'YYYY-MM-DD')\n ELSE to_char(local_period, 'YYYY-MM-DD')\n END AS \"Period\",\n local_period AS date,\n sum(duration_min)*60 AS sum_duration_h, \n convert_km(max(end_km)::integer - min(start_km)::integer, '$length_unit') AS sum_distance_$length_unit,\n count(*) AS cnt,\n sum(distance)/sum(range_diff) AS efficiency\nFROM data WHERE\n car_id = $car_id AND\n $__timeFilter(start_date)\nGROUP BY date\nORDER BY date", + "rawSql": "WITH data AS (\nSELECT\n duration_min > 1 AND\n distance > 1 AND\n ( \n start_position.usable_battery_level IS NULL OR\n (end_position.battery_level - end_position.usable_battery_level) = 0 \n ) AS is_sufficiently_precise,\n NULLIF(GREATEST(start_ideal_range_km - end_ideal_range_km, 0), 0) AS range_diff,\n date_trunc('$period', TIMEZONE('UTC', start_date)) as local_period,\n drives.*\nFROM drives\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)\nSELECT\n EXTRACT(EPOCH FROM local_period)*1000 AS date_from,\n EXTRACT(EPOCH FROM (local_period + interval '1 $period'))*1000 AS date_to,\n CASE '$period'\n WHEN 'month' THEN to_char(local_period, 'YYYY Month')\n WHEN 'year' THEN to_char(local_period, 'YYYY')\n WHEN 'week' THEN 'week ' || to_char(local_period, 'WW') || ' starting ' || to_char(local_period, 'YYYY-MM-DD')\n ELSE to_char(local_period, 'YYYY-MM-DD')\n END AS \"Period\",\n local_period AS date,\n sum(duration_min)*60 AS sum_duration_h, \n convert_km(max(end_km)::integer - min(start_km)::integer, '$length_unit') AS sum_distance_$length_unit,\n count(*) AS cnt,\n sum(distance)/sum(range_diff) AS efficiency\nFROM data WHERE\n car_id = $car_id AND\n $__timeFilter(start_date)\nGROUP BY date\nORDER BY date", "refId": "A", "select": [ [ @@ -714,14 +736,14 @@ "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, - "definition": "SELECT name AS __text, id AS __value FROM cars ORDER BY display_priority ASC, name ASC;", + "definition": "SELECT\n id as __value,\n CASE WHEN COUNT(id) OVER (PARTITION BY name) > 1 AND name IS NOT NULL THEN CONCAT(name, ' - ', RIGHT(vin, 6)) ELSE COALESCE(name, RIGHT(vin, 6)) end as __text \nFROM cars\nORDER BY display_priority ASC, name ASC, vin ASC;", "hide": 2, "includeAll": true, "label": "Car", "multi": false, "name": "car_id", "options": [], - "query": "SELECT name AS __text, id AS __value FROM cars ORDER BY display_priority ASC, name ASC;", + "query": "SELECT\n id as __value,\n CASE WHEN COUNT(id) OVER (PARTITION BY name) > 1 AND name IS NOT NULL THEN CONCAT(name, ' - ', RIGHT(vin, 6)) ELSE COALESCE(name, RIGHT(vin, 6)) end as __text \nFROM cars\nORDER BY display_priority ASC, name ASC, vin ASC;", "refresh": 1, "regex": "", "skipUrlSync": false, @@ -849,6 +871,6 @@ "timezone": "", "title": "Mileage Stats", "uid": "jchmNjtMTFx", - "version": 5, + "version": 1, "weekStart": "" } \ No newline at end of file diff --git a/dashboards/SpeedRates.json b/dashboards/SpeedRates.json index 73971ee..fcaa5c3 100644 --- a/dashboards/SpeedRates.json +++ b/dashboards/SpeedRates.json @@ -11,11 +11,11 @@ "type": "grafana", "id": "grafana", "name": "Grafana", - "version": "10.1.2" + "version": "11.2.3" }, { "type": "datasource", - "id": "postgres", + "id": "grafana-postgresql-datasource", "name": "PostgreSQL", "version": "1.0.0" }, @@ -40,9 +40,9 @@ "type": "datasource", "uid": "grafana" }, + "definition": "TeslaMate|U2FsdGVkX1/cEWK+8cz7pjEKXtzJnDN7b21ZDXt1MGneFGPWTLqOPtxKmu02mJPLzi/f29I+NBHd3vi0FB8R4Xn0+GtobWDgk6VAVSBTdSNniOKO8i2WPlhRaOsl2+hG7gnZ7wrf1Th2nxR7f1uYCrbwOek0IzkfLzrkjh7gkr6inT6bbDuJqrmogZajLxmAMrQ6V+/vHxBRGiwjJhgiEeq3hM1q2h04JKkNiZ8RHbsF5Cd/xd8Q9u0JVrZzIrtnhM/SFlaApU7RtRMu8CSj1llTX7WEOj6VDZAMSf+XUAanWdk725kEPN9MNu89o2zEq5P3E3cju8IbbBdPzXLV3oVuzD6/tMnxFToIIV1E/BrpF7s2RtNa8+KJJ1PF8xgs6m+/KTD2hy+WsP0636AgObRAmYg7+qotGrgNvpNPdE0EgrB7WHYlV7R/1q66bcq6tCe51X1Un70k+zo+K6AK0o4B1H6IyMlEVuRH/Fz8QVl9aYu2ztd08RbuKJlYVKpkH+pxVETAO9MclYQ90tzE6TfwDZrQZzsAlMenr4s1ZB1OlFXjLjVjnddnUilzO76cqv4yI2THQEuyQ47nuVQ4gUbx02K59vMQhns3C01JOAYokOaSXe66Y7QYdMlk09Lf|aes-256-cbc", "enable": true, "hide": true, - "definition": "TeslaMate|U2FsdGVkX1/cEWK+8cz7pjEKXtzJnDN7b21ZDXt1MGneFGPWTLqOPtxKmu02mJPLzi/f29I+NBHd3vi0FB8R4Xn0+GtobWDgk6VAVSBTdSNniOKO8i2WPlhRaOsl2+hG7gnZ7wrf1Th2nxR7f1uYCrbwOek0IzkfLzrkjh7gkr6inT6bbDuJqrmogZajLxmAMrQ6V+/vHxBRGiwjJhgiEeq3hM1q2h04JKkNiZ8RHbsF5Cd/xd8Q9u0JVrZzIrtnhM/SFlaApU7RtRMu8CSj1llTX7WEOj6VDZAMSf+XUAanWdk725kEPN9MNu89o2zEq5P3E3cju8IbbBdPzXLV3oVuzD6/tMnxFToIIV1E/BrpF7s2RtNa8+KJJ1PF8xgs6m+/KTD2hy+WsP0636AgObRAmYg7+qotGrgNvpNPdE0EgrB7WHYlV7R/1q66bcq6tCe51X1Un70k+zo+K6AK0o4B1H6IyMlEVuRH/Fz8QVl9aYu2ztd08RbuKJlYVKpkH+pxVETAO9MclYQ90tzE6TfwDZrQZzsAlMenr4s1ZB1OlFXjLjVjnddnUilzO76cqv4yI2THQEuyQ47nuVQ4gUbx02K59vMQhns3C01JOAYokOaSXe66Y7QYdMlk09Lf|aes-256-cbc", "iconColor": "rgba(0, 211, 255, 1)", "name": "Annotations & Alerts", "target": { @@ -96,7 +96,7 @@ "panels": [ { "datasource": { - "type": "postgres", + "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, "fieldConfig": { @@ -369,7 +369,6 @@ "y": 0 }, "id": 2, - "links": [], "options": { "cellHeight": "sm", "footer": { @@ -384,18 +383,19 @@ "showHeader": true, "sortBy": [] }, - "pluginVersion": "10.1.2", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { - "type": "postgres", + "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, + "editorMode": "code", "format": "table", "group": [], "metricColumn": "none", "rawQuery": true, - "rawSql": "SELECT\r\n BinnedData.speed_bin AS speed_range_$length_unit,\r\n convert_km(BinnedData.total_odometer_distance::numeric, '$length_unit') AS avg_distance_$length_unit,\r\n BinnedData.avg_speed * CASE WHEN '$length_unit' = 'km' THEN 1 WHEN '$length_unit' = 'mi' THEN 0.621371 END AS avg_speed_$length_unit,\r\n ((BinnedData.total_energy_consumed / (BinnedData.total_distance * CASE WHEN '$length_unit' = 'km' THEN 1 WHEN '$length_unit' = 'mi' THEN 0.621371 END)) * 1000 ) / (BinnedData.avg_speed * CASE WHEN '$length_unit' = 'km' THEN 1 WHEN '$length_unit' = 'mi' THEN 0.621371 END) AS avg_consumption_$length_unit,\r\n avg_power\r\nFROM\r\n (SELECT\r\n CASE\r\n WHEN elevation_diff >= 1 THEN 'Uphill'\r\n WHEN elevation_diff <= -1 THEN 'Downhill'\r\n ELSE 'Flat'\r\n END AS terrain_type,\r\n ROUND(speed * CASE WHEN '$length_unit' = 'km' THEN 1 WHEN '$length_unit' = 'mi' THEN 0.621371 END / 10, 0) * 10 AS speed_bin,\r\n AVG(power) AS avg_power,\r\n SUM(power::integer * speed::integer / 60.0) AS total_energy_consumed,\r\n SUM(speed / 60.0) AS total_distance,\r\n SUM(odometer_distance) AS total_odometer_distance,\r\n AVG(speed) AS avg_speed,\r\n car_id\r\n FROM\r\n (SELECT\r\n drives.car_id,\r\n positions.speed,\r\n positions.power,\r\n positions.elevation - LAG(positions.elevation) OVER (PARTITION BY positions.drive_id ORDER BY positions.date) AS elevation_diff,\r\n positions.odometer - LAG(positions.odometer) OVER (PARTITION BY positions.drive_id ORDER BY positions.date) AS odometer_distance\r\n FROM\r\n drives\r\n JOIN positions ON drives.id = positions.drive_id\r\n WHERE\r\n $__timeFilter(drives.start_date)\r\n AND drives.car_id = $car_id\r\n AND drives.end_date IS NOT NULL\r\n AND drives.distance >= convert_km($min_distance::numeric, '$length_unit')\r\n ) AS DifferentialData\r\n GROUP BY speed_bin, terrain_type, car_id\r\n ) AS BinnedData\r\nJOIN cars ON BinnedData.car_id = cars.id\r\nWHERE BinnedData.terrain_type = '$terrain_type'\r\n AND BinnedData.total_distance > 0 \r\n AND BinnedData.total_odometer_distance > 0\r\n AND BinnedData.speed_bin >= $min_speed_segment\r\nORDER BY BinnedData.speed_bin DESC;\r\n", + "rawSql": "SELECT\r\n BinnedData.speed_bin AS speed_range_$length_unit,\r\n convert_km(BinnedData.total_odometer_distance::numeric, '$length_unit') AS avg_distance_$length_unit,\r\n convert_km(BinnedData.avg_speed, '$length_unit') AS avg_speed_$length_unit,\r\n ((BinnedData.total_energy_consumed / convert_km(BinnedData.total_distance, '$length_unit')) * 1000 ) / convert_km(BinnedData.avg_speed, '$length_unit') AS avg_consumption_$length_unit,\r\n avg_power\r\nFROM\r\n (SELECT\r\n CASE\r\n WHEN elevation_diff >= 1 THEN 'Uphill'\r\n WHEN elevation_diff <= -1 THEN 'Downhill'\r\n ELSE 'Flat'\r\n END AS terrain_type,\r\n ROUND(convert_km(speed, '$length_unit') / 10, 0) * 10 AS speed_bin,\r\n AVG(power) AS avg_power,\r\n SUM(power::integer * speed::integer / 60.0) AS total_energy_consumed,\r\n SUM(speed / 60.0) AS total_distance,\r\n SUM(odometer_distance) AS total_odometer_distance,\r\n AVG(speed) AS avg_speed,\r\n car_id\r\n FROM\r\n (SELECT\r\n drives.car_id,\r\n positions.speed,\r\n positions.power,\r\n positions.elevation - LAG(positions.elevation) OVER (PARTITION BY positions.drive_id ORDER BY positions.date) AS elevation_diff,\r\n positions.odometer - LAG(positions.odometer) OVER (PARTITION BY positions.drive_id ORDER BY positions.date) AS odometer_distance\r\n FROM\r\n drives\r\n JOIN positions ON drives.id = positions.drive_id\r\n WHERE\r\n $__timeFilter(drives.start_date)\r\n AND drives.car_id = $car_id\r\n AND drives.end_date IS NOT NULL\r\n AND drives.distance >= convert_km($min_distance::numeric, '$length_unit')\r\n ) AS DifferentialData\r\n GROUP BY speed_bin, terrain_type, car_id\r\n ) AS BinnedData\r\nJOIN cars ON BinnedData.car_id = cars.id\r\nWHERE BinnedData.terrain_type = '$terrain_type'\r\n AND BinnedData.total_distance > 0 \r\n AND BinnedData.total_odometer_distance > 0\r\n AND BinnedData.speed_bin >= $min_speed_segment\r\nORDER BY BinnedData.speed_bin DESC;\r\n", "refId": "A", "select": [ [ @@ -407,6 +407,23 @@ } ] ], + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + }, "table": "addresses", "timeColumn": "inserted_at", "timeColumnType": "timestamp", @@ -424,7 +441,7 @@ }, { "datasource": { - "type": "postgres", + "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, "fieldConfig": { @@ -476,7 +493,6 @@ "y": 0 }, "id": 6, - "links": [], "maxDataPoints": 100, "options": { "colorMode": "value", @@ -488,6 +504,7 @@ "graphMode": "none", "justifyMode": "auto", "orientation": "horizontal", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "mean" @@ -495,13 +512,15 @@ "fields": "", "values": false }, - "textMode": "value" + "showPercentChange": false, + "textMode": "value", + "wideLayout": true }, - "pluginVersion": "10.1.2", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { - "type": "postgres", + "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, "format": "table", @@ -537,7 +556,7 @@ }, { "datasource": { - "type": "postgres", + "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, "fieldConfig": { @@ -590,7 +609,6 @@ "y": 6 }, "id": 4, - "links": [], "maxDataPoints": 100, "options": { "colorMode": "value", @@ -602,6 +620,7 @@ "graphMode": "none", "justifyMode": "auto", "orientation": "horizontal", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "mean" @@ -609,20 +628,23 @@ "fields": "", "values": false }, - "textMode": "value" + "showPercentChange": false, + "textMode": "value", + "wideLayout": true }, - "pluginVersion": "10.1.2", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { - "type": "postgres", + "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, + "editorMode": "code", "format": "table", "group": [], "metricColumn": "none", "rawQuery": true, - "rawSql": "select \n sum((start_${preferred_range}_range_km - end_${preferred_range}_range_km) * cars.efficiency) / sum(distance) * 1000 * \n CASE WHEN '$length_unit' = 'km' THEN 1\n WHEN '$length_unit' = 'mi' THEN 1.60934\n END AS \"consumption_$length_unit\"\nfrom drives \ninner join cars on cars.id = car_id\nwhere $__timeFilter(end_date) \n and distance is not null and\n start_${preferred_range}_range_km - end_${preferred_range}_range_km >= 0.1 and\n car_id = $car_id", + "rawSql": "select \n sum((start_${preferred_range}_range_km - end_${preferred_range}_range_km) * cars.efficiency) / convert_km(sum(distance)::numeric, '$length_unit') * 1000 as \"consumption_$length_unit\"\nfrom drives \ninner join cars on cars.id = car_id\nwhere $__timeFilter(end_date) \n and distance is not null and\n start_${preferred_range}_range_km - end_${preferred_range}_range_km >= 0.1 and\n car_id = $car_id", "refId": "A", "select": [ [ @@ -634,6 +656,23 @@ } ] ], + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + }, "table": "addresses", "timeColumn": "inserted_at", "timeColumnType": "timestamp", @@ -651,7 +690,7 @@ }, { "datasource": { - "type": "postgres", + "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, "fieldConfig": { @@ -704,7 +743,6 @@ "y": 6 }, "id": 8, - "links": [], "maxDataPoints": 100, "options": { "colorMode": "value", @@ -716,6 +754,7 @@ "graphMode": "none", "justifyMode": "auto", "orientation": "horizontal", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "mean" @@ -723,20 +762,23 @@ "fields": "", "values": false }, - "textMode": "value" + "showPercentChange": false, + "textMode": "value", + "wideLayout": true }, - "pluginVersion": "10.1.2", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { - "type": "postgres", + "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, + "editorMode": "code", "format": "table", "group": [], "metricColumn": "none", "rawQuery": true, - "rawSql": "WITH d1 AS (\n\tSELECT\n\t\tc.car_id,\n\t\tlag(end_${preferred_range}_range_km) OVER (ORDER BY start_date) - start_${preferred_range}_range_km AS range_loss,\n\t\tp.odometer - lag(p.odometer) OVER (ORDER BY start_date) AS distance\n\tFROM\n\t\tcharging_processes c\n\tLEFT JOIN positions p ON p.id = c.position_id \n\tWHERE\n\t $__timeFilter(end_date)\n\t and end_date IS NOT NULL AND\n\t c.car_id = $car_id\n\tORDER BY\n\t\tstart_date\n),\nd2 AS (\nSELECT\n\tcar_id,\n\tsum(range_loss) AS range_loss,\n\tsum(distance) AS distance\nFROM\n\td1\nWHERE\n\tdistance > 0 AND range_loss >= 0\nGROUP BY\n\tcar_id\n)\nSELECT\nrange_loss * c.efficiency / distance * 1000 *\n CASE WHEN '$length_unit' = 'km' THEN 1\n WHEN '$length_unit' = 'mi' THEN 1.60934\n END AS \"consumption_$length_unit\"\nFROM\n\td2\n\tLEFT JOIN cars c ON c.id = car_id", + "rawSql": "WITH d1 AS (\n\tSELECT\n\t\tc.car_id,\n\t\tlag(end_${preferred_range}_range_km) OVER (ORDER BY start_date) - start_${preferred_range}_range_km AS range_loss,\n\t\tp.odometer - lag(p.odometer) OVER (ORDER BY start_date) AS distance\n\tFROM\n\t\tcharging_processes c\n\tLEFT JOIN positions p ON p.id = c.position_id \n\tWHERE\n\t $__timeFilter(end_date)\n\t and end_date IS NOT NULL AND\n\t c.car_id = $car_id\n\tORDER BY\n\t\tstart_date\n),\nd2 AS (\nSELECT\n\tcar_id,\n\tsum(range_loss) AS range_loss,\n\tsum(distance) AS distance\nFROM\n\td1\nWHERE\n\tdistance > 0 AND range_loss >= 0\nGROUP BY\n\tcar_id\n)\nSELECT\nrange_loss * c.efficiency / convert_km(distance::numeric, '$length_unit') * 1000 as \"consumption_$length_unit\"\nFROM\n\td2\n\tLEFT JOIN cars c ON c.id = car_id", "refId": "A", "select": [ [ @@ -748,6 +790,23 @@ } ] ], + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + }, "table": "addresses", "timeColumn": "inserted_at", "timeColumnType": "timestamp", @@ -765,7 +824,7 @@ }, { "datasource": { - "type": "postgres", + "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, "fieldConfig": { @@ -820,13 +879,13 @@ "y": 6 }, "id": 14, - "links": [], "maxDataPoints": 100, "options": { "colorMode": "value", "graphMode": "area", "justifyMode": "auto", "orientation": "horizontal", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "lastNotNull" @@ -834,20 +893,23 @@ "fields": "", "values": false }, - "textMode": "auto" + "showPercentChange": false, + "textMode": "auto", + "wideLayout": true }, - "pluginVersion": "10.1.2", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { - "type": "postgres", + "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, + "editorMode": "code", "format": "table", "group": [], "metricColumn": "none", "rawQuery": true, - "rawSql": "SELECT\n\tCASE WHEN '$length_unit' = 'km' THEN efficiency\n\t WHEN '$length_unit' = 'mi' THEN efficiency * 1.60934\n\tEND * 1000 as \"efficiency_$length_unit\"\nFROM\n\tcars\nWHERE\n\tid = $car_id;", + "rawSql": "SELECT\n efficiency / convert_km(1, '$length_unit') * 1000 as \"efficiency_$length_unit\"\nFROM\n\tcars\nWHERE\n\tid = $car_id;", "refId": "A", "select": [ [ @@ -859,6 +921,23 @@ } ] ], + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + }, "table": "charges", "timeColumn": "date", "timeColumnType": "timestamp", @@ -876,7 +955,7 @@ }, { "datasource": { - "type": "postgres", + "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, "fieldConfig": { @@ -922,11 +1001,12 @@ "y": 13 }, "id": 16, - "links": [], "options": { "displayMode": "gradient", + "maxVizHeight": 300, "minVizHeight": 10, "minVizWidth": 0, + "namePlacement": "auto", "orientation": "horizontal", "reduceOptions": { "calcs": [ @@ -936,13 +1016,14 @@ "values": true }, "showUnfilled": false, + "sizing": "auto", "valueMode": "color" }, - "pluginVersion": "10.1.2", + "pluginVersion": "11.2.3", "targets": [ { "datasource": { - "type": "postgres", + "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, "editorMode": "code", @@ -994,8 +1075,7 @@ } ], "refresh": "", - "schemaVersion": 38, - "style": "dark", + "schemaVersion": 39, "tags": [ "TeslamateCustomDashboards" ], @@ -1004,17 +1084,17 @@ { "current": {}, "datasource": { - "type": "postgres", + "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, - "definition": "SELECT name AS __text, id AS __value FROM cars ORDER BY display_priority ASC, name ASC;", + "definition": "SELECT\n id as __value,\n CASE WHEN COUNT(id) OVER (PARTITION BY name) > 1 AND name IS NOT NULL THEN CONCAT(name, ' - ', RIGHT(vin, 6)) ELSE COALESCE(name, RIGHT(vin, 6)) end as __text \nFROM cars\nORDER BY display_priority ASC, name ASC, vin ASC;", "hide": 0, "includeAll": false, "label": "Car", "multi": false, "name": "car_id", "options": [], - "query": "SELECT name AS __text, id AS __value FROM cars ORDER BY display_priority ASC, name ASC;", + "query": "SELECT\n id as __value,\n CASE WHEN COUNT(id) OVER (PARTITION BY name) > 1 AND name IS NOT NULL THEN CONCAT(name, ' - ', RIGHT(vin, 6)) ELSE COALESCE(name, RIGHT(vin, 6)) end as __text \nFROM cars\nORDER BY display_priority ASC, name ASC, vin ASC;", "refresh": 1, "regex": "", "skipUrlSync": false, @@ -1027,7 +1107,7 @@ { "current": {}, "datasource": { - "type": "postgres", + "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, "definition": "select unit_of_length from settings limit 1;", @@ -1050,7 +1130,7 @@ { "current": {}, "datasource": { - "type": "postgres", + "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, "definition": "select preferred_range from settings limit 1;", @@ -1071,7 +1151,7 @@ }, { "current": { - "selected": true, + "selected": false, "text": "50", "value": "50" }, @@ -1114,7 +1194,7 @@ }, { "current": { - "selected": true, + "selected": false, "text": "25", "value": "25" }, @@ -1173,7 +1253,7 @@ { "current": {}, "datasource": { - "type": "postgres", + "type": "grafana-postgresql-datasource", "uid": "TeslaMate" }, "definition": "select base_url from settings limit 1;", @@ -1195,7 +1275,7 @@ }, { "current": { - "selected": true, + "selected": false, "text": "Flat", "value": "Flat" }, @@ -1249,6 +1329,6 @@ "timezone": "", "title": "Speed Rates", "uid": "jchmfu4SiQgWz", - "version": 10, + "version": 1, "weekStart": "" } \ No newline at end of file