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}) ]"
;; Ideally neighbourhood as well as city or county, but
;; maybe just city.
"is circling over [{neighbourhood}, {locality}|{neighbourhood}, {county}|{locality}|{localadmin}] "
"is circling over [{neighbourhood}, {locality}|{neighbourhood}, {county}|{locality}|{localadmin}|{name}] "
;; Altitude.
"?:[at {alt} feet, ]"
;; Speed;
@ -325,7 +325,9 @@
:militaryicao 2
:icao 1
:neighbourhood 3
:locality 3}}))]
:locality 3
:localadmin 1
:name 0.5}}))]
;;(log-info "Top description candidates (%s total):" (count results))
;;(log-table results [:score :text])
(first results)))
@ -656,10 +658,16 @@
(write-history-db new-db (:history-db-path config))
(let [end-time (current-time)]
(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)
(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
(log-error "%s" e)
(log-error "%s" (.-stack e))

View File

@ -115,13 +115,13 @@
(deftest merge-adsbx-sqb
(is (= (advisorycircular/merge-adsbx-sqb {:registration "N1"}
{:registration "N2" :type "B52"})
{:registration "N2" :type "B52"})
{:registration "N1", :type "B52"}))
(is (= (advisorycircular/merge-adsbx-sqb {:registration nil}
{:registration "N2" :type "B52"})
{:registration "N2" :type "B52"})
{:registration "N2", :type "B52"}))
(is (= (advisorycircular/merge-adsbx-sqb {:registration "N1"}
{:registration "N2" :type nil})
{:registration "N2" :type nil})
{:registration "N1", :type nil})))
@ -172,91 +172,140 @@
{:properties {:name "Musso & Frank's"}}
{:properties {:name "Johnny Depp's Star"}}]]
(is (= (advisorycircular/filter-landmarks {:blocklist ["Johnny Depp"]}
landmarks)
landmarks)
[{:properties {:name "Musso & Frank's"}}]))
(is (= (advisorycircular/filter-landmarks {:blocklist ["Frank"]}
landmarks)
landmarks)
[{:properties {:name "Johnny Depp"}}
{:properties {:name "Johnny Depp's Star"}}])))))
(def r2508-data [{:continent "North America"
:accuracy "point"
:country_a "USA"
:continent_gid "whosonfirst:continent:102191575"
:name "Haystack Butte"
:county_a "SA"
:county "San Bernardino County"
:source "openstreetmap"
:gid "openstreetmap:venue:node/358808120"
:region "California"
:region_a "CA"
:layer "venue"
:country_gid "whosonfirst:country:85633793"
:label "Haystack Butte, San Bernardino County, CA, USA"
:id "node/358808120"
:region_gid "whosonfirst:region:85688637"
:county_gid "whosonfirst:county:102085395"
:distance 4.261
:source_id "node/358808120"
:confidence 0.5
:country "United States"}
{:continent "North America"
:military?
true
:alt 5825
:speed "226"
:normalized-curviness 14.188938867970446
:accuracy "centroid"
:country_a "USA"
:continent_gid "whosonfirst:continent:102191575"
:name "San Bernardino County"
:squawk "0026"
:icao "AE264F"
:county_a "SA"
:county "San Bernardino County"
:type "Beechcraft C-12C Huron"
:source "whosonfirst"
:gid "whosonfirst:county:102085395"
:curviness 1463.4205557421808
:region "California"
:militaryicao "AE264F"
:region_a "CA"
:nearbydistance "2.65"
:callsign "COBRA02"
:layer "county"
:mlat? false
:country_gid "whosonfirst:country:85633793"
:label "San Bernardino County, CA, USA"
:id "102085395"
:lon -117.629528
:region_gid "whosonfirst:region:85688637"
:lat 34.884804
:militaryregistration "73-1215?"
:county_gid "whosonfirst:county:102085395"
:started-circling-time 1581098223891
:distance 132.69
:source_id "102085395"
:registration "73-1215?"
:confidence 0.5
:country "United States",
:postime 1581098213228
:nearbylandmark "Haystack Butte"}])
(def r2508-data1
[{:continent "North America"
:accuracy "point"
:country_a "USA"
:continent_gid "whosonfirst:continent:102191575"
:name "Haystack Butte"
:county_a "SA"
:county "San Bernardino County"
:source "openstreetmap"
:gid "openstreetmap:venue:node/358808120"
:region "California"
:region_a "CA"
:layer "venue"
:country_gid "whosonfirst:country:85633793"
:label "Haystack Butte, San Bernardino County, CA, USA"
:id "node/358808120"
:region_gid "whosonfirst:region:85688637"
:county_gid "whosonfirst:county:102085395"
:distance 4.261
:source_id "node/358808120"
:confidence 0.5
:country "United States"}
{:continent "North America"
:military?
true
:alt 5825
:speed "226"
:normalized-curviness 14.188938867970446
:accuracy "centroid"
:country_a "USA"
:continent_gid "whosonfirst:continent:102191575"
:name "San Bernardino County"
:squawk "0026"
:icao "AE264F"
:county_a "SA"
:county "San Bernardino County"
:type "Beechcraft C-12C Huron"
:source "whosonfirst"
:gid "whosonfirst:county:102085395"
:curviness 1463.4205557421808
:region "California"
:militaryicao "AE264F"
:region_a "CA"
:nearbydistance "2.65"
:callsign "COBRA02"
:layer "county"
:mlat? false
:country_gid "whosonfirst:country:85633793"
:label "San Bernardino County, CA, USA"
:id "102085395"
:lon -117.629528
:region_gid "whosonfirst:region:85688637"
:lat 34.884804
:militaryregistration "73-1215?"
:county_gid "whosonfirst:county:102085395"
:started-circling-time 1581098223891
:distance 132.69
:source_id "102085395"
:registration "73-1215?"
:confidence 0.5
:country "United States",
: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
{
:name "Haystack Butte"
:distance 4.61
:locality nil
:county "San Bernadino County"
:region "California"
}
}
(deftest r2508-description
(testing "R-2508 generation"
(is (= (:text (advisorycircular/expand-template (nth r2508-data1 0)))
"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"))
(is (= (:text (advisorycircular/expand-template (nth r2508-data1 1)))
"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"))
(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")))
;; | :distance | :label | :locality | :neighborhood | :county | :gid |
;; |-----------+--------------------------------------------------------+-----------+---------------+-----------------------+------------------------------------|
;; | 4.261 | Haystack Butte, San Bernardino County, CA, USA | | | San Bernardino County | openstreetmap:venue:node/358808120 |
;; | 6.576 | Reclamation Dam Edwards Air Base, Kern County, CA, USA | | | Kern County | openstreetmap:venue:node/358813789 |
;; | 8.376 | Mound, Kern County, CA, USA | | | Kern County | openstreetmap:venue:node/358789455 |
(testing "foo"
(let [ac {:military? false :alt 1300 :speed 72.1 :squawk "1200"
: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"}}
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)))))