Пример #1
0
def stats_handler(data):
    pos, line = data

    if not line:
        raise StopIteration
    try:
        stats = json.loads(line)
    except (ValueError, TypeError):
        logging.error("Failed to process rosh review stats: %s", line)
        raise StopIteration

    student_email = stats.get('email', '').lower()
    student_id = User.email_to_student_id(student_email)
    if student_id is None:
        logging.error(
            "Failed to process rosh review stats: invalid student email (%s)",
            line)
        raise StopIteration

    student = Student.get_by_id(student_id)
    if student is None:
        logging.error(
            "Failed to process rosh review stats: student not found (%s)",
            line)
        raise StopIteration

    user_stats = RoshReviewUserStats.new_stats(student, stats, commit=False)
    user_topic_stats = user_stats.update_topic_stats(commit=False)

    yield op.db.Put(user_stats)
    for ts in user_topic_stats:
        yield op.db.Put(ts)

    yield op.counters.Increment('User stats', 1)
    yield op.counters.Increment('User topic stats', len(user_topic_stats))
Пример #2
0
 def add_roshreview_stats(self, student):
     perfs = {
         k: random.randint(40, 100) for k in self.random_rosh_review_topics
     }
     average = sum(perfs.itervalues()) / len(perfs)
     data = {
         "email": student.secondary_email,
         "training_level": "Student",
         "pgy": None,
         "category_performances": perfs,
         "cumulative_performance": average,
         "percentage_complete": random.randint(10, 100),
     }
     stats = RoshReviewUserStats.new_stats(student, data, commit=False)
     stats.put_async()
     t_stats = stats.update_topic_stats(commit=False)
     ndb.put_multi_async(t_stats)
Пример #3
0
def stats_handler(data):
    pos, line = data

    if not line:
        raise StopIteration
    try:
        stats = json.loads(line)
    except (ValueError, TypeError):
        logging.error("Failed to process rosh review stats: %s", line)
        raise StopIteration

    student_email = stats.get('email', '').lower()
    student_id = User.email_to_student_id(student_email)
    if student_id is None:
        logging.error(
            "Failed to process rosh review stats: invalid student email (%s)",
            line
        )
        raise StopIteration

    student = Student.get_by_id(student_id)
    if student is None:
        logging.error(
            "Failed to process rosh review stats: student not found (%s)",
            line
        )
        raise StopIteration

    user_stats = RoshReviewUserStats.new_stats(
        student, stats, commit=False
    )
    user_topic_stats = user_stats.update_topic_stats(commit=False)

    yield op.db.Put(user_stats)
    for ts in user_topic_stats:
        yield op.db.Put(ts)

    yield op.counters.Increment('User stats', 1)
    yield op.counters.Increment('User topic stats', len(user_topic_stats))