Removing extracted map-mash subtree

This commit is contained in:
Dan Buch
2012-05-05 17:27:21 -04:00
parent dc110b78de
commit b70a59831a
114 changed files with 0 additions and 19596 deletions

View File

@@ -1,67 +0,0 @@
require 'fastercsv'
class Map < ActiveRecord::Base
def self.from_city_name(city_name)
self.find_or_initialize_by_name(city_name).save!
end
def self.pair
second = nil
max_tries = self.count
tries = 0
while second.nil? && tries < max_tries
first = self.all(:order => 'RANDOM()', :limit => 1).first
second = self.all(:order => 'RANDOM()', :limit => 1,
:conditions => [%{
(
points >= :first_points
AND id <> :first_id
) OR (
id NOT IN (
SELECT map_a_id
FROM mashes
WHERE map_b_id = :first_id
)
AND id NOT IN (
SELECT map_b_id
FROM mashes
WHERE map_a_id = :first_id
)
)}, {
:first_id => first.id,
:first_points => first.points
}
]
).first
tries += 1
end
if second.nil?
logger.error('OH CRAP thar be no more pairings for ye olde mashes')
[first, first]
else
[first, second]
end
end
def self.import(csv_filename)
FasterCSV.parse(open(csv_filename), :headers => true,
:header_converters => [:downcase, :symbol]).each do |row|
map = self.find_or_initialize_by_name("#{row[:city]}, #{row[:region]}")
map.save
if block_given?
yield map
end
end
end
def self.mashes
Mash.all(:conditions => ['map_a = :id OR map_b = :id', {:id => self.id}])
end
def rounds
Mash.count(:conditions => ['map_a = :id OR map_b = :id', {:id => self.id}])
end
end

View File

@@ -1,13 +0,0 @@
class Mash < ActiveRecord::Base
belongs_to :map_a, :class_name => 'Map'
belongs_to :map_b, :class_name => 'Map'
belongs_to :winner, :class_name => 'Map'
has_one :tournament, :class_name => 'MashTournament'
has_one :round, :class_name => 'MashTournamentRound'
named_scope :unplayed, :conditions => [%{
winner_id IS NULL
AND map_a_id IS NOT NULL
AND map_b_id IS NOT NULL
}]
end

View File

@@ -1,39 +0,0 @@
class MashTournament < ActiveRecord::Base
belongs_to :requester
has_many :mashes
has_many :rounds, :class_name => 'MashTournamentRound'
def next_unplayed_mash
mash = self.mashes.unplayed.first
if not mash
filled = self.builder.fill_in_next_round
if filled
return self.mashes.unplayed.first
else
return nil
end
else
return mash
end
end
def total_rounds_options
@total_rounds_options ||= [3, 4, 5, 6, 7]
end
def done?
self.rounds.collect(&:done?).uniq == [true]
end
def round(number = 0)
MashTournamentRound.find_by_mash_tournament_id(self.id,
:conditions => {:number => number}
)
end
def builder
MashTournamentBuilder.new(
self, MashTournament, MashTournamentRound, Map, Mash
)
end
end

View File

@@ -1,16 +0,0 @@
class MashTournamentRound < ActiveRecord::Base
belongs_to :tournament, :class_name => 'MashTournament'
has_many :mashes
def self.for_round(tournament, round_number)
self.find_by_mash_tournament_id_and_number(tournament, round_number)
end
def done?
winners = []
self.mashes.collect do |mash|
winners << mash.winner_id
end
!winners.include?(nil)
end
end

View File

@@ -1,7 +0,0 @@
class Requester < ActiveRecord::Base
has_many :mash_tournaments
def current_tournament
self.mash_tournaments.last
end
end