Skip to content

Commit

Permalink
Update don't display inactive instruments on map
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterMartin committed Mar 6, 2023
1 parent e31fbee commit 4a5e5a7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
33 changes: 18 additions & 15 deletions app/controllers/sites_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ def edit
def map
end

## generates json for all sites, format:
## generates json for all sites:
# (status is true if all instruments at the site are active and have recent data.
# We should have a more descriptive key than "status" for this.)
# {
# "type": "FeatureCollection",
# "features": [
Expand All @@ -39,29 +41,31 @@ def map
# }
# ]
# }
# status is true if all instruments at the site are active and have recent data.
# We should use a better key than "status" for this.
def map_markers_geojson
features = []

json_data = @sites.each do |site|
# determine whether site is active (ie. all active instruments are receiving data)
# filter on the sites that are active but not receiving data.
is_receiving = (site.instruments.select{|i| ((i.is_receiving_data == false) && (i.is_active == true))}.length == 0)

geometry = {type: "Point", coordinates: [site.lon, site.lat]}
properties = {name: site.name, url: site_url(site), status: is_receiving}

feature = {type: "Feature", geometry: geometry, properties: properties}
features << feature
# Are there any instruments at this site which are active and missing data?
missing_recent_data = (site.instruments.select{|i| ((i.is_receiving_data == false) && (i.is_active == true))}.length == 0)
# Only consider sites with active instruments
if (site.instruments.select{|i| i.is_active == true}.length > 0)
geometry = {type: "Point", coordinates: [site.lon, site.lat]}
properties = {name: site.name, url: site_url(site), status: missing_recent_data}

feature = {type: "Feature", geometry: geometry, properties: properties}
features << feature
end
end
logger.debug "*** map_markers_geojson features: #{features}"

sites_geojson = {type: "FeatureCollection", features: features}.to_json

render json: sites_geojson
end

## generate json for particular site's active instruments, format:
## generate json for particular site's active instruments
# (status is true if the instrument is active and has recent data.
# We should have a more descriptive key than "status" for this.)
# [
# {
# "name": "Instrument 1",
Expand All @@ -74,8 +78,7 @@ def map_markers_geojson
# "url": "asdfasdf"
# }
# ]
# status is true if the instrument is active and has recent data.
# We should use a better key than "status" for this.
# .
def map_balloon_json
instrument_json = []

Expand Down
2 changes: 1 addition & 1 deletion app/views/sites/map.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// configurations to set up marker clustering
%link{rel: "stylesheet", href: "https://unpkg.com/leaflet.markercluster@1.3.0/dist/MarkerCluster.css"}
%script{src: "https://unpkg.com/leaflet.markercluster@1.3.0/dist/leaflet.markercluster-src.js"}
%div#refreshinfo{style: "width: 800px; display: block; margin: auto"} Data source is refreshed every 5 minutes.
%div#refreshinfo{style: "width: 800px; display: block; margin: auto"} The map is refreshed every 5 minutes. Instruments marked inactive are not included.
%div#geomap{style: "width: 800px; height: 600px; display: block; margin: auto"}
%div#buttons{style: "width: 800px; display: block; margin: auto"}
%button#street{style: "z-index: 1000; margin-top: 5px"} Street View
Expand Down

0 comments on commit 4a5e5a7

Please sign in to comment.