當前位置: 首頁>>代碼示例>>Python>>正文


Python Course.getStudents方法代碼示例

本文整理匯總了Python中models.Course.getStudents方法的典型用法代碼示例。如果您正苦於以下問題:Python Course.getStudents方法的具體用法?Python Course.getStudents怎麽用?Python Course.getStudents使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.Course的用法示例。


在下文中一共展示了Course.getStudents方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: process

# 需要導入模塊: from models import Course [as 別名]
# 或者: from models.Course import getStudents [as 別名]

#.........這裏部分代碼省略.........

    # For testing, print values of courses.
    #for k, v in courses.iteritems():
    #    print([k])
    #    print(u"Course: {}; Seats: {}".format(v.getName(), v.getSeats()))

    # Do allocation of students, returns unsorted students and courses that were
    # not found, and also inserts students into the students list in each course
    unsorted_students, missing_courses = sortStudents(students, courses)
    # At this point,  courses will have had their arrays filled with students.
    
    ### UNSORTED STUDENTS ###
    u_students_filename = timeStamped("unsorted-students.xls")
    u_students_wb_path = os.path.join(
        app.config['UPLOAD_FOLDER'],
        u_students_filename
    )

    # Construct workbooks and populate them.
    unsorted_students_wb = xlwt.Workbook()
    unsorted_students_sheet = unsorted_students_wb.add_sheet("Students")
    unsorted_student_headers = [
        "ID", "First Name", "Last Name", "First Year Seminar DDB 1", "First Year Seminar DDB 2", "First Year Seminar DDB 3"
    ]
    for index, header in enumerate(unsorted_student_headers):
        unsorted_students_sheet.write(0, index, header)

    for i, student in enumerate(unsorted_students):
        unsorted_students_sheet.write(i + 1, 0, student.getStudentId())
        unsorted_students_sheet.write(i + 1, 1, student.getFName())
        unsorted_students_sheet.write(i + 1, 2, student.getLName())
        prefs = student.getRawPreferences()
        for j, pref in enumerate(prefs):
            unsorted_students_sheet.write(i + 1, j + 3, pref)

    unsorted_students_wb.save(u_students_wb_path)

    ### SORTED STUDENTS ###
    sorted_student_headers = [
        "ID", "First Name", "Last Name", "FSEM Chosen"
    ]
    sorted_students_wb = xlwt.Workbook()
    sorted_students_sheet = sorted_students_wb.add_sheet("Students")
    s_students_filename = timeStamped("sorted-students.xls")
    s_students_wb_path = os.path.join(
        app.config['UPLOAD_FOLDER'],
        s_students_filename
    )
    # Create sorted students array
    sorted_students = []
    for course_name, course in courses.iteritems():
        course_students = map(lambda s: (course_name, s), course.getStudents())
        sorted_students.extend(course_students)

    # Add headers to sorted student sheet
    for index, header in enumerate(sorted_student_headers):
        sorted_students_sheet.write(0, index, header)

    for (i, (course_name, student)) in enumerate(sorted_students):
        sorted_students_sheet.write(i + 1, 0, student.getStudentId())
        sorted_students_sheet.write(i + 1, 1, student.getFName())
        sorted_students_sheet.write(i + 1, 2, student.getLName())
        sorted_students_sheet.write(i + 1, 3, course_name)

    sorted_students_wb.save(s_students_wb_path)
    print(s_students_wb_path)

    ### CLOSED COURSES ###
    closed_courses_filename = timeStamped("closed-courses.xls")
    c_courses_wb_path = os.path.join(
        app.config['UPLOAD_FOLDER'],
        closed_courses_filename
    )
    closed_courses = [c for (name, c) in courses.iteritems() if c.isFull()]
    closed_course_headers = [
        "Course Name", "Seats", "Requests"
    ]
    closed_courses_wb = xlwt.Workbook()
    closed_course_sheet = closed_courses_wb.add_sheet("Courses")
    for index, header in enumerate(closed_course_headers):
        closed_course_sheet.write(0, index, header)
    
    for i, course in enumerate(closed_courses):
        closed_course_sheet.write(i + 1, 0, course.getName())
        closed_course_sheet.write(i + 1, 1, course.getSeats())
        closed_course_sheet.write(i + 1, 2, course.getRequests())

    closed_courses_wb.save(c_courses_wb_path)
    
    # Inform about rows with invalid students.
    if (invalid_students):
        invalid_student_list = ', '.join([str(x) for x in invalid_students])
        flash("The following row{} in the Student spreadsheet were missing necessary values: {}".format('s' if len(invalid_students) > 1 else "", invalid_student_list))

    # Inform about requests made for missing courses.
    if (missing_courses):
        invalid_courses_list = '; '.join(["{} ({})".format(k, len(v)) for k, v in missing_courses.iteritems()])
        flash("The following course{} requested but not found in the course spreadsheet (number of times requested listed): {}".format('s were' if len(missing_courses) > 1 else ' was', invalid_courses_list))

    return render_template('results.html', s_path=s_students_filename, us_path=u_students_filename, c_courses=closed_courses_filename)
開發者ID:chrahunt,項目名稱:fsem-scheduler,代碼行數:104,代碼來源:app.py


注:本文中的models.Course.getStudents方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。