当前位置: 首页>>代码示例>>Python>>正文


Python Course.getRequests方法代码示例

本文整理汇总了Python中models.Course.getRequests方法的典型用法代码示例。如果您正苦于以下问题:Python Course.getRequests方法的具体用法?Python Course.getRequests怎么用?Python Course.getRequests使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Course的用法示例。


在下文中一共展示了Course.getRequests方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process

# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import getRequests [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.getRequests方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。