コード例 #1
0
ファイル: views.py プロジェクト: war-on-ice/woi-web
def show_team_standings():
    rd = setup_nav()
    # Determine season(s) to get information from
    teamgames = get_r_seasons()
    form = SeasonSelectForm(request.form)
    form.seasons.choices = [(x, str(x)[0:4] + "-" + str(x)[4:])
                            for x in sorted(teamgames.keys(), reverse=True)]
    try:
        form.seasons.data = [int(x) for x in form.seasons.data]
    except:
        pass
    allseasons = [(x, str(x)[0:4] + "-" + str(x)[4:])
                  for x in sorted(teamgames.keys(), reverse=True)]
    if request.method == "POST" and form.validate():
        seasons = [int(x) for x in form.seasons.data]
    else:
        smax = max(teamgames.keys())
        seasons = [
            smax,
        ]
    seasongames = get_r_standings(teamgames, seasons=seasons)

    return render_template('teams/teams.html',
                           rd=rd,
                           seasongames=seasongames,
                           form=form,
                           allseasons=allseasons,
                           seasons=seasons)
コード例 #2
0
ファイル: views.py プロジェクト: MartinCote1978/woi-web
def show_team_standings():
    rd = setup_nav()
    # Determine season(s) to get information from
    teamgames = get_r_seasons()
    form = SeasonSelectForm(request.form)
    form.seasons.choices = [(x, str(x)[0:4] + "-" + str(x)[4:]) for x in sorted(teamgames.keys(), reverse=True)]
    try:
        form.seasons.data = [int(x) for x in form.seasons.data]
    except:
        pass
    allseasons = [(x, str(x)[0:4] + "-" + str(x)[4:]) for x in sorted(teamgames.keys(), reverse=True)]
    if request.method == "POST" and form.validate():
        seasons = [int(x) for x in form.seasons.data]
    else:
        smax = max(teamgames.keys())
        seasons = [smax, ]
    seasongames = get_r_standings(teamgames, seasons=seasons)

    return render_template('teams/teams.html',
        rd=rd,
        seasongames=seasongames,
        form=form,
        allseasons=allseasons,
        seasons=seasons)
コード例 #3
0
ファイル: views.py プロジェクト: war-on-ice/woi-web
def show_team_comparisons():
    rd = setup_nav()
    cpg = ComparisonGraphForm()
    teamgames = get_r_seasons()
    tablecolumns = [
        0,
    ]
    form = ComparisonForm(request.form)
    form.startingSeason.choices = [
        (x, str(x)[0:4] + "-" + str(x)[4:])
        for x in sorted(teamgames.keys(), reverse=True)
    ]
    form.endingSeason.choices = [
        (x, str(x)[0:4] + "-" + str(x)[4:])
        for x in sorted(teamgames.keys(), reverse=True)
    ]
    filterteams = form.filterTeams.data
    if filterteams is None:
        filterteams = []
    allteams = form.filterTeams.choices

    try:
        oldStart = form.startingSeason.data
        oldEnd = form.endingSeason.data
        form.startingSeason.data = int(form.startingSeason.data)
        form.endingSeason.data = int(form.endingSeason.data)
    except:
        pass
    allseasons = [(x, str(x)[0:4] + "-" + str(x)[4:])
                  for x in sorted(teamgames.keys(), reverse=True)]
    usedates = False

    if request.method == "POST" and form.validate():
        startingSeason = form.startingSeason.data
        endingSeason = form.endingSeason.data
        form.startingSeason.data = oldStart
        form.endingSeason.data = oldEnd
        startingDate = form.startingDate.data
        endingDate = form.endingDate.data
        usedates = form.bydate.data
        if not usedates:
            if endingSeason > startingSeason:
                begin = startingSeason
                end = endingSeason
            else:
                begin = endingSeason
                end = startingSeason
            currSeason = begin
            seasons = [
                begin,
            ]
            # TODO: Error check this?
            while begin != end:
                bsplit = str(begin)[0:4]
                begin = int(bsplit) * 10000 + 10001 + int(bsplit) + 1
                seasons.append(begin)
        else:
            if endingDate < startingDate:
                temp = endingDate
                endingDate = startingDate
                startingDate = temp
    else:
        smax = max(teamgames.keys())
        seasons = [
            smax,
        ]
    # Filter teamrun based on form data
    teamstrengths = int(form.teamstrengths.data)
    if teamstrengths == 7:
        teamstrengths = [
            constants.strength_situations_dict[x]["value"]
            for x in constants.strength_situations_dict
        ]
    else:
        teamstrengths = [
            teamstrengths,
        ]
    scoresituations = int(form.scoresituations.data)
    if scoresituations == 7:
        scoresituations = [
            constants.score_situations_dict[x]["value"]
            for x in constants.score_situations_dict
        ]
    homeaway = form.homeAway.data
    if homeaway == "all":
        homeaway = [0, 1]
    else:
        homeaway = [
            int(homeaway),
        ]
    periods = constants.periods_options[form.period.data]["value"]
    if 0 in periods:
        periods = [
            0,
        ]
    if 7 in scoresituations:
        scoresituations = [
            7,
        ]
    if 7 in teamstrengths:
        teamstrengths = [
            7,
        ]

    if not usedates:
        if len(filterteams) == 0:
            teamrun = TeamRun.query.filter(
                TeamRun.season.in_(seasons),
                TeamRun.gamestate.in_(teamstrengths),
                TeamRun.scorediffcat.in_(scoresituations),
                TeamRun.home.in_(homeaway), TeamRun.period.in_(periods)).all()
        else:
            teamrun = TeamRun.query.filter(
                TeamRun.season.in_(seasons),
                TeamRun.gamestate.in_(teamstrengths),
                TeamRun.scorediffcat.in_(scoresituations),
                TeamRun.home.in_(homeaway), TeamRun.Team.in_(filterteams),
                TeamRun.period.in_(periods)).all()
    else:
        if len(filterteams) == 0:
            teamrun = TeamRun.query.filter(
                TeamRun.Date >= startingDate, TeamRun.Date <= endingDate,
                TeamRun.gamestate.in_(teamstrengths),
                TeamRun.scorediffcat.in_(scoresituations),
                TeamRun.home.in_(homeaway), TeamRun.period.in_(periods)).all()
        else:
            teamrun = TeamRun.query.filter(
                TeamRun.Date >= startingDate, TeamRun.Date <= endingDate,
                TeamRun.gamestate.in_(teamstrengths),
                TeamRun.scorediffcat.in_(scoresituations),
                TeamRun.home.in_(homeaway), TeamRun.Team.in_(filterteams),
                TeamRun.period.in_(periods)).all()

    games, seasons = helpers.calculate(teamrun, form.divideSeason.data)
    if form.splitgame.data == True:
        summaries = games
    else:
        summaries = seasons

    return render_template('teams/teamcomparison.html',
                           rd=rd,
                           form=form,
                           summaries=summaries,
                           cpg=cpg,
                           filterteams=filterteams,
                           allteams=allteams)
コード例 #4
0
ファイル: views.py プロジェクト: MartinCote1978/woi-web
def show_team_comparisons():
    rd = setup_nav()
    cpg = ComparisonGraphForm()
    teamgames = get_r_seasons()
    tablecolumns = [0, ]
    form = ComparisonForm(request.form)
    form.startingSeason.choices = [(x, str(x)[0:4] + "-" + str(x)[4:]) for x in sorted(teamgames.keys(), reverse=True)]
    form.endingSeason.choices = [(x, str(x)[0:4] + "-" + str(x)[4:]) for x in sorted(teamgames.keys(), reverse=True)]
    filterteams = form.filterTeams.data
    if filterteams is None:
        filterteams = []
    allteams = form.filterTeams.choices

    try:
        oldStart = form.startingSeason.data
        oldEnd = form.endingSeason.data
        form.startingSeason.data = int(form.startingSeason.data)
        form.endingSeason.data = int(form.endingSeason.data)
    except:
        pass
    allseasons = [(x, str(x)[0:4] + "-" + str(x)[4:]) for x in sorted(teamgames.keys(), reverse=True)]
    usedates = False

    if request.method == "POST" and form.validate():
        startingSeason = form.startingSeason.data
        endingSeason = form.endingSeason.data
        form.startingSeason.data = oldStart
        form.endingSeason.data = oldEnd
        startingDate = form.startingDate.data
        endingDate = form.endingDate.data
        usedates = form.bydate.data
        if not usedates:
            if endingSeason > startingSeason:
                begin = startingSeason
                end = endingSeason
            else:
                begin = endingSeason
                end = startingSeason
            currSeason = begin
            seasons = [begin, ]
            # TODO: Error check this?
            while begin != end:
                bsplit = str(begin)[0:4]
                begin = int(bsplit) * 10000 + 10001 + int(bsplit) + 1
                seasons.append(begin)
        else:
            if endingDate < startingDate:
                temp = endingDate
                endingDate = startingDate
                startingDate = temp
    else:
        smax = max(teamgames.keys())
        seasons = [smax, ]
    # Filter teamrun based on form data
    teamstrengths = int(form.teamstrengths.data)
    if teamstrengths == 7:
        teamstrengths = [constants.strength_situations_dict[x]["value"] for x in constants.strength_situations_dict]
    else:
        teamstrengths = [teamstrengths, ]
    scoresituations = int(form.scoresituations.data)
    if scoresituations == 7:
        scoresituations = [constants.score_situations_dict[x]["value"] for x in constants.score_situations_dict]
    homeaway = form.homeAway.data
    if homeaway == "all":
        homeaway = [0, 1]
    else:
        homeaway = [int(homeaway), ]
    periods = constants.periods_options[form.period.data]["value"]
    if 0 in periods:
        periods = [0, ]
    if 7 in scoresituations:
        scoresituations = [7, ]
    if 7 in teamstrengths:
        teamstrengths = [7, ]

    if not usedates:
        if len(filterteams) == 0:
            teamrun = TeamRun.query.filter(TeamRun.season.in_(seasons), TeamRun.gamestate.in_(teamstrengths),
                TeamRun.scorediffcat.in_(scoresituations), TeamRun.home.in_(homeaway),
                TeamRun.period.in_(periods)).all()
        else:
            teamrun = TeamRun.query.filter(TeamRun.season.in_(seasons), TeamRun.gamestate.in_(teamstrengths),
                TeamRun.scorediffcat.in_(scoresituations), TeamRun.home.in_(homeaway),
                TeamRun.Team.in_(filterteams),
                TeamRun.period.in_(periods)).all()
    else:
        if len(filterteams) == 0:
            teamrun = TeamRun.query.filter(TeamRun.Date >= startingDate, TeamRun.Date <= endingDate,
                TeamRun.gamestate.in_(teamstrengths),
                TeamRun.scorediffcat.in_(scoresituations), TeamRun.home.in_(homeaway),
                TeamRun.period.in_(periods)).all()
        else:
            teamrun = TeamRun.query.filter(TeamRun.Date >= startingDate, TeamRun.Date <= endingDate,
                TeamRun.gamestate.in_(teamstrengths),
                TeamRun.scorediffcat.in_(scoresituations), TeamRun.home.in_(homeaway),
                TeamRun.Team.in_(filterteams),
                TeamRun.period.in_(periods)).all()

    games, seasons = helpers.calculate(teamrun, form.divideSeason.data)
    if form.splitgame.data == True:
        summaries = games
    else:
        summaries = seasons

    return render_template('teams/teamcomparison.html',
        rd=rd,
        form=form,
        summaries=summaries,
        cpg=cpg,
        filterteams=filterteams,
        allteams=allteams)