Permalink
Browse files

Add stats to rides/index (per bike rides & mileage)

  • Loading branch information...
1 parent aca625e commit 16382fd612995f9bee97c09f0b1dc18dd78849b9 Stuart Fletcher committed Oct 22, 2011
Showing with 8 additions and 1 deletion.
  1. +5 −0 app/controllers/rides_controller.rb
  2. +3 −1 app/views/rides/index.html.erb
View
5 app/controllers/rides_controller.rb
@@ -13,6 +13,11 @@ def index
@rides = @user.rides.reals.bike(bike).month_and_year(month, year).sort_by(&:date)
@services = @user.rides.reals.service.bike(bike).month_and_year(month, year).sort_by(&:date)
+ @rides_only = @rides - @services
+
+ # these could perhaps be simpler?
+ @rides_by_bike = @rides_only.map(&:bike).uniq.map {|b| [b.name, @rides_only.select {|r| r.bike_id == b.id}.size, @rides_only.select {|r| r.bike_id == b.id}.map(&:miles).sum]}
+ @services_by_bike = @services.map(&:bike).uniq.map {|b| [b.name, @services.select {|r| r.bike_id == b.id}.size]}
else
@rides = @user.rides.reals.sort_by(&:date)
@services = @user.rides.reals.service.sort_by(&:date)
View
4 app/views/rides/index.html.erb
@@ -41,10 +41,12 @@
<%= nice_number(@rides.map(&:kilometers).sum) %> km
</p>
<p>
-Rides: <%= @rides.size - @services.size %>
+Rides: <%= @rides_only.size %>
+(<%= @rides_by_bike.map {|r| "#{r.first}: #{r.second} for #{nice_number(r.third)} miles"}.join(", ") %>)
</p>
<p>
Services: <%= @services.size %>
+(<%= @services_by_bike.map {|s| "#{s.first}: #{s.last}"}.join(", ") %>)
</p>
<p><%= link_to "New Ride", new_ride_path %></p>

0 comments on commit 16382fd

Please sign in to comment.