forked from osbridge/openconferenceware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add room assignment script and a short README to /util
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |