Exemple #1
0
 def testFloorEnergyGoal(self):
   profile = self.user.get_profile()
   points = profile.points
   
   goal = FloorEnergyGoal(
       floor=self.floor, 
       goal_usage=str(1.0), 
       actual_usage=str(0.5),
   )
   goal.save()
   profile = Profile.objects.get(user__username="******")
   self.assertEqual(profile.points, points, 
       "User that did not complete the setup process should not be awarded points.")
   
   profile.setup_complete = True
   profile.save()
   
   goal.actual_usage = "1.5"
   goal.save()
   profile = Profile.objects.get(user__username="******")
   self.assertEqual(profile.points, points, 
       "Floor that failed the goal should not be awarded any points.")
       
   goal.actual_usage = "0.5"
   goal.save()
   profile = Profile.objects.get(user__username="******")
   self.assertEqual(profile.points, points + FloorEnergyGoal.GOAL_POINTS,
       "User that setup their profile should be awarded points.")
Exemple #2
0
  def simulate_goals_for_round_1(self):
    round_start = datetime.datetime.strptime(settings.COMPETITION_ROUNDS["Round 1"]["start"], "%Y-%m-%d").date()
    round_end = datetime.datetime.strptime(settings.COMPETITION_ROUNDS["Round 1"]["end"], "%Y-%m-%d").date()
    voting_end = round_start + datetime.timedelta(days=2)
    self.stdout.write("Simulating goal participation in the first round.\n")
    
    goal = EnergyGoal(start_date=round_start, end_date=round_end, voting_end_date=voting_end)
    goal.save()
    
    # Simulate votes.
    for profile in Profile.objects.all():
      # Assume 1 in 5 users do not vote.
      if random.randint(0, 4) % 5 != 0:
        # User likely to vote between 0 and 25% reduction.
        value = random.randint(0, 5) * 5
        vote = EnergyGoalVote(user=profile.user, goal=goal, percent_reduction=value)
        vote.save()
        
    # Generate floor energy goals.
    for floor in Floor.objects.all():
      results = goal.get_floor_results(floor)
      percent_reduction = 0
      if len(results) > 0:
        percent_reduction = results[0]["percent_reduction"]

      floor_goal = FloorEnergyGoal(floor=floor, goal=goal, percent_reduction=percent_reduction)
      
      # Assume 1 in 5 goals fail.
      if random.randint(0, 4) % 5 != 0:
        floor_goal.completed = True
        
      floor_goal.save()
Exemple #3
0
 def award_point(self, source, goal, actual):
     try:
         floor = Floor.objects.get(floor_identifier=source)
         goal = FloorEnergyGoal(
             floor=floor,
             goal_usage=goal,
             actual_usage=actual,
         )
         goal.save()
     except Floor.DoesNotExist:
         print 'floor with identifier %s does not exist' % source
 def award_point(self, source, goal, actual):
   try:
     floor = Floor.objects.get(floor_identifier=source)
     goal = FloorEnergyGoal(
         floor=floor,
         goal_usage=goal,
         actual_usage=actual,
     )
     goal.save()
   except Floor.DoesNotExist:
     print 'floor with identifier %s does not exist' % source
Exemple #5
0
def generate_floor_goals():
  """Called by a cron task to generate the floor goals for a floor."""
  goal = EnergyGoal.get_current_goal()
  today = datetime.date.today()
  if goal and goal.voting_end_date <= today and goal.floorenergygoal_set.count() == 0:
    # Go through the votes and create energy goals for the floor.
    for floor in Floor.objects.all():
      results = goal.get_floor_results(floor)
      percent_reduction = 0
      if len(results) > 0:
        percent_reduction = results[0]["percent_reduction"]

      floor_goal = FloorEnergyGoal(floor=floor, goal=goal, percent_reduction=percent_reduction)
      floor_goal.save()
Exemple #6
0
def generate_floor_goals():
    """Called by a cron task to generate the floor goals for a floor."""
    goal = EnergyGoal.get_current_goal()
    today = datetime.date.today()
    if goal and goal.voting_end_date <= today and goal.floorenergygoal_set.count(
    ) == 0:
        # Go through the votes and create energy goals for the floor.
        for floor in Floor.objects.all():
            results = goal.get_floor_results(floor)
            percent_reduction = 0
            if len(results) > 0:
                percent_reduction = results[0]["percent_reduction"]

            floor_goal = FloorEnergyGoal(floor=floor,
                                         goal=goal,
                                         percent_reduction=percent_reduction)
            floor_goal.save()
Exemple #7
0
 def testRoundPoints(self):
   """Test that we can assign points to a round when the goal ends at the same time."""
   user = User.objects.get(username="******")
   profile = user.get_profile()
   floor = profile.floor
   overall_points = profile.points
   entry, created = ScoreboardEntry.objects.get_or_create(profile=profile, round_name=self.current_round)
   round_points = entry.points
   
   floor_goal = FloorEnergyGoal(floor=floor, goal=self.goal, percent_reduction=10, completed=True)
   floor_goal.save()
   
   self.assertTrue(floor_goal.awarded, "Check that the goal was awarded.")
   test_profile = Profile.objects.get(user=user)
   self.assertEqual(test_profile.points, overall_points + 10, "Check that points are awarded overall.")
   entry = ScoreboardEntry.objects.get(profile=user.get_profile(), round_name=self.current_round)
   self.assertEqual(entry.points, round_points + 10, "Check that points are awarded for this round.")
  def handle(self, *args, **options):
    goal = EnergyGoal.get_current_goal()
    today = datetime.date.today()
    if goal and goal.voting_end_date <= today and goal.floorenergygoal_set.count() == 0:
      self.stdout.write("Generating goals for each floor.\n")
      # Go through the votes and create energy goals for the floor.
      for floor in Floor.objects.all():
        results = goal.get_floor_results(floor)
        percent_reduction = 0
        if len(results) > 0:
          percent_reduction = results[0]["percent_reduction"]

        floor_goal = FloorEnergyGoal(floor=floor, goal=goal, percent_reduction=percent_reduction)
        floor_goal.save()
        
    elif not goal:
      self.stdout.write("There is no goal to process.\n")
    else:
      self.stdout.write("The floor goals are already created.\n")
Exemple #9
0
    def simulate_goals_for_round_1(self):
        round_start = datetime.datetime.strptime(
            settings.COMPETITION_ROUNDS["Round 1"]["start"],
            "%Y-%m-%d").date()
        round_end = datetime.datetime.strptime(
            settings.COMPETITION_ROUNDS["Round 1"]["end"], "%Y-%m-%d").date()
        voting_end = round_start + datetime.timedelta(days=2)
        self.stdout.write(
            "Simulating goal participation in the first round.\n")

        goal = EnergyGoal(start_date=round_start,
                          end_date=round_end,
                          voting_end_date=voting_end)
        goal.save()

        # Simulate votes.
        for profile in Profile.objects.all():
            # Assume 1 in 5 users do not vote.
            if random.randint(0, 4) % 5 != 0:
                # User likely to vote between 0 and 25% reduction.
                value = random.randint(0, 5) * 5
                vote = EnergyGoalVote(user=profile.user,
                                      goal=goal,
                                      percent_reduction=value)
                vote.save()

        # Generate floor energy goals.
        for floor in Floor.objects.all():
            results = goal.get_floor_results(floor)
            percent_reduction = 0
            if len(results) > 0:
                percent_reduction = results[0]["percent_reduction"]

            floor_goal = FloorEnergyGoal(floor=floor,
                                         goal=goal,
                                         percent_reduction=percent_reduction)

            # Assume 1 in 5 goals fail.
            if random.randint(0, 4) % 5 != 0:
                floor_goal.completed = True

            floor_goal.save()
    def handle(self, *args, **options):
        goal = EnergyGoal.get_current_goal()
        today = datetime.date.today()
        if goal and goal.voting_end_date <= today and goal.floorenergygoal_set.count(
        ) == 0:
            self.stdout.write("Generating goals for each floor.\n")
            # Go through the votes and create energy goals for the floor.
            for floor in Floor.objects.all():
                results = goal.get_floor_results(floor)
                percent_reduction = 0
                if len(results) > 0:
                    percent_reduction = results[0]["percent_reduction"]

                floor_goal = FloorEnergyGoal(
                    floor=floor,
                    goal=goal,
                    percent_reduction=percent_reduction)
                floor_goal.save()

        elif not goal:
            self.stdout.write("There is no goal to process.\n")
        else:
            self.stdout.write("The floor goals are already created.\n")