Пример #1
0
    def get(self):
        """Return the list of PGY.

        """
        self.response.cache_control = 'public'
        self.response.cache_control.max_age = 300
        self.render_json({
            "type": "topics",
            "topics": [{
                "id": topic,
                "label": topic.title()
            } for topic in RoshReviewUserStats.get_topics()]
        })
Пример #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 get(self):
        """List student stats.

        """
        self.staff_required()
        cursor_key = self.request.GET.get('cursor')
        topic = self.request.GET.get('topic')
        sort_by = self.request.GET.get('sortBy')
        if topic == 'all':
            topic = None

        sort_by_options = {
            'performance': 'performance',
            'percentageComplete': 'percentage_complete'
        }
        sort_by = sort_by_options.get(sort_by)

        try:
            limit = int(self.request.GET.get('limit'))
        except (ValueError, TypeError,):
            limit = None

        try:
            residents = self.request.GET.get('residents')
            if residents == 'all':
                residents = None
            else:
                residents = int(residents)
        except (ValueError, TypeError,):
            residents = None

        stats, cursor = RoshReviewUserStats.get_stats(
            cursor_key=cursor_key,
            limit=limit,
            year=residents,
            topic=topic,
            sort_by=sort_by
        )
        self.render_json({
            'stats': [s.summary() for s in stats],
            'cursor': cursor if cursor else ''
        })
Пример #4
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))
Пример #5
0
    def get(self, studentId):
        """Get the detailed stats for a student.

        """
        student_id = studentId.upper()
        current_user = self.login_required()
        if current_user.student_id != student_id:
            self.staff_required()

        stats = RoshReviewUserStats.get_by_id(student_id)
        if stats is None:
            self.abort(404)
        details = stats.details()
        today = datetime.date.today()

        details['history'] = [
            {
                'performance': 0,
                'date': (today - datetime.timedelta(days=i)).isoformat()
            } for i in reversed(range(183))
        ]
        self.render_json(details)
Пример #6
0
 def __init__(self, *args, **kw):
     super(FakeStudents, self).__init__(*args, **kw)
     self.rosh_review_topics = RoshReviewUserStats.get_topics()
     self.firstaid_topics = FirstAidUserStats.get_topics().map(
         lambda k: k.id(), keys_only=True
     )