<commit_before>(function() {
    'use strict';

    angular
        .module('owcast')
        .service('counterGenerator', counterGenerator);

    function counterGenerator() {
        this.getCounterPlayers = function() {
            // This is the scaffoled method i guess?
        }
    }
})();<commit_msg>Add the team counter generator function<commit_after>(function() {
  'use strict';

  angular
    .module('owcast')
    .service('counterGenerator', counterGenerator);

  function counterGenerator() {
    // Takes an array of enemy hero names and a score matrix and returns the top counter heroes
    this.getCounterPlayers = function(enemyTeam, scores) {
      // Helper to get the enemy heros that a hero is strong or weak against
      function enemies(hero) {
        var weak = -1;
        var strong = 1;
        return {
          isWeakAgainst: function() {
            return this.is(weak).against();
          },
          isStrongAgainst: function() {
            return this.is(strong).against();
          },
          is: function(x) {
            return {
              against: function() {
                return enemyTeam.filter(enemy => {
                  return scores[hero] && scores[hero][enemy] == x;
                });
              }
            };
          }
        };
      };

      var heroes = Object.keys(scores);
      // Assign a score to each hero that describes how strong it is against the enemy team as a whole
      var heroScores = heroes.map(hero => {
        var scoreSum = enemyTeam.reduce((sum, enemyHero) => {
          // if hero is strong against enemyHero, then score[hero][enemyHero] = 1
          var score = scores[hero] && scores[hero][enemyHero];
          if (score != undefined) {
            return sum + score;
          }
          return sum;
        }, 0);
        return { name: hero, score: scoreSum };
      });

      // Sort the heroes descending by score and grab the first 6
      var topHeroes = heroScores.sort((a, b) => {
        return b.score - a.score;
      }).slice(0, 6);

      // Return some additional info with the top heroes
      return topHeroes.map(hero => {
        return {
          hero: hero.name,
          strongAgainst: enemies(hero.name).isStrongAgainst(),
          weakAgainst: enemies(hero.name).isWeakAgainst(),
          score: hero.score
        };
      });
    }
  }
})();
{'fraction_non_alphanumeric': 0.11362683438155136, 'fraction_numerical': 0.0029350104821802936, 'mean_word_length': 1.8438617401668653, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '677613', 'n_tokens_mistral': 666, 'n_tokens_neox': 631, 'n_words': 189}