def get_matches_by_player(player): user = User.objects.get(username=player) wins = Match.objects.filter(winner=user) losses = Match.objects.filter(loser=user) rating_history = dict() for win in wins: rating_history[win.match_date] = win.winner_after_elo for loss in losses: rating_history[loss.match_date] = loss.loser_after_elo sorted_rating_history = collections.OrderedDict() for k in sorted(rating_history.keys()): sorted_rating_history[k] = rating_history[k] #javascript wants a zero based month, what the hell? resp = [{'x': 'new Date(' + ','.join(str(a) for a in [date.year, date.month - 1, date.day, date.hour, date.minute, date.second]) + ')', 'y': elo} for date, elo in sorted_rating_history.items()] resp = JsonResponse( resp, safe=False ) #Unfortunate formatting adjustments to give canvasjs what it wants resp = str(resp.content.decode('utf-8')).replace("\"", '') resp = resp.replace("Content-Type: application/json", "") return resp
def get_matches_by_player(player): user = User.objects.get(username=player) wins = Match.objects.filter(winner=user) losses = Match.objects.filter(loser=user) rating_history = dict() for win in wins: rating_history[win.match_date] = win.winner_after_elo for loss in losses: rating_history[loss.match_date] = loss.loser_after_elo sorted_rating_history = collections.OrderedDict() for k in sorted(rating_history.keys()): sorted_rating_history[k] = rating_history[k] #javascript wants a zero based month, what the hell? resp = [{ 'x': 'new Date(' + ','.join( str(a) for a in [ date.year, date.month - 1, date.day, date.hour, date.minute, date.second ]) + ')', 'y': elo } for date, elo in sorted_rating_history.items()] resp = JsonResponse(resp, safe=False) #Unfortunate formatting adjustments to give canvasjs what it wants resp = str(resp.content.decode('utf-8')).replace("\"", '') resp = resp.replace("Content-Type: application/json", "") return resp