Skip to content

Commit

Permalink
Improve performance in queries
Browse files Browse the repository at this point in the history
  • Loading branch information
jheredianet committed Aug 20, 2024
1 parent 436f16b commit 64ea0de
Showing 1 changed file with 42 additions and 13 deletions.
55 changes: 42 additions & 13 deletions grafana/dashboards/drive-stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"version": "11.0.1"
"version": "11.1.0"
},
{
"type": "datasource",
Expand All @@ -30,11 +30,11 @@
"list": [
{
"builtIn": 1,
"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",
"datasource": {
"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,
"iconColor": "rgba(0, 211, 255, 1)",
Expand Down Expand Up @@ -106,6 +106,7 @@
"graphMode": "area",
"justifyMode": "auto",
"orientation": "horizontal",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"sum"
Expand All @@ -117,7 +118,7 @@
"textMode": "value",
"wideLayout": true
},
"pluginVersion": "11.0.1",
"pluginVersion": "11.1.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -219,6 +220,7 @@
"graphMode": "area",
"justifyMode": "auto",
"orientation": "horizontal",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"sum"
Expand All @@ -230,18 +232,19 @@
"textMode": "value",
"wideLayout": true
},
"pluginVersion": "11.0.1",
"pluginVersion": "11.1.0",
"targets": [
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"editorMode": "code",
"format": "time_series",
"group": [],
"metricColumn": "none",
"rawQuery": true,
"rawSql": "WITH since as (\n\tSELECT date FROM positions\n\tWHERE car_id = $car_id\n\tORDER BY date ASC\n\tLIMIT 1\n),\nactual AS (\n\tSELECT\n\t\tdate_trunc('day', date)::date AS date,\n\t\tmax(odometer) - min(odometer) AS distance\n\tFROM positions\n\tWHERE car_id = $car_id\n\tGROUP BY 1\n),\nbase_line AS (\n\tSELECT date_trunc('day', dd)::date AS date\n FROM generate_series((select date from since) , now(), '1 day'::interval) dd\n)\nSELECT \n $__time(base_line.date), \n convert_km(COALESCE(distance, 0)::numeric, '$length_unit') as \"distance_$length_unit\"\nFROM base_line\nLEFT JOIN actual ON actual.date = base_line.date\nWHERE $__timeFilter(base_line.date)\nORDER BY 1;",
"rawSql": "SELECT \n DATE(start_date) AS \"time\",\n SUM(convert_km((end_km - start_km)::numeric, '$length_unit')) AS \"distance_$length_unit\"\nFROM drives \nWHERE car_id = $car_id\n\tAND $__timeFilter(start_date)\nGROUP BY DATE(start_date)\nORDER BY DATE(start_date);\n\n",
"refId": "A",
"select": [
[
Expand All @@ -253,6 +256,23 @@
}
]
],
"sql": {
"columns": [
{
"parameters": [],
"type": "function"
}
],
"groupBy": [
{
"property": {
"type": "string"
},
"type": "groupBy"
}
],
"limit": 50
},
"table": "addresses",
"timeColumn": "inserted_at",
"timeColumnType": "timestamp",
Expand Down Expand Up @@ -307,6 +327,7 @@
"graphMode": "area",
"justifyMode": "auto",
"orientation": "horizontal",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"sum"
Expand All @@ -318,7 +339,7 @@
"textMode": "value",
"wideLayout": true
},
"pluginVersion": "11.0.1",
"pluginVersion": "11.1.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -430,6 +451,7 @@
"graphMode": "none",
"justifyMode": "auto",
"orientation": "horizontal",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"mean"
Expand All @@ -441,7 +463,7 @@
"textMode": "value",
"wideLayout": true
},
"pluginVersion": "11.0.1",
"pluginVersion": "11.1.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -543,6 +565,7 @@
"graphMode": "none",
"justifyMode": "auto",
"orientation": "horizontal",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"mean"
Expand All @@ -554,7 +577,7 @@
"textMode": "value",
"wideLayout": true
},
"pluginVersion": "11.0.1",
"pluginVersion": "11.1.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -631,6 +654,7 @@
"graphMode": "none",
"justifyMode": "auto",
"orientation": "horizontal",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"mean"
Expand All @@ -642,7 +666,7 @@
"textMode": "value",
"wideLayout": true
},
"pluginVersion": "11.0.1",
"pluginVersion": "11.1.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -744,6 +768,7 @@
"graphMode": "none",
"justifyMode": "auto",
"orientation": "horizontal",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"mean"
Expand All @@ -755,7 +780,7 @@
"textMode": "value",
"wideLayout": true
},
"pluginVersion": "11.0.1",
"pluginVersion": "11.1.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -857,6 +882,7 @@
"graphMode": "none",
"justifyMode": "auto",
"orientation": "horizontal",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"mean"
Expand All @@ -868,7 +894,7 @@
"textMode": "value",
"wideLayout": true
},
"pluginVersion": "11.0.1",
"pluginVersion": "11.1.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -961,7 +987,7 @@
"sizing": "auto",
"valueMode": "color"
},
"pluginVersion": "11.0.1",
"pluginVersion": "11.1.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -1139,6 +1165,10 @@
},
{
"current": {},
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"definition": "WITH splits AS (\n SELECT unnest(string_to_array('$exclude', ', ')) AS part\n),\nsplit_strings AS (\n\tSELECT COALESCE(part, ' ') AS part\n\tFROM (VALUES (NULL)) AS v(dummy)\n\tLEFT JOIN splits ON TRUE\n),\nexclude_string AS (\n\tSELECT array_to_string(array_agg('''%' || part || '%'''), ', ') AS formatted_string\n\tFROM split_strings\n)\nSELECT '(ARRAY[' || formatted_string || '])' FROM exclude_string",
"hide": 2,
"includeAll": false,
Expand All @@ -1158,7 +1188,6 @@
"from": "now-1y",
"to": "now"
},
"timeRangeUpdatedDuringEditOrView": false,
"timepicker": {
"hidden": false,
"refresh_intervals": [
Expand Down

0 comments on commit 64ea0de

Please sign in to comment.