|
1816 | 1816 | }, |
1817 | 1817 | "gridPos": { |
1818 | 1818 | "h": 3, |
1819 | | - "w": 6, |
| 1819 | + "w": 3, |
1820 | 1820 | "x": 0, |
1821 | 1821 | "y": 28 |
1822 | 1822 | }, |
|
1898 | 1898 | }, |
1899 | 1899 | "gridPos": { |
1900 | 1900 | "h": 3, |
1901 | | - "w": 6, |
1902 | | - "x": 6, |
| 1901 | + "w": 3, |
| 1902 | + "x": 3, |
1903 | 1903 | "y": 28 |
1904 | 1904 | }, |
1905 | 1905 | "id": 20, |
|
2389 | 2389 | ], |
2390 | 2390 | "title": "Ø Speed", |
2391 | 2391 | "type": "stat" |
| 2392 | + }, |
| 2393 | + { |
| 2394 | + "datasource": { |
| 2395 | + "type": "grafana-postgresql-datasource", |
| 2396 | + "uid": "TeslaMate" |
| 2397 | + }, |
| 2398 | + "description": "Estimated trip cost. Cost/kWh uses the average of charges that ended within 24 h before this drive; if none have cost data, falls back to the single most recent charge before the trip.", |
| 2399 | + "fieldConfig": { |
| 2400 | + "defaults": { |
| 2401 | + "decimals": 2, |
| 2402 | + "mappings": [ |
| 2403 | + { |
| 2404 | + "options": { |
| 2405 | + "match": "null", |
| 2406 | + "result": { |
| 2407 | + "text": "N/A" |
| 2408 | + } |
| 2409 | + }, |
| 2410 | + "type": "special" |
| 2411 | + } |
| 2412 | + ], |
| 2413 | + "thresholds": { |
| 2414 | + "mode": "absolute", |
| 2415 | + "steps": [ |
| 2416 | + { |
| 2417 | + "color": "super-light-blue", |
| 2418 | + "value": 0 |
| 2419 | + } |
| 2420 | + ] |
| 2421 | + }, |
| 2422 | + "unit": "none" |
| 2423 | + }, |
| 2424 | + "overrides": [] |
| 2425 | + }, |
| 2426 | + "gridPos": { |
| 2427 | + "h": 3, |
| 2428 | + "w": 3, |
| 2429 | + "x": 6, |
| 2430 | + "y": 28 |
| 2431 | + }, |
| 2432 | + "id": 41, |
| 2433 | + "maxDataPoints": 100, |
| 2434 | + "options": { |
| 2435 | + "colorMode": "value", |
| 2436 | + "graphMode": "none", |
| 2437 | + "justifyMode": "center", |
| 2438 | + "orientation": "auto", |
| 2439 | + "percentChangeColorMode": "standard", |
| 2440 | + "reduceOptions": { |
| 2441 | + "calcs": [ |
| 2442 | + "lastNotNull" |
| 2443 | + ], |
| 2444 | + "fields": "/.*/", |
| 2445 | + "values": false |
| 2446 | + }, |
| 2447 | + "showPercentChange": false, |
| 2448 | + "textMode": "auto", |
| 2449 | + "wideLayout": true |
| 2450 | + }, |
| 2451 | + "pluginVersion": "12.4.0", |
| 2452 | + "targets": [ |
| 2453 | + { |
| 2454 | + "datasource": { |
| 2455 | + "type": "grafana-postgresql-datasource", |
| 2456 | + "uid": "TeslaMate" |
| 2457 | + }, |
| 2458 | + "editorMode": "code", |
| 2459 | + "format": "table", |
| 2460 | + "rawQuery": true, |
| 2461 | + "rawSql": "WITH drive AS (\n SELECT\n d.start_date,\n (start_${preferred_range}_range_km - end_${preferred_range}_range_km) * car.efficiency AS energy_kwh\n FROM drives d\n JOIN cars car ON car.id = d.car_id\n WHERE d.id = $drive_id\n),\nrecent_cost AS (\n SELECT sum(cp.cost) / NULLIF(sum(cp.charge_energy_added), 0) AS cost_per_kwh\n FROM charging_processes cp\n CROSS JOIN drive\n WHERE cp.car_id = $car_id\n AND cp.cost IS NOT NULL AND cp.charge_energy_added > 0\n AND cp.end_date <= drive.start_date\n AND cp.end_date >= drive.start_date - INTERVAL '24 hours'\n),\nlast_charge_cost AS (\n SELECT cp.cost / NULLIF(cp.charge_energy_added, 0) AS cost_per_kwh\n FROM charging_processes cp\n CROSS JOIN drive\n WHERE cp.car_id = $car_id\n AND cp.cost IS NOT NULL AND cp.charge_energy_added > 0\n AND cp.end_date <= drive.start_date\n ORDER BY cp.end_date DESC\n LIMIT 1\n),\neffective_cost AS (\n SELECT COALESCE(recent_cost.cost_per_kwh, last_charge_cost.cost_per_kwh) AS cost_per_kwh\n FROM last_charge_cost LEFT JOIN recent_cost ON true\n)\nSELECT ROUND((drive.energy_kwh * effective_cost.cost_per_kwh)::numeric, 2) AS \"Trip Cost\"\nFROM drive CROSS JOIN effective_cost", |
| 2462 | + "refId": "A", |
| 2463 | + "sql": { |
| 2464 | + "columns": [ |
| 2465 | + { |
| 2466 | + "parameters": [], |
| 2467 | + "type": "function" |
| 2468 | + } |
| 2469 | + ], |
| 2470 | + "groupBy": [ |
| 2471 | + { |
| 2472 | + "property": { |
| 2473 | + "type": "string" |
| 2474 | + }, |
| 2475 | + "type": "groupBy" |
| 2476 | + } |
| 2477 | + ], |
| 2478 | + "limit": 50 |
| 2479 | + } |
| 2480 | + } |
| 2481 | + ], |
| 2482 | + "title": "Trip Cost (est.)", |
| 2483 | + "type": "stat" |
| 2484 | + }, |
| 2485 | + { |
| 2486 | + "datasource": { |
| 2487 | + "type": "grafana-postgresql-datasource", |
| 2488 | + "uid": "TeslaMate" |
| 2489 | + }, |
| 2490 | + "description": "Estimated cost per 100 km/mi. Cost/kWh uses the average of charges that ended within 24 h before this drive; if none have cost data, falls back to the single most recent charge before the trip.", |
| 2491 | + "fieldConfig": { |
| 2492 | + "defaults": { |
| 2493 | + "decimals": 2, |
| 2494 | + "mappings": [ |
| 2495 | + { |
| 2496 | + "options": { |
| 2497 | + "match": "null", |
| 2498 | + "result": { |
| 2499 | + "text": "N/A" |
| 2500 | + } |
| 2501 | + }, |
| 2502 | + "type": "special" |
| 2503 | + } |
| 2504 | + ], |
| 2505 | + "thresholds": { |
| 2506 | + "mode": "absolute", |
| 2507 | + "steps": [ |
| 2508 | + { |
| 2509 | + "color": "super-light-blue", |
| 2510 | + "value": 0 |
| 2511 | + } |
| 2512 | + ] |
| 2513 | + }, |
| 2514 | + "unit": "none" |
| 2515 | + }, |
| 2516 | + "overrides": [] |
| 2517 | + }, |
| 2518 | + "gridPos": { |
| 2519 | + "h": 3, |
| 2520 | + "w": 3, |
| 2521 | + "x": 9, |
| 2522 | + "y": 28 |
| 2523 | + }, |
| 2524 | + "id": 42, |
| 2525 | + "maxDataPoints": 100, |
| 2526 | + "options": { |
| 2527 | + "colorMode": "value", |
| 2528 | + "graphMode": "none", |
| 2529 | + "justifyMode": "center", |
| 2530 | + "orientation": "auto", |
| 2531 | + "percentChangeColorMode": "standard", |
| 2532 | + "reduceOptions": { |
| 2533 | + "calcs": [ |
| 2534 | + "lastNotNull" |
| 2535 | + ], |
| 2536 | + "fields": "/.*/", |
| 2537 | + "values": false |
| 2538 | + }, |
| 2539 | + "showPercentChange": false, |
| 2540 | + "textMode": "auto", |
| 2541 | + "wideLayout": true |
| 2542 | + }, |
| 2543 | + "pluginVersion": "12.4.0", |
| 2544 | + "targets": [ |
| 2545 | + { |
| 2546 | + "datasource": { |
| 2547 | + "type": "grafana-postgresql-datasource", |
| 2548 | + "uid": "TeslaMate" |
| 2549 | + }, |
| 2550 | + "editorMode": "code", |
| 2551 | + "format": "table", |
| 2552 | + "rawQuery": true, |
| 2553 | + "rawSql": "WITH drive AS (\n SELECT\n d.start_date,\n (start_${preferred_range}_range_km - end_${preferred_range}_range_km) * car.efficiency AS energy_kwh,\n convert_km(d.distance::numeric, '$length_unit') AS dist\n FROM drives d\n JOIN cars car ON car.id = d.car_id\n WHERE d.id = $drive_id\n),\nrecent_cost AS (\n SELECT sum(cp.cost) / NULLIF(sum(cp.charge_energy_added), 0) AS cost_per_kwh\n FROM charging_processes cp\n CROSS JOIN drive\n WHERE cp.car_id = $car_id\n AND cp.cost IS NOT NULL AND cp.charge_energy_added > 0\n AND cp.end_date <= drive.start_date\n AND cp.end_date >= drive.start_date - INTERVAL '24 hours'\n),\nlast_charge_cost AS (\n SELECT cp.cost / NULLIF(cp.charge_energy_added, 0) AS cost_per_kwh\n FROM charging_processes cp\n CROSS JOIN drive\n WHERE cp.car_id = $car_id\n AND cp.cost IS NOT NULL AND cp.charge_energy_added > 0\n AND cp.end_date <= drive.start_date\n ORDER BY cp.end_date DESC\n LIMIT 1\n),\neffective_cost AS (\n SELECT COALESCE(recent_cost.cost_per_kwh, last_charge_cost.cost_per_kwh) AS cost_per_kwh\n FROM last_charge_cost LEFT JOIN recent_cost ON true\n)\nSELECT ROUND((drive.energy_kwh / NULLIF(drive.dist, 0) * 100 * effective_cost.cost_per_kwh)::numeric, 2) AS \"Ø Cost / 100 $length_unit\"\nFROM drive CROSS JOIN effective_cost", |
| 2554 | + "refId": "A", |
| 2555 | + "sql": { |
| 2556 | + "columns": [ |
| 2557 | + { |
| 2558 | + "parameters": [], |
| 2559 | + "type": "function" |
| 2560 | + } |
| 2561 | + ], |
| 2562 | + "groupBy": [ |
| 2563 | + { |
| 2564 | + "property": { |
| 2565 | + "type": "string" |
| 2566 | + }, |
| 2567 | + "type": "groupBy" |
| 2568 | + } |
| 2569 | + ], |
| 2570 | + "limit": 50 |
| 2571 | + } |
| 2572 | + } |
| 2573 | + ], |
| 2574 | + "title": "Ø Cost / 100 $length_unit", |
| 2575 | + "type": "stat" |
2392 | 2576 | } |
2393 | 2577 | ], |
2394 | 2578 | "preload": false, |
|
0 commit comments