コード例 #1
0
    def test_get_historical_student_profiles(self):
        """Returns profiles of non-current students after adding them to manually_added_advisees."""
        ManuallyAddedAdvisee.query.delete()
        assert len(ManuallyAddedAdvisee.get_all()) == 0

        profiles = student.get_historical_student_profiles(
            ['2718281828', '3141592653'])
        assert len(profiles) == 2
        assert len(ManuallyAddedAdvisee.get_all()) == 2
コード例 #2
0
def get_historical_student_profiles(sids):
    historical_profile_rows = data_loch.get_historical_student_profiles_for_sids(sids)
    historical_profiles = [_historicize_profile(row) for row in historical_profile_rows]
    # We don't expect photo information to show for historical profiles, but we still need a placeholder element
    # in the feed so the front end can show the proper fallback.
    _merge_photo_urls(historical_profiles)
    for historical_profile in historical_profiles:
        ManuallyAddedAdvisee.find_or_create(historical_profile['sid'])
    return historical_profiles
コード例 #3
0
ファイル: student.py プロジェクト: raydavis/boac
def search_for_student_historical(sid):
    profile = _construct_historical_student_profile(sid=sid)
    if profile:
        ManuallyAddedAdvisee.find_or_create(sid)
        summarize_profile(profile)
        return {
            'students': [profile],
            'totalStudentCount': 1,
        }
    else:
        return {
            'students': [],
            'totalStudentCount': 0,
        }
コード例 #4
0
ファイル: student.py プロジェクト: raydavis/boac
def get_summary_student_profiles(sids, include_historical=False, term_id=None):
    if not sids:
        return []
    benchmark = get_benchmarker('get_summary_student_profiles')
    benchmark('begin')
    # TODO It's probably more efficient to store summary profiles in the loch, rather than distilling them
    # on the fly from full profiles.
    profiles = get_full_student_profiles(sids)
    # TODO Many views require no term enrollment information other than a units count. This datum too should be
    # stored in the loch without BOAC having to crunch it.
    if not term_id:
        term_id = current_term_id()
    benchmark('begin enrollments query')
    enrollments_for_term = data_loch.get_enrollments_for_term(term_id, sids)
    benchmark('end enrollments query')
    enrollments_by_sid = {row['sid']: json.loads(row['enrollment_term']) for row in enrollments_for_term}
    benchmark('begin term GPA query')
    term_gpas = get_term_gpas_by_sid(sids)
    benchmark('end term GPA query')

    remaining_sids = list(set(sids) - set([p.get('sid') for p in profiles]))
    if len(remaining_sids) and include_historical:
        benchmark('begin historical profile supplement')
        historical_profile_rows = data_loch.get_historical_student_profiles_for_sids(remaining_sids)

        def _historicize_profile(row):
            return {
                **json.loads(row['profile']),
                **{
                    'fullProfilePending': True,
                },
            }
        historical_profiles = [_historicize_profile(row) for row in historical_profile_rows]
        # We don't expect photo information to show for historical profiles, but we still need a placeholder element
        # in the feed so the front end can show the proper fallback.
        _merge_photo_urls(historical_profiles)
        for historical_profile in historical_profiles:
            ManuallyAddedAdvisee.find_or_create(historical_profile['sid'])
        profiles += historical_profiles
        historical_enrollments_for_term = data_loch.get_historical_enrollments_for_term(term_id, remaining_sids)
        for row in historical_enrollments_for_term:
            enrollments_by_sid[row['sid']] = json.loads(row['enrollment_term'])
        benchmark('end historical profile supplement')

    benchmark('begin profile transformation')
    for profile in profiles:
        summarize_profile(profile, enrollments=enrollments_by_sid, term_gpas=term_gpas)
    benchmark('end')

    return profiles
コード例 #5
0
ファイル: curated_group.py プロジェクト: raydavis/boac
 def to_api_json(self,
                 order_by='last_name',
                 offset=0,
                 limit=50,
                 include_students=True):
     feed = {
         'id': self.id,
         'ownerId': self.owner_id,
         'name': self.name,
     }
     if include_students:
         sids = CuratedGroupStudent.get_sids(curated_group_id=self.id)
         if sids:
             result = query_students(sids=sids,
                                     order_by=order_by,
                                     offset=offset,
                                     limit=limit,
                                     include_profiles=False)
             feed['students'] = result['students']
             feed['totalStudentCount'] = result['totalStudentCount']
             # Attempt to supplement with historical student rows if we seem to be missing something.
             if result['totalStudentCount'] < len(sids):
                 remaining_sids = list(set(sids) - set(result['sids']))
                 historical_sid_rows = query_historical_sids(remaining_sids)
                 if len(historical_sid_rows):
                     for row in historical_sid_rows:
                         ManuallyAddedAdvisee.find_or_create(row['sid'])
                     feed['totalStudentCount'] += len(historical_sid_rows)
                     page_shortfall = max(0,
                                          limit - len(result['students']))
                     feed[
                         'students'] += historical_sid_rows[:page_shortfall]
         else:
             feed['students'] = []
             feed['totalStudentCount'] = 0
     return feed
コード例 #6
0
def get_manually_added_advisees():
    advisees = ManuallyAddedAdvisee.get_all()
    return tolerant_jsonify([{'sid': advisee.sid} for advisee in advisees])
コード例 #7
0
def mock_manually_added_advisee():
    return ManuallyAddedAdvisee.find_or_create(sid=advisee_sid)