Created
June 2, 2022 08:17
-
-
Save ptz0n/f56e56ec77a45310c6eba1c3159c06ed to your computer and use it in GitHub Desktop.
Teslamate triplog for Sweden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH data AS ( | |
SELECT | |
drives.id as drive_id, | |
round(extract(epoch FROM start_date)) * 1000 AS start_date_ts, | |
round(extract(epoch FROM end_date)) * 1000 AS end_date_ts, | |
start_km, | |
end_km, | |
CONCAT_WS(', ', CONCAT_WS(' ', start_address.road, start_address.house_number), CONCAT_WS(' ', start_address.postcode, start_address.city)) AS start_address, | |
CONCAT_WS(', ', CONCAT_WS(' ', end_address.road, end_address.house_number), CONCAT_WS(' ', end_address.postcode, end_address.city)) AS end_address, | |
duration_min, | |
distance | |
FROM drives | |
LEFT JOIN addresses start_address ON start_address_id = start_address.id | |
LEFT JOIN addresses end_address ON end_address_id = end_address.id | |
LEFT JOIN cars car ON car.id = drives.car_id | |
WHERE $__timeFilter(start_date) AND drives.car_id = $car_id | |
ORDER BY drive_id DESC | |
) | |
SELECT | |
drive_id, | |
start_date_ts, | |
convert_km(start_km::numeric, '$length_unit') as start_$length_unit, | |
start_address, | |
end_date_ts, | |
convert_km(end_km::numeric, '$length_unit') as end_$length_unit, | |
end_address, | |
duration_min, | |
convert_km(distance::numeric, '$length_unit') AS distance_$length_unit | |
FROM data; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment