Offensive power rating: the average amount of points that a team
 contributes to their alliance's score.

 This is high for a good team.
164068
def opr(recalc = false)
			if !@opr || recalc || @opr_recalc
				a = alliance_smooshey @ared, @ablue
				score = alliance_smooshey @scorered, @scoreblue

				@opr = opr_calculate a, score
				@opr_recalc = false
			end

			@opr
		end
753606
def playerSurrendered(cfg):
    """"""
    if cfg.numAgents + cfg.numBots == 2:
          otherResult = c.RESULT_VICTORY
    else: otherResult = c.RESULT_UNDECIDED # if multiple players remain, they need to finish the match
    return assignValue(cfg, c.RESULT_DEFEAT, otherResult)
1281377
function(client, packet) {
            var teams_count  = packet.readUInt32LE();
            var teams_scores = [];

            for (var i=0;i<teams_count;++i) {
                teams_scores.push(packet.readFloat32LE());
            }

            if(JSON.stringify(client.teams_scores) == JSON.stringify(teams_scores)) return;
            var old_scores = client.teams_scores;

            if(client.debug >= 3)
                client.log('teams scores update: ' + JSON.stringify(teams_scores));

            client.teams_scores = teams_scores;

            client.emitEvent('teamsScoresUpdate', old_scores, teams_scores);
        }
83267
def performance_ratings(max, thresh)
      stable, count = false, 0
      while !stable && count < max
        @player.values.each { |p| p.estimate_performance }
        stable = @player.values.inject(true) { |ok, p| p.update_performance(thresh) && ok }
        count+= 1
      end
      raise "performance rating estimation did not converge" if max > 1 && !stable
      count
    end
1242809
def parse_standings(opt={})
      begin
        url = ParamsBuilder.build_link(opt)
        xml = fetch(url,"standings")
        data = []
        xml.xpath("//team").each do |inf|
        c = ScheduleLine.new

        inf.children.each do |child|
          if(child.is_a?(Nokogiri::XML::Element))
            #puts "#{child.name} - #{child.text}"
            #c.create_line({:name => child.name, :text => child.text})
            c.send("create_#{child.name}", child.text)

          end

          #c.send("#{child.name.to_s}=",child['data'])
        end
        data << c

        end
        return data
      rescue => e
        raise e
      end
    end
1085039
def safe_power(a, b):
    
    if abs(a) > MAX_POWER or abs(b) > MAX_POWER:
        raise ValueError('Number too high!')
    return a ** b
533790
def _calculate_apm(index, player_actions, other_actions, duration):
    """"""
    apm_per_player = {}
    for player_index, histogram in player_actions.items():
        apm_per_player[player_index] = sum(histogram.values())
    total_unattributed = sum(other_actions.values())
    total_attributed = sum(apm_per_player.values())
    player_proportion = apm_per_player[index] / total_attributed
    player_unattributed = total_unattributed * player_proportion
    apm = (apm_per_player[index] + player_unattributed) / (duration / 60)
    return int(apm)
252854
def set_innings(element)
        element.elements.each("linescore/inning") { |element|
           @away_innings << element.attributes['away']
           @home_innings << element.attributes['home']
        }
      end
895713
def observe_reward_value(self, state_arr, action_arr):
        '''
        
        '''
        if self.__check_goal_flag(action_arr) is True:
            return 1.0
        else:
            self.__move_enemy(action_arr)

            x, y = np.where(action_arr[-1] == 1)
            x, y = x[0], y[0]

            e_dist_sum = 0.0
            for e in range(self.__enemy_num):
                e_dist = np.sqrt(
                    ((x - self.__enemy_pos_list[e][0]) ** 2) + ((y - self.__enemy_pos_list[e][1]) ** 2)
                )
                e_dist_sum += e_dist

            e_dist_penalty = e_dist_sum / self.__enemy_num
            goal_x, goal_y = self.__goal_pos
            
            if x == goal_x and y == goal_y:
                distance = 0.0
            else:
                distance = np.sqrt(((x - goal_x) ** 2) + (y - goal_y) ** 2)

            if (x, y) in self.__route_long_memory_list:
                repeating_penalty = self.__repeating_penalty
            else:
                repeating_penalty = 0.0

            return 1.0 - distance - repeating_penalty + e_dist_penalty
1239214
def get_projected_player_game_stats_by_team(self, season, week, team_id):
        
        result = self._method_call("PlayerGameProjectionStatsByTeam/{season}/{week}/{team_id}", "projections", season=season, week=week, team_id=team_id)
        return result
515436
def scores(self, result, add_new_line=True):
        """"""
        if result.goalsHomeTeam > result.goalsAwayTeam:
            homeColor, awayColor = (self.colors.WIN, self.colors.LOSE)
        elif result.goalsHomeTeam < result.goalsAwayTeam:
            homeColor, awayColor = (self.colors.LOSE, self.colors.WIN)
        else:
            homeColor = awayColor = self.colors.TIE

        click.secho('%-25s %2s' % (result.homeTeam, result.goalsHomeTeam),
                    fg=homeColor, nl=False)
        click.secho("  vs ", nl=False)
        click.secho('%2s %s' % (result.goalsAwayTeam,
                                result.awayTeam.rjust(25)), fg=awayColor,
                    nl=add_new_line)
1171274
function associateWithTeams(teams, tableModel){
			// Go through all team rows inside the table's data, and add's team object
			// _.forEach(tableModel.table, function(teamRow){
			// 	teamRow['team'] = teams[teamRow.teamId] || {};
			// });

			// Go through all team rows inside scores, and add's a team object
			_.forEach(tableModel.scores, function(teamRow){
				teamRow['team'] = teams[teamRow.teamId] || {};
			});
		}
1283071
def get_score
      results = []
      ls = get_boxscore.linescore
      results << ls.away_team_runs
      results << ls.home_team_runs
      results
    end
561741
def rank(self, member):
        
        score = self._members.get(member)
        if score is None:
            return None
        return bisect_left(self._scores, (score, member))
1178176
def _compute_diplomacy(self):
        """"""
        self._diplomacy = {
            'teams': self.teams(),
            'ffa': len(self.teams()) == (self._player_num + self._computer_num and
                                         self._player_num + self._computer_num > 2),
            'TG':  len(self.teams()) == 2 and self._player_num + self._computer_num > 2,
            '1v1': self._player_num + self._computer_num == 2,
        }
        self._diplomacy['type'] = 'unknown'
        if self._diplomacy['ffa']:
            self._diplomacy['type'] = 'ffa'
        if self._diplomacy['TG']:
            self._diplomacy['type'] = 'TG'
            size = len(self.teams()[0]['player_numbers'])
            self._diplomacy['team_size'] = '{}v{}'.format(size, size)
        if self._diplomacy['1v1']:
            self._diplomacy['type'] = '1v1'
364758
def predict_two_components(self, team_1, team_2, team_1b, team_2b, neutral=False):
        
        if self.latent_variables.estimated is False:
            raise Exception("No latent variables estimated!")
        else:
            if type(team_1) == str:
                team_1_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[0].T[self.team_dict[team_1]], trim='b')[-1]
                team_2_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[0].T[self.team_dict[team_2]], trim='b')[-1]
                team_1_b_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[1].T[self.team_dict[team_1]], trim='b')[-1]
                team_2_b_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[1].T[self.team_dict[team_2]], trim='b')[-1]
  
            else:
                team_1_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[0].T[team_1], trim='b')[-1]
                team_2_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[0].T[team_2], trim='b')[-1]
                team_1_b_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[1].T[team_1_b], trim='b')[-1]
                team_2_b_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[1].T[team_2_b], trim='b')[-1]

        t_z = self.transform_z()

        if neutral is False:
            return self.link(t_z[0] + team_1_ability - team_2_ability + team_1_b_ability - team_2_b_ability)
        else:
            return self.link(team_1_ability - team_2_ability + team_1_b_ability - team_2_b_ability)
1077789
function(){
            // Compute team Wins, Losts, Draws and Goal-Sum
            /*
                // Uses the key as the teamId
                {
                         1: {P: x, S: y, [...]},
                    teamId: {P: x, S: y, [...]}
                 }
            */
            var rawTable = {};
            var _default = {rank: 0, teamId: 0, P: 0, goalsMade: 0, goalsTaken: 0, S: 0, W: 0, D: 0, L: 0, score: 0};

            for(var k in this.matches){
                var match = this.matches[k];

                // Compute game points for both teams
                computeGame(match, match.teamAId, match.teamAScore, match.teamBScore);
                computeGame(match, match.teamBId, match.teamBScore, match.teamAScore);
            }

            // Adds game to the teamId. Should be runned twice for each
            // side of match (teamA and teamB).
            function computeGame(match, teamId, goalsMade, goalsTaken){
                // Skip empty id's
                if(!teamId)
                    return;

                // Generate default template if NOT in array yet
                if(!rawTable[teamId]){
                    var teamRow = _.clone(_default);
                    // Keeps team id under team
                    teamRow.teamId = teamId;
                    // Inserts team in rawTable
                    rawTable[teamId] = teamRow;
                }

                // Get teamRow (it is supposed to exist)
                var teamRow = rawTable[teamId];

                // Compute points ONLY if match is not 'scheduled'
                // logycaly, it's 'ended' or 'playing', so we compute it
                if(match.state == 'scheduled')
                    return;

                // Increment Plays
                teamRow.P++;

                // Compute goals made/taken
                teamRow.goalsMade += goalsMade*1;
                teamRow.goalsTaken += goalsTaken*1;

                // Win
                if(goalsMade > goalsTaken)
                    teamRow.W ++;
                // Loose
                else if(goalsMade < goalsTaken)
                    teamRow.L ++;
                // Drew
                else
                    teamRow.D ++;
            }

            // Compute 'final score' and add column S (goalsMade:goalsTaken)
            // Transfer data to final table array
            var finalTable = [];
            _.forEach(rawTable, function(row){
                row.score = row.W*3 + row.D*1;
                row.S = row.goalsMade*1 + ':' + row.goalsTaken*1;
                row.GD = row.goalsMade*1 - row.goalsTaken*1;

                finalTable.push(row);
            });

            // Sort by 'score' field
            finalTable = _.sortBy(finalTable, 'score').reverse();

            // Rank Table
            var pos = 0;
            var lastScore = -1;

            _.forEach(finalTable, function(row){
                // Keeps the same ranking if scores is the same
                if(lastScore != row.score){
                    pos++;
                    lastScore = row.score;
                }

                row.rank = pos;
            });


            return finalTable;


        }