feat: completar fases 3 y 4 del roadmap mvp (gradebook, drag-and-drop, impersonacion) y actualizar README
This commit is contained in:
@@ -390,28 +390,61 @@ class ReservationOptimizer:
|
||||
}
|
||||
|
||||
def _calculate_preferred_time(self, commission: Commission) -> Dict:
|
||||
"""Calculate preferred time slots for a commission"""
|
||||
# This is a simplified version - would need to be based on actual semester schedule
|
||||
"""Calculate preferred time slots for a commission based on shift and schedule"""
|
||||
current_date = datetime.utcnow()
|
||||
|
||||
# Default to weekday mornings for regular classes
|
||||
days_ahead = (0 - current_date.weekday()) % 7 # Next Monday
|
||||
if days_ahead == 0: # If today is Monday, use next week
|
||||
# Determine day of week from commission schedule or default to Monday
|
||||
target_weekday = 0 # Monday
|
||||
sched = (commission.schedule or '').lower()
|
||||
if 'martes' in sched:
|
||||
target_weekday = 1
|
||||
elif 'miercoles' in sched or 'miércoles' in sched:
|
||||
target_weekday = 2
|
||||
elif 'jueves' in sched:
|
||||
target_weekday = 3
|
||||
elif 'viernes' in sched:
|
||||
target_weekday = 4
|
||||
elif 'sabado' in sched or 'sábado' in sched:
|
||||
target_weekday = 5
|
||||
|
||||
days_ahead = (target_weekday - current_date.weekday()) % 7
|
||||
if days_ahead == 0:
|
||||
days_ahead = 7
|
||||
|
||||
preferred_date = current_date + timedelta(days=days_ahead)
|
||||
|
||||
# Determine hours based on shift
|
||||
shift = (commission.shift or '').strip().lower()
|
||||
if 'mañana' in shift or 'manana' in shift:
|
||||
start_h, start_m = 8, 0
|
||||
end_h, end_m = 12, 0
|
||||
elif 'tarde' in shift:
|
||||
start_h, start_m = 14, 0
|
||||
end_h, end_m = 18, 0
|
||||
elif 'noche' in shift or 'vespertino' in shift:
|
||||
start_h, start_m = 18, 30
|
||||
end_h, end_m = 22, 30
|
||||
else:
|
||||
start_h, start_m = 9, 0
|
||||
end_h, end_m = 13, 0
|
||||
|
||||
return {
|
||||
'start': preferred_date.replace(hour=9, minute=0, second=0, microsecond=0),
|
||||
'end': preferred_date.replace(hour=11, minute=0, second=0, microsecond=0)
|
||||
'start': preferred_date.replace(hour=start_h, minute=start_m, second=0, microsecond=0),
|
||||
'end': preferred_date.replace(hour=end_h, minute=end_m, second=0, microsecond=0)
|
||||
}
|
||||
|
||||
def apply_optimized_reservations(self, reservation_data: List[Dict]) -> List[Reservation]:
|
||||
"""Apply the optimized reservations to the database"""
|
||||
"""Apply the optimized reservations to the database with ISO string parsing and conflict avoidance"""
|
||||
applied_reservations = []
|
||||
|
||||
for data in reservation_data:
|
||||
# Check for conflicts before creating
|
||||
for item in reservation_data:
|
||||
data = dict(item)
|
||||
if isinstance(data.get('start_time'), str):
|
||||
data['start_time'] = datetime.fromisoformat(data['start_time'].replace('Z', '+00:00'))
|
||||
if isinstance(data.get('end_time'), str):
|
||||
data['end_time'] = datetime.fromisoformat(data['end_time'].replace('Z', '+00:00'))
|
||||
|
||||
# Check for physical room conflicts before creating
|
||||
conflicts = Reservation.find_conflicts(
|
||||
data['classroom_id'],
|
||||
data['start_time'],
|
||||
@@ -419,12 +452,17 @@ class ReservationOptimizer:
|
||||
)
|
||||
|
||||
if not conflicts:
|
||||
# Ensure status enum value compatibility
|
||||
if 'status' in data and isinstance(data['status'], str):
|
||||
try:
|
||||
data['status'] = ReservationStatus(data['status']).value
|
||||
except ValueError:
|
||||
data['status'] = ReservationStatus.CONFIRMED.value
|
||||
reservation = Reservation(**data)
|
||||
db.session.add(reservation)
|
||||
applied_reservations.append(reservation)
|
||||
else:
|
||||
# Log conflict - could be handled differently
|
||||
print(f"Conflict detected for reservation data: {data}")
|
||||
current_app.logger.warning(f"Conflict detected for reservation during genetic apply: {data}")
|
||||
|
||||
try:
|
||||
db.session.commit()
|
||||
|
||||
Reference in New Issue
Block a user