Esempio n. 1
0
def prediction(request):
    scoring = request.GET['scoring']
    name = request.GET['name']
    year = date.today().year
    current_week = schedule.current_week()
    bye_week = schedule.bye_week_player(name, year)
    if current_week == bye_week:
        return HttpResponse("Bye Week")
    prediction = predictions.prediction(name, scoring)
    return HttpResponse(prediction['points'])
Esempio n. 2
0
def prediction(request):
    scoring = request.GET['scoring']
    name = request.GET['name']
    year = date.today().year
    current_week = schedule.current_week()
    bye_week = schedule.bye_week_player(name, year)
    if current_week == bye_week:
        return HttpResponse("Bye Week")
    prediction = predictions.prediction(name, scoring)
    return HttpResponse(prediction['points'])
Esempio n. 3
0
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, 'current_week':True})
Esempio n. 4
0
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, 'scoreboard.html', {'scores':scores,'week':wk, 'past_weeks':weeks, 'current_week':False})
Esempio n. 5
0
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,
            'current_week': True
        })
Esempio n. 6
0
def player_points(request):
    scoring = request.GET['scoring']
    name = request.GET['name']
    position = request.GET['position']
    year = date.today().year
    current_week = schedule.current_week()
    bye_week = schedule.bye_week_player(name, year)
    if current_week == bye_week:
        return HttpResponse("Bye Week")
    dictkey = "Week "+str(current_week)
    current_week = [current_week]
    if position == "QB" or position == "RB" or position == "WR" or position == "TE":
        functionname = scoring+"_player_points"
        getpoints = getattr(points, functionname)
        pts = getpoints(name, year, current_week)
        total_points = points.total_points(pts)[dictkey]
        return HttpResponse(total_points)
    if position == "K":
        pts = points.k_points(name, year, current_week)
        total_points = points.total_points(pts)[dictkey]
        return HttpResponse(total_points)
Esempio n. 7
0
def player_points(request):
    scoring = request.GET['scoring']
    name = request.GET['name']
    position = request.GET['position']
    year = date.today().year
    current_week = schedule.current_week()
    bye_week = schedule.bye_week_player(name, year)
    if current_week == bye_week:
        return HttpResponse("Bye Week")
    dictkey = "Week " + str(current_week)
    current_week = [current_week]
    if position == "QB" or position == "RB" or position == "WR" or position == "TE":
        functionname = scoring + "_player_points"
        getpoints = getattr(points, functionname)
        pts = getpoints(name, year, current_week)
        total_points = points.total_points(pts)[dictkey]
        return HttpResponse(total_points)
    if position == "K":
        pts = points.k_points(name, year, current_week)
        total_points = points.total_points(pts)[dictkey]
        return HttpResponse(total_points)
Esempio n. 8
0
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, 'scoreboard.html', {
        'scores': scores,
        'week': wk,
        'past_weeks': weeks,
        'current_week': False
    })
Esempio n. 9
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})
Esempio n. 10
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
        })