diff --git a/src/test/lemondronor/advisorycircular_test.cljs b/src/test/lemondronor/advisorycircular_test.cljs index 58bc51e..916a74c 100644 --- a/src/test/lemondronor/advisorycircular_test.cljs +++ b/src/test/lemondronor/advisorycircular_test.cljs @@ -26,22 +26,21 @@ "dst" "14.6", "reg" "HL7634", "altt" "0", "cou" "South Korea", "postime" "1575488288571", "galt" "139", "mlat" "0", "spd" "10.5", "sqk" "", "talt" "", "wtc" "3", "alt" "100", "lon" "-118.416438", - "opicao" "AAR", "interested" "0", "trak" "264.4", "type" "A388", + "opicao" "AAR", "interested" "0", "trak" "264.4", "trkh" "0", "icao" "71BE34", "lat" "33.937908", "vsit" "1", - "tisb" "0", "vsi" "0", "sat" "0"}] - (is (= (advisorycircular/parse-adsbexchange-ac-element ac) - {:icao "71BE34" - :registration "HL7634" - :callsign nil - :type "A388" - :lon -118.416438 - :lat 33.937908 - :alt 100 - :speed 10.5 - :squawk nil - :military? false - :mlat? false - :postime 1575488288571})))) + "tisb" "0", "vsi" "0", "sat" "0"} + r (advisorycircular/parse-adsbexchange-ac-element ac)] + (is (= (:icao r) "71BE34")) + (is (= (:registration r) "HL7634")) + (is (= (:callsign r) nil)) + (is (a= (:lon r) -118.416438)) + (is (a= (:lat r) 33.937908)) + (is (a= (:alt r) 100)) + (is (a= (:speed r) 10.5)) + (is (= (:squawk r) nil)) + (is (not (:military? r))) + (is (not (:mlat? r))) + (is (a= (:postime r) 1575488288571)))) (deftest prune-history @@ -72,7 +71,7 @@ :history [{:time 1000 :id 0} {:time 2000 :id 1} {:time 3000 :id 2} - {:time 3500 :lat 1 :lon 1}]} + {:time 3500 :lat 1 :lon 1 :alt nil :gnd? nil}]} "1" :anything})))) (testing "Adding a new record" (let [db {"0" {:icao "0" @@ -100,13 +99,93 @@ :lat 1 :lon 1 :postime 3500 - :history [{:time 3500 :lat 1 :lon 1}]}}))))) + :history [{:time 3500 :lat 1 :lon 1 :alt nil :gnd? nil}]}}))))) (deftest expand-template - (let [data {:locality "Palmdale", :continent "North America", :military? true, :alt 3850, :speed "209", :normalized-curviness 14.768651250300287, :accuracy "centroid", :country_a "USA", :continent_gid "whosonfirst:continent:102191575", :name "Palmdale", :squawk "5330", :icao "AE1482", :county_a "LO", :county "Los Angeles County", :source "whosonfirst", :gid "whosonfirst:locality:85923493", :curviness 1269.8089810739468, :locality_gid "whosonfirst:locality:85923493", :region "California", :militaryicao "AE1482", :region_a "CA", :nearbydistance 8.167, :callsign "RAIDR49", :layer "locality", :mlat? false, :country_gid "whosonfirst:country:85633793", :label "Palmdale, CA, USA", :id "85923493", :lon -118.00375, :region_gid "whosonfirst:region:85688637", :lat 34.661074, :militaryregistration "166765", :county_gid "whosonfirst:county:102086957", :started-circling-time 1576266715691, :distance 6.855, :source_id "85923493", :registration "166765", :confidence 0.5, :country "United States", :postime 1576266689756, :nearbylandmark "Living Faith Foursquare Church"}] + (let [data {:locality "Palmdale" + :continent "North America" + :military? true + :alt 3850 + :speed "209" + :normalized-curviness 14.768651250300287 + :accuracy "centroid" + :country_a "USA" + :continent_gid "whosonfirst:continent:102191575" + :name "Palmdale" + :squawk "5330" + :icao "AE1482" + :county_a "LO" + :county "Los Angeles County" + :source "whosonfirst" + :gid "whosonfirst:locality:85923493" + :curviness 1269.8089810739468 + :locality_gid "whosonfirst:locality:85923493" + :region "California" + :militaryicao "AE1482" + :region_a "CA" + :nearbydistance 8.167 + :callsign "RAIDR49" + :layer "locality" + :mlat? false + :country_gid "whosonfirst:country:85633793" + :label "Palmdale, CA, USA" + :id "85923493" + :lon -118.00375 + :region_gid "whosonfirst:region:85688637" + :lat 34.661074 + :militaryregistration "166765" + :county_gid "whosonfirst:county:102086957" + :started-circling-time 1576266715691 + :distance 6.855 + :source_id "85923493" + :registration "166765" + :confidence 0.5 + :country "United States" + :postime 1576266689756 + :nearbylandmark "Living Faith Foursquare Church"}] (is (strmatch #"military" (-> (advisorycircular/expand-template data) :text)))) - (let [data {:locality "Palmdale", :continent "North America", :military? true, :alt 3200, :speed "161", :normalized-curviness 15.783422690487765, :accuracy "centroid", :country_a "USA", :continent_gid "whosonfirst:continent:102191575", :name "Palmdale", :squawk "5330", :icao "AE1482", :county_a "LO", :county "Los Angeles County", :source "whosonfirst", :gid "whosonfirst:locality:85923493", :curviness 1098.803548060181, :locality_gid "whosonfirst:locality:85923493", :region "California", :militaryicao "AE1482", :region_a "CA", :nearbydistance 7.828, :callsign "RAIDR49", :layer "locality", :mlat? false, :country_gid "whosonfirst:country:85633793", :label "Palmdale, CA, USA", :id "85923493", :lon -118.049183, :region_gid "whosonfirst:region:85688637", :lat 34.649808, :militaryregistration "166765", :county_gid "whosonfirst:county:102086957", :started-circling-time 1576267564959, :distance 6.336, :source_id "85923493", :registration "166765", :confidence 0.5, :country "United States", :postime 1576267555709, :nearbylandmark "Living Faith Foursquare Church"}] + (let [data {:locality "Palmdale" + :continent "North America" + :military? true + :alt 3200 + :speed "161" + :normalized-curviness 15.783422690487765 + :accuracy "centroid" + :country_a "USA" + :continent_gid "whosonfirst:continent:102191575" + :name "Palmdale" + :squawk "5330" + :icao "AE1482" + :county_a "LO" + :county "Los Angeles County" + :source "whosonfirst" + :gid "whosonfirst:locality:85923493" + :curviness 1098.803548060181 + :locality_gid "whosonfirst:locality:85923493" + :region "California" + :militaryicao "AE1482" + :region_a "CA" + :nearbydistance 7.828 + :callsign "RAIDR49" + :layer "locality" + :mlat? false + :country_gid "whosonfirst:country:85633793" + :label "Palmdale, CA, USA" + :id "85923493" + :lon -118.049183 + :region_gid "whosonfirst:region:85688637" + :lat 34.649808 + :militaryregistration "166765" + :county_gid "whosonfirst:county:102086957" + :started-circling-time 1576267564959 + :distance 6.336 + :source_id "85923493" + :registration "166765" + :confidence 0.5 + :country "United States" + :postime 1576267555709 + :nearbylandmark "Living Faith Foursquare Church"}] (is (strmatch #"military" (-> (advisorycircular/expand-template data) :text)))) (testing "a vs. an for type" (let [data {:registration "TEST" :icao "123" :type "Airbus 380" :locality "Test City"}] @@ -115,15 +194,15 @@ (is (strmatch #"a Yoyo" (:text (advisorycircular/expand-template data))))))) -(deftest merge-adsbx-sqb - (is (= (advisorycircular/merge-adsbx-sqb {:registration "N1"} - {:registration "N2" :type "B52"}) +(deftest merge-adsbx-db-rec + (is (= (advisorycircular/merge-adsbx-aircraft-db-rec {:registration "N1"} + {:registration "N2" :type "B52"}) {:registration "N1", :type "B52"})) - (is (= (advisorycircular/merge-adsbx-sqb {:registration nil} - {:registration "N2" :type "B52"}) + (is (= (advisorycircular/merge-adsbx-aircraft-db-rec {:registration nil} + {:registration "N2" :type "B52"}) {:registration "N2", :type "B52"})) - (is (= (advisorycircular/merge-adsbx-sqb {:registration "N1"} - {:registration "N2" :type nil}) + (is (= (advisorycircular/merge-adsbx-aircraft-db-rec {:registration "N1"} + {:registration "N2" :type nil}) {:registration "N1", :type nil}))) @@ -160,7 +239,6 @@ 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)) @@ -183,68 +261,67 @@ (def r2508-data1 - [{:continent "North America" - :accuracy "point" - :country_a "USA" + [{:accuracy "point" + :confidence 0.5 + :continent "North America" :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 "United States" + :country_a "USA" :country_gid "whosonfirst:country:85633793" - :label "Haystack Butte, San Bernardino County, CA, USA" - :id "node/358808120" - :region_gid "whosonfirst:region:85688637" + :county "San Bernardino County" + :county_a "SA" :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 + :gid "openstreetmap:venue:node/358808120" + :id "node/358808120" + :label "Haystack Butte, San Bernardino County, CA, USA" + :layer "venue" + :name "Haystack Butte" :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?" + :source "openstreetmap" + :source_id "node/358808120"} + {:accuracy "centroid" + :alt 5825 + :callsign "COBRA02" :confidence 0.5 + :continent "North America" + :continent_gid "whosonfirst:continent:102191575" :country "United States", + :country_a "USA" + :country_gid "whosonfirst:country:85633793" + :county "San Bernardino County" + :county_a "SA" + :county_gid "whosonfirst:county:102085395" + :curviness 1463.4205557421808 + :distance 132.69 + :gid "whosonfirst:county:102085395" + :icao "AE264F" + :id "102085395" + :label "San Bernardino County, CA, USA" + :lat 34.884804 + :layer "county" + :lon -117.629528 + :military? true + :militaryicao "AE264F" + :militaryregistration "73-1215?" + :mlat? false + :name "San Bernardino County" + :nearbydistance "2.65" + :nearbylandmark "Haystack Butte" + :normalized-curviness 14.188938867970446 :postime 1581098213228 - :nearbylandmark "Haystack Butte"} + :region "California" + :region_a "CA" + :region_gid "whosonfirst:region:85688637" + :registration "73-1215?" + :source "whosonfirst" + :source_id "102085395" + :speed "226" + :squawk "0026" + :started-circling-time 1581098223891 + :type "Beechcraft C-12C Huron"} {:continent "North America" :military? true :alt 14000 @@ -289,13 +366,18 @@ (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 (= (advisorycircular/expand-template (nth r2508-data1 0)) + nil)) (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")) + (str "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://globe.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"))) - + (str "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://globe.adsbexchange.com/?icao=AE2651&zoom=13")))) (testing "foo" (let [ac {:military? false :alt 1300 :speed 72.1 :squawk "1200" :icao "AAE0C2" :type nil, :callsign "N80NT", :registration nil} @@ -305,7 +387,6 @@ 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))