Added support for planet-queries that are then locally filtered.
This is just for *me* right now. If you don't specify lat, lon and radius-km in the config, then we assume we should do a planet-scale query to adsbx-api-proxy and filter the returned aircraft to include only the ICAOs specified in the icaos collection in config.
This commit is contained in:
parent
02ee1c5050
commit
6a55807542
@ -110,6 +110,10 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn adsbx-url [{:keys [url lat lon radius-nm rapid-api?]}]
|
(defn adsbx-url [{:keys [url lat lon radius-nm rapid-api?]}]
|
||||||
|
(if (or lat lon radius-nm)
|
||||||
|
(do
|
||||||
|
(when-not (and lat lon radius-nm)
|
||||||
|
(throw (js/Error. "Need all of :lat, :lon, and :radius-nm")))
|
||||||
(let [url-pieces [url
|
(let [url-pieces [url
|
||||||
"lat" lat
|
"lat" lat
|
||||||
"lon" lon
|
"lon" lon
|
||||||
@ -118,6 +122,10 @@
|
|||||||
(map str)
|
(map str)
|
||||||
(string/join "/"))]
|
(string/join "/"))]
|
||||||
url-str))
|
url-str))
|
||||||
|
(do
|
||||||
|
(when rapid-api?
|
||||||
|
(throw (js/Error. "Must specify :lat, :lon, and :radius-nm with RapidAPI")))
|
||||||
|
(str url "/all"))))
|
||||||
|
|
||||||
|
|
||||||
(defn adsbx-headers [{:keys [url api-key api-whitelist rapid-api?]}]
|
(defn adsbx-headers [{:keys [url api-key api-whitelist rapid-api?]}]
|
||||||
@ -153,6 +161,20 @@
|
|||||||
updated))
|
updated))
|
||||||
|
|
||||||
|
|
||||||
|
;; Filters out aircraft that aren't in the keep list--unless the keep
|
||||||
|
;; list is empty, in which case we don't do any filtering.
|
||||||
|
(defn keep-specified-icaos [live-data keep-list]
|
||||||
|
(if (seq keep-list)
|
||||||
|
(let [keep-list (set (map string/upper-case keep-list))]
|
||||||
|
(update
|
||||||
|
live-data
|
||||||
|
:aircraft
|
||||||
|
(fn [aircraft]
|
||||||
|
(filter #(keep-list (string/upper-case (:icao %)))
|
||||||
|
aircraft))))
|
||||||
|
live-data))
|
||||||
|
|
||||||
|
|
||||||
;; Given a vector of position history, removes old entries.
|
;; Given a vector of position history, removes old entries.
|
||||||
|
|
||||||
(defn prune-history [history now config]
|
(defn prune-history [history now config]
|
||||||
@ -872,6 +894,7 @@
|
|||||||
:radius-nm (* (:radius-km config) 0.539957)
|
:radius-nm (* (:radius-km config) 0.539957)
|
||||||
:rapid-api? (:rapid-api? config)}))
|
:rapid-api? (:rapid-api? config)}))
|
||||||
filtered-api-data (remove-blocked-icaos api-data (get config :icao-blocklist '()))
|
filtered-api-data (remove-blocked-icaos api-data (get config :icao-blocklist '()))
|
||||||
|
filtered-api-data (keep-specified-icaos filtered-api-data (get config :icaos '()))
|
||||||
now (current-time)
|
now (current-time)
|
||||||
[new-db potential-circles] (-> db
|
[new-db potential-circles] (-> db
|
||||||
(update-history-db (:aircraft filtered-api-data) now config)
|
(update-history-db (:aircraft filtered-api-data) now config)
|
||||||
|
@ -473,7 +473,21 @@
|
|||||||
:lon 1
|
:lon 1
|
||||||
:radius-nm 2
|
:radius-nm 2
|
||||||
:rapid-api? true})
|
:rapid-api? true})
|
||||||
"http://adsbx/lat/0/lon/1/dist/2")))
|
"http://adsbx/lat/0/lon/1/dist/2"))
|
||||||
|
(is (thrown-with-msg?
|
||||||
|
js/Error #"Need all of :lat, :lon, and :radius-nm"
|
||||||
|
(advisorycircular/adsbx-url
|
||||||
|
{:url "http://adsbx"
|
||||||
|
:lat 0
|
||||||
|
:rapid-api? true})))
|
||||||
|
(is (= (advisorycircular/adsbx-url
|
||||||
|
{:url "http://adsbx"})
|
||||||
|
"http://adsbx/all"))
|
||||||
|
(is (thrown-with-msg?
|
||||||
|
js/Error #"Must specify.*lat.*RapidAPI"
|
||||||
|
(advisorycircular/adsbx-url
|
||||||
|
{:url "http://adsbx"
|
||||||
|
:rapid-api? true}))))
|
||||||
|
|
||||||
|
|
||||||
(deftest adsbx-headers
|
(deftest adsbx-headers
|
||||||
@ -494,3 +508,21 @@
|
|||||||
{:x-rapidapi-key "key"
|
{:x-rapidapi-key "key"
|
||||||
:x-rapidapi-host "adsbx"
|
:x-rapidapi-host "adsbx"
|
||||||
:useQueryString true})))
|
:useQueryString true})))
|
||||||
|
|
||||||
|
|
||||||
|
(deftest remove-blocked-icaos
|
||||||
|
(let [aircraft {:aircraft [{:icao "abc"} {:icao "ADEF"} {:icao "123"} {:icao "124"}]}]
|
||||||
|
(is (= (advisorycircular/remove-blocked-icaos aircraft '())
|
||||||
|
{:aircraft [{:icao "abc"} {:icao "ADEF"} {:icao "123"} {:icao "124"}]}))
|
||||||
|
(is (= (advisorycircular/remove-blocked-icaos aircraft '("a.*"))
|
||||||
|
{:aircraft [{:icao "123"} {:icao "124"}]}))
|
||||||
|
(is (= (advisorycircular/remove-blocked-icaos aircraft '("a.*" "123"))
|
||||||
|
{:aircraft [{:icao "124"}]}))))
|
||||||
|
|
||||||
|
|
||||||
|
(deftest keep-specified-icaos
|
||||||
|
(let [aircraft {:aircraft [{:icao "abc"} {:icao "ADEF"} {:icao "123"} {:icao "124"}]}]
|
||||||
|
(is (= (advisorycircular/keep-specified-icaos aircraft '())
|
||||||
|
{:aircraft [{:icao "abc"} {:icao "ADEF"} {:icao "123"} {:icao "124"}]}))
|
||||||
|
(is (= (advisorycircular/keep-specified-icaos aircraft '("123" "adef"))
|
||||||
|
{:aircraft [{:icao "ADEF"} {:icao "123"}]}))))
|
||||||
|
Loading…
Reference in New Issue
Block a user