- Timestamp:
- 11/09/07 00:09:16 (5 years ago)
- Location:
- hw/hw4/library/app
- Files:
-
- 2 modified
-
controllers/librarymaps_controller.rb (modified) (4 diffs)
-
views/librarymaps/index.rhtml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
hw/hw4/library/app/controllers/librarymaps_controller.rb
r87 r97 16 16 17 17 # Retrieve the list of libraries for the Select (Drop Down) Box 18 # "@" prece eding a variable name indicates an instance variable.18 # "@" preceding a variable name indicates an instance variable. 19 19 # Instance variables can be passed to views, whereas 20 # local variables (variable names without prece eding "@") cannot20 # local variables (variable names without preceding "@") cannot 21 21 # be passed to views. 22 22 @alllibraries = Array.new … … 57 57 :info_window => libraryname)) 58 58 59 # Get all the authors. 59 # The following code fetches all the authors, geocodes their birthplaces, 60 # computes distance to the library, sorts by distance, and plots the 61 # top 15 closest. This chunk is not going to scale well as we 62 # increase the number of authors! 63 64 # Suck all the authors out of the database into a Ruby array, and 65 # loop through them. 60 66 @authors = Array.new 61 67 results = Author.find(:all) … … 70 76 if geoloc.status == Geocoding::GEO_SUCCESS 71 77 authlatlon = geoloc[0].latlon 72 # Distances recalculated from a relativ ley stable set of libraries.78 # Distances recalculated from a relatively stable set of libraries. 73 79 # This is a good candidate for caching. 74 80 dist = distance_between(authlatlon,liblatlon).floor 75 @map.overlay_init(GMarker.new(geoloc[0].latlon, 76 :title => result.name, 77 :info_window => "#{result.name} says:<br> I am #{dist} miles away<br> from #{@mylibrary.lname}")) 78 @authors << [result.name,result.bplace,dist] 81 @authors << [result.name,result.bplace,dist,authlatlon] 79 82 end 80 83 end … … 82 85 # Sort authors in place by dist. "sort!" means in place. 83 86 @authors.sort! {|x,y| x[2] <=> y[2] } 87 # truncate the array to just the top 10 88 @authors = @authors[0..9] 84 89 90 @authors.each do |a| 91 @map.overlay_init(GMarker.new(a[3], 92 :title => a[0], 93 :info_window => "#{a[0]} says:<br> I am #{a[2]} miles away<br> from #{@mylibrary.lname}")) 94 end 85 95 # Measure speed of server-side operation. 86 # Typical times w/ RPC : 3.5 seconds87 # Typical times w/o RPC : 0.3 seconds96 # Typical times w/ RPC on 17 authors: 3.5 seconds 97 # Typical times w/o RPC on 17 authors: 0.3 seconds 88 98 # Rhombus server fluctuations will cause this value to vary. 89 99 endtime = Time.now -
hw/hw4/library/app/views/librarymaps/index.rhtml
r87 r97 28 28 <% end %> 29 29 </table> 30 <i>Top <%= @authors.length %> of <%= Author.count %> shown.</i> 30 31 </td> 31 32 </tr>
