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