Commits

Don Park committed 6e6d22f

when displaying an AP, show how many observations exist for that AP

  • Participants
  • Parent commits afece64

Comments (0)

Files changed (4)

File sinatra/lib/geomena/couch.rb

     end
   end
   
+  def self.get_observation_count_for_mac(macaddr) 
+    body = conn do |http|
+      getparams = "key=#{macaddr.to_json}&group=true"
+      http.get("/geomena/_design/observations/_view/count?#{URI.escape(getparams)}")
+    end.body
+    rows = JSON.parse(body)["rows"]
+    rows.first["value"]
+  end
+
   def self.get_by_mac(macaddr) 
-ref=    conn do |http|
+    conn do |http|
       startkey=[macaddr, "2038"].to_json
       endkey=[macaddr, ""].to_json
       getparams = "startkey=#{startkey}&endkey=#{endkey}&descending=true"
-puts getparams
       http.get("/geomena/_design/observations/_view/bymacdate?#{URI.escape(getparams)}")
     end.body
-puts ref
-ref
   end
   
   def self.get_by_essid(essid) 

File sinatra/lib/geomena/web.rb

     end
     
     get '/' do
-      erb :index, :locals => {:count => GCouch.count}
+      erb :index, :locals => {:ocount => GCouch.count}
     end
     
     get '/api' do
     get '/ap/:mac' do |mac|
       response = GCouch.get_by_mac(mac)
       ap = first_ap(response)
-      erb :apshow, :locals => {:ap => ap, :mac => mac}
+      ocount = GCouch.get_observation_count_for_mac(mac)
+      erb :apshow, :locals => {:ap => ap, :mac => mac, :ocount => ocount}
     end
     
     post '/ap/:mac' do |mac|

File sinatra/views/apshow.erb

    <h3> Wireless Access Point </h3>
     <% if ap %>
       MAC Address: <%= ap["mac"] %>  <br/>
+      Number of observations: <%= ocount %> <br/>
       Name: <%= ap["essid"] %> <br/>
       Created at: <%= Time.parse(ap["created_at"]) if ap["created_at"]%> <br/>
       Latitude: <%= ap["latitude"] %>  <br/>

File sinatra/views/index.erb

   </div>
 
   <p>
-   There are <%= count %> access points in the database.
+   There are <%= ocount %> observations in the database.
   </p>
 
   <div id="browsersetupbox">