def _user_studied_today_or_yesterday(self, student): """Did the given user study today or yesterday? """ study_today = self._get_study_day_on_date(student, date_utils.utc_now()) if not study_today or not study_today.user_has_studied: yesterday = date_utils.utc_now() - datetime.timedelta(days=1) study_yesterday = self._get_study_day_on_date(student, yesterday) if not study_yesterday or not study_yesterday.user_has_studied: return False return True
def _create_study_days(self, num_days, user=None, offset=0): user = user if user else self.student for i in range(num_days): date = date_utils.utc_now() - datetime.timedelta(days=(i + offset)) StudyDay.objects.create(user=user, date=date, question_commitment=10, day_type=StudyDay.STUDY)
def _get_practice_test(self, student): now = date_utils.utc_now() practice_test_days = StudyDay.objects.filter(user=student, date=now) if practice_test_days.exists(): practice_test_day = practice_test_days[0] if practice_test_day.bluebook_sections_completed > 0: return (practice_test_day.bluebook_sections_completed, now) return(0, now)
def _do_work(self, num_days, user=None, offset=0): user = user if user else self.student for i in range(num_days): date = date_utils.utc_now() - datetime.timedelta(days=(i + offset)) path, isession = self.step_through_itinerary(user, self.itinerary, answer_limit=10) for question in path: isq = ItinerarySessionQuestion.objects.get( itinerary_session=isession, question=question) isq.created_on = date isq.save()
def run(self, override=False): coaches = CoachOrganization.objects.all() missed_work_generator = MissedWorkActions() no_meeting_generator = NoMeetingsActions() missed_two_days_generator = MissedTwoDaysInRowAction() uploaded_practice_test_generator = UploadedPracticeTestAction() for coach in coaches: students = self._get_students(coach.coach) if date_utils.utc_now().weekday() == 0 or override is True: # Only run on Mondays missed_work_generator.create(coach.coach, students) no_meeting_generator.create(coach.coach, students) missed_two_days_generator.create(coach.coach, students) uploaded_practice_test_generator.create(coach.coach, students)
def _get_missed_session(self, student): now = date_utils.utc_now() study_days = StudyDay.objects.filter(user=student, day_type=StudyDay.STUDY, date__lt=now) study_days = study_days.order_by('-date') if len(study_days) > 1: last_study_session = study_days[0] two_study_sessions_ago = study_days[1] else: return (False, '') if last_study_session.missed: if two_study_sessions_ago.missed: return (True, two_study_sessions_ago.date) return (False, two_study_sessions_ago.date)
def _create_next_action(self, coach, student, action_type, **kwargs): """Creates a NextAction object for the given coach, student, and action_type. Note: in order to avoid repeated actions we will never create the same type of action for the given coach/student pair within 24 hours of each other. """ one_day_ago = date_utils.utc_now() - datetime.timedelta(days=1) recent_actions = NextActions.objects.filter( coach=coach, student=student, action_type=action_type, created_on__gt=one_day_ago) if recent_actions.exists(): return next_action = NextActions.objects.create( coach=coach, student=student, action_type=action_type) next_action.action_details = kwargs next_action.save()