More unitization.
This commit is contained in:
parent
2e0ad025a9
commit
b9c2e02ecb
@ -5,9 +5,9 @@ dir=$(dirname "$0")
|
|||||||
instance="$1"
|
instance="$1"
|
||||||
config_dir=/etc/advisorycircular
|
config_dir=/etc/advisorycircular
|
||||||
run_dir=/var/run/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
|
config_path="$config_dir"/"$instance"-config.yaml
|
||||||
secrets_path="$config_dir"/"$instance"-secrets.yaml
|
secrets_path="$config_dir"/"$instance"-secrets.yaml
|
||||||
history_path="$run_dir"/"$instance"-history.edn
|
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")
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
|
|
||||||
(logging/deflog "advisorycircular" logger)
|
(logging/deflog "advisorycircular" logger)
|
||||||
|
|
||||||
|
(def log-prefix (atom ""))
|
||||||
|
|
||||||
|
|
||||||
(defn get-basestation-sqb-record [icao db-path]
|
(defn get-basestation-sqb-record [icao db-path]
|
||||||
(log-info "%s: Looking up in %s" icao db-path)
|
(log-info "%s: Looking up in %s" icao db-path)
|
||||||
(p/let [record
|
(p/let [record
|
||||||
@ -168,14 +171,15 @@
|
|||||||
(defn ac-desc [ac]
|
(defn ac-desc [ac]
|
||||||
(str (:icao ac) " " "http://tar1090.adsbexchange.com/?icao=" (:icao ac)
|
(str (:icao ac) " " "http://tar1090.adsbexchange.com/?icao=" (:icao ac)
|
||||||
" " (:lat ac) " " (:lon ac)
|
" " (:lat ac) " " (:lon ac)
|
||||||
" #" (:registration ac) " " (:alt ac) " " (:curviness ac) " "
|
" " (:registration ac) " " (:alt ac) " " (:curviness ac) " "
|
||||||
(:normalized-curviness ac)))
|
(:normalized-curviness ac)))
|
||||||
|
|
||||||
|
|
||||||
(defn screenshot [icao lat lon]
|
(defn screenshot [icao lat lon now]
|
||||||
(p/let [image-path
|
(p/let [image-path (str icao "-" (util/format-utc-ts now) ".png")
|
||||||
(adsbx/screenshot-aircraft icao lat lon
|
_ (adsbx/screenshot-aircraft icao lat lon
|
||||||
{:timeout 30000
|
{:timeout 30000
|
||||||
|
:output-path image-path
|
||||||
;;:headless? false
|
;;:headless? false
|
||||||
;; :viewport {:width 1600 :height 800}
|
;; :viewport {:width 1600 :height 800}
|
||||||
;; :clip {:width 1600 :height 800 :x 0 :y 0}
|
;; :clip {:width 1600 :height 800 :x 0 :y 0}
|
||||||
@ -477,18 +481,18 @@
|
|||||||
(:distance airport-properties)
|
(:distance airport-properties)
|
||||||
(:minimum-airport-distance-km config)
|
(:minimum-airport-distance-km config)
|
||||||
(:label airport-properties)
|
(:label airport-properties)
|
||||||
()))
|
())
|
||||||
(let [alts (map :alt recent-positions)
|
;; (let [alts (map :alt recent-positions)
|
||||||
min-alt (apply min alts)
|
;; min-alt (apply min alts)
|
||||||
max-alt (apply max alts)
|
;; max-alt (apply max alts)
|
||||||
ratio (/ max-alt min-alt)]
|
;; 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))
|
;; (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
|
(do
|
||||||
(p/let [coarse (pelias/reverse (:pelias config) lat lon {:layers "coarse"})]
|
(p/let [coarse (pelias/reverse (:pelias config) lat lon {:layers "coarse"})]
|
||||||
(let [coarse (first (:features coarse))]
|
(let [coarse (first (:features coarse))]
|
||||||
(log-info "%s: Reverse geocode: %s" icao (:properties coarse))
|
(log-info "%s: Reverse geocode: %s" icao (:properties coarse))
|
||||||
;; Note that if we're over the ocean we get null :(
|
;; 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)
|
(p/let [nearby (landmark config lat lon)
|
||||||
_ (log-info "WOOO %s" nearby)
|
_ (log-info "WOOO %s" nearby)
|
||||||
sqb (if-let [sqb-path (:basestation-sqb config)]
|
sqb (if-let [sqb-path (:basestation-sqb config)]
|
||||||
@ -511,14 +515,14 @@
|
|||||||
lat
|
lat
|
||||||
lon)
|
lon)
|
||||||
(log-warn "Skipping tweeting"))
|
(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
|
(util/write-file
|
||||||
path
|
path
|
||||||
(.stringify
|
(.stringify
|
||||||
js/JSON
|
js/JSON
|
||||||
(clj->js (track->geojson older-positions recent-positions icao centroid)))
|
(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]
|
(defn process-potential-circles [acs config now]
|
||||||
@ -536,7 +540,7 @@
|
|||||||
;; This is how many degrees of turning we need to see over
|
;; This is how many degrees of turning we need to see over
|
||||||
;; max-history-age-ms ms to consider it a potential circling
|
;; max-history-age-ms ms to consider it a potential circling
|
||||||
;; aircraft.
|
;; aircraft.
|
||||||
:curviness-threshold-degrees (* 2 360)
|
:curviness-threshold-degrees (* 4 360)
|
||||||
;; If the centroid of the aircraft's positions is less than this
|
;; If the centroid of the aircraft's positions is less than this
|
||||||
;; close to an airport, then it's probably just doing flight
|
;; close to an airport, then it's probably just doing flight
|
||||||
;; training.
|
;; training.
|
||||||
@ -610,7 +614,12 @@
|
|||||||
(.option "--config <path>" "Path to the configuration yaml file")
|
(.option "--config <path>" "Path to the configuration yaml file")
|
||||||
(.option "--secrets <path>" "Path to the secrets yaml file" "secrets.yaml")
|
(.option "--secrets <path>" "Path to the secrets yaml file" "secrets.yaml")
|
||||||
(.option "--history <path>" "Path to history/state file" "advisorycircular.edn")
|
(.option "--history <path>" "Path to history/state file" "advisorycircular.edn")
|
||||||
|
(.option "--log-prefix <prefix>" "Log prefix to use")
|
||||||
(.parse (.-argv js/process)))
|
(.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)]
|
(let [start-time (current-time)]
|
||||||
;; If --config-path is specified, definitely try to read that
|
;; If --config-path is specified, definitely try to read that
|
||||||
;; file. Otherwise, only read config.yaml if it exists.
|
;; file. Otherwise, only read config.yaml if it exists.
|
||||||
|
@ -6,15 +6,34 @@
|
|||||||
(:require-macros
|
(:require-macros
|
||||||
[lemondronor.advisorycircular.logging]))
|
[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)
|
(let [createLogger (.-createLogger winston)
|
||||||
format (.-format winston)
|
format (.-format winston)
|
||||||
transports (.-transports winston)
|
transports (.-transports winston)]
|
||||||
printf-fmt #(gstring/format "%s%-7s %-9s/%-18s| %s"
|
|
||||||
(.-timestamp %)
|
|
||||||
(.-ms %)
|
|
||||||
(.-service %)
|
|
||||||
(.-level %)
|
|
||||||
(.-message %))]
|
|
||||||
(def logger (createLogger
|
(def logger (createLogger
|
||||||
#js {:level "info"
|
#js {:level "info"
|
||||||
:format (.combine
|
:format (.combine
|
||||||
@ -30,7 +49,7 @@
|
|||||||
:defaultMeta #js {}}))
|
:defaultMeta #js {}}))
|
||||||
(.add logger (new (.-Console transports)
|
(.add logger (new (.-Console transports)
|
||||||
#js {:format (.combine format
|
#js {:format (.combine format
|
||||||
(.printf format printf-fmt))})))
|
(.printf format format-msg))})))
|
||||||
|
|
||||||
|
|
||||||
(defn get-logger [service]
|
(defn get-logger [service]
|
||||||
|
@ -85,3 +85,15 @@
|
|||||||
[[k]])))
|
[[k]])))
|
||||||
m))
|
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))))
|
||||||
|
Loading…
Reference in New Issue
Block a user