<commit_before>from django.shortcuts import render, redirect
from django.http import Http404
from django.core import serializers
from football import points, stats, schedule
import nflgame # https://github.com/BurntSushi/nflgame/
from datetime import date
from collections import OrderedDict

def index(request):
    return render(request, 'index.html')

def search(request):
    return render(request, 'search.html')
    
def results(request):
    if 'name' not in request.GET or 'scoring' not in request.GET:
        return render(request, 'results.html', {'error':True, 'title':"Error"})
    name = request.GET['name']
    scoring = request.GET['scoring']
    year = date.today().year
    week = schedule.current_week()
    weeks = []
    for x in range(1,week+1):
        weeks.append(x)
    if scoring == 'standard':
        results = points.standard_player_points(name, year, weeks)
    elif scoring == 'decimal':
        results = points.decimal_player_points(name, year, weeks)
    elif scoring == 'standard_ppr':
        results = points.standard_ppr_player_points(name, year, weeks)
    elif scoring == 'decimal_ppr':
        results = points.decimal_ppr_player_points(name, year, weeks)
    elif scoring == 'standard_half_ppr':
        results = points.standard_half_ppr_player_points(name, year, weeks)
    elif scoring == 'decimal_half_ppr':
        results = points.decimal_half_ppr_player_points(name, year, weeks)
    else:
        return render(request, 'results.html', {'error':True, 'title':"Error"})
    if results == False:
        return render(request, 'results.html', {'error':True, 'title':"Error"})
    position = stats.player_position(name)
    qb = False
    flex = False
    k = False
    if position == "QB":
        qb = True
    elif position == "K":
        k = True
    elif position == "WR" or position == "RB" or position == "TE":
        flex = True
    else:
        return render(request, 'results.html', {'error':True, 'title':"Error"})
    bye_week = schedule.bye_week_player(name, year)
    total_points = points.total_points(results);
    graph_total_points = points.total_points_no_bye(results)
    ordered_total_points = OrderedDict(sorted(total_points.items()))
    graph_ordered_total_points = OrderedDict(sorted(graph_total_points.items()))
    total_stats = stats.total_stats(name, year, week);
    return render(request, 'results.html', {'title':name, 'name':name, 'total_stats':total_stats, 'results':results, 'scoring':scoring, 'graph_ordered_total_points':graph_ordered_total_points, 'bye_week':bye_week, 'position':position, 'qb':qb, 'flex':flex, 'k':k})

def scoreboard(request):
    current_week = schedule.current_week()
    year = date.today().year
    games = nflgame.games(year, week=current_week)
    scores = []
    for x in games:
        scores.append(x)
    weeks = []
    for x in range(0,current_week):
        weeks.append(x+1)
    return render(request, 'scoreboard.html', {'scores':scores,'week':current_week, 'past_weeks':weeks})

def previous_scoreboard(request, offset):
    try:
        wk = int(offset)
    except ValueError:
        raise Http404()
    current_week = schedule.current_week()
    if wk>current_week:
        raise Http404()
    year = date.today().year
    games = nflgame.games(year, week=wk)
    scores = []
    for x in games:
        scores.append(x)
    weeks = []
    for x in range(0,current_week):
        weeks.append(x+1)
    return render(request, 'previous_scoreboard.html', {'scores':scores,'week':wk, 'past_weeks':weeks})

def teamnum(request, offset):
    numteams = request.COOKIES.get('teams', None)
    if numteams == None:
        return redirect('/team/new/')
    try:
        numteams = int(numteams)
    except ValueError:
        raise Http404()
    try:
        team = int(offset)
    except ValueError:
        raise Http404()
    if team < 1 or team > 3 or numteams < 1 or numteams > 3:
        raise Http404()
    teamcookiename = "team"+str(team)
    teamdata = request.COOKIES.get(teamcookiename, None)
    url = "/team/?"+teamdata
    return redirect(url)

def team(request):
    teamname = request.GET['teamname']
    return render(request, "team.html", {'title':teamname, 'teamname':teamname})

def new_team(request):
    numteams = request.COOKIES.get('teams', None)
    if numteams != None:
        try:
            numteams = int(numteams)
        except ValueError:
            raise Http404()
        if numteams < 1 or numteams > 3:
            raise Http404()
        if numteams == 3:
            return render(request, 'new_team.html', {'toomany':True, 'title':'Error'})
    if numteams == None:
        teamnum = 1
    else:
        teamnum = numteams+1
    return render(request, 'new_team.html', {'title':'Create a New Team', 'teamnum':teamnum})

def team_list(request):
    numteams = request.COOKIES.get('teams', None)
    if numteams == None:
        return redirect('/team/new/')
    try:
        numteams = int(numteams)
    except ValueError:
        raise Http404()
    names = []
    for x in range(0, numteams):
        cookiename = "teamname"+str((x+1))
        name = request.COOKIES.get(cookiename, None)<commit_msg>Sorting by position<commit_after>from django.shortcuts import render, redirect
from django.http import Http404
from django.core import serializers
from football import points, stats, schedule
import nflgame # https://github.com/BurntSushi/nflgame/
from datetime import date
from collections import OrderedDict

def index(request):
    return render(request, 'index.html')

def search(request):
    return render(request, 'search.html')
    
def results(request):
    if 'name' not in request.GET or 'scoring' not in request.GET:
        return render(request, 'results.html', {'error':True, 'title':"Error"})
    name = request.GET['name']
    scoring = request.GET['scoring']
    year = date.today().year
    week = schedule.current_week()
    weeks = []
    for x in range(1,week+1):
        weeks.append(x)
    if scoring == 'standard':
        results = points.standard_player_points(name, year, weeks)
    elif scoring == 'decimal':
        results = points.decimal_player_points(name, year, weeks)
    elif scoring == 'standard_ppr':
        results = points.standard_ppr_player_points(name, year, weeks)
    elif scoring == 'decimal_ppr':
        results = points.decimal_ppr_player_points(name, year, weeks)
    elif scoring == 'standard_half_ppr':
        results = points.standard_half_ppr_player_points(name, year, weeks)
    elif scoring == 'decimal_half_ppr':
        results = points.decimal_half_ppr_player_points(name, year, weeks)
    else:
        return render(request, 'results.html', {'error':True, 'title':"Error"})
    if results == False:
        return render(request, 'results.html', {'error':True, 'title':"Error"})
    position = stats.player_position(name)
    qb = False
    flex = False
    k = False
    if position == "QB":
        qb = True
    elif position == "K":
        k = True
    elif position == "WR" or position == "RB" or position == "TE":
        flex = True
    else:
        return render(request, 'results.html', {'error':True, 'title':"Error"})
    bye_week = schedule.bye_week_player(name, year)
    total_points = points.total_points(results);
    graph_total_points = points.total_points_no_bye(results)
    ordered_total_points = OrderedDict(sorted(total_points.items()))
    graph_ordered_total_points = OrderedDict(sorted(graph_total_points.items()))
    total_stats = stats.total_stats(name, year, week);
    return render(request, 'results.html', {'title':name, 'name':name, 'total_stats':total_stats, 'results':results, 'scoring':scoring, 'graph_ordered_total_points':graph_ordered_total_points, 'bye_week':bye_week, 'position':position, 'qb':qb, 'flex':flex, 'k':k})

def scoreboard(request):
    current_week = schedule.current_week()
    year = date.today().year
    games = nflgame.games(year, week=current_week)
    scores = []
    for x in games:
        scores.append(x)
    weeks = []
    for x in range(0,current_week):
        weeks.append(x+1)
    return render(request, 'scoreboard.html', {'scores':scores,'week':current_week, 'past_weeks':weeks})

def previous_scoreboard(request, offset):
    try:
        wk = int(offset)
    except ValueError:
        raise Http404()
    current_week = schedule.current_week()
    if wk>current_week:
        raise Http404()
    year = date.today().year
    games = nflgame.games(year, week=wk)
    scores = []
    for x in games:
        scores.append(x)
    weeks = []
    for x in range(0,current_week):
        weeks.append(x+1)
    return render(request, 'previous_scoreboard.html', {'scores':scores,'week':wk, 'past_weeks':weeks})

def teamnum(request, offset):
    numteams = request.COOKIES.get('teams', None)
    if numteams == None:
        return redirect('/team/new/')
    try:
        numteams = int(numteams)
    except ValueError:
        raise Http404()
    try:
        team = int(offset)
    except ValueError:
        raise Http404()
    if team < 1 or team > 3 or numteams < 1 or numteams > 3:
        raise Http404()
    teamcookiename = "team"+str(team)
    teamdata = request.COOKIES.get(teamcookiename, None)
    url = "/team/?"+teamdata
    return redirect(url)

def team(request):
    teamname = request.GET['teamname']
    teamplayers = []
    for x in range(1,16):
        dataname = "player"+str(x)
        teamplayers.append(request.GET[dataname])
    qb = []
    rb = []
    wr = []
    te = []
    k = []
    none = []
    for x in teamplayers:
        if x == 'empty':
            none.append(x)
        else:
            playerposition = stats.player_position(x)
            if playerposition == "QB":
                qb.append(x)
            elif playerposition == "RB":
                rb.append(x)
            elif playerposition == "WR":
                wr.append(x)
            elif playerposition == "TE":
                te.append(x)
            elif playerposition == "K":
                k.append(x)
            else:
                none.append(x)
    return render(request, "team.html", {'title':teamname, 'teamname':teamname})

def new_team(request):
    numteams = request.COOKIES.get('teams', None)
    if numteams != None:
        try:
            numteams = int(numteams)
        except ValueError:
            raise Http404()
        if numteams < 1 or numteams > 3:
            raise Http404()
        if numteams == 3:
            return render(request, 'new_team.html', {'toomany':True, 'title':'Error'})
    if numteams == None:
        teamnum = 1
    else:
        teamnum = numteams+1
    return render(request, 'new_team.html', {'title':'Create a New Team', 'teamnum':teamnum})

def team_list(request):
    numteams = request.COOKIES.get('teams', None)
    if numteams == None:
        return redirect('/team/new/')
    try:
        numteams = int(numteams)
    except ValueError:
        raise Http404()
    names = []
    for x in range(0, numteams):
        cookiename = "teamname"+str((x+1))
        name = request.COOKIES.get(cookiename, None)
{'fraction_non_alphanumeric': 0.13077617328519855, 'fraction_numerical': 0.008212996389891697, 'mean_word_length': 3.026526162790698, 'pattern_counts': {'":': 11, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4846854', 'n_tokens_mistral': 3576, 'n_tokens_neox': 3469, 'n_words': 822}