Пример #1
0
def resource_supply(request, resource, page_name):
    """Supply the view_objects content.
       :return: team, goals_scoreboard, resource_round_ranks"""

    user = request.user
    team = user.profile.team
    round_resource_ranks = {}
    round_group_resource_ranks = {}
    round_resource_goal_ranks = {}

    today = datetime.datetime.today()

    rounds = challenge_mgr.get_all_round_info()["rounds"]
    for key in rounds.keys():
        if rounds[key]["start"] <= today and\
            (rounds[key]["display_scoreboard"] or page_name == "status"):
            round_resource_ranks[key] = resource_mgr.resource_ranks(resource, key)
            round_group_resource_ranks[key] = resource_mgr.group_resource_ranks(resource, key)
            round_resource_goal_ranks[key] = resource_goal.resource_goal_ranks(resource, key)

    round_resource_ranks["Overall"] = resource_mgr.resource_ranks(resource, "Overall")
    round_group_resource_ranks["Overall"] = resource_mgr.group_resource_ranks(resource, "Overall")
    round_resource_goal_ranks["Overall"] = resource_goal.resource_goal_ranks(resource, "Overall")

    resource_setting = resource_mgr.get_resource_setting(resource)
    return {
        "profile": user.profile,
        "team": team,
        "resource": resource_setting,
        "round_resource_goal_ranks": round_resource_goal_ranks,
        "round_resource_ranks": round_resource_ranks,
        "round_group_resource_ranks": round_group_resource_ranks,
        }
Пример #2
0
def resource_goal_rank_info(team, resource):
    """Get the overall rank for the team. Return a dict of the rank number and usage."""
    if team:
        info = {}
        ranks = resource_goal_ranks(resource)
        if ranks:
            for idx, rank in enumerate(ranks):
                if rank["team__name"] == team.name:
                    info["rank"] = idx + 1
                    break

        ranks = resource_mgr.resource_ranks(resource)
        if ranks:
            for idx, rank in enumerate(ranks):
                if rank["team__name"] == team.name:
                    info["usage"] = rank["total"]
                    info["unit"] = resource_mgr.get_resource_setting(resource).unit
                    break
        return info
    else:
        return None
Пример #3
0
def resource_goal_rank_info(team, resource):
    """Get the overall rank for the team. Return a dict of the rank number and usage."""
    if team:
        info = {}
        ranks = resource_goal_ranks(resource)
        if ranks:
            for idx, rank in enumerate(ranks):
                if rank["team__name"] == team.name:
                    info["rank"] = idx + 1
                    break

        ranks = resource_mgr.resource_ranks(resource)
        if ranks:
            for idx, rank in enumerate(ranks):
                if rank["team__name"] == team.name:
                    info["usage"] = rank["total"]
                    info["unit"] = resource_mgr.get_resource_setting(
                        resource).unit
                    break
        return info
    else:
        return None
Пример #4
0
def resource_supply(request, resource, page_name):
    """Supply the view_objects content.
       :return: team, goals_scoreboard, resource_round_ranks"""

    user = request.user
    team = user.get_profile().team
    round_resource_ranks = {}
    round_resource_goal_ranks = {}

    current_round = challenge_mgr.get_round_name()
    rounds = challenge_mgr.get_all_round_info()["rounds"]
    for key in rounds.keys():
        if key == current_round or page_name == "status":
            round_resource_ranks[key] = resource_mgr.resource_ranks(resource, key)
            round_resource_goal_ranks[key] = resource_goal.resource_goal_ranks(resource, key)

    resource_setting = resource_mgr.get_resource_setting(resource)
    return {
        "profile": user.get_profile(),
        "team": team,
        "resource": resource_setting,
        "round_resource_goal_ranks": round_resource_goal_ranks,
        "round_resource_ranks": round_resource_ranks,
        }