added basic methods for seat arrangement

added number of students in hall allocation
This commit is contained in:
Pranav Jerry 2023-04-22 11:37:27 +05:30
parent 586499df04
commit cd8d0e7230
Signed by: pranav
GPG Key ID: F1DCDC4FED0A0C5B
4 changed files with 64 additions and 20 deletions

View File

@ -26,3 +26,30 @@ class ExamGroup(Document):
self.exams.append(exam_child)
exam = frappe.get_doc("Exam", exam_id)
self.number_of_students += len(exam.students)
def get_students(self):
students_by_exams = []
for exam in self.exams:
exam = frappe.get_doc("Exam", exam.id)
students = []
for student in exam.students:
students.append(student.id)
students.sort()
students_by_exams.append(students)
return students_by_exams
def randomize_students_by_exam(self):
students = self.get_students()
# exams=len(students)
randomized = []
# while students is not empty
while students:
exams = len(students)
# add one student from each exam one at a time
for i in range(exams):
# if there are no more students in that exam, remove it and skip to the while loop
if not students[i]:
students.pop(i)
break
randomized.append(students[i].pop(0))
return randomized

View File

@ -10,14 +10,20 @@ class HallAllocation(Document):
"""automatically allocate exam halls to the exam"""
exam_halls = frappe.get_list("Exam Hall", pluck="name")
exam_group = frappe.get_doc("Exam Group", self.exam_group)
number_of_students = exam_group.number_of_students
remaining_students = exam_group.number_of_students
print(vars(self))
for exam_hall in exam_halls:
if number_of_students <= 0:
# students allocated to the exam hall
number_of_students = 0
if remaining_students <= 0:
break
print(vars(self))
print(exam_hall)
exam_hall = frappe.get_doc("Exam Hall", exam_hall)
number_of_students -= exam_hall.seating_capacity
if remaining_students >= exam_hall.seating_capacity:
number_of_students = exam_hall.seating_capacity
else:
number_of_students = remaining_students
remaining_students -= number_of_students
e = frappe.new_doc("Exam Hall Child")
e.update(
{
@ -25,8 +31,13 @@ class HallAllocation(Document):
"parent": self.name,
"parentfield": "allocated_rooms",
"parenttype": self.doctype,
"number_of_students": number_of_students,
}
)
# e.save()
print(vars(self))
self.allocated_rooms.append(e)
def get_students_randomized(self):
exam_group = frappe.get_doc("Exam Group", self.exam_group)
return exam_group.randomize_students_by_exam()

View File

@ -7,20 +7,12 @@
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"exam_hall",
"exam_group",
"seat_list",
"hall_allocation",
"seating_order",
"amended_from"
],
"fields": [
{
"fieldname": "exam_hall",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Exam Hall",
"options": "Exam Hall",
"reqd": 1
},
{
"fieldname": "exam_group",
"fieldtype": "Link",
@ -39,17 +31,23 @@
"read_only": 1
},
{
"fieldname": "seat_list",
"fieldtype": "Table",
"label": "Seat list",
"options": "Seats And Exams",
"fieldname": "hall_allocation",
"fieldtype": "Link",
"label": "Hall Allocation",
"options": "Hall Allocation",
"reqd": 1
},
{
"fieldname": "seating_order",
"fieldtype": "Table",
"label": "Seating Order",
"options": "Seats And Exams"
}
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2023-04-19 18:37:30.280739",
"modified": "2023-04-22 08:59:16.524150",
"modified_by": "Administrator",
"module": "Exam Helper",
"name": "Seat Arrangement",

View File

@ -6,6 +6,7 @@
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"exam_hall",
"seat_number",
"candidate"
],
@ -24,12 +25,19 @@
"label": "Candidate",
"options": "Student",
"reqd": 1
},
{
"fieldname": "exam_hall",
"fieldtype": "Link",
"label": "Exam Hall",
"options": "Exam Hall",
"reqd": 1
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2023-04-19 18:35:43.409735",
"modified": "2023-04-22 08:57:43.430784",
"modified_by": "Administrator",
"module": "Exam Helper",
"name": "Seats And Exams",