More unitization.

This commit is contained in:
John Wiseman 2020-05-04 14:13:48 -07:00
parent 2e0ad025a9
commit b9c2e02ecb
4 changed files with 105 additions and 65 deletions

View File

@ -5,9 +5,9 @@ dir=$(dirname "$0")
instance="$1"
config_dir=/etc/advisorycircular
run_dir=/var/run/advisorycircular
sqb_path=/usr/local/share/run/advisorycircular/clean-basestation.sqb
sqb_path=/usr/local/share/advisorycircular/clean-basestation.sqb
config_path="$config_dir"/"$instance"-config.yaml
secrets_path="$config_dir"/"$instance"-secrets.yaml
history_path="$run_dir"/"$instance"-history.edn
(cd "$run_dir" && "$dir"/intervalexec 10 node $dir/out/advisorycircular.js --config "$config_path" --secrets "$secrets_path" --basestation-sqb "$sqb_path" --history "$history_path")
(cd "$run_dir" && "$dir"/intervalexec 10 node $dir/out/advisorycircular.js --config "$config_path" --secrets "$secrets_path" --basestation-sqb "$sqb_path" --history "$history_path" --log-prefix "$instance")

View File

@ -19,6 +19,9 @@
(logging/deflog "advisorycircular" logger)
(def log-prefix (atom ""))
(defn get-basestation-sqb-record [icao db-path]
(log-info "%s: Looking up in %s" icao db-path)
(p/let [record
@ -168,14 +171,15 @@
(defn ac-desc [ac]
(str (:icao ac) " " "http://tar1090.adsbexchange.com/?icao=" (:icao ac)
" " (:lat ac) " " (:lon ac)
" #" (:registration ac) " " (:alt ac) " " (:curviness ac) " "
" " (:registration ac) " " (:alt ac) " " (:curviness ac) " "
(:normalized-curviness ac)))
(defn screenshot [icao lat lon]
(p/let [image-path
(adsbx/screenshot-aircraft icao lat lon
(defn screenshot [icao lat lon now]
(p/let [image-path (str icao "-" (util/format-utc-ts now) ".png")
_ (adsbx/screenshot-aircraft icao lat lon
{:timeout 30000
:output-path image-path
;;:headless? false
;; :viewport {:width 1600 :height 800}
;; :clip {:width 1600 :height 800 :x 0 :y 0}
@ -477,18 +481,18 @@
(:distance airport-properties)
(:minimum-airport-distance-km config)
(:label airport-properties)
()))
(let [alts (map :alt recent-positions)
min-alt (apply min alts)
max-alt (apply max alts)
ratio (/ max-alt min-alt)]
(log-info "%s: ratio of min alt to max alt: %s [%s - %s]" icao (.toFixed (/ max-alt min-alt) 1) min-alt max-alt))
())
;; (let [alts (map :alt recent-positions)
;; min-alt (apply min alts)
;; max-alt (apply max alts)
;; ratio (/ max-alt min-alt)]
;; (log-info "%s: ratio of min alt to max alt: %s [%s - %s]" icao (.toFixed (/ max-alt min-alt) 1) min-alt max-alt))
(do
(p/let [coarse (pelias/reverse (:pelias config) lat lon {:layers "coarse"})]
(let [coarse (first (:features coarse))]
(log-info "%s: Reverse geocode: %s" icao (:properties coarse))
;; Note that if we're over the ocean we get null :(
(p/then (p/all [(screenshot (:icao ac) lat lon)
(p/then (p/all [(screenshot (:icao ac) lat lon now)
(p/let [nearby (landmark config lat lon)
_ (log-info "WOOO %s" nearby)
sqb (if-let [sqb-path (:basestation-sqb config)]
@ -511,14 +515,14 @@
lat
lon)
(log-warn "Skipping tweeting"))
(let [path (str (.toFixed (/ now 1000) 0) "-" icao "-recent" ".geojson")]
(let [path (str icao "-" (util/format-utc-ts now) ".geojson")]
(util/write-file
path
(.stringify
js/JSON
(clj->js (track->geojson older-positions recent-positions icao centroid)))
{})))
(log-warn "Skipping tweet %s %s" image-path description))))))))))
(log-warn "Skipping tweet %s %s" image-path description)))))))))))
(defn process-potential-circles [acs config now]
@ -536,7 +540,7 @@
;; This is how many degrees of turning we need to see over
;; max-history-age-ms ms to consider it a potential circling
;; aircraft.
:curviness-threshold-degrees (* 2 360)
:curviness-threshold-degrees (* 4 360)
;; If the centroid of the aircraft's positions is less than this
;; close to an airport, then it's probably just doing flight
;; training.
@ -610,7 +614,12 @@
(.option "--config <path>" "Path to the configuration yaml file")
(.option "--secrets <path>" "Path to the secrets yaml file" "secrets.yaml")
(.option "--history <path>" "Path to history/state file" "advisorycircular.edn")
(.option "--log-prefix <prefix>" "Log prefix to use")
(.parse (.-argv js/process)))
(logging/set-log-prefix! (or (.-logPrefix commander) ""))
(reset! log-prefix (if (.-logPrefix commander)
(str (.-logPrefix commander) "-")
""))
(let [start-time (current-time)]
;; If --config-path is specified, definitely try to read that
;; file. Otherwise, only read config.yaml if it exists.

View File

@ -6,15 +6,34 @@
(:require-macros
[lemondronor.advisorycircular.logging]))
;; (def format-msg [msg]
;; (gstring/format "%s%-7s %-9s/%-18s| %s"
;; (.-timestamp %)
;; (.-ms %)
;; (.-service %)
;; (.-level %)
;; (.-message %)))
(def log-prefix (atom ""))
(defn set-log-prefix! [prefix]
(swap! log-prefix (constantly prefix)))
(defn format-msg [msg]
(let [prefix (if (and @log-prefix (> (count @log-prefix) 0))
(str @log-prefix " ")
"")]
(gstring/format "%s%s %s"
prefix
(.-level msg)
(.-message msg))))
(let [createLogger (.-createLogger winston)
format (.-format winston)
transports (.-transports winston)
printf-fmt #(gstring/format "%s%-7s %-9s/%-18s| %s"
(.-timestamp %)
(.-ms %)
(.-service %)
(.-level %)
(.-message %))]
transports (.-transports winston)]
(def logger (createLogger
#js {:level "info"
:format (.combine
@ -30,7 +49,7 @@
:defaultMeta #js {}}))
(.add logger (new (.-Console transports)
#js {:format (.combine format
(.printf format printf-fmt))})))
(.printf format format-msg))})))
(defn get-logger [service]

View File

@ -85,3 +85,15 @@
[[k]])))
m))
[]))
(defn format-utc-ts [millis]
(let [date (js/Date. millis)]
(str (.getUTCFullYear date)
(.getUTCMonth date)
(.getUTCDate date)
"-"
(.getUTCHours date)
(.getUTCMinutes date)
(.getUTCSeconds date)
(.getUTCMilliseconds date))))