Esempio n. 1
0
    def testEnergy(self):
        """test Energy."""
        date = datetime.date.today()
        EnergyUsage(
            team=self.team,
            date=date,
            time=datetime.time(hour=15),
            usage=100,
        ).save()

        rank = resource_mgr.resource_team_rank_info(self.team, "energy")["rank"]
        usage = resource_mgr.team_resource_usage(date=date, team=self.team, resource="energy")
        self.assertEqual(rank, 1, "The team should be first rank.")
        self.assertEqual(usage, 100, "The team usage is not correct.")
Esempio n. 2
0
def get_history_resource_usage(resource, session, team, date, hour):
    """returns the team's resource usage based on team's goal settings."""
    goal_settings = team_goal_settings(team, resource)

    usage = 0
    if not hour:
        # for daily data, try to get it from resource usage table
        # if not found, get if from ResourceStorage
        usage = resource_mgr.team_resource_usage(date, team, resource)

    if not usage and goal_settings and not goal_settings.manual_entry:
        storage = get_resource_storage(goal_settings.data_storage)
        usage = resource_mgr.get_history_resource_data(session, team, date, hour, storage)

    return usage
Esempio n. 3
0
def get_history_resource_usage(resource, session, team, date, hour):
    """returns the team's resource usage based on team's goal settings."""
    goal_settings = team_goal_settings(team, resource)

    usage = 0
    if not hour:
        # for daily data, try to get it from resource usage table
        # if not found, get if from ResourceStorage
        usage = resource_mgr.team_resource_usage(date, team, resource)

    if not usage and goal_settings and not goal_settings.manual_entry:
        storage = get_resource_storage(goal_settings.data_storage)
        usage = resource_mgr.get_history_resource_data(session, team, date,
                                                       hour, storage)

    return usage
Esempio n. 4
0
    def testEnergy(self):
        """test Energy."""
        date = datetime.date.today()
        EnergyUsage(
            team=self.team,
            date=date,
            time=datetime.time(hour=15),
            usage=100,
        ).save()

        rank = resource_mgr.resource_team_rank_info(self.team,
                                                    "energy")["rank"]
        usage = resource_mgr.team_resource_usage(date=date,
                                                 team=self.team,
                                                 resource="energy")
        self.assertEqual(rank, 1, "The team should be first rank.")
        self.assertEqual(usage, 100, "The team usage is not correct.")
Esempio n. 5
0
def get_daily_goal_data(team, resource):
    """:return: the daily energy goal data."""

    round_info = challenge_mgr.get_round_info()
    if not round_info:
        return None

    start = round_info["start"].date()
    end = round_info["end"].date()
    delta = (end - start).days + 1
    data_table = []
    for day in range(0, delta):
        date = start + datetime.timedelta(days=day)

        goal_info = {"date": date}

        if day == 0:
            # cal and store the filler_days in the first day goal_info
            goal_info["filler_days"] = range(0, date.weekday())

        if day == (delta - 1):
            # cal and store the filler_days in the last day goal_info
            goal_info["filler_days"] = range(0, 6 - date.weekday())

        goal = resource_goal.team_goal(date, team, resource)
        goal_settings = resource_goal.team_goal_settings(team, resource)
        unit = resource_mgr.get_resource_setting(resource).unit
        goal_usage = resource_goal.team_daily_goal_usage(date, team, resource, goal_settings)
        goal_info["goal_info"] = "%d %s" % (goal_usage, unit)
        if goal:
            goal_info["goal_status"] = goal.goal_status
            goal_info["verbose_info"] = "%d %s used within the last 24 hours (ends at %s). " \
                                        "The goal is %d %s." % (
                resource_mgr.team_resource_usage(date, team, resource),
                unit,
                goal_settings.manual_entry_time,
                goal_usage,
                unit
            )

        data_table.append(goal_info)

    return data_table
Esempio n. 6
0
def supply(request, page_name):
    """Supply view_objects contents, which are the player name, team and points."""
    _ = page_name
    
    resources = {'energy','water','waste'}
    group_entries = {}

    today = datetime.datetime.today()

    for group in Group.objects.all():         
        temp = {}
        for resource in resources: 
            total = 0
            for team in Team.objects.all():
                if team.group.name == group.name: 
                    total = total + resource_mgr.team_resource_usage(today, team, resource)
            temp[resource] = total        
        group_entries[group] = temp;

    return {
        "group_entries": group_entries,
    }