Example #1
0
def update_energy_usage():
    """update energy usage."""
    date = datetime.datetime.today()
    print '****** Processing energy usage update at %s *******\n' % date

    challenge_mgr.init()
    resource_goal.update_resource_usage("energy", date)
Example #2
0
    def setUp(self):
        challenge_mgr.init()
        self.user = User(username="******", password="******")
        self.user.save()

        self.quest = test_utils.create_quest(completion_conditions=False)
        test_utils.set_competition_round()
Example #3
0
def update_fake_water_usage():
    """update fake water usage."""
    date = datetime.datetime.today()
    print '****** Processing water usage update at %s *******\n' % date

    challenge_mgr.init()
    resource_mgr.update_fake_water_usage(date)
    def setUp(self):
        challenge_mgr.init()
        self.user = User(username="******", password="******")
        self.user.save()

        self.quest = test_utils.create_quest(completion_conditions=False)
        test_utils.set_competition_round()
    def setUp(self):
        """Set up a team and log in."""
        challenge_mgr.init()
        self.user = test_utils.setup_user(username="******", password="******")

        test_utils.setup_round_prize("Round 1", "team_overall", "energy")
        test_utils.setup_round_prize("Round 2", "team_overall", "energy")
        test_utils.setup_round_prize("Round 1", "team_overall", "points")
        test_utils.setup_round_prize("Round 2", "team_overall", "points")
        test_utils.setup_round_prize("Round 1", "individual_overall", "points")
        test_utils.setup_round_prize("Round 2", "individual_overall", "points")
        test_utils.setup_round_prize("Round 1", "individual_team", "points")
        test_utils.setup_round_prize("Round 2", "individual_team", "points")

        challenge_mgr.register_page_widget("win", "prizes")

        from apps.managers.cache_mgr import cache_mgr

        cache_mgr.clear()

        profile = self.user.get_profile()
        profile.add_points(10, datetime.datetime.today(), "test")
        profile.save()

        self.client.login(username="******", password="******")
Example #6
0
def update_energy_usage():
    """Update the energy usage from WattDepot server."""

    challenge_mgr.init()
    date = datetime.datetime.today()

    # workaround the issue that wattdepot might not have the latest data yet.
    date = date - datetime.timedelta(minutes=5)

    start_time = date.strftime("%Y-%m-%dT00:00:00")
    end_time = date.strftime("%Y-%m-%dT%H:%M:%S")

    s = requests.session()
    s.params = {'startTime': start_time, 'endTime': end_time}

    for team in Team.objects.all():
        usage = get_energy_usage(s, team.name)
        if usage:
            try:
                latest_usage = EnergyUsage.objects.get(team=team, date=date.date())
            except ObjectDoesNotExist:
                latest_usage = EnergyUsage(team=team, date=date.date())

            latest_usage.time = date.time()
            latest_usage.usage = usage
            latest_usage.save()
            print 'team %s energy usage updated at %s.' % (team, date)
Example #7
0
def send_reminders():
    """send reminders."""
    print '****** Processing send_reminders at %s *******' % datetime.datetime.today(
    )

    challenge_mgr.init()
    smartgrid.send_reminders()
    smartgrid.check_new_submissions()
    participation.award_participation()
def set_competition_round():
    """set the competition round for test. current date is in round 1"""
    start = datetime.datetime.today() - datetime.timedelta(days=1)
    end = start + datetime.timedelta(days=7)
    end2 = end + datetime.timedelta(days=7)
    RoundSetting.objects.all().delete()
    RoundSetting.objects.create(name="Round 1", start=start, end=end)
    RoundSetting.objects.create(name="Round 2", start=end, end=end2)
    challenge_mgr.init()
Example #9
0
def set_competition_round():
    """set the competition round for test. current date is in round 1"""
    start = datetime.datetime.today() - datetime.timedelta(days=1)
    end = start + datetime.timedelta(days=7)
    end2 = end + datetime.timedelta(days=7)
    RoundSetting.objects.all().delete()
    RoundSetting.objects.create(name="Round 1", start=start, end=end)
    RoundSetting.objects.create(name="Round 2", start=end, end=end2)
    challenge_mgr.init()
Example #10
0
def process_notices():
    """Send out notifications such as commitment end,
    and process rsvp reminder and penalty."""
    print '****** Processing notices at %s *******' % datetime.datetime.today()

    challenge_mgr.init()
    smartgrid.notify_commitment_end()
    smartgrid.process_rsvp()
    smartgrid.check_daily_submissions()
    badges.award_possible_daily_badges()
Example #11
0
    def setUp(self):
        """
        setup
        """
        challenge_mgr.init()

        self.user = test_utils.setup_user(username="******", password="******")
        test_utils.set_competition_round()
        challenge_mgr.register_page_widget("learn", "participation")
        cache_mgr.clear()
        self.client.login(username="******", password="******")
Example #12
0
    def setUp(self):
        """
        setup
        """
        challenge_mgr.init()

        self.user = test_utils.setup_user(username="******", password="******")
        test_utils.set_competition_round()
        challenge_mgr.register_page_widget("learn", "participation")
        cache_mgr.clear()
        self.client.login(username="******", password="******")
Example #13
0
def check_water_goal():
    """check the water goal for all teams and update energy baseline"""
    today = datetime.datetime.today()
    print '****** Processing check_water_goal and update baseline for %s *******\n' % today

    challenge_mgr.init()
    today = today.date()
    resource_goal.check_resource_goals("water", today)

    # update the baseline
    resource_goal.update_resource_baseline("water", today, 2)
def set_two_rounds():
    """set two rounds for this test. current date is in round 2"""
    start = datetime.datetime.today() - datetime.timedelta(days=8)
    end1 = start + datetime.timedelta(days=7)
    end2 = end1 + datetime.timedelta(days=7)
    end3 = end2 + datetime.timedelta(days=7)
    RoundSetting.objects.all().delete()
    RoundSetting.objects.create(name="Round 1", start=start, end=end1)
    RoundSetting.objects.create(name="Round 2", start=end1, end=end2)
    RoundSetting.objects.create(name="Round 3", start=end2, end=end3)
    challenge_mgr.init()
Example #15
0
def set_two_rounds():
    """set two rounds for this test. current date is in round 2"""
    start = datetime.datetime.today() - datetime.timedelta(days=8)
    end1 = start + datetime.timedelta(days=7)
    end2 = end1 + datetime.timedelta(days=7)
    end3 = end2 + datetime.timedelta(days=7)
    RoundSetting.objects.all().delete()
    RoundSetting.objects.create(name="Round 1", start=start, end=end1)
    RoundSetting.objects.create(name="Round 2", start=end1, end=end2)
    RoundSetting.objects.create(name="Round 3", start=end2, end=end3)
    challenge_mgr.init()
Example #16
0
    def setUp(self):
        """Generate test user and activity. Set the competition settings to the
        current date for testing."""
        challenge_mgr.init()
        self.user = User.objects.create_user('user', '*****@*****.**')
        self.user.save()
        self.activity = test_utils.create_activity()
        self.event = test_utils.create_event()

        self.current_round = "Round 1"

        test_utils.set_competition_round()
Example #17
0
    def setUp(self):
        """Generate test user and activity. Set the competition settings to the
        current date for testing."""
        challenge_mgr.init()
        self.user = User.objects.create_user('user', '*****@*****.**')
        self.user.save()
        self.activity = test_utils.create_activity()
        self.event = test_utils.create_event()

        self.current_round = "Round 1"

        test_utils.set_competition_round()
Example #18
0
    def setUp(self):
        """setup"""
        challenge_mgr.init()
        self.user = test_utils.setup_user(username="******", password="******")
        test_utils.set_competition_round()
        challenge_mgr.register_page_widget("home", "quests")
        challenge_mgr.register_page_widget("profile", "my_achievements")
        challenge_mgr.register_page_widget("profile", "my_commitments")

        from apps.managers.cache_mgr import cache_mgr
        cache_mgr.clear()

        self.client.login(username="******", password="******")
Example #19
0
    def setUp(self):
        """
        setup
        """
        challenge_mgr.init()

        self.user = test_utils.setup_user(username="******", password="******")

        challenge_mgr.register_page_widget("learn", "smartgrid")
        challenge_mgr.register_page_widget("learn", "scoreboard")
        cache_mgr.clear()

        self.client.login(username="******", password="******")
Example #20
0
    def setUp(self):
        """setup"""
        challenge_mgr.init()
        self.user = test_utils.setup_user(username="******", password="******")
        test_utils.set_competition_round()

        test_utils.enable_quest()
        challenge_mgr.register_page_widget("home", "home")
        challenge_mgr.register_page_widget("profile", "my_achievements")
        challenge_mgr.register_page_widget("profile", "my_commitments")

        from apps.managers.cache_mgr import cache_mgr
        cache_mgr.clear()

        self.client.login(username="******", password="******")
Example #21
0
    def testRoundInfo(self):
        """Tests that round info is available for the page to process."""
        challenge_mgr.init()
        test_utils.set_competition_round()
        current_round = challenge_mgr.get_round_name()

        User.objects.create_user("user", "*****@*****.**", password="******")
        self.client.login(username="******", password="******")

        challenge_mgr.register_page_widget("home", "home")
        response = self.client.get(reverse("home_index"))
        # Response context should have round info corresponding to the past days.

        self.assertEqual(response.context["CURRENT_ROUND_INFO"]["name"], current_round,
            "Expected %s but got %s" % (
                current_round, response.context["CURRENT_ROUND_INFO"]["name"]))
Example #22
0
    def testRoundInfo(self):
        """Tests that round info is available for the page to process."""
        challenge_mgr.init()
        test_utils.set_competition_round()
        current_round = challenge_mgr.get_round_name()

        User.objects.create_user("user", "*****@*****.**", password="******")
        self.client.login(username="******", password="******")

        challenge_mgr.register_page_widget("home", "home")
        response = self.client.get(reverse("home_index"))
        # Response context should have round info corresponding to the past days.

        self.assertEqual(
            response.context["CURRENT_ROUND_INFO"]["name"], current_round,
            "Expected %s but got %s" %
            (current_round, response.context["CURRENT_ROUND_INFO"]["name"]))
Example #23
0
def update_fake_water_usage():
    """update fake water usage."""
    challenge_mgr.init()
    date = datetime.datetime.today()
    for team in Team.objects.all():
        count = team.profile_set.count()
        if count:
            # assume the average water usage is 80 gallon per person per day
            average_usage = 80
            actual_usage = average_usage * 0.9
            water = WaterUsage.objects.filter(team=team, date=date.date())
            if water:
                water = water[0]
            else:
                water = WaterUsage(team=team, date=date.date())

            water.time = date.time()
            water.usage = actual_usage * count
            water.save()
            print 'team %s fake water usage updated at %s.' % (team, date)
Example #24
0
    def testCurrentRound(self):
        """Tests that the current round retrieval is correct."""
        current_round = "Round 1"

        test_utils.set_competition_round()

        current = challenge_mgr.get_round_name()
        self.assertEqual(current, current_round,
                         "Test that the current round is returned.")

        start = datetime.datetime.today() + datetime.timedelta(days=1)
        end = start + datetime.timedelta(days=7)
        rounds = RoundSetting.objects.get(name="Round 1")
        rounds.start = start
        rounds.end = end
        rounds.save()

        challenge_mgr.init()
        current_round = challenge_mgr.get_round_name()
        self.assertTrue(current_round is None,
                        "Test that there is no current round.")
Example #25
0
    def testCurrentRound(self):
        """Tests that the current round retrieval is correct."""
        current_round = "Round 1"

        test_utils.set_competition_round()

        current = challenge_mgr.get_round_name()
        self.assertEqual(current, current_round,
            "Test that the current round is returned.")

        start = datetime.datetime.today() + datetime.timedelta(days=1)
        end = start + datetime.timedelta(days=7)
        rounds = RoundSetting.objects.get(name="Round 1")
        rounds.start = start
        rounds.end = end
        rounds.save()

        challenge_mgr.init()
        current_round = challenge_mgr.get_round_name()
        self.assertTrue(current_round is None,
            "Test that there is no current round.")
Example #26
0
    def process_request(self, request):
        """Check the competition period and that setup is completed."""
        #time_start = datetime.datetime.now()

        path = request.path

        # pass through for trivial requests
        pattern = "^/(log|site_media|favicon.ico)/"
        if re.compile(pattern).match(path):
            return None

        # load the db settings if not done yet.
        challenge_mgr.init()

        # pass through for trivial requests
        pattern = "^/(home\/restricted|admin|about|account)/"
        if re.compile(pattern).match(path):
            return None

        user = request.user
        if not user.is_authenticated():
            return None

        # user logged in
        # if user logged in and go to landing page, re-direct to home page
        if path.startswith("/landing/"):
            return HttpResponseRedirect(reverse("home_index"))

        # now the user is authenticated and going to the non-trivial pages.
        response = self.check_competition_period(request)

        if response is None:
            response = self.check_setup_completed(request)

            if response is None:
                response = self.track_login(request)

        #time_end = datetime.datetime.now()
        #print "%s time: %s" % ("player middleware", (time_end - time_start))
        return response
Example #27
0
    def process_request(self, request):
        """Check the competition period and that setup is completed."""
        #time_start = datetime.datetime.now()

        path = request.path

        # pass through for trivial requests
        pattern = "^/(log|site_media|favicon.ico)/"
        if re.compile(pattern).match(path):
            return None

        # load the db settings if not done yet.
        challenge_mgr.init()

        # pass through for trivial requests
        pattern = "^/(home\/restricted|admin|about|account)/"
        if re.compile(pattern).match(path):
            return None

        user = request.user
        if not user.is_authenticated():
            return None

        # user logged in
        # if user logged in and go to landing page, re-direct to home page
        if path.startswith("/landing/"):
            return HttpResponseRedirect(reverse("home_index"))

        # now the user is authenticated and going to the non-trivial pages.
        response = self.check_competition_period(request)

        if response is None:
            response = self.check_setup_completed(request)

            if response is None:
                response = self.track_login(request)

        #time_end = datetime.datetime.now()
        #print "%s time: %s" % ("player middleware", (time_end - time_start))
        return response
Example #28
0
 def setUp(self):
     challenge_mgr.init()
     self.user = User(username="******", password="******")
     self.user.save()
Example #29
0
 def setUp(self):
     challenge_mgr.init()
     self.user = User(username="******", password="******")
     self.user.save()
Example #30
0
def process_rounds():
    """Send out notifications such as round transition."""
    print '****** Processing rounds at %s *******' % datetime.datetime.today()

    challenge_mgr.init()
    smartgrid.notify_round_started()