diff --git a/src/main/lemondronor/advisorycircular.cljs b/src/main/lemondronor/advisorycircular.cljs index ec99dcb..3b98956 100644 --- a/src/main/lemondronor/advisorycircular.cljs +++ b/src/main/lemondronor/advisorycircular.cljs @@ -119,6 +119,21 @@ result)))) +;; Removes from adsbx API results any ICAOs that match a pattern in +;; the blocklist. + +(defn remove-blocked-icaos [live-data blocklist] + (let [updated (let [blocklist-patterns (map #(re-pattern (str "(?i)" %)) blocklist)] + (update + live-data + :aircraft + (fn [aircraft] + (remove (fn [ac] (some #(re-find % (:icao ac)) + blocklist-patterns)) + aircraft))))] + updated)) + + ;; Given a vector of position history, removes old entries. (defn prune-history [history now config] @@ -784,14 +799,15 @@ (log-info "%s does not exist; creating empty one." history-db-path) (write-history-db {} history-db-path)) db (read-history-db history-db-path) - data (get-adsbexchange-live-data - (merge (:adsbx config) - {:lat (:lat config) - :lon (:lon config) - :radius-nm (* (:radius-km config) 0.539957)})) + api-data (get-adsbexchange-live-data + (merge (:adsbx config) + {:lat (:lat config) + :lon (:lon config) + :radius-nm (* (:radius-km config) 0.539957)})) + filtered-api-data (remove-blocked-icaos api-data (get config :icao-blocklist '())) now (current-time) [new-db potential-circles] (-> db - (update-history-db (:aircraft data) now config) + (update-history-db (:aircraft filtered-api-data) now config) (detect-circles now config))] (p/do (when potential-circles