def __arrange_results(results, subjects_map, custom_metadata_map):
    '''
    This method arranges the data retrieved from the db to make it easier to consume by the client
    '''
    new_results = []
    for result in results:

        result['student_full_name'] = format_full_name(result['first_name'],
                                                       result['middle_name'],
                                                       result['last_name'])
        # asmt_type is an enum, so we would to capitalize it to make it presentable
        result['asmt_type'] = capwords(result['asmt_type'], ' ')
        result['asmt_score_interval'] = get_overall_asmt_interval(result)

        # custom metadata
        subject_name = subjects_map[result["asmt_subject"]]
        custom = custom_metadata_map.get(subject_name)
        # format and rearrange cutpoints
        result = get_cut_points(custom, result)

        result['claims'] = get_claims(number_of_claims=5,
                                      result=result,
                                      include_names=True,
                                      include_scores=True,
                                      include_min_max_scores=True,
                                      include_indexer=True)
        result['accommodations'] = get_accommodations(result=result)

        new_results.append(result)

    # rearranging the json so we could use it more easily with mustache
    for idx, value in enumerate(new_results):
        new_results[idx] = __calculateClaimScoreRelativeDifference(value)
    return {"all_results": new_results}
 def test_get_claims_for_names_only(self):
     result = {'asmt_cut_point_name_1': 'one',
               'asmt_claim_1_score_range_min': 1,
               'asmt_claim_1_score_range_max': 4,
               'asmt_claim_1_score_min': 2,
               'asmt_claim_1_score_max': 5,
               'asmt_score_max': 500,
               'asmt_claim_1_score': 2,
               'asmt_claim_1_name': 'name',
               'asmt_subject': 'ELA',
               'asmt_cut_point_name_2': 'two',
               'asmt_claim_2_score_range_min': 1,
               'asmt_claim_2_score_range_max': 4,
               'asmt_claim_2_score_min': 2,
               'asmt_claim_2_score_max': 5,
               'asmt_score_max': 500,
               'asmt_claim_2_score': 2,
               'asmt_claim_2_name': 'Two',
               'asmt_type': 'SUMMATIVE'}
     claims = get_claims(number_of_claims=2, result=result, include_names=True)
     self.assertEqual(len(result), 5)
     self.assertTrue(len(claims), 2)
     self.assertEqual(claims[1]['name2'], '{{labels.claim}} 2')
     self.assertEqual(len(claims[0]), 4)
     self.assertEqual(len(claims[1]), 4)
 def test_get_claims_for_scores_only(self):
     result = {'asmt_cut_point_name_1': 'one',
               'asmt_claim_1_score_range_min': 1,
               'asmt_claim_1_score_range_max': 4,
               'asmt_claim_1_score_min': 2,
               'asmt_claim_1_score_max': 5,
               'asmt_claim_1_perf_lvl': 3,
               'asmt_score_max': 500,
               'asmt_claim_1_score': 2,
               'asmt_claim_1_name': 'name',
               'asmt_claim_perf_lvl_name_3': 'Above Standard',
               'asmt_subject': 'ELA',
               'asmt_cut_point_name_2': 'two',
               'asmt_claim_2_score_range_min': 1,
               'asmt_claim_2_score_range_max': 4,
               'asmt_claim_2_score_min': 2,
               'asmt_claim_2_score_max': 5,
               'asmt_score_max': 500,
               'asmt_claim_2_score': 2,
               'asmt_claim_2_name': 'Two',
               'asmt_type': 'SUMMATIVE'}
     claims = get_claims(number_of_claims=2, result=result, include_scores=True)
     self.assertEqual(len(claims), 2)
     self.assertEqual(len(claims[0]), 6)
     self.assertEqual(claims[0]['score'], '2')
     self.assertEqual(claims[0]['perf_lvl'], '3')
     self.assertEqual(claims[0]['perf_lvl_name'], 'Above Standard')
示例#4
0
def __arrange_results_iab(results, subjects_map, custom_metadata_map):
    '''
    This method arranges the data retrieved from the db to make it easier to consume by the client
    '''
    iab_results = {}
    if len(results) is 0:
        return iab_results
    first_result = results[0]
    iab_results['student_full_name'] = format_full_name(first_result['first_name'], first_result['middle_name'], first_result['last_name'])
    iab_results['first_name'] = first_result.get('first_name')
    iab_results['middle_name'] = first_result.get('middle_name')
    iab_results['last_name'] = first_result.get('last_name')
    iab_results['asmt_grade'] = first_result.get('asmt_grade')
    iab_results['asmt_type'] = capwords(first_result.get('asmt_type'), ' ')
    iab_results['asmt_period_year'] = first_result.get('asmt_period_year')
    iab_results['student_id'] = first_result.get('student_id')

    # Go through each of the different subjects ELA, Math etc.
    subject_data = {}
    for alias in subjects_map.values():
        subject_data[alias] = []
    # Check each DB result against the subject
    for result in results:
        subject_list = {}
        subject = result['asmt_subject']
        subject_list['claims'] = get_claims(number_of_claims=1, result=result, include_names=True, include_scores=False, include_min_max_scores=False, include_indexer=False, include_complete_admin_cond=True)
        subject_list['grade'] = result.get('asmt_grade')
        subject_list['date_taken'] = result.get('date_taken')
        subject_data[subjects_map.get(subject)].append(subject_list)
    # Create map from subject to all value for it's type
    for k, v in subject_data.items():
        iab_results[k] = v
    return {"all_results": iab_results}
示例#5
0
def __arrange_results(results, subjects_map, custom_metadata_map):
    '''
    This method arranges the data retrieved from the db to make it easier to consume by the client
    '''
    new_results = []
    for result in results:

        result['student_full_name'] = format_full_name(result['first_name'], result['middle_name'], result['last_name'])
        # asmt_type is an enum, so we would to capitalize it to make it presentable
        result['asmt_type'] = capwords(result['asmt_type'], ' ')
        result['asmt_score_interval'] = get_overall_asmt_interval(result)

        # custom metadata
        subject_name = subjects_map[result["asmt_subject"]]
        custom = custom_metadata_map.get(subject_name)
        # format and rearrange cutpoints
        result = get_cut_points(custom, result)

        result['claims'] = get_claims(number_of_claims=5, result=result, include_names=True, include_scores=True, include_min_max_scores=True, include_indexer=True)
        result['accommodations'] = get_accommodations(result=result)

        new_results.append(result)

    # rearranging the json so we could use it more easily with mustache
    for idx, value in enumerate(new_results):
        new_results[idx] = __calculateClaimScoreRelativeDifference(value)
    return {"all_results": new_results}
def format_assessments_fao(results, subjects_map):
    '''
    Format student assessments.
    '''

    assessments = {}
    # Formatting data for Front End
    for result in results:
        dateTaken = result['date_taken']  # e.g. 20140401
        asmtType = capwords(result['asmt_type'], ' ')  # Summative, Interim
        asmtDict = assessments.get(asmtType, {})
        studentDataByDate = {}
        studentId = result['student_id']  # e.g. student_1
        asmtList = asmtDict.get(studentId, [])

        student = {}
        student['student_id'] = studentId
        student['student_first_name'] = result['first_name']
        student['student_middle_name'] = result['middle_name']
        student['student_last_name'] = result['last_name']
        student['enrollment_grade'] = result['enrollment_grade']
        student['state_code'] = result['state_code']
        student['demographic'] = get_student_demographic(result)
        student[Constants.ROWID] = result['student_id']

        subject = subjects_map[result['asmt_subject']]
        assessment = student.get(subject, {})
        assessment['group'] = []  # for student group filter
        for i in range(1, 11):
            if result['group_{count}_id'.format(count=i)] is not None:
                assessment['group'].append(
                    result['group_{count}_id'.format(count=i)])
        assessment['asmt_grade'] = result['asmt_grade']
        assessment['asmt_perf_lvl'] = result['asmt_perf_lvl']
        assessment['asmt_score'] = result['asmt_score']
        assessment['asmt_score_range_min'] = result['asmt_score_range_min']
        assessment['asmt_score_range_max'] = result['asmt_score_range_max']
        assessment['asmt_score_interval'] = get_overall_asmt_interval(result)
        assessment['claims'] = get_claims(number_of_claims=4,
                                          result=result,
                                          include_scores=True,
                                          include_names=False)
        assessment['administration_condition'] = result[
            'administration_condition']
        assessment['complete'] = result['complete']

        student[subject] = assessment
        studentDataByDate[dateTaken] = student
        asmtList.append(studentDataByDate)
        asmtDict[studentId] = asmtList
        assessments[asmtType] = asmtDict
    return assessments
示例#7
0
def format_assessments_iab(results, subjects_map):
    '''
    Format student assessments.
    '''

    assessments = {}
    # Formatting data for Front End
    for result in results:
        date_taken = result['date_taken']  # e.g. 20140401
        studentId = result['student_id']  # e.g. student_1
        student = assessments.get(studentId, {})
        if not student:
            student['student_id'] = studentId
            student['student_first_name'] = result['first_name']
            student['student_middle_name'] = result['middle_name']
            student['student_last_name'] = result['last_name']
            student['enrollment_grade'] = result['enrollment_grade']
            student['state_code'] = result['state_code']
            student['demographic'] = get_student_demographic(result)
            student[Constants.ROWID] = result['student_id']
            student['group'] = set()  # for student group filter

        for i in range(1, 11):
            if result.get('group_{count}_id'.format(count=i)) is not None:
                student['group'].add(result['group_{count}_id'.format(count=i)])

        assessment = {Constants.DATE_TAKEN: date_taken}
        assessment['asmt_grade'] = result['asmt_grade']
        assessment['administration_condition'] = result['administration_condition']
        assessment['complete'] = result['complete']
        claims = assessment.get('claims', [])
        claim = get_claims(number_of_claims=1, result=result, include_scores=False, include_names=True)[0]
        claims.append(claim)
        assessment['claims'] = claims
        claim_name = claims[0]['name']

        subject = subjects_map[result['asmt_subject']]
        claim_dict = student.get(subject, {})
        date_taken_data = claim_dict.get(claim_name, [])

        date_taken_data.append(assessment)
        claim_dict[claim_name] = date_taken_data
        student[subject] = claim_dict
        assessments[studentId] = student

    for student in assessments.values():
        student['group'] = list(student['group'])

    return {AssessmentType.INTERIM_ASSESSMENT_BLOCKS: assessments}
 def test_get_claims_with_one_claim(self):
     result = {'asmt_cut_point_name_1': 'one',
               'asmt_claim_1_score_range_min': 1,
               'asmt_claim_1_score_range_max': 4,
               'asmt_claim_1_score_min': 2,
               'asmt_claim_1_score_max': 5,
               'asmt_score_max': 500,
               'asmt_claim_1_score': 2,
               'asmt_claim_1_name': 'name',
               'asmt_subject': 'ELA',
               'asmt_type': 'SUMMATIVE'}
     claims = get_claims(number_of_claims=1, result=result, include_scores=True, include_names=True)
     self.assertEqual(len(result), 4)
     self.assertTrue(len(claims), 1)
     self.assertEqual(claims[0]['name2'], '{{labels.claim}} 1')
示例#9
0
def format_assessments_fao(results, subjects_map):
    '''
    Format student assessments.
    '''

    assessments = {}
    # Formatting data for Front End
    for result in results:
        dateTaken = result['date_taken']  # e.g. 20140401
        asmtType = capwords(result['asmt_type'], ' ')  # Summative, Interim
        asmtDict = assessments.get(asmtType, {})
        studentDataByDate = {}
        studentId = result['student_id']  # e.g. student_1
        asmtList = asmtDict.get(studentId, [])

        student = {}
        student['student_id'] = studentId
        student['student_first_name'] = result['first_name']
        student['student_middle_name'] = result['middle_name']
        student['student_last_name'] = result['last_name']
        student['enrollment_grade'] = result['enrollment_grade']
        student['state_code'] = result['state_code']
        student['demographic'] = get_student_demographic(result)
        student[Constants.ROWID] = result['student_id']

        subject = subjects_map[result['asmt_subject']]
        assessment = student.get(subject, {})
        assessment['group'] = []  # for student group filter
        for i in range(1, 11):
            if result['group_{count}_id'.format(count=i)] is not None:
                assessment['group'].append(result['group_{count}_id'.format(count=i)])
        assessment['asmt_grade'] = result['asmt_grade']
        assessment['asmt_perf_lvl'] = result['asmt_perf_lvl']
        assessment['asmt_score'] = result['asmt_score']
        assessment['asmt_score_range_min'] = result['asmt_score_range_min']
        assessment['asmt_score_range_max'] = result['asmt_score_range_max']
        assessment['asmt_score_interval'] = get_overall_asmt_interval(result)
        assessment['claims'] = get_claims(number_of_claims=4, result=result, include_scores=True, include_names=False)
        assessment['administration_condition'] = result['administration_condition']
        assessment['complete'] = result['complete']

        student[subject] = assessment
        studentDataByDate[dateTaken] = student
        asmtList.append(studentDataByDate)
        asmtDict[studentId] = asmtList
        assessments[asmtType] = asmtDict
    return assessments
示例#10
0
def __format_cut_points(results, subjects_map, custom_metadata_map):
    '''
    Returns formatted cutpoints in JSON
    '''
    cutpoints = {}
    claims = {}
    for result in results:
        subject_name = subjects_map[result["asmt_subject"]]
        custom = custom_metadata_map.get(subject_name)
        # Get formatted cutpoints data
        cutpoint = get_cut_points(custom, result)
        cutpoints[subject_name] = cutpoint
        # Get formatted claims data
        claims[subject_name] = get_claims(number_of_claims=4, result=result, include_names=True)
        # Remove unnecessary data
        del(cutpoint['asmt_subject'])
    return {'cutpoints': cutpoints, 'claims': claims, Constants.BRANDING: custom_metadata_map.get(Constants.BRANDING)}
 def test_get_claims_for_complete_admin_cond(self):
     result = {'asmt_cut_point_name_1': 'one',
               'asmt_claim_1_score_range_min': 1,
               'asmt_claim_1_score_range_max': 4,
               'asmt_claim_1_score_min': 2,
               'asmt_claim_1_score_max': 5,
               'asmt_score_max': 500,
               'asmt_claim_1_score': 2,
               'asmt_claim_1_name': 'name',
               'asmt_subject': 'ELA',
               'asmt_cut_point_name_2': 'two',
               'asmt_score_max': 500,
               'asmt_type': 'INTERIM',
               'complete': True,
               'administration_condition': 'SD'}
     claims = get_claims(number_of_claims=1, result=result, include_names=True, include_scores=False, include_min_max_scores=False, include_indexer=False, include_complete_admin_cond=True)
     self.assertTrue(claims[0]['complete'])
     self.assertEqual(claims[0]['administration_condition'], 'SD')
def __arrange_results_iab(results, subjects_map, custom_metadata_map):
    '''
    This method arranges the data retrieved from the db to make it easier to consume by the client
    '''
    iab_results = {}
    if len(results) is 0:
        return iab_results
    first_result = results[0]
    iab_results['student_full_name'] = format_full_name(
        first_result['first_name'], first_result['middle_name'],
        first_result['last_name'])
    iab_results['first_name'] = first_result.get('first_name')
    iab_results['middle_name'] = first_result.get('middle_name')
    iab_results['last_name'] = first_result.get('last_name')
    iab_results['asmt_grade'] = first_result.get('asmt_grade')
    iab_results['asmt_type'] = capwords(first_result.get('asmt_type'), ' ')
    iab_results['asmt_period_year'] = first_result.get('asmt_period_year')
    iab_results['student_id'] = first_result.get('student_id')

    # Go through each of the different subjects ELA, Math etc.
    subject_data = {}
    for alias in subjects_map.values():
        subject_data[alias] = []
    # Check each DB result against the subject
    for result in results:
        subject_list = {}
        subject = result['asmt_subject']
        subject_list['claims'] = get_claims(number_of_claims=1,
                                            result=result,
                                            include_names=True,
                                            include_scores=False,
                                            include_min_max_scores=False,
                                            include_indexer=False,
                                            include_complete_admin_cond=True)
        subject_list['grade'] = result.get('asmt_grade')
        subject_list['date_taken'] = result.get('date_taken')
        subject_data[subjects_map.get(subject)].append(subject_list)
    # Create map from subject to all value for it's type
    for k, v in subject_data.items():
        iab_results[k] = v
    return {"all_results": iab_results}
def __format_cut_points(results, subjects_map, custom_metadata_map):
    '''
    Returns formatted cutpoints in JSON
    '''
    cutpoints = {}
    claims = {}
    for result in results:
        subject_name = subjects_map[result["asmt_subject"]]
        custom = custom_metadata_map.get(subject_name)
        # Get formatted cutpoints data
        cutpoint = get_cut_points(custom, result)
        cutpoints[subject_name] = cutpoint
        # Get formatted claims data
        claims[subject_name] = get_claims(number_of_claims=4,
                                          result=result,
                                          include_names=True)
        # Remove unnecessary data
        del (cutpoint['asmt_subject'])
    return {
        'cutpoints': cutpoints,
        'claims': claims,
        Constants.BRANDING: custom_metadata_map.get(Constants.BRANDING)
    }
 def test_get_claims_for_indexer_only(self):
     result = {'asmt_cut_point_name_1': 'one',
               'asmt_claim_1_score_range_min': 1,
               'asmt_claim_1_score_range_max': 4,
               'asmt_claim_1_score_min': 2,
               'asmt_claim_1_score_max': 5,
               'asmt_score_max': 500,
               'asmt_claim_1_score': 2,
               'asmt_claim_1_name': 'name',
               'asmt_subject': 'ELA',
               'asmt_cut_point_name_2': 'two',
               'asmt_claim_2_score_range_min': 1,
               'asmt_claim_2_score_range_max': 4,
               'asmt_claim_2_score_min': 2,
               'asmt_claim_2_score_max': 5,
               'asmt_score_max': 500,
               'asmt_claim_2_score': 2,
               'asmt_claim_2_name': 'Two',
               'asmt_type': 'SUMMATIVE'}
     claims = get_claims(number_of_claims=2, result=result, include_indexer=True)
     self.assertEqual(len(claims), 2)
     self.assertEqual(len(claims[0]), 3)
     self.assertEqual(claims[0]['indexer'], '1')
     self.assertEqual(claims[1]['indexer'], '2')
 def test_get_claims_with_no_claims(self):
     claims = get_claims(number_of_claims=0, result=None, include_scores=True)
     self.assertEqual(len(claims), 0)