Cleaning up use of SQB info.
This commit is contained in:
parent
817e632326
commit
4183048c3c
@ -26,6 +26,9 @@
|
||||
(p/-> (sqlite/open db-path clj->js { js/Promise js/Promise })
|
||||
(.get "SELECT Registration, Type, RegisteredOwners from Aircraft where ModeS = ?" icao))]
|
||||
(log-info "%s: basestation.sqb: %s" icao (js->clj record :keywordize-keys true))
|
||||
(-> record
|
||||
(js->clj :keywordize-keys true)
|
||||
(set/rename-keys {:Registration :registration :Type :type :RegisteredOwners :registered-owners}))
|
||||
(js->clj record :keywordize-keys true)))
|
||||
|
||||
|
||||
@ -309,6 +312,14 @@
|
||||
(.toFixed n d))
|
||||
|
||||
|
||||
(defn merge-adsbx-sqb [ac sqb]
|
||||
(cond-> ac
|
||||
(and (nil? (:registration ac)) (:registration sqb))
|
||||
(assoc :registration (:registration sqb))
|
||||
true
|
||||
(assoc :type (:type sqb))))
|
||||
|
||||
|
||||
;; Creates a template expansion map from the following:
|
||||
;;
|
||||
;; * ac - The ADSBX API entry
|
||||
@ -321,11 +332,9 @@
|
||||
(let [rev-props (:properties reverse)
|
||||
nearby (:properties (first nearby))
|
||||
wiki-nearby (:properties (first wiki-nearby))
|
||||
info (cond-> (-> ac (dissoc :history :type) (merge rev-props))
|
||||
(:Type sqb)
|
||||
(assoc :type (:Type sqb))
|
||||
(and (nil? (:registration ac)) (:Registration sqb))
|
||||
(assoc :registration (:Registration sqb))
|
||||
info (cond-> (-> ac (dissoc :history :type)
|
||||
(merge rev-props)
|
||||
(merge-adsbx-sqb sqb))
|
||||
(:military? ac)
|
||||
(-> (assoc :militaryregistration (:registration ac)
|
||||
:militaryicao (:icao ac)))
|
||||
|
@ -106,12 +106,24 @@
|
||||
(is (re-find #"a Yoyo" (:text (circlebot/expand-template data)))))))
|
||||
|
||||
|
||||
(deftest merge-adsbx-sqb
|
||||
(is (= (circlebot/merge-adsbx-sqb {:registration "N1"}
|
||||
{:registration "N2" :type "B52"})
|
||||
{:registration "N1", :type "B52"}))
|
||||
(is (= (circlebot/merge-adsbx-sqb {:registration nil}
|
||||
{:registration "N2" :type "B52"})
|
||||
{:registration "N2", :type "B52"}))
|
||||
(is (= (circlebot/merge-adsbx-sqb {:registration "N1"}
|
||||
{:registration "N2" :type nil})
|
||||
{:registration "N1", :type nil})))
|
||||
|
||||
|
||||
(deftest generate-description
|
||||
(testing "Basic generation"
|
||||
(let [ac {:icao "B00B00"
|
||||
:registration "NBADB0Y"}
|
||||
sqb {:Registration "NGOODB0Y"
|
||||
:Type "B52"}
|
||||
sqb {:registration "NGOODB0Y"
|
||||
:type "B52"}
|
||||
reverse {:properties {:neighbourhood "Silver Lake" :locality "Los Angeles"}}
|
||||
wiki-nearby {}
|
||||
nearby []
|
||||
@ -119,8 +131,8 @@
|
||||
(is (= desc "NBADB0Y, a B52, is circling over Silver Lake, Los Angeles #NBADB0Y"))))
|
||||
(testing "Missing ADSBX registration"
|
||||
(let [ac {:icao "B00B00"}
|
||||
sqb {:Registration "NGOODB0Y"
|
||||
:Type "B52"}
|
||||
sqb {:registration "NGOODB0Y"
|
||||
:type "B52"}
|
||||
reverse {:properties {:neighbourhood "Silver Lake" :locality "Los Angeles"}}
|
||||
wiki-nearby {}
|
||||
nearby {:name "Disneyland" :distance 2}
|
||||
@ -129,7 +141,7 @@
|
||||
(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"}
|
||||
sqb {:registration "N80NT", :type "Eurocopter Squirrel AS 350 B2"}
|
||||
reverse {:properties {:neighbourhood "Silver Lake" :locality "Los Angeles"}}
|
||||
wiki-nearby {}
|
||||
nearby {:name "Disneyland" :distance 2}
|
||||
|
Loading…
Reference in New Issue
Block a user