コード例 #1
0
ファイル: models.py プロジェクト: ylopez/squashtai
def update_scores(match_id):
  current_match = Match.get_by_id(match_id)
  
  # update wins and loses of the players
  [ winner, looser, gap ] = get_winner_looser(current_match)
  update_wins_loses(winner, looser)

  # get all matches that took place after this one 
  # FIXME what if some matches happen the same day? - we don't really care
  matches = Match.all().order('date').filter('date >=', current_match.date).fetch(100)

  # erase scores that need to be re-computed ### C'est ca qui marche pas
  obsolete_scores = Score.all().filter('date >=', current_match.date).fetch(1000)
  db.delete(obsolete_scores)
  #return

  for match in matches:
    [ winner, looser, gap ] = get_winner_looser(match)
    winner_previous_score = get_last_score(winner, match.date)
    looser_previous_score = get_last_score(looser, match.date)
    [ winner_new_score, looser_new_score ] = elo.compute_score(winner_previous_score, looser_previous_score, gap)
    #print 'old win' + str(winner_previous_score)
    #print 'old lose' + str(looser_previous_score)

    update_or_create_score(winner_new_score, winner, match.date, True)
    update_or_create_score(looser_new_score, looser, match.date, False)
    #print 'new win' + str(winner_new_score)
    #print 'new lose' + str(looser_new_score)

  compute_ranks()
コード例 #2
0
ファイル: models.py プロジェクト: nic0d/squashtai
def update_scores(match_id):
    current_match = Match.get_by_id(match_id)

    # get all matches that took place after this one, or the same day
    # FIXME what if some matches happen the same day? -> we don't really care
    matches = Match.all().order('date').filter('date >=',
                                               current_match.date).fetch(100)

    # erase scores that need to be re-computed
    obsolete_scores = Score.all().filter('date >=',
                                         current_match.date).fetch(1000)
    db.delete(obsolete_scores)

    for match in matches:
        [winner, looser, gap] = get_winner_looser(match)
        winner_previous_score = get_last_score(winner, match.date)
        looser_previous_score = get_last_score(looser, match.date)
        [winner_new_score,
         looser_new_score] = elo.compute_score(winner_previous_score,
                                               looser_previous_score, gap)

        update_or_create_score(winner_new_score, winner, match.date, True)
        update_or_create_score(looser_new_score, looser, match.date, False)

    compute_ranks()
コード例 #3
0
ファイル: main.py プロジェクト: nic0d/squashtai
  def post(self):
    if not requires_registered(self):
      return

    score1 = long(self.request.get('score1', 0))
    score2 = long(self.request.get('score2', 0))
    opponent = long(self.request.get('player2', 0))

    if (score1 != 3 and score2 != 3) or (score1 == 3 and score2 == 3):
      self.redirect('/match/simulate')
      return

    me = models.get_user_(users.get_current_user())
    userscore1 = me.score
    userscore2 = models.get_user(opponent).score

    if score1 > score2:
      [ userscore1, userscore2 ] = elo.compute_score(userscore1, userscore2, abs(score1 - score2))
    else:
      [ userscore2, userscore1 ] = elo.compute_score(userscore2, userscore1, abs(score1 - score2))

    template_file = os.path.join(os.path.dirname(__file__), 'templates/simulate.html')
    template_values = {
      'greeting': get_greeting(),
      'is_admin': is_admin(),
      'is_registered': is_registered(),
      'me': me,
      'registered_users': models.get_possible_opponents(),
      'score1': score1,
      'score2': score2,
      'opponent': opponent,
      'opponent_nickname': models.get_user(opponent).nickname,
      'userscore1': userscore1,
      'userscore2': userscore2
    }
    self.response.out.write(Template(filename=template_file,lookup=mylookup).render_unicode(**template_values))
コード例 #4
0
ファイル: models.py プロジェクト: lbesson/squashtai
def update_scores(match_id):
  current_match = Match.get_by_id(match_id)
  
  # get all matches that took place after this one, or the same day
  # FIXME what if some matches happen the same day? -> we don't really care
  matches = Match.all().order('date').filter('date >=', current_match.date).fetch(100)

  # erase scores that need to be re-computed
  obsolete_scores = Score.all().filter('date >=', current_match.date).fetch(1000)
  db.delete(obsolete_scores)

  for match in matches:
    [ winner, looser, gap ] = get_winner_looser(match)
    winner_previous_score = get_last_score(winner, match.date)
    looser_previous_score = get_last_score(looser, match.date)
    [ winner_new_score, looser_new_score ] = elo.compute_score(winner_previous_score, looser_previous_score, gap)

    update_or_create_score(winner_new_score, winner, match.date, True)
    update_or_create_score(looser_new_score, looser, match.date, False)

  compute_ranks()