Apply patch from florian
parent
fd4ca459bc
commit
36d2fe7b4f
|
@ -1,6 +1,7 @@
|
|||
# import cakecms api module even if it is not installed
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
|
||||
import cakecms
|
||||
|
@ -11,15 +12,17 @@ USAGE: Seat on testing #3, order by #5-points descending
|
|||
python change_seating.py "http://localhost/cakecms" prog1 2q4q3dsLrnFsXf8AMFSKEZj3 3 --order 5
|
||||
'''
|
||||
|
||||
|
||||
def order_students_by_points(cms, students, testing_id, desc=True):
|
||||
results = cms.testingresults_index_by_student_id(testing_id=testing_id)
|
||||
students.sort(key=lambda studentid: results[studentid]['points'])
|
||||
if desc: students = students[::-1]
|
||||
return students
|
||||
|
||||
|
||||
def order_students_by_matriculation(cms, students, desc=True):
|
||||
matriculations = cms.students_index()['students']
|
||||
matriculations = {student['Student']['id'] : int(student['Student']['matriculation']) for student in matriculations}
|
||||
matriculations = {student['Student']['id']: int(student['Student']['matriculation']) for student in matriculations}
|
||||
students.sort(key=lambda studentid: matriculations[studentid])
|
||||
if desc: students = students[::-1]
|
||||
return students
|
||||
|
@ -32,11 +35,15 @@ def seat_bad_students_before_good_students(students, seats):
|
|||
:return: list of new seatings: {student_id: ?, room_id: ?, row: ?, seat: ?, rownumber: ?, seatnumber: ?} (optional: code)
|
||||
"""
|
||||
seat_set = set(seats)
|
||||
front_seats = [(room, row, seat, rownum, seatnum) for room, row, seat, rownum, seatnum in seats if not (room, row-1, seat, rownum, seatnum) in seat_set]
|
||||
back_seats = [(room, row, seat, rownum, seatnum) for room, row, seat, rownum, seatnum in seats if (room, row-1, seat, rownum, seatnum) in seat_set]
|
||||
front_seats = [(room, row, seat, rownum, seatnum) for room, row, seat, rownum, seatnum in seats
|
||||
if not (room, row - 1, seat, rownum - 1, seatnum) in seat_set]
|
||||
back_seats = [(room, row, seat, rownum, seatnum) for room, row, seat, rownum, seatnum in seats
|
||||
if (room, row - 1, seat, rownum - 1, seatnum) in seat_set]
|
||||
front_students = students[len(back_seats):]
|
||||
back_students = students[:len(back_seats)]
|
||||
# bug-hunting
|
||||
assert len(front_seats) != 0 and len(front_seats) != len(seats)
|
||||
assert len(back_seats) != 0 and len(back_seats) != len(seats)
|
||||
assert len(seats) == len(seat_set)
|
||||
assert len(front_seats) == len(front_students)
|
||||
assert len(back_seats) == len(back_students)
|
||||
|
@ -44,8 +51,7 @@ def seat_bad_students_before_good_students(students, seats):
|
|||
assert len(seats) == len(students)
|
||||
# bug-hunting end
|
||||
return [{'student_id': student, 'room_id': room, 'row': row, 'seat': seat, 'rownumber': rownum, 'seatnumber': seatnum}
|
||||
for (room, row, seat, rownum, seatnum), student in zip(front_seats + back_seats, front_students + back_students)]
|
||||
|
||||
for (room, row, seat, rownum, seatnum), student in zip(front_seats + back_seats, front_students + back_students)]
|
||||
|
||||
|
||||
def assign_seating(cms, testing_id, student_order_function, seating_function):
|
||||
|
@ -62,12 +68,13 @@ def assign_seating(cms, testing_id, student_order_function, seating_function):
|
|||
|
||||
# split in students / seats
|
||||
students = [adm['Admission']['student_id'] for adm in admissions]
|
||||
seats = [(adm['Admission']['room_id'], adm['Admission']['row'], adm['Admission']['seat'], adm['Admission']['rownumber'], adm['Admission']['seatnumber'])
|
||||
seats = [(adm['Admission']['room_id'], adm['Admission']['row'], adm['Admission']['seat'], adm['Admission']['rownumber'],
|
||||
adm['Admission']['seatnumber'])
|
||||
for adm in admissions]
|
||||
assert len(seats) == len(set(seats))
|
||||
|
||||
# order seats
|
||||
#TODO if you want a special room order, apply it HERE
|
||||
# TODO if you want a special room order, apply it HERE
|
||||
seats.sort()
|
||||
|
||||
# order students
|
||||
|
@ -101,6 +108,7 @@ def on_localhost():
|
|||
seat_bad_students_before_good_students # how to seat students
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
# Run <script> -h to list parameters
|
||||
parser = argparse.ArgumentParser(description='Change seating order for an exam.')
|
||||
|
@ -119,7 +127,7 @@ def main():
|
|||
else:
|
||||
student_order_function = lambda students: order_students_by_points(cms, students, int(args.order))
|
||||
# If you want your own seating distribution, add it here
|
||||
seating_function = seat_bad_students_before_good_students
|
||||
seating_function = seat_bad_students_before_good_students
|
||||
|
||||
assign_seating(cms, args.id, student_order_function, seating_function)
|
||||
|
||||
|
|
Loading…
Reference in New Issue