Exemple #1
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 #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()