More touchup in map pair generation while thinking about mash storage
This commit is contained in:
parent
824bbb4865
commit
ec6d9d5146
@ -2,31 +2,18 @@ require 'fastercsv'
|
|||||||
|
|
||||||
|
|
||||||
class Map < ActiveRecord::Base
|
class Map < ActiveRecord::Base
|
||||||
named_scope :lowest_scoring, :conditions => [
|
|
||||||
%{`maps`.`points` = (
|
|
||||||
SELECT `points` FROM `maps`
|
|
||||||
ORDER BY `points` ASC
|
|
||||||
LIMIT 1
|
|
||||||
)}]
|
|
||||||
|
|
||||||
def self.from_city_name(city_name)
|
def self.from_city_name(city_name)
|
||||||
self.find_or_initialize_by_name(city_name).save!
|
self.find_or_initialize_by_name(city_name).save!
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.pair
|
def self.pair
|
||||||
if Mash.count == 0
|
self.all(:order => 'RANDOM()', :limit => 2)
|
||||||
self.all(:order => 'RANDOM()', :limit => 2)
|
|
||||||
else
|
|
||||||
self.lowest_scoring.all(:order => 'RANDOM()', :limit => 2)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.import(csv_filename)
|
def self.import(csv_filename)
|
||||||
FasterCSV.parse(open(csv_filename), :headers => true,
|
FasterCSV.parse(open(csv_filename), :headers => true,
|
||||||
:header_converters => [:downcase, :symbol]).each do |row|
|
:header_converters => [:downcase, :symbol]).each do |row|
|
||||||
map = self.find_or_initialize_by_name(
|
map = self.find_or_initialize_by_name("#{row[:city]}, #{row[:region]}")
|
||||||
"#{row[:city]}, #{row[:region]}"
|
|
||||||
)
|
|
||||||
map.save
|
map.save
|
||||||
if block_given?
|
if block_given?
|
||||||
yield map
|
yield map
|
||||||
|
Loading…
Reference in New Issue
Block a user