@@ -54,13 +54,82 @@ def timestamps_fields
5454
5555 def detailed_attributes
5656 {
57- match_id : @scrim . match_id ,
57+ match_id : @scrim . match_id ,
5858 pre_game_notes : @scrim . pre_game_notes ,
5959 post_game_notes : @scrim . post_game_notes ,
60- game_results : @scrim . game_results ,
61- objectives : @scrim . objectives ,
62- outcomes : @scrim . outcomes ,
63- objectives_met : @scrim . objectives_met?
60+ game_results : @scrim . game_results ,
61+ objectives : @scrim . objectives ,
62+ outcomes : @scrim . outcomes ,
63+ objectives_met : @scrim . objectives_met? ,
64+ opponent_detail : opponent_detail ,
65+ head_to_head : head_to_head
66+ }
67+ end
68+
69+ TIER_SCORE = {
70+ 'CHALLENGER' => 9 , 'GRANDMASTER' => 8 , 'MASTER' => 7 ,
71+ 'DIAMOND' => 6 , 'EMERALD' => 5 , 'PLATINUM' => 4 ,
72+ 'GOLD' => 3 , 'SILVER' => 2 , 'BRONZE' => 1
73+ } . freeze
74+
75+ TIER_LABEL = {
76+ 9 => 'Challenger' , 8 => 'Grandmaster' , 7 => 'Master' ,
77+ 6 => 'Diamond' , 5 => 'Emerald' , 4 => 'Platinum' ,
78+ 3 => 'Gold' , 2 => 'Silver' , 1 => 'Bronze' , 0 => 'Iron'
79+ } . freeze
80+
81+ def opponent_detail
82+ return nil unless @scrim . opponent_team
83+
84+ t = @scrim . opponent_team
85+
86+ # Try to find the registered Organization with the same name
87+ org = Organization . unscoped . find_by ( name : t . name )
88+ roster , avg_tier = org_roster_and_avg ( org )
89+
90+ {
91+ league : t . league ,
92+ discord_server : t . discord_server || org &.discord_invite_url ,
93+ known_players : Array ( t . known_players ) ,
94+ playstyle_notes : t . playstyle_notes ,
95+ strengths : Array ( t . strengths ) ,
96+ weaknesses : Array ( t . weaknesses ) ,
97+ roster : roster ,
98+ avg_tier : avg_tier
99+ }
100+ end
101+
102+ def org_roster_and_avg ( org )
103+ return [ [ ] , nil ] unless org
104+
105+ players = org . players . active . select ( :summoner_name , :role , :solo_queue_tier )
106+ scores = players . map { |p | TIER_SCORE [ p . solo_queue_tier . to_s . upcase ] || 0 }
107+ avg = scores . empty? ? nil : TIER_LABEL [ ( scores . sum . to_f / scores . size ) . round ]
108+
109+ roster = players . map { |p | { summoner_name : p . summoner_name , role : p . role , tier : p . solo_queue_tier } }
110+ [ roster , avg ]
111+ end
112+
113+ def head_to_head
114+ return nil unless @scrim . opponent_team_id
115+
116+ past = Scrim . unscoped
117+ . where ( organization_id : @scrim . organization_id ,
118+ opponent_team_id : @scrim . opponent_team_id )
119+ . where . not ( id : @scrim . id )
120+ . where . not ( games_completed : nil )
121+ . where ( 'games_completed >= games_planned' )
122+ . order ( scheduled_at : :desc )
123+ . limit ( 10 )
124+ . to_a
125+
126+ wins = past . count { |s | s . win_rate . to_f >= 50 }
127+ losses = past . count - wins
128+
129+ {
130+ wins : wins ,
131+ losses : losses ,
132+ total : past . count
64133 }
65134 end
66135
@@ -76,12 +145,16 @@ def calendar_attributes
76145 def opponent_team_summary
77146 return nil unless @scrim . opponent_team
78147
148+ t = @scrim . opponent_team
79149 {
80- id : @scrim . opponent_team . id ,
81- name : @scrim . opponent_team . name ,
82- tag : @scrim . opponent_team . tag ,
83- tier : @scrim . opponent_team . tier ,
84- logo_url : @scrim . opponent_team . logo_url
150+ id : t . id ,
151+ name : t . name ,
152+ tag : t . tag ,
153+ tier : t . tier ,
154+ region : t . region ,
155+ scrims_won : t . scrims_won || 0 ,
156+ scrims_lost : t . scrims_lost || 0 ,
157+ logo_url : t . logo_url
85158 }
86159 end
87160
0 commit comments