Ejemplo n.º 1
0
def ajax_evo_player(request, player_id):
    """
    returns the evolution of the position, 
    progression and points 
    for a player for the season
    """
    if not _validAjaxRequest(request):
        return HttpResponse(status=400)
    if not _validGetRequest(request):
        return HttpResponse(status=400)
    if not isPlayerValid(player_id):
        return HttpResponse(status=400)

    #ad info to context - to be passed to templates -
    context = {
        'evo_weeks': played_weeks(),
        'evo_pos': player_pos_evolution(player_id),
        #'evo_progress':evo_progress(pos),
        #'evo_points':player_points_evolution(player_id),
        #'evo_pts_per_week':player_points_per_week(player_id),
        'player_id': player_id,
        'player_name': getPlayerName(player_id),
        'nb_players': len(getAllPlayers()),
        #'chart_pts_tickInterval': 25,
        #'chart_pos_tickInterval': 1,
        #'chart_pos_minorTickInterval': 0,
    }
    return JsonResponse(context)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 4
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)
Ejemplo n.º 5
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
Ejemplo n.º 6
0
def ajax_league_table(request, week):
    """
    returns the full league until the specified week 
    """
    if not _validAjaxRequest(request):
        return HttpResponse(status=400)
    if not _validGetRequest(request):
        return HttpResponse(status=400)

    try:
        week = int(week)
    except:
        return HttpResponse(status=400)

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

    #ad info to context - to be passed to templates -
    context = {
        'league_table': full_league_table_until__dict(week),
    }

    return render(request, 'contents/classement_league.html', context)
Ejemplo n.º 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)