Skip to content

Commit

Permalink
Added number of days ridden/mo. and percentage of days.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuart Fletcher committed Nov 13, 2011
1 parent a20fe42 commit 079dfeb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README
Expand Up @@ -74,6 +74,9 @@ DONE:
by bicycle and give a total. by bicycle and give a total.
* Having ALL rides on one page is getting unwieldy too. Should organize * Having ALL rides on one page is getting unwieldy too. Should organize
by month or by month&bike or... by month or by month&bike or...
* When filtering rides for a certain month, list # of days in month with
riding vs. number of days w/o riding. To get # of days in a month:
Date.civil(2012, 2, -1).day, or Date.civil(year_num, month_num, -1).day


TODO: TODO:


Expand Down Expand Up @@ -114,6 +117,3 @@ FEATURE TODO:
etc. etc.
* Markdown (or something) for ride descriptions (& probably other more) * Markdown (or something) for ride descriptions (& probably other more)
(maybe rdiscount: https://github.com/rtomayko/rdiscount) (maybe rdiscount: https://github.com/rtomayko/rdiscount)
* When filtering rides for a certain month, list # of days in month with
riding vs. number of days w/o riding. To get # of days in a month:
Date.civil(2012, 2, -1).day, or Date.civil(year_num, month_num, -1).day
21 changes: 21 additions & 0 deletions app/controllers/rides_controller.rb
Expand Up @@ -14,13 +14,34 @@ def index
Array.new(3) # [nil, nil, nil] Array.new(3) # [nil, nil, nil]
end end


# TODO: setting a default year is taken care of in the scope in the
# model, but maybe it's better to do it here and make the model
# dumber? NMW, for now I have to set a default year here TOO, which
# isn't great...
if !month.nil? && month > 0 && (year.nil? || year.zero?)
year = Date.today.year
end

@rides = @user.rides.reals.bike(bike).month_and_year(month, year).sort_by(&:date) @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) @services = @user.rides.reals.service.bike(bike).month_and_year(month, year).sort_by(&:date)
@rides_only = @rides - @services @rides_only = @rides - @services


# these could perhaps be simpler? # 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]} @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]} @services_by_bike = @services.map(&:bike).uniq.map {|b| [b.name, @services.select {|r| r.bike_id == b.id}.size]}

# count # of days/month that were ridden
@days_ridden, @total_days =
if year && month
days = if (year == Date.today.year && month == Date.today.month)
Date.today.day
else
Date.civil(year, month, -1).day
end
[@rides_only.map(&:date).uniq.size, days]
else
[nil, nil]
end
end end


def show def show
Expand Down
7 changes: 7 additions & 0 deletions app/views/rides/index.html.erb
Expand Up @@ -49,4 +49,11 @@ Services: <%= @services.size %>
(<%= @services_by_bike.map {|s| "#{s.first}: #{s.last}"}.join(", ") %>) (<%= @services_by_bike.map {|s| "#{s.first}: #{s.last}"}.join(", ") %>)
</p> </p>


<%- if @days_ridden && @total_days -%>
<p>
<%= @days_ridden %> days ridden out of <%= @total_days %>
(<%= nice_number(1.0 * @days_ridden / @total_days * 100) %>% of days)
</p>
<%- end -%>

<p><%= link_to "New Ride", new_ride_path %></p> <p><%= link_to "New Ride", new_ride_path %></p>

0 comments on commit 079dfeb

Please sign in to comment.