Added reverse geocode description fallback: name.

Previously the bot couldn't generate a description or tweet if the
centroid wasn't in a locality or localadmin. Now there's a "name"
fallback so it will always tweet if it can reverse geocode at all.
Typically this means you'll see something like "over Los Angeles
County".
This commit is contained in:
John Wiseman 2020-05-06 13:36:37 -07:00
parent 9ab7b0616f
commit 9d9e9ba59e
2 changed files with 143 additions and 86 deletions

View File

@ -301,7 +301,7 @@
"?:[(callsign {callsign}) ]" "?:[(callsign {callsign}) ]"
;; Ideally neighbourhood as well as city or county, but ;; Ideally neighbourhood as well as city or county, but
;; maybe just city. ;; maybe just city.
"is circling over [{neighbourhood}, {locality}|{neighbourhood}, {county}|{locality}|{localadmin}] " "is circling over [{neighbourhood}, {locality}|{neighbourhood}, {county}|{locality}|{localadmin}|{name}] "
;; Altitude. ;; Altitude.
"?:[at {alt} feet, ]" "?:[at {alt} feet, ]"
;; Speed; ;; Speed;
@ -325,7 +325,9 @@
:militaryicao 2 :militaryicao 2
:icao 1 :icao 1
:neighbourhood 3 :neighbourhood 3
:locality 3}}))] :locality 3
:localadmin 1
:name 0.5}}))]
;;(log-info "Top description candidates (%s total):" (count results)) ;;(log-info "Top description candidates (%s total):" (count results))
;;(log-table results [:score :text]) ;;(log-table results [:score :text])
(first results))) (first results)))
@ -656,10 +658,16 @@
(write-history-db new-db (:history-db-path config)) (write-history-db new-db (:history-db-path config))
(let [end-time (current-time)] (let [end-time (current-time)]
(log-info (log-info
"Completed processing in %f seconds: tracking %s aircraft; %s potential circles" "Completed processing in %f seconds: tracking %s aircraft; %s potential circles; top curvinesses: %s"
(/ (- end-time start-time) 1000) (/ (- end-time start-time) 1000)
(count new-db) (count new-db)
(count potential-circles))))) (count potential-circles)
(->> (vals new-db)
(sort-by :curviness)
reverse
(take 3)
(map #(str (:icao %) ":" (.toFixed (:curviness %) 0)))
(string/join " "))))))
(p/catch :default e (p/catch :default e
(log-error "%s" e) (log-error "%s" e)
(log-error "%s" (.-stack e)) (log-error "%s" (.-stack e))

View File

@ -115,13 +115,13 @@
(deftest merge-adsbx-sqb (deftest merge-adsbx-sqb
(is (= (advisorycircular/merge-adsbx-sqb {:registration "N1"} (is (= (advisorycircular/merge-adsbx-sqb {:registration "N1"}
{:registration "N2" :type "B52"}) {:registration "N2" :type "B52"})
{:registration "N1", :type "B52"})) {:registration "N1", :type "B52"}))
(is (= (advisorycircular/merge-adsbx-sqb {:registration nil} (is (= (advisorycircular/merge-adsbx-sqb {:registration nil}
{:registration "N2" :type "B52"}) {:registration "N2" :type "B52"})
{:registration "N2", :type "B52"})) {:registration "N2", :type "B52"}))
(is (= (advisorycircular/merge-adsbx-sqb {:registration "N1"} (is (= (advisorycircular/merge-adsbx-sqb {:registration "N1"}
{:registration "N2" :type nil}) {:registration "N2" :type nil})
{:registration "N1", :type nil}))) {:registration "N1", :type nil})))
@ -172,91 +172,140 @@
{:properties {:name "Musso & Frank's"}} {:properties {:name "Musso & Frank's"}}
{:properties {:name "Johnny Depp's Star"}}]] {:properties {:name "Johnny Depp's Star"}}]]
(is (= (advisorycircular/filter-landmarks {:blocklist ["Johnny Depp"]} (is (= (advisorycircular/filter-landmarks {:blocklist ["Johnny Depp"]}
landmarks) landmarks)
[{:properties {:name "Musso & Frank's"}}])) [{:properties {:name "Musso & Frank's"}}]))
(is (= (advisorycircular/filter-landmarks {:blocklist ["Frank"]} (is (= (advisorycircular/filter-landmarks {:blocklist ["Frank"]}
landmarks) landmarks)
[{:properties {:name "Johnny Depp"}} [{:properties {:name "Johnny Depp"}}
{:properties {:name "Johnny Depp's Star"}}]))))) {:properties {:name "Johnny Depp's Star"}}])))))
(def r2508-data [{:continent "North America" (def r2508-data1
:accuracy "point" [{:continent "North America"
:country_a "USA" :accuracy "point"
:continent_gid "whosonfirst:continent:102191575" :country_a "USA"
:name "Haystack Butte" :continent_gid "whosonfirst:continent:102191575"
:county_a "SA" :name "Haystack Butte"
:county "San Bernardino County" :county_a "SA"
:source "openstreetmap" :county "San Bernardino County"
:gid "openstreetmap:venue:node/358808120" :source "openstreetmap"
:region "California" :gid "openstreetmap:venue:node/358808120"
:region_a "CA" :region "California"
:layer "venue" :region_a "CA"
:country_gid "whosonfirst:country:85633793" :layer "venue"
:label "Haystack Butte, San Bernardino County, CA, USA" :country_gid "whosonfirst:country:85633793"
:id "node/358808120" :label "Haystack Butte, San Bernardino County, CA, USA"
:region_gid "whosonfirst:region:85688637" :id "node/358808120"
:county_gid "whosonfirst:county:102085395" :region_gid "whosonfirst:region:85688637"
:distance 4.261 :county_gid "whosonfirst:county:102085395"
:source_id "node/358808120" :distance 4.261
:confidence 0.5 :source_id "node/358808120"
:country "United States"} :confidence 0.5
{:continent "North America" :country "United States"}
:military? {:continent "North America"
true :military?
:alt 5825 true
:speed "226" :alt 5825
:normalized-curviness 14.188938867970446 :speed "226"
:accuracy "centroid" :normalized-curviness 14.188938867970446
:country_a "USA" :accuracy "centroid"
:continent_gid "whosonfirst:continent:102191575" :country_a "USA"
:name "San Bernardino County" :continent_gid "whosonfirst:continent:102191575"
:squawk "0026" :name "San Bernardino County"
:icao "AE264F" :squawk "0026"
:county_a "SA" :icao "AE264F"
:county "San Bernardino County" :county_a "SA"
:type "Beechcraft C-12C Huron" :county "San Bernardino County"
:source "whosonfirst" :type "Beechcraft C-12C Huron"
:gid "whosonfirst:county:102085395" :source "whosonfirst"
:curviness 1463.4205557421808 :gid "whosonfirst:county:102085395"
:region "California" :curviness 1463.4205557421808
:militaryicao "AE264F" :region "California"
:region_a "CA" :militaryicao "AE264F"
:nearbydistance "2.65" :region_a "CA"
:callsign "COBRA02" :nearbydistance "2.65"
:layer "county" :callsign "COBRA02"
:mlat? false :layer "county"
:country_gid "whosonfirst:country:85633793" :mlat? false
:label "San Bernardino County, CA, USA" :country_gid "whosonfirst:country:85633793"
:id "102085395" :label "San Bernardino County, CA, USA"
:lon -117.629528 :id "102085395"
:region_gid "whosonfirst:region:85688637" :lon -117.629528
:lat 34.884804 :region_gid "whosonfirst:region:85688637"
:militaryregistration "73-1215?" :lat 34.884804
:county_gid "whosonfirst:county:102085395" :militaryregistration "73-1215?"
:started-circling-time 1581098223891 :county_gid "whosonfirst:county:102085395"
:distance 132.69 :started-circling-time 1581098223891
:source_id "102085395" :distance 132.69
:registration "73-1215?" :source_id "102085395"
:confidence 0.5 :registration "73-1215?"
:country "United States", :confidence 0.5
:postime 1581098213228 :country "United States",
:nearbylandmark "Haystack Butte"}]) :postime 1581098213228
:nearbylandmark "Haystack Butte"}
{:continent "North America"
:military? true
:alt 14000
:speed "139"
:normalized-curviness 6.97888492071943
:accuracy "centroid"
:country_a "USA"
:continent_gid "whosonfirst:continent:102191575"
:name "Kern County"
:squawk "0006"
:icao "AE2651"
:county_a "KE"
:county "Kern County"
:type "Beechcraft C-12C Huron"
:source "whosonfirst"
:gid "whosonfirst:county:102081727"
:curviness 1447.2660076871339
:region "California"
:militaryicao "AE2651"
:region_a "CA"
:nearbydistance "1.93"
:callsign "COBRA37"
:layer "county"
:mlat? false
:country_gid "whosonfirst:country:85633793"
:label "Kern County, CA, USA"
:id "102081727"
:lon -117.654247
:region_gid "whosonfirst:region:85688637"
:lat 35.076273
:militaryregistration "76-0166"
:county_gid "whosonfirst:county:102081727"
:started-circling-time 1588785019767
:distance 101.122
:source_id "102081727"
:registration "76-0166"
:confidence 0.5
:country "United States"
:postime 1588785014065
:nearbylandmark "Russell Mine"}])
{:landmark (deftest r2508-description
{ (testing "R-2508 generation"
:name "Haystack Butte" (is (= (:text (advisorycircular/expand-template (nth r2508-data1 0)))
:distance 4.61 "73-1215?, a military Beechcraft C-12C Huron, (callsign COBRA02) is circling over San Bernardino County at 5825 feet, speed 226 MPH, squawking 0026, 2.65 miles from Haystack Butte #73-1215? https://tar1090.adsbexchange.com/?icao=AE264F&zoom=13"))
:locality nil (is (= (:text (advisorycircular/expand-template (nth r2508-data1 1)))
:county "San Bernadino County" "73-1215?, a military Beechcraft C-12C Huron, (callsign COBRA02) is circling over San Bernardino County at 5825 feet, speed 226 MPH, squawking 0026, 2.65 miles from Haystack Butte #73-1215? https://tar1090.adsbexchange.com/?icao=AE264F&zoom=13"))
:region "California" (is (= (:text (advisorycircular/expand-template (nth r2508-data1 2)))
} "76-0166, a military Beechcraft C-12C Huron, (callsign COBRA37) is circling over Kern County at 14000 feet, speed 139 MPH, squawking 0006, 1.93 miles from Russell Mine #76-0166 https://tar1090.adsbexchange.com/?icao=AE2651&zoom=13")))
}
(testing "foo"
;; | :distance | :label | :locality | :neighborhood | :county | :gid | (let [ac {:military? false :alt 1300 :speed 72.1 :squawk "1200"
;; |-----------+--------------------------------------------------------+-----------+---------------+-----------------------+------------------------------------| :icao "AAE0C2" :type nil, :callsign "N80NT", :registration nil}
;; | 4.261 | Haystack Butte, San Bernardino County, CA, USA | | | San Bernardino County | openstreetmap:venue:node/358808120 | sqb {:registration "N80NT", :type "Eurocopter Squirrel AS 350 B2"}
;; | 6.576 | Reclamation Dam Edwards Air Base, Kern County, CA, USA | | | Kern County | openstreetmap:venue:node/358813789 | reverse {:properties {:neighbourhood "Silver Lake" :locality "Los Angeles"}}
;; | 8.376 | Mound, Kern County, CA, USA | | | Kern County | openstreetmap:venue:node/358789455 | nearby {:name "Disneyland" :distance 2}
desc (advisorycircular/generate-description ac sqb reverse nearby)]
(is (strmatch #"N80NT" desc))
(is (strmatch #"a Eurocopter Squirrel AS 350 B2" desc))
(is (strmatch #"callsign N80NT" desc))
(is (strmatch #"Silver Lake.*Los Angeles" desc))
(is (strmatch #"1300 feet" desc))
(is (strmatch #"speed 83 MPH" desc))
(is (strmatch #"squawking 1200" desc))
(is (strmatch #"#N80NT" desc)))))