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)
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 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): """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="******")
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)
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()
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()
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="******")
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()
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()
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="******")
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="******")
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="******")
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"]))
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"]))
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)
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.")
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
def setUp(self): challenge_mgr.init() self.user = User(username="******", password="******") self.user.save()
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()