def main():
    qs.logger.config(__file__)
    schoolcode = sys.argv[1]
    backup = qs.API(schoolcode, 'backup')
    live = qs.API(schoolcode)

    for section_dict in qs.bar(backup.get_sections()):
        section_id = section_dict['id']
        backup_enrollment = backup.get_section_enrollment(section_id)
        backup_enrollment = backup_enrollment['students']
        enrolled_ids = [i['smsStudentStubId'] for i in backup_enrollment]

        if enrolled_ids:
            live.post_section_enrollment(section_id, enrolled_ids)
def main():
    qs.logger.config(__file__)
    schoolcode = sys.argv[1]
    q = qs.API(schoolcode)

    for section_dict in qs.bar(q.get_sections()):
        q.delete_all_section_enrollments_for_section(section_dict['id'])
Exemple #3
0
def main():
    qs.logger.config(__file__)

    schoolcode = sys.argv[1]
    filename = sys.argv[2]
    q = qs.API(schoolcode)
    csv_assignments = qs.CSV(filename)

    # Check for missing columns

    missing_columns = []
    if 'Section ID' not in csv_assignments.cols:
        missing_columns.append('Section ID')
    if 'Assignment ID' not in csv_assignments.cols:
        missing_columns.append('Assignment ID')

    if missing_columns:
        for missing_column in missing_columns:
            qs.logger.info('Missing columns: ', missing_columns, cc_print=True)
            sys.tracebacklimit = 0
            raise ValueError("Columns Missing. See above for details.")

    # Delete Assignments

    for assign in qs.bar(csv_assignments):
        assignment = assign['Assignment ID']
        section = assign['Section ID']

        q.delete_assignment(section, assignment)

    qs.logger.info('Assignments deleted', cc_print=True)
def main():
    qs.logger.config(__file__)
    schoolcode = sys.argv[1]
    filename = sys.argv[2]

    q = qs.API(schoolcode)
    csv = qs.CSV(filename)

    # {student_id: StudentRC}
    student_rcs = {}
    for row in csv:
        student_id = row['Student ID']
        section_id = row['Section ID']
        identifier = row['Identifier']
        value = row['Value']

        if student_id not in student_rcs:
            student_rcs[student_id] = StudentRC()
        rc = student_rcs[student_id]

        rc.add_section_data(section_id, identifier, value)

    report_cycle_id = q.get_active_report_cycle()['id']
    for student_id, rc in student_rcs.iteritems():
        rc_data = rc.full_report_card_data()
        q.post_report_card_section_level(student_id, report_cycle_id, rc_data)
Exemple #5
0
def main():
    qs.logger.config(__file__)

    schoolcode = sys.argv[1]
    filename = sys.argv[2]
    csv_sections = qs.CSV(filename)
    q = qs.API(schoolcode)
    sections = {}

    qs.logger.info('Retrieving section info from CSV...', cc_print=True)
    for section in csv_sections:
        section_name = section['Section Name']
        section_code = section['Section Code']
        class_id = section['Class ID']
        teacher_id = section['Teacher ID']

        sections[section_code] = {
            'section_name': section_name,
            'section_code': section_code,
            'class_id': class_id,
            'teacher_id': teacher_id
        }

        if 'Credit Hours' in section:
            credit_hours = section['Credit Hours']

            sections[section_code]['credit_hours'] = credit_hours

    qs.logger.info('POSTing sections...', cc_print=True)

    new_sections = q.post_sections(sections_dict=sections)
Exemple #6
0
def setup():
    global q, posted_section
    q = qs.API()
    for section in q.get_sections():
        if 'temp' in section['sectionName']:
            q.delete_section(section['id'])
    posted_section = q.post_section('temp 1', 'temp 1', CLASS_ID, TEACHER_ID)
Exemple #7
0
def main():
    qs.logger.config(__file__)

    schoolcode = sys.argv[1]
    identifier = sys.argv[2]
    filename = sys.argv[3]
    q = qs.API(schoolcode)
    csv_report_card_data = qs.CSV(filename)
    student_report_card_data = {}

    if 'Student ID' not in csv_report_card_data.cols:
        raise ValueError("'Student ID' column is required.")
    if 'Report Cycle ID' not in csv_report_card_data.cols:
        raise ValueError("'Report Cycle ID' column is required.")

    qs.logger.info(
        'GETting all report card data for each student enrollment...',
        cc_print=True)
    for csv_student in qs.bar(csv_report_card_data):
        student_id = csv_student['Student ID']
        section_id = csv_student['Section ID']
        report_cycle_id = csv_student['Report Cycle ID']

        report_card_data = q.get_report_card(student_id,
                                             report_cycle_id)['sectionLevel']

        csv_student[identifier] = report_card_data[section_id][identifier]

    qs.logger.info('Values retrieved for identifier:',
                   identifier,
                   cc_print=True)
    filepath = qs.unique_path(csv_report_card_data.filepath, suffix="-values")
    csv_report_card_data.save(filepath)
Exemple #8
0
def main():
    qs.logger.config(__file__)

    schoolcode = sys.argv[1]
    filename = sys.argv[2]
    ignore_case = bool(sys.argv[3]) if len(sys.argv) > 3 else True
    enrolled_only = bool(sys.argv[4]) if len(sys.argv) > 4 else False
    csv_students = qs.CSV(filename)
    q = qs.API(schoolcode)

    if not ('Full Name' in csv_students.cols or
            ('First' in csv_students.cols and 'Last' in csv_students.cols)):
        raise ValueError('"Full Name" or "First" and "Last" columns required.')

    if enrolled_only is True:
        db_students = q.get_students()
    elif enrolled_only is False:
        db_students = q.get_students(show_has_left=True,
                                     show_deleted=True,
                                     ignore_deleted_duplicates=True)
    db_duplicates = qs.find_dups_in_dict_list(db_students, 'fullName')

    if db_duplicates:
        qs.logger.critical('Student names are not unique in DB, duplicates:',
                           db_duplicates)
    else:
        qs.logger.info('Student names are unique.')

    if ignore_case is True:
        for student in db_students:
            student['fullName'] = student['fullName'].lower()
    db_by_name = qs.dict_list_to_dict(db_students, 'fullName')

    student_names_not_matched = set()
    for csv_student in csv_students:
        if 'Full Name' in csv_student:
            csv_full_name = csv_student['Full Name']
        else:
            csv_full_name = '{}, {}'.format(csv_student['Last'],
                                            csv_student['First'])

        csv_original_full_name = csv_full_name
        if ignore_case:
            csv_full_name = csv_full_name.lower()
        db_match = db_by_name.get(csv_full_name)
        if db_match:
            csv_student['Student ID'] = db_match['id']
        else:
            student_names_not_matched.add(csv_original_full_name)

    if student_names_not_matched:
        qs.logger.warning(('{} students in the file were not found in the db'
                           ''.format(len(student_names_not_matched))),
                          student_names_not_matched)
    else:
        qs.logger.info('All students were matched in the db.', cc_print=True)
        filepath = qs.unique_path(csv_students.filepath,
                                  suffix="with student IDs")
        csv_students.save(filepath)
def main():
    qs.logger.config(__file__)
    schoolcode = sys.argv[1]
    server = sys.argv[2]
    q = qs.API(schoolcode, server)

    for section in qs.bar(q.get_sections()):
        q.delete_section(section['id'])
Exemple #10
0
def test_get_assignment():
    assignment = q.get_assignment(ASSIGNMENT_ID)
    assert_equals(assignment['name'], ASSIGNMENT_NAME)

    other_cache = qs.API()
    assignment = other_cache.get_assignment(ASSIGNMENT_ID)
    assert_equals(assignment['name'], ASSIGNMENT_NAME)
    assert_in('sectionId', assignment)
Exemple #11
0
def test_make_request():
    request = qs.QSRequest('Testing', '/students')
    q = qs.API()
    data = q._make_request(request, critical=True)
    assert_is_instance(data, list)
    assert_equals(request.api_key, q.api_key)
    assert_in('apiKey', request.params)
    assert_equals(request.params['apiKey'], q.api_key)
    assert_true(request.critical)
Exemple #12
0
def main():
    qs.logger.config(__file__)
    schoolcode = sys.argv[1]
    q = qs.API(schoolcode)
    data = json.load(open('rolling_migration.json'))

    for section_id, section_dict in qs.bar(data.iteritems()):
        to_delete = section_dict['enrolled_no_valid_grades']
        if to_delete:
            q.delete_section_enrollments(section_id, to_delete)
def main():
    qs.logger.config(__file__)
    schoolcode = sys.argv[1]
    filename = sys.argv[2]
    attendance = qs.CSV(filename)
    q = qs.API(schoolcode)

    for row in qs.bar(attendance):
        q.post_attendance(row['Student ID'], row['Teacher ID'], row['Date'],
                          row['Status'], row['Remarks'], row['Description'])
Exemple #14
0
def main():
    qs.logger.config(__file__)

    schoolcode = sys.argv[1]
    filename = sys.argv[2]
    ignore_case = bool(sys.argv[3]) if len(sys.argv) > 3 else True
    csv_classes = qs.CSV(filename)
    q = qs.API(schoolcode)

    if not ('Class Name' in csv_classes.cols or
            ('Grade' in csv_classes.cols) or
            ('Grade Level' in csv_classes.cols)):
        raise ValueError('Class Name, Grade Level, or Grade column required.')

    db_classes = q.get_classes()
    db_duplicates = qs.find_dups_in_dict_list(db_classes, 'name')

    if db_duplicates:
        qs.logger.critical('Class Names are not unique in DB, duplicates:',
                           db_duplicates)
    else:
        qs.logger.info('class names are unique.')

    if ignore_case is True:
        for class_name in db_classes:
            class_name['name'] = class_name['name'].lower()
    db_by_name = qs.dict_list_to_dict(db_classes, 'name')

    class_names_not_matched = set()
    for csv_class in csv_classes:
        if 'Class Name' in csv_class:
            csv_class_name = csv_class['Class Name']
        elif 'Grade' in csv_class:
            csv_class_name = csv_class['Grade']
        else:
            csv_class_name = csv_class['Grade Level']

        csv_orginal_class_name = csv_class_name
        if ignore_case:
            csv_class_name = csv_class_name.lower()
        db_match = db_by_name.get(csv_class_name)
        if db_match:
            csv_class['Class ID'] = db_match['id']
        else:
            class_names_not_matched.add(csv_orginal_class_name)

    if class_names_not_matched:
        qs.logger.warning(('{} classes in the file were not found in the db'
                           ''.format(len(class_names_not_matched))),
                          class_names_not_matched)
    else:
        qs.logger.info('All classes were matched in the db.', cc_print=True)
        filepath = qs.unique_path(csv_classes.filepath,
                                  suffix="with student IDs")
        csv_classes.save(filepath)
Exemple #15
0
def main():
    qs.logger.config(__file__)
    schoolcode = sys.argv[1]
    q = qs.API(schoolcode)

    for section in qs.bar(q.get_sections()):
        section_id = section['id']
        assignments = q.get_assignments(section_id, include_final_grades=True)
        if assignments:
            for assignment in assignments:
                q.delete_assignment(section_id, assignment['id'])
Exemple #16
0
def test_adding_api_key():
    fake_schoolcode = 'fakeschool'
    fake_api_key = '{}.fakeapikey'.format(fake_schoolcode)
    q = qs.API(fake_api_key)
    q.api_key = API_KEY
    q.get_students()
    if q.get_students():
        assert_equals(q.schoolcode, fake_schoolcode)
        assert_equals(qs.api_keys.get(['qs', 'live', fake_schoolcode]),
                      API_KEY)
        qs.api_keys.remove(['qs', 'live', 'fakeschool'])
Exemple #17
0
def main():
    qs.logger.config(__file__)

    schoolcode = sys.argv[1]
    server = sys.argv[2]
    identifier = sys.argv[3]
    level = sys.argv[4]
    filename = sys.argv[5]
    q = qs.API(schoolcode, server)
    csv_transcript_data = qs.CSV(filename)
    student_transcript_data = {}

    if 'Student ID' not in csv_transcript_data.cols:
        raise ValueError("'Student ID' column is required.")
    if not (len(sys.argv) == 6):
        raise ValueError("Incorrect number of params. Please review.")
    if ('Section ID' not in csv_transcript_data.cols and level == "section"):
        raise ValueError("'Section ID' column is required.")
    if (level != "transcript" and level != "section"):
        raise ValueError(
            "'Level' param not defined properly. Please chose 'section' or 'transcript'."
        )

    qs.logger.info(
        'GETting all transcript data for each student enrollment...',
        cc_print=True)
    for csv_student in qs.bar(csv_transcript_data):
        student_id = csv_student['Student ID']

        if level == "section":
            section_id = csv_student['Section ID']

            transcript_data = q.get_transcript(student_id)['sectionLevel']

            if section_id in transcript_data:
                if identifier in transcript_data[section_id]:
                    csv_student[identifier] = transcript_data[section_id][
                        identifier]
                else:
                    csv_student[identifier] = None
        if level == "transcript":
            transcript_data = q.get_transcript(student_id)['transcriptLevel']
            if identifier in transcript_data:
                csv_student[identifier] = transcript_data[identifier]
            else:
                csv_student[identifier] = None
        else:
            qs.logger.critical('Transcript level param incorrect.')

    qs.logger.info('Values retrieved for identifier:',
                   identifier,
                   cc_print=True)
    filepath = qs.unique_path(csv_transcript_data.filepath, suffix="-values")
    csv_transcript_data.save(filepath)
def main():
    qs.logger.config(__file__)

    schoolcode = sys.argv[1]
    section_id = sys.argv[2]
    filename = sys.argv[3]
    q = qs.API(schoolcode)
    csv_grades = qs.CSV(filename)
    section_name = q.get_section(section_id)['sectionName']
    matched_categories = list()
    unmatched_categories = list()

    if section_name is None:
        raise ValueError("Section doesn't exist")
    if not ('Category Name') in csv_grades.cols:
        raise ValueError("'Category Name' column required")

    qs.logger.info(
        "GETting grading categories based of the gradebook in section: " +
        section_name,
        cc_print=True)

    categories = q.get_grade_category_ids(section_id)

    for csv_grade in qs.bar(csv_grades):
        category_name = csv_grade['Category Name']
        if category_name in categories:
            csv_grade['Category ID'] = categories[category_name]
            matched_categories.append(category_name)
        else:
            unmatched_categories.append(category_name)

    # Return new csv if successful

    if 'Category ID' in csv_grade:
        qs.logger.info(
            "Completed getting category ids. {} categories matched.".format(
                len(matched_categories)),
            cc_print=True)
        qs.logger.info("{} outstanding unmatched categories\n".format(
            len(unmatched_categories)),
                       cc_print=True)
        filepath = qs.unique_path(csv_grades.filepath, suffix="w category IDs")
        csv_grades.save(filepath)
    else:
        qs.logger.info("Outstanding categories ({}) are unmatched\n".format(
            len(unmatched_categories)),
                       cc_print=True)
        for unmatched_category in unmatched_categories:
            qs.logger.info(unmatched_category, cc_print=True)
Exemple #19
0
def main():
    qs.logger.config(__file__)
    schoolcode = sys.argv[1]
    filename = sys.argv[2]
    q = qs.API(schoolcode)
    fees = qs.CSV(filename)

    for fee in qs.bar(fees):
        q.post_fee(
            fee['Student ID'],
            fee['Category ID'],
            fee['Amount'],
            fee['Date'],
            fee['Description'])
Exemple #20
0
def main():
    qs.logger.config(__file__)

    schoolcode = sys.argv[1]
    filename = sys.argv[2]
    q = qs.API(schoolcode)
    csv_semesters = qs.CSV(filename)

    # Check CSV for proper columns and verify unique semester names in db

    if not ("Semester" in csv_semesters.cols):
        raise ValueError("'Semester' column required")

    db_semesters = q.get_semesters()
    db_duplicates = qs.find_dups_in_dict_list(db_semesters, "semesterName")

    if db_duplicates:
        qs.logger.critical('Semester names are not unique in DB. Duplicates:',
                           db_duplicates)
    else:
        qs.logger.info('Semester names are unique. Matching...', cc_print=True)

    db_semesters_by_name = qs.dict_list_to_dict(db_semesters, "semesterName")

    # Check for semesters in CSV that are not in db

    semester_names_not_matched = set()

    for csv_semester in csv_semesters:
        csv_semester_name = csv_semester['Semester']

        csv_original_semester_name = csv_semester_name
        db_match = db_semesters_by_name.get(csv_semester_name)

        if db_match:
            csv_semester['Semester ID'] = db_match['id']
        else:
            semester_names_not_matched.add(csv_original_semester_name)

    # Match semesters if all are matched

    if semester_names_not_matched:
        qs.logger.info('Semester Names do not match DB:',
                       semester_names_not_matched,
                       cc_print=True)
    else:
        qs.logger.info('All semester names matched', cc_print=True)
        filepath = qs.unique_path(csv_semesters.filepath)
        csv_semesters.save(filepath)
Exemple #21
0
def main():
    qs.logger.config(__file__)

    schoolcode = sys.argv[1]
    filename = sys.argv[2]
    ignore_case = bool(sys.argv[3]) if len(sys.argv) > 3 else True
    csv_teachers = qs.CSV(filename)
    q = qs.API(schoolcode)

    if not ('Teacher Name' in csv_teachers.cols):
        raise ValueError('Teacher Name column required.')

    db_teachers = q.get_teachers()
    db_duplicates = qs.find_dups_in_dict_list(db_teachers, 'fullName')

    if db_duplicates:
        qs.logger.critical('Teacher names are not unique in DB, duplicates:',
                           db_duplicates)
    else:
        qs.logger.info('Teacher names are unique.')

    if ignore_case is True:
        for teacher in db_teachers:
            teacher['fullName'] = teacher['fullName'].lower()
    db_by_name = qs.dict_list_to_dict(db_teachers, 'fullName')

    teacher_names_not_matched = set()
    for csv_teacher in csv_teachers:
        csv_full_name = csv_teacher['Teacher Name']

        if ignore_case:
            csv_full_name = csv_full_name.lower()

        db_match = db_by_name.get(csv_full_name)
        if db_match:
            csv_teacher['Teacher ID'] = db_match['id']
        else:
            teacher_names_not_matched.add(csv_full_name)

    if teacher_names_not_matched:
        qs.logger.warning(('{} Teachers in the file were not found in the db'
                           ''.format(len(teacher_names_not_matched))),
                          teacher_names_not_matched)
    else:
        qs.logger.info('All teachers were matched in the db.', cc_print=True)
        filepath = qs.unique_path(csv_teachers.filepath,
                                  suffix="with teacher IDs")
        csv_teachers.save(filepath)
Exemple #22
0
def main():
    qs.logger.config(__file__)

    schoolcode = sys.argv[1]
    q = qs.API(schoolcode)
    section1 = sys.argv[2]
    section2 = sys.argv[3]

    discrepancies = q.check_section_enrollment_match(section_1_id=section1,
                                                     section_2_id=section2)

    qs.pp({
        "section1": section1,
        "section2": section2,
        "discrepancies": discrepancies
    })
def main():
    qs.logger.config(__file__)
    schoolcode = sys.argv[1]
    filename = sys.argv[2]
    q = qs.API(schoolcode)
    csv_enrollments = qs.CSV(filename)
    section_info = {}
    student_enrollments = {}

    # Get Section Info

    if 'Section ID' not in csv_enrollments.cols:
        qs.logger.critical('"Section ID" column required. Current columns: ',
                           csv_enrollments.cols)
    if 'Student ID' not in csv_enrollments.cols:
        qs.logger.critical('"Student ID" column required. Current columns: ',
                           csv_enrollments.cols)

    qs.logger.info('Setting up enrollment info from csv data...',
                   cc_print=True)
    for enrollment in csv_enrollments:
        section_name = enrollment['Section Name']
        section_id = enrollment['Section ID']
        student_id = enrollment['Student ID']
        if 'Section Code' in enrollment:
            section_code = enrollment['Section Code']
        else:
            section_code = enrollment['Section Name']

        if section_id not in student_enrollments:
            student_enrollments[section_id] = list()
        student_enrollments[section_id].append(student_id)

        section_info[section_id] = {
            'section_name': section_name,
            'section_id': section_id,
            'section_code': section_code,
            'student_ids': student_enrollments[section_id]
        }

    qs.logger.info('POSTing section enrollments...', cc_print=True)
    for section in qs.bar(section_info):
        section_id = section_info[section]['section_id']
        students = section_info[section]['student_ids']

        new_enrollment = q.post_section_enrollment(section_id, students)
Exemple #24
0
def main():
    qs.logger.config(__file__)

    schoolcode = sys.argv[1]
    filename = sys.argv[2]
    q = qs.API(schoolcode)
    csv_report_cycles = qs.CSV(filename)

    if 'Report Cycle' not in csv_report_cycles.cols:
        raise ValueError("'Report Cycle' column required")

    db_report_cycles = q.get_report_cycles()
    db_duplicates = qs.find_dups_in_dict_list(db_report_cycles, 'name')

    db_by_name = qs.dict_list_to_dict(db_report_cycles, 'name')

    if db_duplicates:
        qs.logger.info('Report Cycle names are not unique', cc_print=True)
    else:
        qs.logger.info('Report Cycle names are unique', cc_print=True)

    report_cycle_names_not_matched = set()
    for csv_report_cycle in csv_report_cycles:
        csv_report_cycle_name = csv_report_cycle['Report Cycle']

        if csv_report_cycle_name in db_duplicates:
            qs.logger.info('Report Cycle name has multiple matches',
                           cc_print=True)

        db_match = db_by_name.get(csv_report_cycle_name)
        if db_match:
            csv_report_cycle['Report Cycle ID'] = db_match['id']
        else:
            report_cycle_names_not_matched.add(csv_report_cycle_name)

    if report_cycle_names_not_matched:
        qs.logger.warning(
            ('{} Report Cycles in the file were not found in the db'
             ''.format(len(report_cycle_names_not_matched))),
            report_cycle_names_not_matched)
    else:
        qs.logger.info('All Report Cycles were matched in the db.',
                       cc_print=True)
        filepath = qs.unique_path(csv_report_cycles.filepath,
                                  suffix="with-report-cycle-IDs")
        csv_report_cycles.save(filepath)
Exemple #25
0
def main():
    qs.logger.config(__file__)
    schoolcode = sys.argv[1]
    q = qs.API(schoolcode)
    student = sys.argv[2]
    assign_name = sys.argv[3]
    assign_date = sys.argv[4]
    total_possible = sys.argv[5]
    category_id = sys.argv[6]
    marks = sys.argv[7]
    grading_scale_id = sys.argv[8]
    section = sys.argv[9]

    new_grade = q.post_assignment_with_grades(section, assign_name,
                                              assign_date, total_possible,
                                              category_id, grading_scale_id,
                                              grades_date)
    qs.logger.info({"section": section, "grade": section_data['grades_data']})
Exemple #26
0
def main():
    qs.logger.config(__file__)

    schoolcode = sys.argv[1]
    from_identifier = sys.argv[2]
    to_identifier = sys.argv[3]
    filename = sys.argv[4]
    q = qs.API(schoolcode)
    csv_section_values = qs.CSV(filename)
    sections = dict()
    empty_sections = list()

    if 'Student ID' not in csv_section_values.cols:
        raise ValueError("'Student ID' column required")
    elif 'Section ID' not in csv_section_values.cols:
        raise ValueError("'Section ID' column required")
    elif from_identifier not in csv_section_values.cols:
        raise ValueError("Identifier '{}'column is required" .format(from_identifier))

    qs.logger.info("Retrieving section information and identifier values...", cc_print=True)
    for section in qs.bar(csv_section_values):
        student_id = section['Student ID']
        section_id = section['Section ID']
        identifier_values = section[from_identifier]

        if identifier_values is not None:
            if student_id not in sections:
                sections[student_id] = dict()
            sections[student_id][section_id] = {'values': {to_identifier: identifier_values}}
        else:
            if 'Full Name' in csv_section_values.cols and 'Section Name' in csv_section_values.cols:
                student_name = section['Student Name']
                section_name = section['Section Name']
                empty_sections.append({student_id: section_id, student_name: section_name})
            else:
                empty_sections.append({student_id: section_id})

    qs.logger.info("POSTing data to transcripts' sections...", cc_print=True)
    for student in qs.bar(sections):

        student_id = student
        transcript_data = sections[student]

        q.post_transcript_section_level(student_id, transcript_data)
Exemple #27
0
def main():
    qs.logger.config(__file__)
    schoolcode = sys.argv[1]
    q = qs.API(schoolcode)
    data = json.load(open('rolling_migration.json'))

    for old_section_id, old_section_dict in qs.bar(data.iteritems()):
        new_section = q.match_section(old_section_id)
        new_section_id = new_section['id']
        enrolled_no_valid_grades = old_section_dict['enrolled_no_valid_grades']
        invalid_grades = old_section_dict['invalid_grades']

        if not enrolled_no_valid_grades: continue

        q.post_section_enrollment(new_section_id, enrolled_no_valid_grades)

        invalid_by_assignment = {i['assignmentId']: [] for i in invalid_grades}
        for grade in invalid_grades:
            if grade['isFinalGrade'] is False:
                invalid_by_assignment[grade['assignmentId']].append(grade)

        for assignment_id, grades in invalid_by_assignment.iteritems():
            old_assignment = q.get_assignment(assignment_id)
            new_assignment = q.post_assignment(
                new_section_id, old_assignment.get('name'),
                old_assignment.get('date'),
                old_assignment.get('totalMarksPossible'),
                old_assignment.get('categoryId'),
                old_assignment.get('gradingScaleId'))

            grades_to_upload = []
            for grade in grades:
                student_id = grade['studentId']
                if student_id in enrolled_no_valid_grades:
                    grades_to_upload.append(grade)
                else:
                    warning = ("student {} has some, but not all valid grades "
                               "for section {}").format(
                                   student_id, old_section_id)
                    qs.logger.warning(warning)

            q.post_grades(new_section_id, new_assignment['id'],
                          grades_to_upload)
def main():
    qs.logger.config(__file__)

    schoolcode = sys.argv[1]
    server = sys.argv[2]
    filename = sys.argv[3]
    q = qs.API(schoolcode, server)
    csv_student_report_cycles = qs.CSV(filename)
    tr_enrollments = list()

    if 'Student ID' not in csv_student_report_cycles.cols:
        raise ValueError("'Student ID' column required.")

    for csv_student in qs.bar(csv_student_report_cycles):
        student_id = csv_student['Student ID']
        if 'Full Name' in csv_student:
            full_name = csv_student['Full Name']
        else:
            full_name = None

        tr_data = q.get_transcript(student_id)['sectionLevel']

        for section in tr_data:
            section_id = section

            if full_name:
                tr_enrollments.append({'Student ID': student_id,
                                       'Full Name': full_name,
                                       'Section ID': section_id})
            else:
                tr_enrollments.append({'Student ID': student_id,
                                       'Section ID': section_id})

    if tr_enrollments:
        qs.logger.info('Transcript section enrollment retrieved', cc_print=True)
        filepath = qs.unique_path(csv_student_report_cycles.filepath)
        qs.write_csv(tr_enrollments, filepath)
    else:
        qs.logger.info('No enrollments found for these students', cc_print=True)
Exemple #29
0
def main():
    qs.logger.config(__file__)

    schoolcode = sys.argv[1]
    filename = sys.argv[2]
    silent = bool(sys.argv[3]) if len(sys.argv) > 3 else False
    csv_sections = qs.CSV(filename)
    q = qs.API(schoolcode)
    row_num = 1

    if 'Semester ID' in csv_sections.cols:
        qs.logger.info('Matching with db by Semester ID...', cc_print=True)

        for csv_section_info in qs.bar(csv_sections):
            section_name = csv_section_info['Section Name']
            semester_id = csv_section_info['Semester ID']

            if 'Section Code' in csv_sections.cols:
                section_code = csv_section_info['Section Code']
                section = {'sectionCode': section_code}
                matched_section = q.match_section(
                    section,
                    fail_silent=silent,
                    match_code=True,
                    target_semester_id=semester_id)
            else:
                matched_section = q.match_section(
                    identifier=section_name,
                    fail_silent=silent,
                    target_semester_id=semester_id)
            if matched_section is "FALSE":
                section_id = "FALSE"
            else:
                section_id = matched_section['id']

            csv_section_info['Section ID'] = section_id

    elif 'Student ID' in csv_sections.cols:
        qs.logger.info('Matching with db by Student ID...', cc_print=True)

        for csv_section_info in qs.bar(csv_sections):
            section_name = csv_section_info['Section Name']
            student = csv_section_info['Student ID']
            row_num += 1

            section = q.match_section(identifier=section_name,
                                      student_id=student,
                                      match_name=True)
            section_id = section['id']
            csv_section_info['Section ID'] = section_id

    elif 'Section Code' in csv_sections.cols:
        qs.logger.info('Matching with db by Section Code...', cc_print=True)

        sections = {}
        sections_with_id = {}
        row_num = 1

        for csv_section_info in csv_sections:
            section_name = csv_section_info['Section Name']
            section_code = csv_section_info['Section Code']
            row_num += 1

            if section_code not in sections:
                sections[section_code] = {'sectionCode': section_code}

        qs.logger.info('GETting matching section ids by Section Code...',
                       cc_print=True)
        for section_code in sections:
            matched_section = q.match_section(sections[section_code],
                                              match_code=True)
            section_id = matched_section['id']

            if section_id not in sections_with_id:
                sections[section_code] = {'section_id': section_id}

        qs.logger.info('Matching section ids to csv section data...',
                       cc_print=True)
        for csv_section_info in csv_sections:
            section_code = csv_section_info['Section Code']
            csv_section_info['Section ID'] = sections[section_code][
                'section_id']

    else:
        qs.logger.critical(
            '"Student ID", "Semester ID", or "Section Code" columns required. Current columns:',
            csv_sections.cols)

    # Make CSV only if successful
    if 'Section ID' in csv_section_info:
        filepath = qs.unique_path(csv_sections.filepath,
                                  suffix="with section IDs")
        csv_sections.save(filepath)
Exemple #30
0
def setup():
    global q
    q = qs.API()