def _update_ratings(): calc = RatingCalculator() START_RATING = cur_config().rating_start players = {} match_ids = list( set( PlayerResult.objects.filter(rating=None).values_list('match_id', flat=True))) for match in Match.objects.filter(id__in=match_ids).order_by('date', 'id'): player_positions = match.get_positions() rating_results = [] for p in player_positions: # Fetch the current rating value rated_results = PlayerResult.objects.filter( player=p['id']).exclude(rating=None).order_by( '-match__date', '-match__id') if not rated_results.exists(): rating = START_RATING else: rating = rated_results[0].rating rating_results.append(RatingResult(p['id'], rating, p['position'])) # Calculate new ratings new_player_ratings = calc.new_ratings(rating_results) # Update for p in new_player_ratings: players[p.dbid] = p.rating PlayerResult.objects.filter(player=p.dbid).filter( match=match).update(rating=p.rating)
def setUp(self): self.calc = RatingCalculator()