Beispiel #1
0
def leagueForecastsResults():
    """
    returns the list of forecasts results for the mid and end of season
    """
    results = {}
    if midSeason():
        league_table = full_league_table_until(midSeasonWeek())
        results['winner_midseason'] = league_table[0][0]
    if endOfSeason():
        league_table = full_league_table()
        results['winner'] = league_table[0][0]
        results['second'] = league_table[1][0]
        results['third'] = league_table[2][0]
        results['fourth'] = league_table[3][0]
        results['fifth'] = league_table[4][0]
        results['looser1'] = league_table[-1][0]
        results['looser2'] = league_table[-2][0]
        results['looser3'] = league_table[-3][0]
        results['looser4'] = league_table[-4][0]
    return results
Beispiel #2
0
def player_points_per_week(player_id):
    """
    returns the points per week
    earned by a player for the season
    """
    pts_weeks = []
    for week in played_weeks():
        try:
            pts = int(user_total(player_id, week)[0][0])
            pts_weeks.append(pts)
        except:
            pass
    try:
        if endOfSeason():
            #in case of season end, need to add bonus points to last week points
            bonus = LeagueForecast.objects.get(user__id=player_id).points
            pts_weeks[len(pts_weeks) - 1] += bonus
    except:
        pass
    return pts_weeks
Beispiel #3
0
def player_points_evolution(player_id):
    """
    returns the evolution of points 
    earned by a player for the season
    """
    pts_evo = []
    for week in played_weeks():
        try:
            pts = int(user_total_until(player_id, week)[0][0])
            pts_evo.append(pts)
        except:
            pass
    try:
        if endOfSeason():
            #in case of season end, need to add bonus points to last week points
            bonus = LeagueForecast.objects.get(user__id=player_id).points
            pts_evo[len(pts_evo) - 1] = pts_evo[len(pts_evo) - 1] + bonus
    except:
        pass
    return pts_evo
Beispiel #4
0
def check_season_results():
    """
    check results for season forecasts
    at the end of the season
    """
    if endOfSeason():
        #get the list of forecasts for the season
        season_forecasts = LeagueForecast.objects.all()

        #get the results for the season
        season_results = _get_season_results()

        #for each forecast,
        for season_forecast in season_forecasts:
            #if points have not been calculated before
            if not season_forecast.points:
                #calculate the number of points
                points = 0

                try:
                    for attribute in [
                            'winner', 'second', 'third', 'fourth', 'fifth',
                            'winner_midseason'
                    ]:
                        value = getattr(season_forecast, attribute)
                        if value.id == season_results[attribute]:
                            points += 10
                    for attribute in [
                            'looser1', 'looser2', 'looser3', 'looser4'
                    ]:
                        value = getattr(season_forecast, attribute)
                        if value.id in season_results['lasts']:
                            points += 10
                except:
                    pass

                #update season forecast with calculated points
                season_forecast.points = points

                #and save it in the databse
                season_forecast.save()
Beispiel #5
0
def ajax_players_table(request, week):
    """
    returns the players table for the specified week
    if week is None, returns the full table for all played weeks 
    """
    if not _validAjaxRequest(request):
        return HttpResponse(status=400)
    if not _validGetRequest(request):
        return HttpResponse(status=400)

    #if week is given, check validity
    if not week is None:
        try:
            week = int(week)
        except:
            return HttpResponse(status=400)

        if not week in played_weeks():
            return HttpResponse(status=400)

    #end of season boolean
    eos = endOfSeason()

    #players table, if week, table for given week
    #else full season table - depending on end of season -
    players_table = None
    if not week is None:
        players_table = full_players_table_for_week(week)
    else:
        players_table = full_players_table_until_auto(
        ) if not eos else full_players_table_with_bonus()

    #ad info to context - to be passed to templates -
    context = {
        'eos': eos,
        'players_table': players_table,
        'final_players_table': eos and week is None,
    }

    return render(request, 'contents/classement_pronos.html', context)
Beispiel #6
0
def player_pos_evolution(player_id):
    """
    returns the evolution of position 
    for a player for the season
    """
    pos_evo = []
    weeks = played_weeks()
    eos = endOfSeason()
    last_week = weeks[-1]
    for week in weeks:
        try:
            user_table = user_table_until_week(week)
            #in case of last week - and end of season - need to use
            #table with bonuses instead on simple table
            if eos and week == last_week:
                user_table = user_table_with_bonus()
            players_pos = [x[0] for x in user_table]
            pos = players_pos.index(int(player_id)) + 1
            pos_evo.append({'x': week, 'y': pos})
        except:
            pass
    return pos_evo
Beispiel #7
0
def tables(request):
    """
    render the tables full page
    """
    #get last played week available for league table
    currentweek = last_played_week()

    #end of season boolean
    eos = endOfSeason()

    #ad info to context - to be passed to templates -
    context = {
        'selectedmenu':
        'tables',
        'page_title':
        _('Tables'),
        'season':
        settings.SEASON,
        'currentweek':
        currentweek,
        'weeks':
        played_weeks(),
        'league_table':
        full_league_table_until__dict(currentweek),
        'eos':
        eos,
        'players_table':
        full_players_table_until_auto()
        if not eos else full_players_table_with_bonus(),
        'final_players_table':
        eos,
        'teams':
        getAllTeams(),
    }

    return render(request, 'pages/classements.html', context)