def from_data(cls, data, commit=True): student_id = User.email_to_student_id(data['email']) topic_id = data['category_id'] date = cls.cal_day_to_date(data['cal_day_dt']) return cls.new_activity( student_id, topic_id, date, data, commit=commit )
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))
def from_data(cls, data, commit=True): student_id = User.email_to_student_id(data['email']) topic_id = data['category_id'] date = cls.cal_day_to_date(data['cal_day_dt']) return cls.new_activity(student_id, topic_id, date, data, commit=commit)
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))