def test_get_current_no_extended_end_date(self): team_id = 'Team_001' strictly_past_cycle = Cycle.create( team_id=team_id, ordinal=1, start_date=date.today() - timedelta(days=2), end_date=date.today() - timedelta(days=1), ) strictly_past_cycle.put() strictly_current_cycle = Cycle.create( team_id=team_id, ordinal=2, start_date=date.today() - timedelta(days=1), end_date=date.today() + timedelta(days=1), ) strictly_current_cycle.put() strictly_future_cycle = Cycle.create( team_id=team_id, ordinal=3, start_date=date.today() + timedelta(days=1), end_date=date.today() + timedelta(days=2), ) strictly_future_cycle.put() self.assertEqual( Cycle.get_current_for_team(team_id), strictly_current_cycle )
def post(self, team_id, date_str=None): if date_str: today = datetime.strptime(date_str, config.iso_date_format).date() else: today = date.today() # Guaranteed to have start and end dates. cycle = Cycle.get_current_for_team(team_id, today) if not cycle: logging.info( "Either the team doesn't exist, or they don't have a cycle " "matching the current date. Doing nothing.") return team = Team.get_by_id(team_id) classrooms = Classroom.get(team_id=team_id) if len(classrooms) == 0: logging.info("No classrooms, setting participation to 0.") cycle.students_completed = 0 else: ppn = get_participation(cycle, classrooms) num_complete = 0 for code, counts in ppn.items(): complete_count = next( (c for c in counts if c['value'] == '100'), None) num_complete += complete_count['n'] if complete_count else 0 cycle.students_completed = num_complete cycle.put()