Skip to content

Commit

Permalink
Add room assignment script and a short README to /util
Browse files Browse the repository at this point in the history
  • Loading branch information
reidab committed Jun 16, 2014
1 parent e623205 commit 34bf040
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions util/README.md
@@ -0,0 +1,3 @@
# /util

This directory contains useful scripts that we've written to automate bits and peices of things that came up while running [Open Source Bridge](http://opensourcebridge.org). It would be nice to wrap some of the more common things up into rake tasks, but for now, they live here.
40 changes: 40 additions & 0 deletions util/assign_rooms.rb
@@ -0,0 +1,40 @@
# Assigns rooms, based on user_favorite popularily
#
# Usage: rails runner assign_rooms.rb

class RoomAllocator
LARGE_ROOMS = ["B202/203", "B302/303"]
SMALL_ROOMS = ["B201", "B204", "B301", "B304"]

def initialize
@current_event = OpenConferenceWare::Event.current
@sessions = @current_event.proposals.confirmed.scheduled.sort_by{|s| s.user_favorites.count }.reverse
@rooms = (LARGE_ROOMS + SMALL_ROOMS).map{|rn| @current_event.rooms.find_by_name(rn) }
end

def room_available_at?(room, start_time)
@sessions.select{|s| s.start_time == start_time}.all?{|s| s.room != room}
end

def allocate_rooms
@sessions.each do |session|
next if session.room.present?
first_available_room = @rooms.find{|room| room_available_at?(room, session.start_time)}
if first_available_room.present?
puts "[#{session.user_favorites.count}] Assigned #{session.title} to #{first_available_room.name}"
session.room = first_available_room
else
puts "[!!] Could not find a room assignment for #{session.title}"
end
end

puts "---"
puts "Accept room assignments? (y/n)"
if gets.chomp == "y"
@sessions.each{|s| s.save!}
end
end
end


RoomAllocator.new.allocate_rooms

0 comments on commit 34bf040

Please sign in to comment.