Added landmark blocklist. Fixes issue #8.
This commit is contained in:
parent
29f9030413
commit
709b8b7d25
@ -260,8 +260,8 @@
|
||||
(let [s (with-out-str (pprint/print-table keys table))
|
||||
lines (string/split-lines s)]
|
||||
(doseq [l lines]
|
||||
(log-info "%s" l)))
|
||||
)
|
||||
(log-info "%s" l))))
|
||||
|
||||
|
||||
(def description-templates
|
||||
(map generation/parse-template
|
||||
@ -279,6 +279,7 @@
|
||||
"?:[#{registration} |#{militaryregistration} ]"
|
||||
"https://tar1090.adsbexchange.com/?icao={icao}&zoom=13")]))
|
||||
|
||||
|
||||
(defn expand-template [data]
|
||||
(let [results (take 3 (generation/expand
|
||||
description-templates
|
||||
@ -317,10 +318,9 @@
|
||||
;; * wiki-nearby - nearby landmarks w/ Wikipedia pages
|
||||
;; * nearby - nearby landmarks.
|
||||
|
||||
(defn template-data [ac sqb reverse wiki-nearby nearby]
|
||||
(defn template-data [ac sqb reverse nearby]
|
||||
(let [rev-props (:properties reverse)
|
||||
nearby (:properties (first nearby))
|
||||
wiki-nearby (:properties (first wiki-nearby))
|
||||
nearby (:properties nearby)
|
||||
info (cond-> (-> ac
|
||||
(dissoc :history :type)
|
||||
(merge rev-props)
|
||||
@ -328,10 +328,7 @@
|
||||
(:military? ac)
|
||||
(-> (assoc :militaryregistration (:registration ac)
|
||||
:militaryicao (:icao ac)))
|
||||
wiki-nearby
|
||||
(assoc :nearbylandmark (:name wiki-nearby)
|
||||
:nearbydistance (-> wiki-nearby :distance km->miles (to-fixed 2)))
|
||||
(and nearby (not wiki-nearby))
|
||||
nearby
|
||||
(assoc :nearbylandmark (:name nearby)
|
||||
:nearbydistance (-> nearby :distance km->miles (to-fixed 2)))
|
||||
(:speed ac)
|
||||
@ -343,8 +340,8 @@
|
||||
info))
|
||||
|
||||
|
||||
(defn generate-description [ac sqb reverse wiki-nearby nearby]
|
||||
(let [info (template-data ac sqb reverse wiki-nearby nearby)
|
||||
(defn generate-description [ac sqb reverse nearby]
|
||||
(let [info (template-data ac sqb reverse nearby)
|
||||
expansion (expand-template info)]
|
||||
(when (not expansion)
|
||||
(log-warn "Info: %s" info))
|
||||
@ -362,6 +359,34 @@
|
||||
recent-hist))
|
||||
|
||||
|
||||
(defn filter-landmarks [config landmarks]
|
||||
(log-info "%s %s" config landmarks)
|
||||
(let [block-regexes (map re-pattern (:blocklist config))
|
||||
blocked? (fn [l]
|
||||
(some #(re-find % (-> l :properties :name)) block-regexes))]
|
||||
(filter #(not (blocked? %)) landmarks)))
|
||||
|
||||
|
||||
(defn landmark [config lat lon]
|
||||
(p/let [landmarks (p/-> (pelias/nearby
|
||||
(:pelias config)
|
||||
lat
|
||||
lon
|
||||
{:boundary.circle.radius 100
|
||||
:layers "venue"
|
||||
:size 50})
|
||||
:features)
|
||||
_ (log-info "Nearest landmarks:")
|
||||
_ (log-table (->> landmarks (take 3) (map :properties))
|
||||
[:distance :label :locality :neighborhood :county :gid])
|
||||
filtered-landmarks (filter-landmarks (:landmarks config) landmarks)
|
||||
_ (when (not (= (take 3 landmarks) (take 3 filtered-landmarks)))
|
||||
(log-info "After filtering landmarks:")
|
||||
(log-table (->> landmarks (take 3) (map :properties))
|
||||
[:distance :label :locality :neighborhood :county :gid]))]
|
||||
(first filtered-landmarks)))
|
||||
|
||||
|
||||
(defn process-potential-circle [ac config now]
|
||||
(p/let [icao (:icao ac)
|
||||
recent-positions (recent-history (:history ac))
|
||||
@ -392,31 +417,11 @@
|
||||
(log-info "%s: Reverse geocode: %s" icao (:properties coarse))
|
||||
;; Note that if we're over the ocean we get null :(
|
||||
(p/then (p/all [(screenshot (:icao ac) lat lon)
|
||||
(p/let [nearby (pelias/nearby
|
||||
(:pelias config)
|
||||
lat
|
||||
lon
|
||||
{:boundary.circle.radius 100
|
||||
:layers "venue"
|
||||
:size 50})
|
||||
(p/let [nearby (landmark config lat lon)
|
||||
nearby (:features nearby)
|
||||
wiki-nearby (filter feature-has-wikipedia-page? nearby)
|
||||
sqb (if-let [sqb-path (:basestation-sqb config)]
|
||||
(get-basestation-sqb-record icao sqb-path))]
|
||||
(log-info "%s: Nearby geo search: %s potential landmarks, %s with wikipedia pages"
|
||||
icao (count nearby) (count wiki-nearby))
|
||||
(log-info "Nearest venues:")
|
||||
(log-table (->> nearby (take 3) (map :properties))
|
||||
[:distance :label :locality :neighborhood :county :gid])
|
||||
(log-info "Nearest venues with locality:")
|
||||
(log-table (->> nearby (map :properties) (filter :locality) (take 3))
|
||||
[:distance :label :locality :neighborhood :county :gid])
|
||||
(doseq [f wiki-nearby]
|
||||
(log-info "%s: Wiki landmark: %s %s"
|
||||
icao
|
||||
(get-in f [:properties :label] f)
|
||||
(get-in f [:properties :addendum] f)))
|
||||
(let [description (generate-description ac sqb coarse wiki-nearby nearby)]
|
||||
(let [description (generate-description ac sqb coarse nearby)]
|
||||
(log-info "Description: %s" description)
|
||||
description))])
|
||||
(fn [[image-path description]]
|
||||
|
@ -125,9 +125,8 @@
|
||||
sqb {:registration "NGOODB0Y"
|
||||
:type "B52"}
|
||||
reverse {:properties {:neighbourhood "Silver Lake" :locality "Los Angeles"}}
|
||||
wiki-nearby {}
|
||||
nearby []
|
||||
desc (circlebot/generate-description ac sqb reverse wiki-nearby nearby)]
|
||||
nearby nil
|
||||
desc (circlebot/generate-description ac sqb reverse nearby)]
|
||||
(is (re-find #"NBADB0Y" desc))
|
||||
(is (re-find #"a B52" desc))
|
||||
(is (re-find #"Silver Lake.*Los Angeles" desc))
|
||||
@ -137,9 +136,8 @@
|
||||
sqb {:registration "NGOODB0Y"
|
||||
:type "B52"}
|
||||
reverse {:properties {:neighbourhood "Silver Lake" :locality "Los Angeles"}}
|
||||
wiki-nearby {}
|
||||
nearby {:name "Disneyland" :distance 2}
|
||||
desc (circlebot/generate-description ac sqb reverse wiki-nearby nearby)]
|
||||
desc (circlebot/generate-description ac sqb reverse nearby)]
|
||||
(is (re-find #"NGOODB0Y" desc))
|
||||
(is (re-find #"a B52" desc))
|
||||
(is (re-find #"Silver Lake.*Los Angeles" desc))
|
||||
@ -149,9 +147,8 @@
|
||||
:icao "AAE0C2" :type nil, :callsign "N80NT", :registration nil}
|
||||
sqb {:registration "N80NT", :type "Eurocopter Squirrel AS 350 B2"}
|
||||
reverse {:properties {:neighbourhood "Silver Lake" :locality "Los Angeles"}}
|
||||
wiki-nearby {}
|
||||
nearby {:name "Disneyland" :distance 2}
|
||||
desc (circlebot/generate-description ac sqb reverse wiki-nearby nearby)]
|
||||
desc (circlebot/generate-description ac sqb reverse nearby)]
|
||||
(is (re-find #"N80NT" desc))
|
||||
(is (re-find #"a Eurocopter Squirrel AS 350 B2" desc))
|
||||
(is (re-find #"callsign N80NT" desc))
|
||||
@ -160,3 +157,17 @@
|
||||
(is (re-find #"speed 83 MPH" desc))
|
||||
(is (re-find #"squawking 1200" desc))
|
||||
(is (re-find #"#N80NT" desc)))))
|
||||
|
||||
|
||||
(deftest filter-landmarks
|
||||
(testing "filter-landmarks"
|
||||
(let [landmarks [{:features {:name "Johnny Depp"}}
|
||||
{:features {:name "Musso & Frank's"}}
|
||||
{:features {:name "Johnny Depp's Star"}}]]
|
||||
(is (= (circlebot/filter-landmarks {:blocklist ["Johnny Depp"]}
|
||||
landmarks)
|
||||
[{:features {:name "Musso & Frank's"}}]))
|
||||
(is (= (circlebot/filter-landmarks {:blocklist ["Frank"]}
|
||||
landmarks)
|
||||
[{:features {:name "Johnny Depp"}}
|
||||
{:features {:name "Johnny Depp's Star"}}])))))
|
||||
|
Loading…
Reference in New Issue
Block a user