feat: parse departure to be more useful
This commit is contained in:
parent
c52ddc2e09
commit
62b816496c
@ -4,10 +4,9 @@ WITH exceptions AS (
|
|||||||
WHERE
|
WHERE
|
||||||
calendar_dates.date = date(:time)
|
calendar_dates.date = date(:time)
|
||||||
)
|
)
|
||||||
SELECT timediff(
|
SELECT
|
||||||
stop_times.departure,
|
unixepoch(stop_times.departure) -
|
||||||
time(:time)
|
unixepoch(time(:time)) as wait,
|
||||||
) as wait,
|
|
||||||
routes.*,
|
routes.*,
|
||||||
trips.headsign,
|
trips.headsign,
|
||||||
trips.short_name as trip_name,
|
trips.short_name as trip_name,
|
||||||
|
|||||||
@ -1,34 +1,57 @@
|
|||||||
(local {: client : query} (require :sqlite))
|
(local {: client : query} (require :sqlite))
|
||||||
(local {: encode-wkb} (require :wkb))
|
(local {: encode-wkb} (require :wkb))
|
||||||
(local {: dofile} (require :fennel))
|
(local {: dofile : compile} (require :fennel))
|
||||||
|
|
||||||
(local dev-config (dofile :config.fnl))
|
(local dev-config (dofile :config.fnl))
|
||||||
|
|
||||||
(fn now []
|
(fn now []
|
||||||
(os.date :%Y-%m-%dT%T (os.time)))
|
(os.date :%Y-%m-%dT%T (os.time)))
|
||||||
|
(fn parse-sqltime [sqltime]
|
||||||
|
(let [(hour min sec)
|
||||||
|
(string.match sqltime "(%d%d):(%d%d):(%d%d)")]
|
||||||
|
{:hour (tonumber hour)
|
||||||
|
:min (tonumber min)
|
||||||
|
:sec (tonumber sec)}))
|
||||||
|
|
||||||
(local types {:0 :tram
|
(local types {0 :tram
|
||||||
:1 :metro
|
1 :metro
|
||||||
:2 :train
|
2 :train
|
||||||
:3 :bus
|
3 :bus
|
||||||
:4 :boat
|
4 :boat
|
||||||
:5 :cable-tram
|
5 :cable-tram
|
||||||
:6 :aerial-tram
|
6 :aerial-tram
|
||||||
:7 :funicular
|
7 :funicular
|
||||||
:11 :trolleybus
|
11 :trolleybus
|
||||||
:12 :monorail})
|
12 :monorail})
|
||||||
|
|
||||||
(fn parse-departure [{: color :text_color text-color}]
|
(fn parse-departure [{: color
|
||||||
|
: arrival
|
||||||
|
: wait
|
||||||
|
: short_name
|
||||||
|
: long_name
|
||||||
|
: headsign
|
||||||
|
: description
|
||||||
|
: type
|
||||||
|
:text_color text-color
|
||||||
|
&as raw}]
|
||||||
(fn color->html [?color]
|
(fn color->html [?color]
|
||||||
(and ?color (string.format :#%x color))))
|
(and ?color (string.format :#%06x color)))
|
||||||
|
{: raw
|
||||||
|
:type (. types type)
|
||||||
|
:name short_name
|
||||||
|
: headsign
|
||||||
|
: wait
|
||||||
|
:arrival (parse-sqltime arrival)
|
||||||
|
:color (color->html color)
|
||||||
|
:text-color (color->html text-color)})
|
||||||
|
|
||||||
(with-open [client (client)]
|
(fn get-departures [client location]
|
||||||
(let [q (partial query client)]
|
(let [q (partial query client)]
|
||||||
(icollect
|
(icollect
|
||||||
[{:short_name name : id &as stop}
|
[{:short_name name : id &as stop}
|
||||||
(q
|
(q
|
||||||
:find-stops
|
:find-stops
|
||||||
{:searchgeom (encode-wkb dev-config.dev-location)})]
|
{:searchgeom (encode-wkb location)})]
|
||||||
{: stop
|
{: stop
|
||||||
:departures
|
:departures
|
||||||
(icollect [departure
|
(icollect [departure
|
||||||
@ -36,4 +59,7 @@
|
|||||||
:time
|
:time
|
||||||
"2026-01-12T07:00:00"
|
"2026-01-12T07:00:00"
|
||||||
:stop id})]
|
:stop id})]
|
||||||
departure)})))
|
(parse-departure departure))})))
|
||||||
|
|
||||||
|
(with-open [client (client)]
|
||||||
|
(get-departures client dev-config.dev-location))
|
||||||
|
|||||||
@ -29,7 +29,8 @@
|
|||||||
mask)))
|
mask)))
|
||||||
|
|
||||||
(fn normalize-time [value]
|
(fn normalize-time [value]
|
||||||
(let [(hour min sec) (string.match value "(%d+):(%d+):(%d+)")]
|
(let [(hour min sec)
|
||||||
|
(string.match value "(%d+):(%d+):(%d+)")]
|
||||||
(string.format "'%02d:%02d:%02d'"
|
(string.format "'%02d:%02d:%02d'"
|
||||||
(tonumber hour)
|
(tonumber hour)
|
||||||
(tonumber min)
|
(tonumber min)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user