From ac56fb0b617a7c76ace68fcb673ce4f9fe0fc25b Mon Sep 17 00:00:00 2001 From: John Wiseman Date: Sat, 4 Apr 2020 16:32:33 -0700 Subject: [PATCH] Write geojson of each track. --- .gitignore | 1 + README.md | 9 ++++ src/main/lemondronor/circlebot.cljs | 20 +++++---- src/main/lemondronor/circlebot/util.cljs | 56 ++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 60cbe00..126bf4a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules out .DS_Store +secrets.yaml diff --git a/README.md b/README.md index a5022cb..37997bc 100644 --- a/README.md +++ b/README.md @@ -158,3 +158,12 @@ more than once every 10 seconds. * **Do not run the script more often than once every 10 seconds, or adsbexchange.com will ban your IP.** + + +## Development + +To run a test watcher: + +``` +npx shadow-cljs watch script test +``` diff --git a/src/main/lemondronor/circlebot.cljs b/src/main/lemondronor/circlebot.cljs index d2f298f..a592b4e 100644 --- a/src/main/lemondronor/circlebot.cljs +++ b/src/main/lemondronor/circlebot.cljs @@ -19,7 +19,6 @@ (logging/deflog "circlebot" logger) - (defn get-basestation-sqb-record [icao db-path] (log-info "%s: Looking up in %s" icao db-path) (p/let [record @@ -455,13 +454,18 @@ (= (get-in coarse [:properties :name]) "California")) (log-info "%s: Filtering out because it is outside Los Angeles County" (:icao ac)) (if (and image-path description) - (if (get-in config [:twitter :enabled?]) - (twitter/tweet (twitter/twit (:twitter config)) - description - [image-path] - lat - lon) - (log-warn "Skipping tweeting")) + (do + (if (get-in config [:twitter :enabled?]) + (twitter/tweet (twitter/twit (:twitter config)) + description + [image-path] + lat + lon) + (log-warn "Skipping tweeting")) + (let [path (str (.toFixed (/ now 1000) 0) "-" icao ".geojson")] + (util/write-file path (.stringify + js/JSON + (clj->js (util/->geojson recent-positions icao centroid)))))) (log-warn "Skipping tweet %s %s" image-path description))))))))))) diff --git a/src/main/lemondronor/circlebot/util.cljs b/src/main/lemondronor/circlebot/util.cljs index b82d334..e92987b 100644 --- a/src/main/lemondronor/circlebot/util.cljs +++ b/src/main/lemondronor/circlebot/util.cljs @@ -85,3 +85,59 @@ [[k]]))) m)) [])) + + + ;; "type": "FeatureCollection", + ;; "features": [ + ;; { + ;; "type": "Feature", + ;; "properties": {}, + ;; "geometry": { + ;; "type": "LineString", + ;; "coordinates": [ + ;; [ + ;; -118.27262878417969, + ;; 33.920001740102585 + ;; ], + ;; [ + ;; -118.2176971435547, + ;; 33.946777683283706 + ;; ], + ;; ] + ;; } + ;; }, + ;; { + ;; "type": "Feature", + ;; "properties": { + ;; "marker-color": "#7e7e7e", + ;; "marker-size": "medium", + ;; "marker-symbol": "", + ;; "ICAO": "AE0000" + ;; }, + ;; "geometry": { + ;; "type": "Point", + ;; "coordinates": [ + ;; -118.17649841308594, + ;; 33.99176508196857 + ;; ] + ;; } + ;; } + ;; ] + ;; } + + (defn ->geojson [positions icao centroid] + {:type "FeatureCollection" + :features + [{:type "Feature" + :properties {} + :geometry + {:type "LineString" + :coordinates (map (fn [pos] [(:lon pos) (:lat pos)]) positions)}} + {:type "Feature" + :properties {:marker-color "#7e7e7e" + :marker-size "medium" + :marker-symbol "" + :ICAO icao} + :geometry {:type "Point" + :coordinates [(:lon centroid) (:lat centroid)]}}]}) +