Added support for airport blocklists.

E.g., this will stop the seaplane base from being considered as a
possible circle blocker:

airport:
  blocklist:
    - New York Skyports Incorporated Seaplane Base
This commit is contained in:
John Wiseman 2020-06-02 15:27:43 -07:00
parent 8b0b1abdb3
commit 9b65ea88dd
2 changed files with 45 additions and 13 deletions

View File

@ -184,9 +184,9 @@
(:normalized-curviness ac))) (:normalized-curviness ac)))
(defn screenshot (defn map-screenshot
([icao lat lon now] ([icao lat lon now]
(screenshot icao lat lon now {})) (map-screenshot icao lat lon now {}))
([icao lat lon now options] ([icao lat lon now options]
(p/let [image-path (str (string/join "-" [@log-prefix icao (util/format-utc-ts now)]) (p/let [image-path (str (string/join "-" [@log-prefix icao (util/format-utc-ts now)])
".png") ".png")
@ -271,10 +271,14 @@
(p/let [results (pelias/nearby (:pelias config) (p/let [results (pelias/nearby (:pelias config)
lat lon lat lon
{:categories "transport:air:aerodrome" {:categories "transport:air:aerodrome"
:boundary.circle.radius 7})] :boundary.circle.radius 7})
(-> results blocklist (get-in config [:airport :blocklist] [])
(get :features) blocklist-patterns (map #(re-pattern (str "(?i)" %)) blocklist)
(->> (sort-by #(get-in % [:properties :distance]))) _ (println blocklist-patterns)]
(->> (:features results)
(remove (fn [airport] (some #(re-find % (get-in airport [:properties :label]))
blocklist-patterns)))
(sort-by #(get-in % [:properties :distance]))
first))) first)))
@ -509,9 +513,9 @@
(log-info "%s: Reverse geocode: %s" icao (:properties coarse)) (log-info "%s: Reverse geocode: %s" icao (:properties coarse))
(log-error "%s: Reverse geocode failed: %s" icao coarse)) (log-error "%s: Reverse geocode failed: %s" icao coarse))
;; Note that if we're over the ocean we get null :( ;; Note that if we're over the ocean we get null :(
(p/then (p/all [(screenshot (:icao ac) lat lon now (:screenshot config)) (p/then (p/all [(map-screenshot (:icao ac) lat lon now (:screenshot config))
(p/let [nearby (landmark config lat lon) (p/let [nearby (landmark config lat lon)
_ (log-info "WOOO %s" nearby) ;;_ (log-info "WOOO %s" nearby)
sqb (if-let [sqb-path (:basestation-sqb config)] sqb (if-let [sqb-path (:basestation-sqb config)]
(get-basestation-sqb-record icao sqb-path))] (get-basestation-sqb-record icao sqb-path))]
(let [description (generate-description ac sqb coarse nearby)] (let [description (generate-description ac sqb coarse nearby)]
@ -521,8 +525,9 @@
(if (or (nil? coarse) (if (or (nil? coarse)
;; TODO: Filter using the layer hierarchy; we want ;; TODO: Filter using the layer hierarchy; we want
;; anything smaller than "region" (state). ;; anything smaller than "region" (state).
(= (get-in coarse [:properties :name]) "California")) ;;(= (get-in coarse [:properties :name]) "California")
(log-info "%s: Filtering out because it is outside Los Angeles County" (:icao ac)) )
(log-info "%s: Filtering out because we have insuffucient reverse geo info" (:icao ac))
(if (and image-path description) (if (and image-path description)
(do (do
(if (get-in config [:twitter :enabled?]) (if (get-in config [:twitter :enabled?])

View File

@ -1,6 +1,8 @@
(ns lemondronor.advisorycircular-test (ns lemondronor.advisorycircular-test
(:require [cljs.test :refer (deftest is testing)] (:require [cljs.test :refer (async deftest is testing)]
[lemondronor.advisorycircular :as advisorycircular])) [kitchen-async.promise :as p]
[lemondronor.advisorycircular :as advisorycircular]
[lemondronor.advisorycircular.pelias :as pelias]))
(def epsilon 0.0000010) (def epsilon 0.0000010)
@ -309,3 +311,28 @@
(is (strmatch #"speed 83 MPH" desc)) (is (strmatch #"speed 83 MPH" desc))
(is (strmatch #"squawking 1200" desc)) (is (strmatch #"squawking 1200" desc))
(is (strmatch #"#N80NT" desc))))) (is (strmatch #"#N80NT" desc)))))
(deftest closest-airport
(let [a1 {:properties {:distance 1.5 :label "Bridge heliport"}}
a2 {:properties {:distance 0.5 :label "New York Seaport"}}
a3 {:properties {:distance 1.0 :label "LAX"}}
nearby (fn [config lat lon options]
{:features [a1 a2 a3]})]
(async
done
(p/do
(testing "closest-airport 1"
;; Note that the with-redefs only works for the first
;; binding clause in p/let.
(with-redefs [pelias/nearby nearby]
(p/let [r (advisorycircular/closest-airport {} 0 0)]
(is (= r a2)))))
(testing "closest-airport with blocklist"
(with-redefs [pelias/nearby nearby]
(let [conf {:airport {:blocklist ["seaport"]}}]
(p/let [r (advisorycircular/closest-airport conf 0 0)]
(is (= r a3))))))
(done))
)))