Beispiel #1
0
def team(request):
    teamname = request.GET['teamname']
    teamnum = request.GET['teamnum']
    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)
    scoring = request.GET['scoring']
    return render(request, "team.html", {'title':teamname, 'teamnum':teamnum, 'teamname':teamname, 'qb':qb, 'rb':rb, 'wr':wr, 'te':te, 'k':k, 'other':none, 'scoring':scoring})
Beispiel #2
0
def team(request):
    teamname = request.GET['teamname']
    teamnum = request.GET['teamnum']
    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)
    scoring = request.GET['scoring']
    return render(
        request, "team.html", {
            'title': teamname,
            'teamnum': teamnum,
            'teamname': teamname,
            'qb': qb,
            'rb': rb,
            'wr': wr,
            'te': te,
            'k': k,
            'other': none,
            'scoring': scoring
        })
Beispiel #3
0
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 = capwords(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)
    position = stats.player_position(name)
    team = stats.player_team(name)
    if position == "QB" or position == "RB" or position == "WR" or position == "TE":
        functionname = scoring+"_player_points"
        getpoints = getattr(points, functionname)
        results = getpoints(name, year, weeks)
    elif position == "K":
        results = points.k_points(name, year, weeks)
    else:
        results = False
    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)
    if position == "QB" or position == "RB" or position == "WR" or position == "TE":
        output_total_stats = convert.main_stats(total_stats)
        sorted_output_total_stats = OrderedDict(sorted(output_total_stats.items(), key=operator.itemgetter(1), reverse=True))
    elif position == "K":
        output_total_stats = convert.k_stats(total_stats)
        sorted_output_total_stats = OrderedDict(sorted(output_total_stats.items(), key=operator.itemgetter(1), reverse=True))
    else:
        return render(request, 'results.html', {'error':True, 'title':"Error"})
    average_points = predictions.average(name, scoring)
    prediction_stats = predictions.prediction(name, scoring)
    if prediction_stats == "Bye Week":
        prediction_points = "Bye Week"
        sorted_output_prediction_stats = {'Bye Week': "Bye Week"}
    else:
        if position == "QB":
            prediction_points = prediction_stats['points']
            output_prediction_stats = convert.qb_prediction(prediction_stats)
            sorted_output_prediction_stats = OrderedDict(sorted(output_prediction_stats.items(), key=operator.itemgetter(1), reverse=True))
        elif position == "RB":
            prediction_points = prediction_stats['points']
            output_prediction_stats = convert.rb_prediction(prediction_stats)
            sorted_output_prediction_stats = OrderedDict(sorted(output_prediction_stats.items(), key=operator.itemgetter(1), reverse=True))
        elif position == "WR" or position == "TE":
            prediction_points = prediction_stats['points']
            output_prediction_stats = convert.rec_prediction(prediction_stats)
            sorted_output_prediction_stats = OrderedDict(sorted(output_prediction_stats.items(), key=operator.itemgetter(1), reverse=True))
        elif position == "K":
            prediction_points = prediction_stats
            sorted_output_prediction_stats = {'Points':prediction_points}
        else:
            return render(request, 'results.html', {'error':True, 'title':"Error"})
    return render(request, 'results.html', {'title':name, 'name':name, 'total_stats':sorted_output_total_stats, 'results':results, 'scoring':scoring, 'graph_ordered_total_points':graph_ordered_total_points, 'bye_week':bye_week, 'position':position, 'team':team, 'qb':qb, 'flex':flex, 'k':k, 'average':average_points, 'predictions':sorted_output_prediction_stats, 'prediction':prediction_points})
Beispiel #4
0
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 = capwords(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)
    position = stats.player_position(name)
    team = stats.player_team(name)
    if position == "QB" or position == "RB" or position == "WR" or position == "TE":
        functionname = scoring + "_player_points"
        getpoints = getattr(points, functionname)
        results = getpoints(name, year, weeks)
    elif position == "K":
        results = points.k_points(name, year, weeks)
    else:
        results = False
    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)
    if position == "QB" or position == "RB" or position == "WR" or position == "TE":
        output_total_stats = convert.main_stats(total_stats)
        sorted_output_total_stats = OrderedDict(
            sorted(output_total_stats.items(),
                   key=operator.itemgetter(1),
                   reverse=True))
    elif position == "K":
        output_total_stats = convert.k_stats(total_stats)
        sorted_output_total_stats = OrderedDict(
            sorted(output_total_stats.items(),
                   key=operator.itemgetter(1),
                   reverse=True))
    else:
        return render(request, 'results.html', {
            'error': True,
            'title': "Error"
        })
    average_points = predictions.average(name, scoring)
    prediction_stats = predictions.prediction(name, scoring)
    if prediction_stats == "Bye Week":
        prediction_points = "Bye Week"
        sorted_output_prediction_stats = {'Bye Week': "Bye Week"}
    else:
        if position == "QB":
            prediction_points = prediction_stats['points']
            output_prediction_stats = convert.qb_prediction(prediction_stats)
            sorted_output_prediction_stats = OrderedDict(
                sorted(output_prediction_stats.items(),
                       key=operator.itemgetter(1),
                       reverse=True))
        elif position == "RB":
            prediction_points = prediction_stats['points']
            output_prediction_stats = convert.rb_prediction(prediction_stats)
            sorted_output_prediction_stats = OrderedDict(
                sorted(output_prediction_stats.items(),
                       key=operator.itemgetter(1),
                       reverse=True))
        elif position == "WR" or position == "TE":
            prediction_points = prediction_stats['points']
            output_prediction_stats = convert.rec_prediction(prediction_stats)
            sorted_output_prediction_stats = OrderedDict(
                sorted(output_prediction_stats.items(),
                       key=operator.itemgetter(1),
                       reverse=True))
        elif position == "K":
            prediction_points = prediction_stats
            sorted_output_prediction_stats = {'Points': prediction_points}
        else:
            return render(request, 'results.html', {
                'error': True,
                'title': "Error"
            })
    return render(
        request, 'results.html', {
            'title': name,
            'name': name,
            'total_stats': sorted_output_total_stats,
            'results': results,
            'scoring': scoring,
            'graph_ordered_total_points': graph_ordered_total_points,
            'bye_week': bye_week,
            'position': position,
            'team': team,
            'qb': qb,
            'flex': flex,
            'k': k,
            'average': average_points,
            'predictions': sorted_output_prediction_stats,
            'prediction': prediction_points
        })