<commit_before>App.CurrentGameController = Ember.ObjectController.extend
  needs: ['person', 'people', 'auth', 'challenge', 'application']
  currentRound: 1
  authPerson: Ember.computed.alias('controllers.auth.person')
  confirmEndMatch: false
  message: ""
  gameOverFlag: false
  gameStartedFlag: false
  confirmOpenRound: false
  cancelGameConfirm: false
  isActiveGame: Ember.computed.alias('controllers.application.isActiveGame')
  roundsWithIndex: ( ->
    rounds = @get('rounds')
    authPerson = @get('authPerson')
    game = @get('model')
    @set('gameStartedFlag', true)
    @recountMatchScores()
    homePerson = game.get('home')
    awayPerson = game.get('away')
    @set('isMe', false)
    if authPerson?
      if authPerson.get('id') == homePerson.get('id') or authPerson.get('id') == awayPerson.get('id')
        @set('isMe', true)
    if !rounds?
      if(!@get('authPerson').get('id') == "1410921259")
        @transitionTo("/games")
      return
    currentRound = game.get('currentRound')
    @get('rounds').map((round, index) =>
      round:
        homeWon: round.homeScore > round.awayScore
        awayWon: round.homeScore < round.awayScore
        homeScore: round.homeScore
        awayScore: round.awayScore
        index: index
        hIndex: index + 1
        isComplete: round.isComplete
        isCurrent: (index + 1) == currentRound
        isFirst: index == 0
        isMe: @get('isMe')
      index: index + 1
    ).reverse()
  ).property('rounds', 'content', 'authPerson')
  gameOver: ->
    @set('gameOverFlag', true)
    game = @get('model')
    completedGame = @get('store').createRecord("completedGame",
      home: game.get('home')
      away: game.get('away')
      createdAt: game.get('createdAt')
      startedAt: game.get('startedAt')
      homeScore: game.get('homeScore')
      awayScore: game.get('awayScore')
      rounds: game.get('rounds')
      completedAt: new Date()
    )
    completedGame.save()

    homePerson = game.get('home')
    awayPerson = game.get('away')

    tweetCompleted = @get('store').createRecord('completedRequest',
      home: homePerson.get('twitter')
      away: awayPerson.get('twitter')
      homeScore: game.get('homeScore')
      awayScore: game.get('awayScore')
    )
    tweetCompleted.save()
    
    game.delete()
    @transitionTo('/games')
  recountMatchScores: ->
    if @get('gameOverFlag')
      return
    if !@get('gameStartedFlag')
      return
    game = @get('model')
    rounds = game.get('rounds')
    if rounds == undefined or rounds == null
      return

    rounds = rounds.toArray()
    #recalc score...
    recountAwayScore = 0
    recountHomeScore = 0
    for round in rounds
      if not round.isCurrent
        if round.awayScore > round.homeScore
          recountAwayScore++
        else
          if round.homeScore > round.awayScore
            recountHomeScore++
          else
            console.log "Scoring error, scores equal or not valid."

    game.set('awayScore', recountAwayScore)
    game.set('homeScore', recountHomeScore)
    game.save()
    @set('awayScore', recountAwayScore)
    @set('homeScore', recountHomeScore)
  openRound: (round) ->
    @set('confirmOpenRound', false)
    game = @get('model')<commit_msg>added not round check<commit_after>App.CurrentGameController = Ember.ObjectController.extend
  needs: ['person', 'people', 'auth', 'challenge', 'application']
  currentRound: 1
  authPerson: Ember.computed.alias('controllers.auth.person')
  confirmEndMatch: false
  message: ""
  gameOverFlag: false
  gameStartedFlag: false
  confirmOpenRound: false
  cancelGameConfirm: false
  isActiveGame: Ember.computed.alias('controllers.application.isActiveGame')
  roundsWithIndex: ( ->
    rounds = @get('rounds')
    authPerson = @get('authPerson')
    game = @get('model')
    @set('gameStartedFlag', true)
    @recountMatchScores()
    homePerson = game.get('home')
    awayPerson = game.get('away')
    @set('isMe', false)
    if authPerson?
      if authPerson.get('id') == homePerson.get('id') or authPerson.get('id') == awayPerson.get('id')
        @set('isMe', true)
    if !rounds?
      if(!@get('authPerson').get('id') == "1410921259")
        @transitionTo("/games")
      return
    currentRound = game.get('currentRound')
    @get('rounds').map((round, index) =>
      round:
        homeWon: round.homeScore > round.awayScore
        awayWon: round.homeScore < round.awayScore
        homeScore: round.homeScore
        awayScore: round.awayScore
        index: index
        hIndex: index + 1
        isComplete: round.isComplete
        isCurrent: (index + 1) == currentRound
        isFirst: index == 0
        isMe: @get('isMe')
      index: index + 1
    ).reverse()
  ).property('rounds', 'content', 'authPerson')
  gameOver: ->
    @set('gameOverFlag', true)
    game = @get('model')
    completedGame = @get('store').createRecord("completedGame",
      home: game.get('home')
      away: game.get('away')
      createdAt: game.get('createdAt')
      startedAt: game.get('startedAt')
      homeScore: game.get('homeScore')
      awayScore: game.get('awayScore')
      rounds: game.get('rounds')
      completedAt: new Date()
    )
    completedGame.save()

    homePerson = game.get('home')
    awayPerson = game.get('away')

    tweetCompleted = @get('store').createRecord('completedRequest',
      home: homePerson.get('twitter')
      away: awayPerson.get('twitter')
      homeScore: game.get('homeScore')
      awayScore: game.get('awayScore')
    )
    tweetCompleted.save()
    
    game.delete()
    @transitionTo('/games')
  recountMatchScores: ->
    if @get('gameOverFlag')
      return
    if !@get('gameStartedFlag')
      return
    game = @get('model')
    rounds = game.get('rounds')
    if rounds == undefined or rounds == null or !rounds
      return

    rounds = rounds.toArray()
    #recalc score...
    recountAwayScore = 0
    recountHomeScore = 0
    for round in rounds
      if not round.isCurrent
        if round.awayScore > round.homeScore
          recountAwayScore++
        else
          if round.homeScore > round.awayScore
            recountHomeScore++
          else
            console.log "Scoring error, scores equal or not valid."

    game.set('awayScore', recountAwayScore)
    game.set('homeScore', recountHomeScore)
    game.save()
    @set('awayScore', recountAwayScore)
    @set('homeScore', recountHomeScore)
  openRound: (round) ->
    @set('confirmOpenRound', false)
    game = @get('model')
{'fraction_non_alphanumeric': 0.14188876906485903, 'fraction_numerical': 0.005238021876444308, 'mean_word_length': 2.992619926199262, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '6430037', 'n_tokens_mistral': 2040, 'n_tokens_neox': 1968, 'n_words': 410}