Skip to content

Commit e64fafa

Browse files
committed
Optimized queries in "Charging Costs Stats" dashboard
1 parent 51a6985 commit e64fafa

1 file changed

Lines changed: 39 additions & 39 deletions

File tree

dashboards/Charging Costs Stats.json

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"fiscalYearStartMonth": 0,
7373
"graphTooltip": 1,
7474
"id": null,
75-
"iteration": 1672676508324,
75+
"iteration": 1672724648351,
7676
"links": [
7777
{
7878
"icon": "dashboard",
@@ -218,6 +218,10 @@
218218
"pluginVersion": "8.5.6",
219219
"targets": [
220220
{
221+
"datasource": {
222+
"type": "postgres",
223+
"uid": "${DS_TESLAMATE}"
224+
},
221225
"format": "table",
222226
"group": [],
223227
"metricColumn": "none",
@@ -243,11 +247,7 @@
243247
"params": [],
244248
"type": "macro"
245249
}
246-
],
247-
"datasource": {
248-
"type": "postgres",
249-
"uid": "${DS_TESLAMATE}"
250-
}
250+
]
251251
}
252252
],
253253
"title": "Total charging cost",
@@ -331,11 +331,15 @@
331331
"pluginVersion": "8.5.6",
332332
"targets": [
333333
{
334-
"format": "time_series",
334+
"datasource": {
335+
"type": "postgres",
336+
"uid": "${DS_TESLAMATE}"
337+
},
338+
"format": "table",
335339
"group": [],
336340
"metricColumn": "none",
337341
"rawQuery": true,
338-
"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;",
342+
"rawSql": "SELECT convert_km((max(odometer) - min(odometer))::numeric, 'km') as \"distance_km\"\nFROM positions\nWHERE car_id = '1' AND date BETWEEN '2022-12-31T23:00:00Z' AND '2023-01-02T19:57:48.6Z'\nORDER BY 1;",
339343
"refId": "A",
340344
"select": [
341345
[
@@ -356,11 +360,7 @@
356360
"params": [],
357361
"type": "macro"
358362
}
359-
],
360-
"datasource": {
361-
"type": "postgres",
362-
"uid": "${DS_TESLAMATE}"
363-
}
363+
]
364364
}
365365
],
366366
"title": "$length_unit driven",
@@ -419,6 +419,10 @@
419419
"pluginVersion": "8.5.6",
420420
"targets": [
421421
{
422+
"datasource": {
423+
"type": "postgres",
424+
"uid": "${DS_TESLAMATE}"
425+
},
422426
"format": "table",
423427
"group": [],
424428
"metricColumn": "none",
@@ -444,11 +448,7 @@
444448
"params": [],
445449
"type": "macro"
446450
}
447-
],
448-
"datasource": {
449-
"type": "postgres",
450-
"uid": "${DS_TESLAMATE}"
451-
}
451+
]
452452
}
453453
],
454454
"title": "Number of charges",
@@ -507,6 +507,10 @@
507507
"pluginVersion": "8.5.6",
508508
"targets": [
509509
{
510+
"datasource": {
511+
"type": "postgres",
512+
"uid": "${DS_TESLAMATE}"
513+
},
510514
"format": "table",
511515
"group": [],
512516
"metricColumn": "none",
@@ -532,11 +536,7 @@
532536
"params": [],
533537
"type": "macro"
534538
}
535-
],
536-
"datasource": {
537-
"type": "postgres",
538-
"uid": "${DS_TESLAMATE}"
539-
}
539+
]
540540
}
541541
],
542542
"title": "Charged in total",
@@ -735,6 +735,10 @@
735735
"pluginVersion": "8.5.6",
736736
"targets": [
737737
{
738+
"datasource": {
739+
"type": "postgres",
740+
"uid": "${DS_TESLAMATE}"
741+
},
738742
"format": "time_series",
739743
"group": [],
740744
"metricColumn": "none",
@@ -760,11 +764,7 @@
760764
"params": [],
761765
"type": "macro"
762766
}
763-
],
764-
"datasource": {
765-
"type": "postgres",
766-
"uid": "${DS_TESLAMATE}"
767-
}
767+
]
768768
}
769769
],
770770
"title": "AC/DC – Energy added",
@@ -817,6 +817,10 @@
817817
"pluginVersion": "8.5.6",
818818
"targets": [
819819
{
820+
"datasource": {
821+
"type": "postgres",
822+
"uid": "${DS_TESLAMATE}"
823+
},
820824
"format": "table",
821825
"group": [],
822826
"metricColumn": "none",
@@ -842,11 +846,7 @@
842846
"params": [],
843847
"type": "macro"
844848
}
845-
],
846-
"datasource": {
847-
"type": "postgres",
848-
"uid": "${DS_TESLAMATE}"
849-
}
849+
]
850850
}
851851
],
852852
"title": "Cost per 100 $length_unit",
@@ -901,6 +901,10 @@
901901
"pluginVersion": "8.5.6",
902902
"targets": [
903903
{
904+
"datasource": {
905+
"type": "postgres",
906+
"uid": "${DS_TESLAMATE}"
907+
},
904908
"format": "table",
905909
"group": [],
906910
"metricColumn": "none",
@@ -916,11 +920,7 @@
916920
"params": [],
917921
"type": "macro"
918922
}
919-
],
920-
"datasource": {
921-
"type": "postgres",
922-
"uid": "${DS_TESLAMATE}"
923-
}
923+
]
924924
}
925925
],
926926
"title": "Average cost per kWh",
@@ -3135,6 +3135,6 @@
31353135
"timezone": "browser",
31363136
"title": "Charging Costs Stats",
31373137
"uid": "LdwdLXt4z",
3138-
"version": 1,
3138+
"version": 2,
31393139
"weekStart": ""
31403140
}

0 commit comments

Comments
 (0)