Improved filtering when computing recent centroid.

This commit is contained in:
John Wiseman 2019-12-15 16:39:21 -08:00
parent 63a22d8618
commit 6d80d0e77c

View File

@ -284,6 +284,7 @@
:icao 1
:neighbourhood 3
:locality 3}}))]
(log-info "Top description candidates (%s total):" (count results))
(log-table results [:score :text])
(first results)))
@ -315,8 +316,6 @@
;; TODO: If layer is "county", find the nearest city.
)
expansion (expand-template info)]
(log-info "Description data: %s" info)
(log-info "Description [score: %s] %s" (:score expansion) (:text expansion))
(:text expansion)))
@ -324,6 +323,13 @@
(get-in f [:addendum :osm :wikipedia]))
(defn recent-history [history]
(let [most-recent-time (:time (last history))
cutoff-time (- most-recent-time (* 6 60 1000))
recent-hist (filter #(> (:time %) cutoff-time) history)]
recent-hist))
;; If the centroid of the aircraft's positions is less than this close
;; to an airport, then it's probably just doinf flight training.
(def minimum-airport-distance-km 2.5)
@ -331,12 +337,18 @@
(defn process-potential-circle [ac config now]
(p/let [icao (:icao ac)
centroid (geo/centroid (filter #(< (- now (:time %)) (* 6 60 1000)) (:history ac)))
recent-positions (recent-history (:history ac))
_ (log-info "WOO %s" (last recent-positions))
_ (log-info "%s: Recent history has %s positions, most recent is %s secs old"
icao
(count recent-positions)
(/ (- now (:time (last recent-positions))) 1000))
centroid (geo/centroid recent-positions)
lat (:lat centroid)
lon (:lon centroid)
_ (log-info "%s: Recent centroid: %s %s" icao lat lon)
airport (closest-airport lat lon)
airport-properties (:properties airport)]
(log-info "%s: Recent centroid is %s %s" icao lat lon)
(if airport
(log-info "%s: Closest airport is %s, distance: %s km"
(:icao ac) (:label airport-properties) (:distance airport-properties))
@ -353,30 +365,35 @@
(let [coarse (first (:features coarse))]
(log-info "%s: Reverse geocode: %s" icao (:properties coarse))
;; Note that if we're over the ocean we get null :(
(if (or (nil? coarse)
;; TODO: Filter using the layer hierarchy; we want
;; anything smaller than "region" (state).
(= (get-in coarse [:properties :name]) "California"))
(log-info "%s: Filtering out because it is outside Los Angeles County" (:icao ac))
(p/then (p/all [(screenshot (:icao ac) lat lon)
(p/let [nearby (pelias/nearby lat lon {:boundary.circle.radius 100
:layers "venue"
:size 50})
nearby (:features nearby)
wiki-nearby (filter feature-has-wikipedia-page? nearby)]
(log-info "%s: Nearby geo search: %s potential landmarks, %s with wikipedia pages"
icao (count nearby) (count wiki-nearby))
(doseq [l (take 3 nearby)]
(log-info "%s: Landmark: %s" icao (:properties l)))
(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 coarse wiki-nearby nearby)]
(log-warn "Description: %s" description)
description))])
(fn [[image-path description]]
(p/then (p/all [(screenshot (:icao ac) lat lon)
(p/let [nearby (pelias/nearby lat lon {:boundary.circle.radius 100
:layers "venue"
:size 50})
nearby (:features nearby)
wiki-nearby (filter feature-has-wikipedia-page? nearby)]
(log-info "%s: Nearby geo search: %s potential landmarks, %s with wikipedia pages"
icao (count nearby) (count wiki-nearby))
(log-info "%s" (->> nearby (take 3) (map :properties)))
(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 coarse wiki-nearby nearby)]
(log-warn "Description: %s" description)
description))])
(fn [[image-path description]]
(if (or (nil? coarse)
;; TODO: Filter using the layer hierarchy; we want
;; anything smaller than "region" (state).
(= (get-in coarse [:properties :name]) "California"))
(log-info "%s: Filtering out because it is outside Los Angeles County" (:icao ac))
(if (and image-path description)
(if (and (:tweeting-enabled? config) (:twitter config))
(twitter/tweet (twitter/twit (:twitter config))