diff --git a/deps.fnl b/deps.fnl index 06f1c51..9c2af7a 100644 --- a/deps.fnl +++ b/deps.fnl @@ -1,26 +1,29 @@ -{:project-name "gtf-server" - :project-version "0.1.0" - - :deps {:ftcsv {:type :rock - :version :1.5.0} - :lsqlite3 {:type :rock - :version :0.9.6} - :io.github.luafun/luafun - {:type :git - :sha "12837884993a3d25bda8aaf835bb9d79132fcbc6" - :paths {:lua [ "?.lua" ]}}} - - :paths {:fennel ["src/?.fnl"] - :macro ["src/?.fnlm"] - :lua ["src/?.lua"]} - - :profiles - {:dev - {:deps {:ht.sr.technomancy/faith - {:type :git :sha "89f7a6677821cfd6a0702cf22725dccbde1eb08c" - :paths {:fennel ["?.fnl"]}}} - :paths {:fennel ["test/?.fnl"] - :macro ["test/?.fnlm"] - :lua ["test/?.lua"]}} - :aot - {:deps {"fennel" {:type :rock :version "1.5.3"}}}}} +{:deps {:ftcsv {:type "rock" :version "1.5.0"} + :http {:dependencies {:basexx {:type "rock" :version "0.4.1-1"} + :binaryheap {:type "rock" :version "0.4-1"} + :bit32 {:type "rock" :version "5.3.5.1-1"} + :compat53 {:type "rock" :version "0.14.4-1"} + :cqueues {:type "rock" :version "20200726.53-0"} + :fifo {:type "rock" :version "0.2-0"} + :lpeg {:type "rock" :version "1.1.0-2"} + :lpeg_patterns {:dependencies {:lpeg {:type "rock" + :version "1.1.0-2"}} + :type "rock" + :version "0.5-0"} + :luaossl {:type "rock" :version "20250929-0"}} + :type "rock" + :version "0.4"} + :io.github.luafun/luafun {:paths {:lua ["?.lua"]} + :sha "12837884993a3d25bda8aaf835bb9d79132fcbc6" + :type "git"} + :lsqlite3 {:type "rock" :version "0.9.6"}} + :paths {:fennel ["src/?.fnl"] :lua ["src/?.lua"] :macro ["src/?.fnlm"]} + :profiles {:aot {:deps {:fennel {:type "rock" :version "1.5.3"}}} + :dev {:deps {:ht.sr.technomancy/faith {:paths {:fennel ["?.fnl"]} + :sha "89f7a6677821cfd6a0702cf22725dccbde1eb08c" + :type "git"}} + :paths {:fennel ["test/?.fnl"] + :lua ["test/?.lua"] + :macro ["test/?.fnlm"]}}} + :project-name "gtf-server" + :project-version "0.1.0"} \ No newline at end of file diff --git a/sql/find-stops.sql b/sql/find-stops.sql index 1801d47..a2352c6 100644 --- a/sql/find-stops.sql +++ b/sql/find-stops.sql @@ -1,11 +1,31 @@ --- find a stop near *pos* -SELECT * +SELECT +id, +description, +name, +ST_AsBinary(ST_Transform(location, 4326)) as location, +ST_Distance( + stops.location, + ST_Transform( + ST_GeomFromWkb(:searchgeom, 4326), + 25832 + ) +) as dist FROM stops WHERE - ST_Distance( - stops.location, +dist < 500 +AND stops.ROWID IN ( + SELECT ROWID + FROM SpatialIndex + WHERE + f_table_name ='stops' + AND search_frame = ST_Buffer( ST_Transform( ST_GeomFromWkb(:searchgeom, 4326), 25832 - ) - ) < 500; + ), + 500 + ) +) +ORDER BY +dist diff --git a/src/departures.fnl b/src/departures.fnl index 639b917..d460c2e 100644 --- a/src/departures.fnl +++ b/src/departures.fnl @@ -1,8 +1,8 @@ (local {: client : query} (require :sqlite)) -(local {: encode-wkb} (require :wkb)) -(local {: dofile : compile} (require :fennel)) +(local {: encode-wkb : decode-wkb} (require :wkb)) +(local {: dofile} (require :fennel)) -(local dev-config (dofile :config.fnl)) +(local config (dofile :config.fnl)) (fn now [] (os.date :%Y-%m-%dT%T (os.time))) @@ -26,40 +26,48 @@ (fn parse-departure [{: color : arrival + : departure : wait : short_name - : long_name : headsign - : description : type :text_color text-color - &as raw}] + &as raw} + include-raw?] (fn color->html [?color] (and ?color (string.format :#%06x color))) - {: raw + {:raw (if include-raw? raw) :type (. types type) :name short_name : headsign : wait - :arrival (parse-sqltime arrival) + :arrival (if (not= arrival departure) + (parse-sqltime arrival)) + :departure (parse-sqltime departure) :color (color->html color) :text-color (color->html text-color)}) -(fn get-departures [client location] - (let [q (partial query client)] +(fn get-departures [client location time] + (let [time (or time (now)) + q (partial query client)] (icollect - [{:short_name name : id &as stop} + [{: name :dist distance : location : description : id} (q :find-stops {:searchgeom (encode-wkb location)})] - {: stop + {: name + : distance + : description + :location (decode-wkb location) :departures (icollect [departure (q :get-departures {:limit 5 - :time - "2026-01-12T07:00:00" + : time :stop id})] (parse-departure departure))}))) (with-open [client (client)] - (get-departures client dev-config.dev-location)) + (get-departures client + config.dev-location)) + +{: get-departures}