Grafana vehicules : nuage km/kWh une trame par serie (plus de points a zero), compteur en km

This commit is contained in:
Tallagrand Thierry
2026-10-04 00:54:53 +02:00
parent cb4b0c0b78
commit d40e8f5cdc
2 changed files with 118 additions and 36 deletions

View File

@@ -605,7 +605,62 @@
"format": "table",
"rawQuery": true,
"editorMode": "code",
"rawSql": "WITH i AS (SELECT * FROM km_intervalle WHERE statut = 'valide'),\ncap AS (SELECT DISTINCT ON (vehicule) capacite_kwh AS c FROM releve_km\n WHERE capacite_kwh > 0 ORDER BY vehicule, ts DESC),\nx AS (SELECT round(kwh_consommes::numeric, 2)::float8 AS x, vehicule, km_parcourus::float8 AS km FROM i\n UNION ALL SELECT 0, NULL, NULL\n UNION ALL SELECT c::float8, NULL, NULL FROM cap)\nSELECT x AS \"kWh consommes\",\n CASE WHEN vehicule = 'JEEP' THEN km END AS \"JEEP\",\n CASE WHEN vehicule = 'VW' THEN km END AS \"VW\",\n CASE WHEN vehicule = 'ZERO' THEN km END AS \"ZERO\",\n round((x * (SELECT autonomie_ref_km / capacite_kwh FROM releve_km\n WHERE vehicule = 'JEEP' AND capacite_kwh > 0 AND autonomie_ref_km > 0 ORDER BY ts DESC LIMIT 1))::numeric, 1)::float8 AS \"Reference JEEP\",\n round((x * (SELECT autonomie_ref_km / capacite_kwh FROM releve_km\n WHERE vehicule = 'VW' AND capacite_kwh > 0 AND autonomie_ref_km > 0 ORDER BY ts DESC LIMIT 1))::numeric, 1)::float8 AS \"Reference VW\",\n round((x * (SELECT autonomie_ref_km / capacite_kwh FROM releve_km\n WHERE vehicule = 'ZERO' AND capacite_kwh > 0 AND autonomie_ref_km > 0 ORDER BY ts DESC LIMIT 1))::numeric, 1)::float8 AS \"Reference ZERO\"\nFROM x ORDER BY 1"
"rawSql": "SELECT x AS \"kWh ref JEEP\", round((x * autonomie_ref_km / capacite_kwh)::numeric, 1)::float8 AS \"Reference JEEP\"\nFROM (SELECT autonomie_ref_km, capacite_kwh FROM releve_km\n WHERE vehicule = 'JEEP' AND capacite_kwh > 0 AND autonomie_ref_km > 0\n ORDER BY ts DESC LIMIT 1) r,\n LATERAL (VALUES (0::float8), (r.capacite_kwh::float8)) v(x) ORDER BY 1"
},
{
"refId": "B",
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "evcs-pg"
},
"format": "table",
"rawQuery": true,
"editorMode": "code",
"rawSql": "SELECT x AS \"kWh ref VW\", round((x * autonomie_ref_km / capacite_kwh)::numeric, 1)::float8 AS \"Reference VW\"\nFROM (SELECT autonomie_ref_km, capacite_kwh FROM releve_km\n WHERE vehicule = 'VW' AND capacite_kwh > 0 AND autonomie_ref_km > 0\n ORDER BY ts DESC LIMIT 1) r,\n LATERAL (VALUES (0::float8), (r.capacite_kwh::float8)) v(x) ORDER BY 1"
},
{
"refId": "C",
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "evcs-pg"
},
"format": "table",
"rawQuery": true,
"editorMode": "code",
"rawSql": "SELECT x AS \"kWh ref ZERO\", round((x * autonomie_ref_km / capacite_kwh)::numeric, 1)::float8 AS \"Reference ZERO\"\nFROM (SELECT autonomie_ref_km, capacite_kwh FROM releve_km\n WHERE vehicule = 'ZERO' AND capacite_kwh > 0 AND autonomie_ref_km > 0\n ORDER BY ts DESC LIMIT 1) r,\n LATERAL (VALUES (0::float8), (r.capacite_kwh::float8)) v(x) ORDER BY 1"
},
{
"refId": "D",
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "evcs-pg"
},
"format": "table",
"rawQuery": true,
"editorMode": "code",
"rawSql": "SELECT round(kwh_consommes::numeric, 2)::float8 AS \"kWh JEEP\",\n km_parcourus::float8 AS \"JEEP\"\nFROM km_intervalle WHERE statut = 'valide' AND vehicule = 'JEEP' ORDER BY 1"
},
{
"refId": "E",
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "evcs-pg"
},
"format": "table",
"rawQuery": true,
"editorMode": "code",
"rawSql": "SELECT round(kwh_consommes::numeric, 2)::float8 AS \"kWh VW\",\n km_parcourus::float8 AS \"VW\"\nFROM km_intervalle WHERE statut = 'valide' AND vehicule = 'VW' ORDER BY 1"
},
{
"refId": "F",
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "evcs-pg"
},
"format": "table",
"rawQuery": true,
"editorMode": "code",
"rawSql": "SELECT round(kwh_consommes::numeric, 2)::float8 AS \"kWh ZERO\",\n km_parcourus::float8 AS \"ZERO\"\nFROM km_intervalle WHERE statut = 'valide' AND vehicule = 'ZERO' ORDER BY 1"
}
],
"fieldConfig": {
@@ -620,11 +675,23 @@
"fixed": 10
},
"pointShape": "circle",
"lineWidth": 1,
"lineWidth": 2,
"fillOpacity": 60
}
},
"overrides": [
{
"matcher": {
"id": "byRegexp",
"options": "^kWh .*"
},
"properties": [
{
"id": "unit",
"value": "kwatth"
}
]
},
{
"matcher": {
"id": "byName",
@@ -766,13 +833,13 @@
"frame": {
"matcher": {
"id": "byIndex",
"options": 0
"options": 3
}
},
"x": {
"matcher": {
"id": "byName",
"options": "kWh consommes"
"options": "kWh JEEP"
}
},
"y": {
@@ -786,13 +853,13 @@
"frame": {
"matcher": {
"id": "byIndex",
"options": 0
"options": 4
}
},
"x": {
"matcher": {
"id": "byName",
"options": "kWh consommes"
"options": "kWh VW"
}
},
"y": {
@@ -806,13 +873,13 @@
"frame": {
"matcher": {
"id": "byIndex",
"options": 0
"options": 5
}
},
"x": {
"matcher": {
"id": "byName",
"options": "kWh consommes"
"options": "kWh ZERO"
}
},
"y": {
@@ -832,7 +899,7 @@
"x": {
"matcher": {
"id": "byName",
"options": "kWh consommes"
"options": "kWh ref JEEP"
}
},
"y": {
@@ -846,13 +913,13 @@
"frame": {
"matcher": {
"id": "byIndex",
"options": 0
"options": 1
}
},
"x": {
"matcher": {
"id": "byName",
"options": "kWh consommes"
"options": "kWh ref VW"
}
},
"y": {
@@ -866,13 +933,13 @@
"frame": {
"matcher": {
"id": "byIndex",
"options": 0
"options": 2
}
},
"x": {
"matcher": {
"id": "byName",
"options": "kWh consommes"
"options": "kWh ref ZERO"
}
},
"y": {
@@ -1117,7 +1184,11 @@
"properties": [
{
"id": "unit",
"value": "lengthkm"
"value": "suffix: km"
},
{
"id": "decimals",
"value": 0
}
]
}