Commit 3b3f30d6 authored by alain's avatar alain 🐙
Browse files

filter out things without datastreams

parent 622c2f62
...@@ -9,6 +9,12 @@ ...@@ -9,6 +9,12 @@
`gem install csv` `gem install csv`
`gem install redis`
`gem install rack`
`gem install rack-cors`
## to start ## to start
`brew services start redis` `brew services start redis`
......
...@@ -37,14 +37,14 @@ get '/sensor/:type' do ...@@ -37,14 +37,14 @@ get '/sensor/:type' do
end end
body = nil body = nil
if($redis.exists uri) if($redis.exists uri )
body = $redis.get uri body = $redis.get uri
puts "cache hit" puts "cache hit"
else else
pages = [] pages = []
getPageRecursive(pages,uri,false) getPageRecursive(pages,uri,false)
things = pages.map{|page|page["value"]}.flatten things = pages.map{|page|page["value"]}.flatten.select{|thing|thing["Datastreams"] != nil}
result = things.map{|thing| result = things.map{|thing|
ds_list = thing["Datastreams"] ds_list = thing["Datastreams"]
...@@ -145,10 +145,12 @@ end ...@@ -145,10 +145,12 @@ end
def getPageRecursive(pages,uri,filter) def getPageRecursive(pages,uri,filter)
#start = Time.now
response = RestClient.get uri response = RestClient.get uri
page = JSON.parse(response) page = JSON.parse(response)
nextLink = page["@iot.nextLink"] nextLink = page["@iot.nextLink"]
nextLink = "#{nextLink}&$select=phenomenonTime,result" if(filter and nextLink != nil and not nextLink.empty?) nextLink = "#{nextLink}&$select=phenomenonTime,result" if(filter and nextLink != nil and not nextLink.empty?)
pages << page pages << page
#puts "#{uri}: #{Time.now - start} s"
getPageRecursive(pages,nextLink,filter) if (nextLink != nil and not nextLink.empty?) getPageRecursive(pages,nextLink,filter) if (nextLink != nil and not nextLink.empty?)
end end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment