Skip to content
This repository has been archived by the owner on Feb 27, 2018. It is now read-only.

Commit

Permalink
Updated stats on talks to return total slots available and in the
Browse files Browse the repository at this point in the history
future.
  • Loading branch information
martian-a committed Jul 5, 2012
1 parent f6e6e20 commit ff9e848
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/stats_controller.rb
Expand Up @@ -4,7 +4,7 @@ class StatsController < ActionController::Base
def talks

@talks = Talk.find_attendee_talks.count
@slots_free = Slot.find_available.count
@slots_free = Slot.find_all_available_upcoming.count

result = {:talks => @talks, :slots_free => @slots_free}
render :json => result.to_json
Expand Down
46 changes: 41 additions & 5 deletions app/models/slot.rb
Expand Up @@ -44,21 +44,57 @@ def self.find_empty
return @slots
end

# Empty and unlocked
def self.find_available
# Empty and in the future (but not necessarily available)
def self.find_empty_upcoming
@slots = Array.new()

empty_slots = Slot.find_empty
upcoming_timeslots = Timeslot.upcoming
empty_slots.find_empty.each do | slot |
if (upcoming_timeslots.include?(slot.timeslot))
@slots << slot
end
end
return @slots

end

# Empty and unlocked (but not necessarily in the future)
def self.find_all_available
self.find_available(Slot.all)
end

# Empty and unlocked from set of slots provided (but not necessarily in the future)
def self.find_available(slots_to_check)

@slots = Array.new()
empty_slots.each do | slot |
if (!slot.locked)
slots_to_check.each do | slot |
if (!slot.locked && slot.is_empty?)
@slots << slot
end
end

return @slots
end

# Available and in the future
def self.find_all_available_upcoming
Slot.find_available_upcoming(Slot.all)
end

# Available and in the future
def self.find_available_upcoming(slots_to_check)

@slots = Array.new()
slots_to_check.each do | slot |
if (!slot.locked && slot.is_empty? && slot.timeslot.is_upcoming?)
@slots << slot
end
end

return @slots

end

def self.find_occupied
Slot.select {|slot| !slot.is_empty?}
end
Expand Down
6 changes: 5 additions & 1 deletion app/models/timeslot.rb
Expand Up @@ -42,6 +42,10 @@ def on_now?
def on_next?
self == Timeslot.on_next
end

def is_upcoming?
self.start >= Time.now
end

# Returns the timeslot that immediately follows the current timeslot
def next
Expand All @@ -61,7 +65,7 @@ def self.today
# Returns all timeslots that begin during the first day of the event
def self.first_day
Timeslot.by_date(Timeslot.all.first.start.to_date)
end
end

# Returns all timeslots that begin during date specified
def self.by_date(date_in)
Expand Down

0 comments on commit ff9e848

Please sign in to comment.