<commit_before>import Ember from 'ember';

export default Ember.Component.extend({
  statistic: function() {
    let teams = this.get('teams'),
        matches = this.get('matches'),
        teamStatistic,
        tablescore = {};

    teamStatistic = {
      matches:          0,
      wins:             0,
      draws:            0,
      loses:            0,
      goalsScored:      0,
      goalsAgainsted:   0,
      goalsDifference:  0,
      points:           0
    };

    teams.forEach(function(team) {
      tablescore[team] = teamStatistic;
      tablescore[team]['name'] = team;
    });

    matches.forEach(function(match) {
      let homeTeam = match.get('homeTeam'),
          awayTeam = match.get('awayTeam'),
          homeScore = +match.get('homeScore'),
          awayScore = +match.get('awayScore'),
          homeTeamStats = tablescore[homeTeam],
          awayTeamStats = tablescore[awayTeam];

      if (match.get('status') !== 'finished') {
        return false;
      }

      if (homeScore > awayScore) {
        // home wins
        homeTeamStats['wins']++;
        awayTeamStats['loses']++;
      } else if (homeScore < awayScore) {
        // away wins
        homeTeamStats['loses']++;
        awayTeamStats['wins']++;
      } else {
        // draw, maybe
        homeTeamStats['draws']++;
        awayTeamStats['draws']++;
      }

      homeTeamStats['matches']++;
      awayTeamStats['matches']++;

      homeTeamStats['goalsScored'] += homeScore;
      awayTeamStats['goalsScored'] += awayScore;
      homeTeamStats['goalsAgainsted'] += awayScore;
      awayTeamStats['goalsAgainsted'] += homeScore;
      homeTeamStats['goalsDifference'] += (homeScore - awayScore);
      awayTeamStats['goalsDifference'] += (awayScore - homeScore);

      homeTeamStats['points'] = homeTeamStats['wins']*3 + homeTeamStats['draws'];
      awayTeamStats['points'] = awayTeamStats['wins']*3 + awayTeamStats['draws'];
    });

    return tablescore;
  }.property(),

  tablescore: function() {
    let result = [],
        statistic = this.get('statistic');

    for (let team in statistic) {
      if (!statistic.hasOwnProperty(team)) {
        continue;
      }

      result.push(statistic[team]);
    }

    return result;
  }.property()
});<commit_msg>Fixed bug, when table score has only one team<commit_after>import Ember from 'ember';

export default Ember.Component.extend({
  statistic: function() {
    let teams = this.get('teams'),
        matches = this.get('matches'),
        tablescore = {},
        self = this;

    teams.forEach(function(team) {
      tablescore[team] = self.getBasicStatForTeam(team);
    });

    matches.forEach(function(match) {
      let homeTeam = match.get('homeTeam'),
          awayTeam = match.get('awayTeam'),
          homeScore = +match.get('homeScore'),
          awayScore = +match.get('awayScore'),
          homeTeamStats = tablescore[homeTeam],
          awayTeamStats = tablescore[awayTeam];

      if (match.get('status') !== 'finished') {
        return false;
      }

      if (homeScore > awayScore) {
        // home wins
        homeTeamStats['wins']++;
        awayTeamStats['loses']++;
      } else if (homeScore < awayScore) {
        // away wins
        homeTeamStats['loses']++;
        awayTeamStats['wins']++;
      } else {
        // draw, maybe
        homeTeamStats['draws']++;
        awayTeamStats['draws']++;
      }

      homeTeamStats['matches']++;
      awayTeamStats['matches']++;

      homeTeamStats['goalsScored'] += homeScore;
      awayTeamStats['goalsScored'] += awayScore;
      homeTeamStats['goalsAgainsted'] += awayScore;
      awayTeamStats['goalsAgainsted'] += homeScore;
      homeTeamStats['goalsDifference'] += (homeScore - awayScore);
      awayTeamStats['goalsDifference'] += (awayScore - homeScore);

      homeTeamStats['points'] = homeTeamStats['wins']*3 + homeTeamStats['draws'];
      awayTeamStats['points'] = awayTeamStats['wins']*3 + awayTeamStats['draws'];
    });

    return tablescore;
  }.property(),

  tablescore: function() {
    let result = [],
        statistic = this.get('statistic');

    for (let team in statistic) {
      if (!statistic.hasOwnProperty(team)) {
        continue;
      }

      result.push(statistic[team]);
    }

    return result;
  }.property(),

  getBasicStatForTeam: function(team) {
    return {
      name:             team,
      matches:          0,
      wins:             0,
      draws:            0,
      loses:            0,
      goalsScored:      0,
      goalsAgainsted:   0,
      goalsDifference:  0,
      points:           0
    };
  }
});
{'fraction_non_alphanumeric': 0.14632034632034632, 'fraction_numerical': 0.004329004329004329, 'mean_word_length': 2.3292507204610953, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3950576', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1355, 'n_words': 251}