fix spanish
This commit is contained in:
@@ -55,6 +55,70 @@ class Classroom(db.Model):
|
||||
location += f" ({self.campus_location})"
|
||||
return location
|
||||
|
||||
@staticmethod
|
||||
def find_best_classroom(max_students, start_time, end_time, exclude_reservation_id=None):
|
||||
"""Find the best suitable classroom for a commission based on capacity and availability"""
|
||||
from app.models.reservation import Reservation, ReservationStatus
|
||||
|
||||
# Get all active classrooms with sufficient capacity
|
||||
suitable_classrooms = Classroom.query.filter(
|
||||
Classroom.is_active == True,
|
||||
Classroom.capacity >= max_students
|
||||
).order_by(Classroom.capacity.asc()).all() # Start with smallest suitable
|
||||
|
||||
# Check availability for each classroom
|
||||
available_classrooms = []
|
||||
for classroom in suitable_classrooms:
|
||||
# Check for conflicts
|
||||
conflicts = Reservation.find_conflicts(
|
||||
classroom.id, start_time, end_time, exclude_reservation_id
|
||||
)
|
||||
|
||||
if not conflicts:
|
||||
# Calculate efficiency score (how well the capacity matches)
|
||||
efficiency = classroom.capacity / max_students if max_students > 0 else float('inf')
|
||||
available_classrooms.append({
|
||||
'classroom': classroom,
|
||||
'efficiency': efficiency,
|
||||
'wasted_capacity': classroom.capacity - max_students
|
||||
})
|
||||
|
||||
# Sort by efficiency (closest capacity match first)
|
||||
available_classrooms.sort(key=lambda x: x['efficiency'])
|
||||
|
||||
return available_classrooms
|
||||
|
||||
@staticmethod
|
||||
def get_availability_status(start_time, end_time, exclude_reservation_id=None):
|
||||
"""Get all classrooms classified as available or occupied for a time slot"""
|
||||
from app.models.reservation import Reservation, ReservationStatus
|
||||
|
||||
all_classrooms = Classroom.query.filter_by(is_active=True).all()
|
||||
available = []
|
||||
occupied = []
|
||||
|
||||
for classroom in all_classrooms:
|
||||
conflicts = Reservation.find_conflicts(
|
||||
classroom.id, start_time, end_time, exclude_reservation_id
|
||||
)
|
||||
|
||||
classroom_info = {
|
||||
'classroom': classroom,
|
||||
'conflicts': conflicts
|
||||
}
|
||||
|
||||
if conflicts:
|
||||
occupied.append(classroom_info)
|
||||
else:
|
||||
available.append(classroom_info)
|
||||
|
||||
return {
|
||||
'available': available,
|
||||
'occupied': occupied,
|
||||
'total_available': len(available),
|
||||
'total_occupied': len(occupied)
|
||||
}
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Classroom {self.code_display}>'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user