Esempio n. 1
0
 def test_new_activity_with_different_topic(self):
     sess1 = self.session(datetime.date(2014, 9, 7), 1, 'A0001', '13')
     sess2 = self.session(datetime.date(2014, 9, 7), 1, 'A0001', '14')
     self.assertNotEqual(
         FirstAidActivity.from_data(sess1).key.id(),
         FirstAidActivity.from_data(sess2).key.id()
     )
Esempio n. 2
0
    def test_create(self):
        sess1 = self.session(datetime.date(2014, 9, 7), 1, 'A0001', '13')
        sess2 = self.session(datetime.date(2014, 9, 2), 1, 'A0001', '13')
        sess3 = self.session(datetime.date(2014, 9, 2), 1, 'A0001', '14')
        for s in (
                sess1,
                sess2,
                sess3,
        ):
            FirstAidActivity.from_data(s).key.get(use_cache=False)

        stats = list(FirstAidUserStats.new_user_stats(self.student))
        self.assertEqual(3, len(stats))
        topic_stats = {s.topic_id: s for s in stats[:-1]}

        self.assertIn('13', topic_stats)
        self.assertEqual(6, topic_stats['13'].question_taken)
        self.assertEqual(33, topic_stats['13'].performance)

        self.assertIn('14', topic_stats)
        self.assertEqual(3, topic_stats['14'].question_taken)
        self.assertEqual(33, topic_stats['14'].performance)

        user_stats = stats[-1]
        self.assertEqual(9, user_stats.question_taken)
        self.assertEqual(33, user_stats.performance)

        ndb.put_multi(stats)
Esempio n. 3
0
 def add_firstaid_session_stats(self, student):
     for topic_id in self.random_firstaid_topics:
         questions = random.randint(3, 20)
         correct = random.randint(0, questions)
         incorrect = random.randint(0, questions - correct)
         taken_test = random.randint(1, questions)
         str_date = '07-Nov-00'
         data = {
             'email': student.secondary_email,
             'category_id': str(topic_id),
             'cal_day_dt': str(str_date),
             'user_test_taken': str(taken_test),
             'user_questions': str(questions),
             'user_answered_correct': str(correct),
             'user_answered_incorrect': str(incorrect),
             'user_not_answered': str(questions - correct - incorrect),
             'user_predictive': str(random.randint(-310, 310)),
         }
         yield FirstAidActivity.new_activity(
             student.key.id(),
             topic_id,
             FirstAidActivity.cal_day_to_date(str_date),
             data,
             commit=False
         )
Esempio n. 4
0
 def test_new_activity_same_session(self):
     sess1 = self.session(datetime.date(2014, 9, 7), 1, 'A0001', '13')
     sess2 = self.session(datetime.date(2014, 9, 7), 1, 'A0001', '13')
     self.assertEqual(
         FirstAidActivity.from_data(sess1).key.id(),
         FirstAidActivity.from_data(sess2).key.id()
     )
Esempio n. 5
0
    def test_new_activity_from_data(self):
        day = datetime.date(2014, 9, 7)
        session = self.session(day, 1, 'A0001', '13')
        self.assertEqual('07-Sep-14', session['cal_day_dt'])

        activity = FirstAidActivity.from_data(session)
        self.assertEqual('A0001', activity.student_id)
        self.assertEqual('13', activity.topic_id)
        self.assertEqual(day, activity.day.date())
Esempio n. 6
0
    def test_new_activity_from_data(self):
        day = datetime.date(2014, 9, 7)
        session = self.session(day, 1, 'A0001', '13')
        self.assertEqual('07-Sep-14', session['cal_day_dt'])

        activity = FirstAidActivity.from_data(session)
        self.assertEqual('A0001', activity.student_id)
        self.assertEqual('13', activity.topic_id)
        self.assertEqual(day, activity.day.date())
Esempio n. 7
0
    def test_create(self):
        sess1 = self.session(datetime.date(2014, 9, 7), 1, 'A0001', '13')
        sess2 = self.session(datetime.date(2014, 9, 2), 1, 'A0001', '13')
        sess3 = self.session(datetime.date(2014, 9, 2), 1, 'A0001', '14')
        for s in (sess1, sess2, sess3,):
            FirstAidActivity.from_data(s).key.get(use_cache=False)

        stats = list(FirstAidUserStats.new_user_stats(self.student))
        self.assertEqual(3, len(stats))
        topic_stats = {s.topic_id: s for s in stats[:-1]}

        self.assertIn('13', topic_stats)
        self.assertEqual(6, topic_stats['13'].question_taken)
        self.assertEqual(33, topic_stats['13'].performance)

        self.assertIn('14', topic_stats)
        self.assertEqual(3, topic_stats['14'].question_taken)
        self.assertEqual(33, topic_stats['14'].performance)

        user_stats = stats[-1]
        self.assertEqual(9, user_stats.question_taken)
        self.assertEqual(33, user_stats.performance)

        ndb.put_multi(stats)
Esempio n. 8
0
def query_handler(data):
    _, url = data
    try:
        session_user_topic_stats = FirstAidApiClient().fetch(url)
    except ServiceRequestError:
        raise FailJobError()
    except ServiceResponseError:
        raise RetrySliceError()

    for session_data in session_user_topic_stats:
        try:
            education.api.validate('FirstAidSessionRowData', session_data)
        except ValidationError:
            logging.error('Invalid session stats: %s', session_data)
            continue
        yield op.db.Put(FirstAidActivity.from_data(session_data, commit=False))
        yield op.counters.Increment('Session stats', 1)
Esempio n. 9
0
def query_handler(data):
    _, url = data
    try:
        session_user_topic_stats = FirstAidApiClient().fetch(url)
    except ServiceRequestError:
        raise FailJobError()
    except ServiceResponseError:
        raise RetrySliceError()

    for session_data in session_user_topic_stats:
        try:
            education.api.validate('FirstAidSessionRowData', session_data)
        except ValidationError:
            logging.error('Invalid session stats: %s', session_data)
            continue
        yield op.db.Put(
            FirstAidActivity.from_data(session_data, commit=False)
        )
        yield op.counters.Increment('Session stats', 1)
Esempio n. 10
0
 def test_new_activity_with_different_topic(self):
     sess1 = self.session(datetime.date(2014, 9, 7), 1, 'A0001', '13')
     sess2 = self.session(datetime.date(2014, 9, 7), 1, 'A0001', '14')
     self.assertNotEqual(
         FirstAidActivity.from_data(sess1).key.id(),
         FirstAidActivity.from_data(sess2).key.id())
Esempio n. 11
0
 def test_new_activity_same_session(self):
     sess1 = self.session(datetime.date(2014, 9, 7), 1, 'A0001', '13')
     sess2 = self.session(datetime.date(2014, 9, 7), 1, 'A0001', '13')
     self.assertEqual(
         FirstAidActivity.from_data(sess1).key.id(),
         FirstAidActivity.from_data(sess2).key.id())