示例#1
0
def load_canvas_externals(uid):
    from boac.externals import canvas

    success_count = 0
    failures = []

    canvas_user_profile = canvas.get_user_for_uid(uid)
    if canvas_user_profile is None:
        failures.append('canvas.get_user_for_uid failed for UID {}'.format(
            uid, ))
    elif canvas_user_profile:
        success_count += 1
        sites = canvas.get_student_courses_in_term(uid)
        if sites:
            success_count += 1
            for site in sites:
                site_id = site['id']
                if not canvas.get_course_sections(site_id):
                    failures.append(
                        'canvas.get_course_sections failed for UID {}, site_id {}'
                        .format(
                            uid,
                            site_id,
                        ))
                    continue
                success_count += 1
                if not canvas.get_student_summaries(site_id):
                    failures.append(
                        'canvas.get_student_summaries failed for site_id {}'.
                        format(site_id, ))
                    continue
                success_count += 1
    return success_count, failures
示例#2
0
def user_analytics(uid):
    canvas_profile = canvas.get_user_for_uid(uid)
    if canvas_profile is False:
        raise errors.ResourceNotFoundError('No Canvas profile found for user')
    elif not canvas_profile:
        raise errors.InternalServerError('Unable to reach bCourses')
    canvas_id = canvas_profile['id']

    user_courses = canvas.get_student_courses_in_term(uid)
    courses_api_feed = api_util.canvas_courses_api_feed(user_courses)

    cohort_data = TeamMember.query.filter_by(member_uid=uid).first()
    if cohort_data and len(user_courses):
        term_id = sis_term_id_for_name(user_courses[0].get('term',
                                                           {}).get('name'))
        merge_sis_enrollments(courses_api_feed, cohort_data.member_csid,
                              term_id)

    merge_analytics_for_user(courses_api_feed, canvas_id)

    if cohort_data:
        sis_profile = merge_sis_profile(cohort_data.member_csid)
        cohort_data = cohort_data.to_api_json()
    else:
        sis_profile = False

    return tolerant_jsonify({
        'uid': uid,
        'canvasProfile': canvas_profile,
        'cohortData': cohort_data,
        'courses': courses_api_feed,
        'sisProfile': sis_profile,
    })
示例#3
0
def load_canvas_profile(uid):
    canvas_profile = False
    canvas_response = canvas.get_user_for_uid(uid)
    if canvas_response:
        canvas_profile = canvas_response
    elif canvas_response is None:
        canvas_profile = {
            'error': 'Unable to reach bCourses',
        }
    return canvas_profile
示例#4
0
def load_member_profiles(team):
    for member in team['members']:
        uid = member['uid']
        cache_key = 'user/{uid}'.format(uid=uid)
        canvas_profile = app.cache.get(cache_key) if app.cache else None
        if not canvas_profile:
            canvas_profile = canvas.get_user_for_uid(uid)
            # Cache Canvas profiles
            if app.cache and canvas_profile:
                app.cache.set(cache_key, canvas_profile)

        if canvas_profile:
            member['avatar_url'] = canvas_profile['avatar_url']
            canvas_courses = canvas_courses_api_feed(
                canvas.get_student_courses_in_term(uid))
            if canvas_courses:
                member['analytics'] = mean_course_analytics_for_user(
                    canvas_courses, canvas_profile['id'])
示例#5
0
def main(app):
    from boac.externals import canvas
    for uid in range(1, 20):
        canvas.get_user_for_uid(uid)