Class: SportsDb::TeamAndRosterBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/sports_db/team_and_roster_builder.rb

Class Method Summary collapse

Class Method Details

.map_poll_key(poll_key) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/sports_db/team_and_roster_builder.rb', line 58

def self.map_poll_key(poll_key)
    case poll_key
        when "poll-ap"
            "1"
        when "poll-usat"
            "2"
        when "ranking-bcs"
            "3"
        when "ap"
          "ap"
        when "coaches"
          "coaches"
        when "rpi"
          "rpi"
        else
            "1"
    end
end

.update_player_image_urlsObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sports_db/team_and_roster_builder.rb', line 4

def self.update_player_image_urls
    p "update_player_image_urls ..."
    config_feeds = SimpleConfig.for(:feeds)
    require 'open-uri'
    open( config_feeds.player_images_url ) do |file|
        doc = Nokogiri::XML(file.read)
        doc.xpath('//row').each do |player_element|
            # The date is in format '08-MAY-77' and we need '8/5/1977' as a string. However, this still doesn't
            # strip leading zeroes off days, which we need to do to match this date as a string.
            # Convert to string, replace last bit so it says "19xx", parse to date, and then format
            # in the D/M/Y format. Then finally remove leading zeroes.
            if !player_element['BIRTH_DATE'].blank?
                adj_birth_date = DateTime.strptime(player_element['BIRTH_DATE'].to_s, "%m/%d/%Y").to_s
            end
            
            # Try only the name first.
            matches = Player.find_by_last_comma_first( player_element['PLAYER_NAME'] )
            # But if there's more than one, then attempt to whittle it down with the birthday
            matches = matches.select {|p| p.birth_date == adj_birth_date } if (matches.length > 1)
            
            if (matches.length == 1)
                player = matches[0]
                player.image_url        = player_element['PLAYER_MUG']
                player.sporting_news_id = player_element['PLAYER_ID'].to_i
                player.save
                
                p "img- #{player_element['PLAYER_NAME']} - #{player_element['PLAYER_MUG']}"
            else
              p "Unable to Match -- #{player_element['PLAYER_NAME']}"
            end

        end
    end              
rescue Exception => e
    Zumobi::ExceptionHandler.error e
end

.update_team_top25_rankObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sports_db/team_and_roster_builder.rb', line 41

def self.update_team_top25_rank
    p "Set Top 25 Rank"

    rank_issuer_key = map_poll_key(CONFIG.rank_based_on_poll)
    
    rankings = PollRanking.all(:conditions => ["issuer_key = ?", rank_issuer_key])
    rankings.each do |obj|
        team_obj = Team.find(obj.team_id)
        # Only rank 1-25 (bug 24359)
        if team_obj.present? && obj.rank.to_i < 26
            p "#{team_obj.city_name} ##{obj.rank}"
            team_obj.rank = obj.rank
            team_obj.save
        end
    end
end