original_docstring: Given a match, updates the rankings for all participants.
docstring: Given a match, updates the rankings for all participants.
docstring_tokens: Given a match updates the rankings for all participants .
code: def compute_rankings_for_match(match):
    """Given a match, updates the rankings for all participants."""
  
    # Find all the participants for this match and split 'em out
    participants = list(match.participant_set.all())
    winners = [ p for p in participants if p.role == ParticipantRole.Win ]
    losers = [ p for p in participants if p.role == ParticipantRole.Loss ]
    drawers = [ p for p in participants if p.role == ParticipantRole.Draw ]
    if drawers:
      raise ValueError('Does not handle draws yet.')
    if not winners or not losers:
      raise ValueError('Ehh?  Missing participants on match id %d' % match.id)
  
    # Get the results
    wins, losses = match.parse_results()
  
    # Get the rankings for the participants (maintaining order)
    winner_rankings = [ Ranking.objects.get_or_create(user=u.user, game=match.game)[0] for u in winners ]
    loser_rankings = [ Ranking.objects.get_or_create(user=u.user, game=match.game)[0] for u in losers ]
  
    # Get the ratings from the rankings (still maintaining order)
    winner_ratings = [ w.to_rating() for w in winner_rankings ]
    loser_ratings = [ l.to_rating() for l in loser_rankings ]
  
    # Compute the rankings doing losses first to reduce their effect
    for i in xrange(losses):
      loser_ratings, winner_ratings = t.rate([loser_ratings, winner_ratings])
    for i in xrange(wins):
      winner_ratings, loser_ratings = t.rate([winner_ratings, loser_ratings])
  
    # Use the fact that things are ordered to update objects
    for ranking, rating in zip(loser_rankings, loser_ratings):
      ranking.from_rating(rating)
      ranking.save()
    for ranking, rating in zip(winner_rankings, winner_ratings):
      ranking.from_rating(rating)
      ranking.save()
code_tokens: def compute_rankings_for_match ( match ) : participants = list ( match . participant_set . all ( ) ) winners = [ p for p in participants if p . role == ParticipantRole . Win ] losers = [ p for p in participants if p . role == ParticipantRole . Loss ] drawers = [ p for p in participants if p . role == ParticipantRole . Draw ] if drawers : raise ValueError ( 'Does not handle draws yet.' ) if not winners or not losers : raise ValueError ( 'Ehh?  Missing participants on match id %d' % match . id ) wins , losses = match . parse_results ( ) winner_rankings = [ Ranking . objects . get_or_create ( user = u . user , game = match . game ) [ 0 ] for u in winners ] loser_rankings = [ Ranking . objects . get_or_create ( user = u . user , game = match . game ) [ 0 ] for u in losers ] winner_ratings = [ w . to_rating ( ) for w in winner_rankings ] loser_ratings = [ l . to_rating ( ) for l in loser_rankings ] for i in xrange ( losses ) : loser_ratings , winner_ratings = t . rate ( [ loser_ratings , winner_ratings ] ) for i in xrange ( wins ) : winner_ratings , loser_ratings = t . rate ( [ winner_ratings , loser_ratings ] ) for ranking , rating in zip ( loser_rankings , loser_ratings ) : ranking . from_rating ( rating ) ranking . save ( ) for ranking , rating in zip ( winner_rankings , winner_ratings ) : ranking . from_rating ( rating ) ranking . save ( )
short_docstring: Given a match, updates the rankings for all participants.
short_docstring_tokens: Given a match updates the rankings for all participants .
comment: """Given a match, updates the rankings for all participants."""$SEP$# Find all the participants for this match and split 'em out$SEP$# Get the results$SEP$# Get the rankings for the participants (maintaining order)$SEP$# Get the ratings from the rankings (still maintaining order)$SEP$# Compute the rankings doing losses first to reduce their effect$SEP$# Use the fact that things are ordered to update objects