fix(optimizer): allow bedelia and operators access to ai room reservation optimizer v3.4.5

This commit is contained in:
2026-10-08 07:49:50 -03:00
parent f2d0179154
commit 25039efdeb
11 changed files with 392 additions and 252 deletions
+88 -82
View File
@@ -143,7 +143,7 @@ class GeneticAlgorithmManager {
const commissionIds = this.getSelectedCommissionIds();
if (commissionIds.length === 0) {
this.showAlert('Please select at least one commission to optimize.', 'warning');
this.showAlert('Por favor seleccione al menos una comisión para optimizar.', 'warning');
return;
}
@@ -153,12 +153,12 @@ class GeneticAlgorithmManager {
if (result.success) {
this.displayOptimizationResults(result.data);
this.showAlert('Optimization completed successfully!', 'success');
this.showAlert('¡Optimización de reservas completada con éxito!', 'success');
} else {
this.showAlert('Optimization failed: ' + (result.error || 'Unknown error'), 'danger');
this.showAlert('Fallo en la optimización: ' + (result.error || 'Error desconocido'), 'danger');
}
} catch (error) {
this.showAlert('Error during optimization: ' + error.message, 'danger');
this.showAlert('Error durante la optimización: ' + error.message, 'danger');
} finally {
this.showLoading(false);
}
@@ -169,7 +169,7 @@ class GeneticAlgorithmManager {
const commissionIds = this.getSelectedCommissionIds();
if (commissionIds.length === 0) {
this.showAlert('Please select at least one commission to preview.', 'warning');
this.showAlert('Por favor seleccione al menos una comisión para previsualizar.', 'warning');
return;
}
@@ -179,12 +179,12 @@ class GeneticAlgorithmManager {
if (result.success) {
this.displayPreviewResults(result.data);
this.showAlert('Preview generated successfully!', 'success');
this.showAlert('¡Previsualización generada con éxito!', 'success');
} else {
this.showAlert('Preview failed: ' + (result.error || 'Unknown error'), 'danger');
this.showAlert('Fallo en la previsualización: ' + (result.error || 'Error desconocido'), 'danger');
}
} catch (error) {
this.showAlert('Error during preview: ' + error.message, 'danger');
this.showAlert('Error durante la previsualización: ' + error.message, 'danger');
} finally {
this.showLoading(false);
}
@@ -195,11 +195,11 @@ class GeneticAlgorithmManager {
const pendingReservations = this.getPendingReservations();
if (!pendingReservations || pendingReservations.length === 0) {
this.showAlert('No pending reservations to apply.', 'warning');
this.showAlert('No hay reservas optimizadas pendientes de aplicar.', 'warning');
return;
}
if (!confirm('Are you sure you want to apply these reservations? This will create actual reservation records.')) {
if (!confirm('¿Está seguro de que desea aplicar estas asignaciones optimizadas? Se crearán las reservas definitivas en el sistema.')) {
return;
}
@@ -208,15 +208,15 @@ class GeneticAlgorithmManager {
const result = await this.applyOptimization(pendingReservations);
if (result.success) {
this.showAlert(`Successfully applied ${result.data.applied_count} reservations!`, 'success');
this.showAlert(`¡Se aplicaron con éxito ${result.data.applied_count} reservas en Bedelía!`, 'success');
this.clearPendingReservations();
// Redirect to reservations page
window.location.href = '/schedule';
// Redirigir al listado de reservas
window.location.href = '/schedule/list_reservations';
} else {
this.showAlert('Failed to apply reservations: ' + (result.error || 'Unknown error'), 'danger');
this.showAlert('Fallo al aplicar reservas: ' + (result.error || 'Error desconocido'), 'danger');
}
} catch (error) {
this.showAlert('Error applying reservations: ' + error.message, 'danger');
this.showAlert('Error al aplicar reservas: ' + error.message, 'danger');
} finally {
this.showLoading(false);
}
@@ -252,47 +252,53 @@ class GeneticAlgorithmManager {
const scorePercentage = (data.fitness_score * 100).toFixed(1);
resultsContainer.innerHTML = `
<div class="card">
<div class="card-header bg-success text-white">
<h5 class="mb-0">Optimization Results</h5>
<div class="card border-0 shadow-sm mb-4">
<div class="card-header bg-success text-white py-3">
<h5 class="mb-0 h6 fw-bold"><i class="bi bi-check-circle-fill me-2"></i>Resultados de la Optimización</h5>
</div>
<div class="card-body">
<div class="row mb-3">
<div class="card-body p-4">
<div class="row g-3 mb-4 text-center">
<div class="col-md-4">
<div class="text-center">
<h4 class="text-primary">${data.assigned_reservations}</h4>
<p class="mb-0">Reservations Assigned</p>
<div class="p-3 rounded bg-primary bg-opacity-10 border border-primary-subtle">
<h3 class="fw-bold text-primary mb-1">${data.assigned_reservations}</h3>
<p class="mb-0 text-muted small fw-semibold">Reservas Asignadas</p>
</div>
</div>
<div class="col-md-4">
<div class="text-center">
<h4 class="text-info">${scorePercentage}%</h4>
<p class="mb-0">Fitness Score</p>
<div class="p-3 rounded bg-info bg-opacity-10 border border-info-subtle">
<h3 class="fw-bold text-info mb-1">${scorePercentage}%</h3>
<p class="mb-0 text-muted small fw-semibold">Puntaje de Aptitud (Fitness)</p>
</div>
</div>
<div class="col-md-4">
<div class="text-center">
<h4 class="text-warning">${data.total_requests}</h4>
<p class="mb-0">Total Requests</p>
<div class="p-3 rounded bg-warning bg-opacity-10 border border-warning-subtle">
<h3 class="fw-bold text-warning mb-1">${data.total_requests}</h3>
<p class="mb-0 text-muted small fw-semibold">Total de Solicitudes</p>
</div>
</div>
</div>
${data.conflicts.length > 0 ? `
<div class="alert alert-warning">
<strong>Warning:</strong> ${data.conflicts.length} potential conflicts detected.
<div class="alert alert-warning d-flex align-items-center">
<i class="bi bi-exclamation-triangle-fill fs-5 me-2"></i>
<div><strong>Atención:</strong> Se detectaron ${data.conflicts.length} conflictos potenciales no resueltos.</div>
</div>
` : ''}
` : `
<div class="alert alert-success d-flex align-items-center">
<i class="bi bi-check-circle-fill fs-5 me-2"></i>
<div><strong>Excelente:</strong> ¡0 conflictos detectados! Todas las asignaciones cumplen aforo y disponibilidad.</div>
</div>
`}
<div class="d-flex gap-2">
<button class="btn btn-primary" onclick="geneticManager.viewReservationDetails()">
View Details
<div class="d-flex gap-2 flex-wrap">
<button class="btn btn-outline-primary" onclick="geneticManager.viewReservationDetails()">
<i class="bi bi-eye me-1"></i>Ver Detalle de Reservas
</button>
<button class="btn btn-success" onclick="geneticManager.handleApplyOptimization()">
Apply Reservations
<button class="btn btn-success fw-bold px-4" onclick="geneticManager.handleApplyOptimization()">
<i class="bi bi-check-circle me-1"></i>Aplicar Reservas en Bedelía
</button>
<button class="btn btn-secondary" onclick="geneticManager.clearResults()">
Clear
<button class="btn btn-outline-secondary" onclick="geneticManager.clearResults()">
<i class="bi bi-trash me-1"></i>Limpiar
</button>
</div>
</div>
@@ -306,30 +312,30 @@ class GeneticAlgorithmManager {
const commissionsHtml = data.commission_details.map(commission => `
<tr>
<td>${commission.code}</td>
<td class="font-monospace fw-bold text-primary">${commission.code}</td>
<td>${commission.name}</td>
<td>${commission.current_students}/${commission.max_students}</td>
<td><span class="badge bg-secondary">${commission.current_students || 0}/${commission.max_students}</span></td>
</tr>
`).join('');
const optimization = data.optimization_result;
previewContainer.innerHTML = `
<div class="card">
<div class="card-header bg-info text-white">
<h5 class="mb-0">Optimization Preview</h5>
<div class="card border-0 shadow-sm mb-4">
<div class="card-header bg-info text-white py-3">
<h5 class="mb-0 h6 fw-bold"><i class="bi bi-eye-fill me-2"></i>Previsualización de la Optimización</h5>
</div>
<div class="card-body">
<div class="row mb-4">
<div class="col-md-6">
<h6>Commissions to Optimize</h6>
<div class="table-responsive">
<table class="table table-sm">
<thead>
<div class="card-body p-4">
<div class="row g-4 mb-4">
<div class="col-md-7">
<h6 class="fw-bold text-muted text-uppercase small mb-2">Comisiones a Optimizar</h6>
<div class="table-responsive border rounded">
<table class="table table-hover table-sm mb-0">
<thead class="table-light">
<tr>
<th>Code</th>
<th>Name</th>
<th>Students</th>
<th>Código</th>
<th>Asignatura</th>
<th>Estudiantes</th>
</tr>
</thead>
<tbody>
@@ -338,20 +344,20 @@ class GeneticAlgorithmManager {
</table>
</div>
</div>
<div class="col-md-6">
<h6>Expected Results</h6>
<ul class="list-group">
<li class="list-group-item d-flex justify-content-between">
<span>Reservations Created:</span>
<strong>${optimization.assigned_reservations}</strong>
<div class="col-md-5">
<h6 class="fw-bold text-muted text-uppercase small mb-2">Resultados Estimados</h6>
<ul class="list-group shadow-sm">
<li class="list-group-item d-flex justify-content-between align-items-center py-2">
<span>Reservas Creadas:</span>
<strong class="text-primary font-monospace fs-6">${optimization.assigned_reservations}</strong>
</li>
<li class="list-group-item d-flex justify-content-between">
<span>Fitness Score:</span>
<strong>${(optimization.fitness_score * 100).toFixed(1)}%</strong>
<li class="list-group-item d-flex justify-content-between align-items-center py-2">
<span>Puntaje de Aptitud:</span>
<strong class="text-info font-monospace fs-6">${(optimization.fitness_score * 100).toFixed(1)}%</strong>
</li>
<li class="list-group-item d-flex justify-content-between">
<span>Conflicts:</span>
<strong class="${optimization.conflicts.length > 0 ? 'text-danger' : 'text-success'}">
<li class="list-group-item d-flex justify-content-between align-items-center py-2">
<span>Conflictos:</span>
<strong class="font-monospace fs-6 ${optimization.conflicts.length > 0 ? 'text-danger' : 'text-success'}">
${optimization.conflicts.length}
</strong>
</li>
@@ -361,10 +367,10 @@ class GeneticAlgorithmManager {
<div class="d-flex gap-2">
<button class="btn btn-primary" onclick="geneticManager.handleOptimizeReservations()">
Run Full Optimization
<i class="bi bi-play-circle me-1"></i>Ejecutar Optimización Completa
</button>
<button class="btn btn-secondary" onclick="geneticManager.clearPreview()">
Close Preview
<button class="btn btn-outline-secondary" onclick="geneticManager.clearPreview()">
<i class="bi bi-x-circle me-1"></i>Cerrar Previsualización
</button>
</div>
</div>
@@ -375,7 +381,7 @@ class GeneticAlgorithmManager {
viewReservationDetails() {
const reservations = this.getPendingReservations();
if (!reservations || reservations.length === 0) {
this.showAlert('No reservation details available.', 'info');
this.showAlert('No hay detalles de reserva disponibles.', 'info');
return;
}
@@ -383,11 +389,11 @@ class GeneticAlgorithmManager {
const detailsHtml = reservations.map((res, index) => `
<tr>
<td>${index + 1}</td>
<td>${res.purpose}</td>
<td>Classroom ${res.classroom_id}</td>
<td>${new Date(res.start_time).toLocaleString()}</td>
<td>${new Date(res.end_time).toLocaleString()}</td>
<td>${res.expected_attendees}</td>
<td>${res.purpose || 'Cursada Académica'}</td>
<td><span class="badge bg-primary">Aula ID ${res.classroom_id}</span></td>
<td class="small font-monospace">${new Date(res.start_time).toLocaleString('es-AR')}</td>
<td class="small font-monospace">${new Date(res.end_time).toLocaleString('es-AR')}</td>
<td><span class="badge bg-secondary">${res.expected_attendees || 0}</span></td>
</tr>
`).join('');
@@ -395,15 +401,15 @@ class GeneticAlgorithmManager {
if (modal) {
modal.querySelector('.modal-body').innerHTML = `
<div class="table-responsive">
<table class="table">
<thead>
<table class="table table-hover table-sm">
<thead class="table-light">
<tr>
<th>#</th>
<th>Purpose</th>
<th>Classroom</th>
<th>Start Time</th>
<th>End Time</th>
<th>Attendees</th>
<th>Propósito</th>
<th>Aula Asignada</th>
<th>Inicio</th>
<th>Fin</th>
<th>Asistentes</th>
</tr>
</thead>
<tbody>