{
    "annotations": {
        "list": [
            {
                "$$hashKey": "object:24",
                "builtIn": 1,
                "datasource": "-- Grafana --",
                "enable": true,
                "hide": true,
                "iconColor": "rgba(0, 211, 255, 1)",
                "name": "Annotations & Alerts",
                "type": "dashboard"
            }
        ]
    },
    "editable": true,
    "gnetId": null,
    "graphTooltip": 0,
    "iteration": 1602596446244,
    "links": [
        {
            "icon": "dashboard",
            "tags": [],
            "title": "TeslaMate",
            "tooltip": "",
            "type": "link",
            "url": "[[base_url:raw]]"
        },
        {
            "asDropdown": true,
            "icon": "external link",
            "tags": ["tesla"],
            "title": "Dashboards",
            "type": "dashboards"
        }
    ],
    "panels": [
        {
            "collapsed": false,
            "datasource": "TeslaMate",
            "gridPos": {
                "h": 1,
                "w": 24,
                "x": 0,
                "y": 0
            },
            "id": 4,
            "panels": [],
            "repeat": "car_id",
            "scopedVars": {
                "car_id": {
                    "selected": false,
                    "text": "1",
                    "value": "1"
                }
            },
            "title": "$car_id",
            "type": "row"
        },
        {
            "datasource": "TeslaMate",
            "fieldConfig": {
                "defaults": {
                    "custom": {
                        "align": null,
                        "filterable": false
                    },
                    "mappings": [],
                    "thresholds": {
                        "mode": "absolute",
                        "steps": [
                            {
                                "color": "green",
                                "value": null
                            },
                            {
                                "color": "red",
                                "value": 80
                            }
                        ]
                    }
                },
                "overrides": [
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "drive_id"
                        },
                        "properties": [
                            {
                                "id": "custom.width",
                                "value": 75
                            },
                            {
                                "id": "unit",
                                "value": "none"
                            },
                            {
                                "id": "displayName",
                                "value": "ID"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byRegexp",
                            "options": ".*_ts"
                        },
                        "properties": [
                            {
                                "id": "unit",
                                "value": "dateTimeAsLocal"
                            },
                            {
                                "id": "custom.width",
                                "value": 200
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byRegexp",
                            "options": ".*_km"
                        },
                        "properties": [
                            {
                                "id": "unit",
                                "value": "km"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byRegexp",
                            "options": ".*_mi"
                        },
                        "properties": [
                            {
                                "id": "unit",
                                "value": "mi"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "start_date_ts"
                        },
                        "properties": [
                            {
                                "id": "displayName",
                                "value": "Start Time"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byRegexp",
                            "options": "start_(km|mi)"
                        },
                        "properties": [
                            {
                                "id": "custom.width",
                                "value": 120
                            },
                            {
                                "id": "displayName",
                                "value": "Start Odometer"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byRegexp",
                            "options": "end_(km|mi)"
                        },
                        "properties": [
                            {
                                "id": "custom.width",
                                "value": 120
                            },
                            {
                                "id": "displayName",
                                "value": "End Odometer"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "end_date_ts"
                        },
                        "properties": [
                            {
                                "id": "displayName",
                                "value": "End Time"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byRegexp",
                            "options": "(start|end)_address"
                        },
                        "properties": [
                            {
                                "id": "custom.width"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "duration_min"
                        },
                        "properties": [
                            {
                                "id": "unit",
                                "value": "m"
                            },
                            {
                                "id": "displayName",
                                "value": "Duration"
                            },
                            {
                                "id": "custom.width",
                                "value": 85
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "distance_km"
                        },
                        "properties": [
                            {
                                "id": "custom.width",
                                "value": 90
                            },
                            {
                                "id": "displayName",
                                "value": "km"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "distance_mi"
                        },
                        "properties": [
                            {
                                "id": "custom.width",
                                "value": 90
                            },
                            {
                                "id": "displayName",
                                "value": "mi"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "start_address"
                        },
                        "properties": [
                            {
                                "id": "displayName",
                                "value": "Start Address"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "end_address"
                        },
                        "properties": [
                            {
                                "id": "displayName",
                                "value": "End Address"
                            }
                        ]
                    }
                ]
            },
            "gridPos": {
                "h": 24,
                "w": 24,
                "x": 0,
                "y": 1
            },
            "id": 2,
            "links": [],
            "options": {
                "showHeader": true,
                "sortBy": [
                    {
                        "desc": true,
                        "displayName": "Start Time"
                    }
                ]
            },
            "pluginVersion": "7.2.2",
            "repeat": "car_id",
            "scopedVars": {
                "car_id": {
                    "selected": false,
                    "text": "1",
                    "value": "1"
                }
            },
            "targets": [
                {
                    "alias": "",
                    "format": "table",
                    "group": [],
                    "metricColumn": "none",
                    "rawQuery": true,
                    "rawSql": "WITH data AS (\n  SELECT\n    drives.id as drive_id,\n    round(extract(epoch FROM start_date)) * 1000 AS start_date_ts,\n    round(extract(epoch FROM end_date)) * 1000 AS end_date_ts,\n    start_km,\n    end_km,\n    CONCAT_WS(', ', CONCAT_WS(' ', start_address.road, start_address.house_number), start_address.city) AS start_address,\n    CONCAT_WS(', ', CONCAT_WS(' ', end_address.road, end_address.house_number), end_address.city) AS end_address,\n    duration_min,\n    distance\n  FROM drives\n  LEFT JOIN addresses start_address ON start_address_id = start_address.id\n  LEFT JOIN addresses end_address ON end_address_id = end_address.id\n  LEFT JOIN cars car ON car.id = drives.car_id\n  WHERE $__timeFilter(start_date) AND drives.car_id = $car_id\n  ORDER BY drive_id DESC\n)\nSELECT\n    drive_id,\n    start_date_ts,\n    convert_km(start_km::numeric, '$length_unit') as start_$length_unit,\n    start_address,\n    end_date_ts,\n    convert_km(end_km::numeric, '$length_unit') as end_$length_unit,\n    end_address,\n    duration_min,\n    convert_km(distance::numeric, '$length_unit') AS distance_$length_unit\nFROM data;",
                    "refId": "A",
                    "select": [
                        [
                            {
                                "params": ["value"],
                                "type": "column"
                            }
                        ]
                    ],
                    "timeColumn": "time",
                    "where": [
                        {
                            "name": "$__timeFilter",
                            "params": [],
                            "type": "macro"
                        }
                    ]
                }
            ],
            "title": "Drive",
            "type": "table"
        }
    ],
    "schemaVersion": 26,
    "style": "dark",
    "tags": [],
    "templating": {
        "list": [
            {
                "allValue": null,
                "current": {
                    "selected": false,
                    "text": "All",
                    "value": "$__all"
                },
                "datasource": "TeslaMate",
                "definition": "SELECT name AS __text, id AS __value FROM cars ORDER BY display_priority ASC, name 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;",
                "refresh": 1,
                "regex": "",
                "skipUrlSync": false,
                "sort": 0,
                "tagValuesQuery": "",
                "tags": [],
                "tagsQuery": "",
                "type": "query",
                "useTags": false
            },
            {
                "allValue": null,
                "current": {
                    "selected": false,
                    "text": "C",
                    "value": "C"
                },
                "datasource": "TeslaMate",
                "definition": "select unit_of_temperature from settings limit 1;",
                "hide": 2,
                "includeAll": false,
                "label": "temperature unit",
                "multi": false,
                "name": "temp_unit",
                "options": [],
                "query": "select unit_of_temperature from settings limit 1;",
                "refresh": 1,
                "regex": "",
                "skipUrlSync": false,
                "sort": 0,
                "tagValuesQuery": "",
                "tags": [],
                "tagsQuery": "",
                "type": "query",
                "useTags": false
            },
            {
                "allValue": null,
                "current": {
                    "selected": false,
                    "text": "km",
                    "value": "km"
                },
                "datasource": "TeslaMate",
                "definition": "select unit_of_length from settings limit 1;",
                "hide": 2,
                "includeAll": false,
                "label": "length unit",
                "multi": false,
                "name": "length_unit",
                "options": [],
                "query": "select unit_of_length from settings limit 1;",
                "refresh": 1,
                "regex": "",
                "skipUrlSync": false,
                "sort": 0,
                "tagValuesQuery": "",
                "tags": [],
                "tagsQuery": "",
                "type": "query",
                "useTags": false
            },
            {
                "allValue": null,
                "current": {
                    "selected": false,
                    "text": "rated",
                    "value": "rated"
                },
                "datasource": "TeslaMate",
                "definition": "select preferred_range from settings limit 1;",
                "hide": 2,
                "includeAll": false,
                "label": "",
                "multi": false,
                "name": "preferred_range",
                "options": [],
                "query": "select preferred_range from settings limit 1;",
                "refresh": 1,
                "regex": "",
                "skipUrlSync": false,
                "sort": 0,
                "tagValuesQuery": "",
                "tags": [],
                "tagsQuery": "",
                "type": "query",
                "useTags": false
            },
            {
                "allValue": null,
                "current": {
                    "selected": false,
                    "value": null
                },
                "datasource": "TeslaMate",
                "definition": "select base_url from settings limit 1;",
                "hide": 2,
                "includeAll": false,
                "label": "",
                "multi": false,
                "name": "base_url",
                "options": [],
                "query": "select base_url from settings limit 1;",
                "refresh": 1,
                "regex": "",
                "skipUrlSync": false,
                "sort": 0,
                "tagValuesQuery": "",
                "tags": [],
                "tagsQuery": "",
                "type": "query",
                "useTags": false
            }
        ]
    },
    "time": {
        "from": "now/y",
        "to": "now/y"
    },
    "timepicker": {
        "refresh_intervals": [
            "5s",
            "10s",
            "30s",
            "1m",
            "5m",
            "15m",
            "30m",
            "1h",
            "2h",
            "1d"
        ],
        "time_options": [
            "5m",
            "15m",
            "1h",
            "6h",
            "12h",
            "24h",
            "2d",
            "7d",
            "30d"
        ]
    },
    "timezone": "",
    "title": "Drives - Dutch tax",
    "uid": "lBIoQIggk",
    "version": 1
}
