Exemplo n.º 1
0
def merged_profile(sid, profile_rows, degree_progress_rows, last_registration_rows, intended_majors=None):
    profile_feed = next((r['feed'] for r in profile_rows if r['sid'] == sid), None)
    progress_feed = next((r['feed'] for r in degree_progress_rows if r['sid'] == sid), None)
    last_registration_feed = next((r['feed'] for r in last_registration_rows if r['sid'] == sid), None)
    return parse_merged_sis_profile({
        'sis_profile_feed': profile_feed,
        'degree_progress_feed': progress_feed,
        'last_registration_feed': last_registration_feed,
        'intended_majors': intended_majors,
    })
Exemplo n.º 2
0
    def collect_merged_profiles(self, sids, feed_file, index_file, names_file):
        successes = []
        sis_profile_feeds = queries.get_non_advisee_api_feeds(sids)
        for row in sis_profile_feeds:
            sid = row['sid']
            uid = row['uid']
            sis_api_feed = row['sis_feed']
            sis_profile = parse_merged_sis_profile({
                'sis_profile_feed':
                sis_api_feed,
                'last_registration_feed':
                row['last_registration_feed'],
            })
            merged_profile = {
                'sid': sid,
                'uid': uid,
                'sisProfile': sis_profile,
            }
            self.fill_names_from_sis_profile(sis_api_feed, merged_profile)
            feed_file.write(
                encoded_tsv_row([sid, uid,
                                 json.dumps(merged_profile)]) + b'\n')

            first_name = merged_profile.get('firstName', '')
            last_name = merged_profile.get('lastName', '')
            level = str(sis_profile.get('level', {}).get('code') or '')
            gpa = str(sis_profile.get('cumulativeGPA') or '')
            units = str(sis_profile.get('cumulativeUnits') or '')
            transfer = str(sis_profile.get('transfer') or False)
            expected_grad_term = str(
                sis_profile.get('expectedGraduationTerm', {}).get('id') or '')
            terms_in_attendance = str(
                sis_profile.get('termsInAttendance', {}) or '')
            index_file.write(
                encoded_tsv_row([
                    sid, uid, first_name, last_name, level, gpa, units,
                    transfer, expected_grad_term, terms_in_attendance
                ]) + b'\n', )

            names_file.write(
                encoded_tsv_row([
                    sid,
                    merged_profile.get('uid'),
                    merged_profile.get('firstName'),
                    merged_profile.get('lastName'),
                ]) + b'\n', )
            successes.append(sid)
        return len(successes)
Exemplo n.º 3
0
    def generate_student_profile_feed(self, feed_elements, advisors,
                                      feed_files, feed_counts):
        sid = feed_elements['sid']
        uid = feed_elements['ldap_uid']
        if not uid:
            return
        sis_profile = parse_merged_sis_profile(feed_elements)
        demographics = feed_elements.get('demographics_feed') and json.loads(
            feed_elements.get('demographics_feed'))
        if demographics:
            demographics = add_demographics_rows(sid, demographics, feed_files,
                                                 feed_counts)

        advisor_feed = []
        for a in advisors:
            advisor_feed.append({
                'uid':
                a['advisor_uid'],
                'sid':
                a['advisor_sid'],
                'firstName':
                a['advisor_first_name'],
                'lastName':
                a['advisor_last_name'],
                'email': (a['advisor_campus_email'] or a['advisor_email']),
                'role':
                a['advisor_role'],
                'title':
                a['advisor_title'],
                'program':
                a['program'],
                'plan':
                a['plan'],
            })

        merged_profile = {
            'sid':
            sid,
            'uid':
            uid,
            'firstName':
            feed_elements.get('first_name'),
            'lastName':
            feed_elements.get('last_name'),
            'name':
            ' '.join([
                feed_elements.get('first_name'),
                feed_elements.get('last_name')
            ]),
            'canvasUserId':
            feed_elements.get('canvas_user_id'),
            'canvasUserName':
            feed_elements.get('canvas_user_name'),
            'sisProfile':
            sis_profile,
            'demographics':
            demographics,
            'advisors':
            advisor_feed,
        }
        feed_counts['student_profiles'] += write_to_tsv_file(
            feed_files['student_profiles'],
            [sid, json.dumps(merged_profile)])

        if sis_profile:
            first_name = merged_profile['firstName'] or ''
            last_name = merged_profile['lastName'] or ''
            level = str(sis_profile.get('level', {}).get('code') or '')
            gpa = str(sis_profile.get('cumulativeGPA') or '')
            units = str(sis_profile.get('cumulativeUnits') or '')
            transfer = str(sis_profile.get('transfer') or False)
            expected_grad_term = str(
                sis_profile.get('expectedGraduationTerm', {}).get('id') or '')
            terms_in_attendance = str(
                sis_profile.get('termsInAttendance', {}) or '')

            feed_counts['student_profile_index'] += write_to_tsv_file(
                feed_files['student_profile_index'],
                [
                    sid, uid, first_name, last_name, level, gpa, units,
                    transfer, expected_grad_term, terms_in_attendance
                ],
            )

            for plan in sis_profile.get('plans', []):
                if plan.get('status') == 'Active':
                    feed_counts['student_majors'] += write_to_tsv_file(
                        feed_files['student_majors'],
                        [
                            sid,
                            plan.get('program', None),
                            plan.get('description', None)
                        ],
                    )
            for hold in sis_profile.get('holds', []):
                feed_counts['student_holds'] += write_to_tsv_file(
                    feed_files['student_holds'], [sid, json.dumps(hold)])
            for intended_major in sis_profile.get('intendedMajors', []):
                feed_counts['intended_majors'] += write_to_tsv_file(
                    feed_files['intended_majors'],
                    [sid, intended_major.get('description', None)])
            for plan in sis_profile.get('plansMinor', []):
                if plan.get('status') == 'Active':
                    feed_counts['minors'] += write_to_tsv_file(
                        feed_files['minors'],
                        [sid, plan.get('description', None)])

        return merged_profile