feat: redesign lateral menu aesthetics, add campus weather and enrich UdeCi capabilities (v3.8.34)
This commit is contained in:
@@ -18,8 +18,10 @@ from app.models.reservation import Reservation
|
||||
from app.models.enrollment import StudentEnrollment
|
||||
from app.models.milestone import AcademicMilestone, MilestoneType
|
||||
from app.models.grade import MilestoneGrade
|
||||
from app import db
|
||||
from app.models.user import User
|
||||
from app.services.gradebook_service import GradebookService
|
||||
from app.services.weather_service import WeatherService
|
||||
|
||||
|
||||
SPANISH_WEEKDAYS = {
|
||||
@@ -442,33 +444,12 @@ class LiveContextService:
|
||||
else:
|
||||
lines.append("COMISIONES: No registras comisiones asignadas como docente titular ni adjunto en el ciclo actual.")
|
||||
|
||||
elif effective_role == "bedelia":
|
||||
lines.append("\n--- BALANCE OPERATIVO DE BEDELÍA (HOY) ---")
|
||||
total_res_today = (
|
||||
Reservation.query
|
||||
.filter(
|
||||
Reservation.start_time >= start_of_day,
|
||||
Reservation.start_time <= end_of_day,
|
||||
Reservation.status != 'CANCELLED'
|
||||
)
|
||||
.count()
|
||||
)
|
||||
pending_res = (
|
||||
Reservation.query
|
||||
.filter(Reservation.status == 'PENDING')
|
||||
.count()
|
||||
)
|
||||
active_commissions_cnt = Commission.query.filter_by(active=True).count()
|
||||
total_subjects_cnt = Subject.query.filter_by(is_active=True).count()
|
||||
|
||||
lines.append(f"- Reservas programadas para hoy: {total_res_today}")
|
||||
lines.append(f"- Reservas pendientes de confirmación: {pending_res}")
|
||||
lines.append(f"- Comisiones activas en el sistema: {active_commissions_cnt}")
|
||||
lines.append(f"- Asignaturas activas: {total_subjects_cnt}")
|
||||
|
||||
elif effective_role == "admin":
|
||||
lines.append("\n--- GOBIERNO Y ESTADÍSTICAS DEL SISTEMA ---")
|
||||
elif effective_role in ("bedelia", "admin"):
|
||||
is_admin = effective_role == "admin"
|
||||
header_title = "GOBIERNO Y ESTADÍSTICAS DEL SISTEMA" if is_admin else "BALANCE OPERATIVO DE BEDELÍA"
|
||||
lines.append(f"\n--- {header_title} ---")
|
||||
try:
|
||||
# Totales de usuarios
|
||||
total_users = User.query.filter_by(is_active=True).count()
|
||||
alumnos_cnt = User.query.filter(User.is_active == True, func.lower(User.role).like('%alumn%')).count()
|
||||
docentes_cnt = User.query.filter(User.is_active == True, func.lower(User.role).like('%docent%')).count()
|
||||
@@ -479,14 +460,77 @@ class LiveContextService:
|
||||
f"USUARIOS ACTIVOS ({total_users}): {alumnos_cnt} Alumnos | {docentes_cnt} Docentes | "
|
||||
f"{bedelia_cnt} Bedelía | {admin_cnt} Administradores"
|
||||
)
|
||||
|
||||
# Comisiones y Asignaciones
|
||||
active_comms = Commission.query.filter_by(active=True).all()
|
||||
unassigned_teacher = [c for c in active_comms if not c.teacher_id and (not c.teachers or len(c.teachers) == 0)]
|
||||
unassigned_teacher_cnt = len(unassigned_teacher)
|
||||
|
||||
# Cuál es la comisión que más alumnos tiene
|
||||
enr_counts = (
|
||||
db.session.query(StudentEnrollment.commission_id, func.count(StudentEnrollment.id))
|
||||
.filter_by(status='activo')
|
||||
.group_by(StudentEnrollment.commission_id)
|
||||
.order_by(func.count(StudentEnrollment.id).desc())
|
||||
.all()
|
||||
)
|
||||
top_comm_str = "No hay comisiones con alumnos inscriptos actualmente."
|
||||
if enr_counts:
|
||||
top_cid, top_qty = enr_counts[0]
|
||||
top_c = Commission.query.get(top_cid)
|
||||
if top_c:
|
||||
subj_n = top_c.subject.name if top_c.subject else top_c.code
|
||||
top_comm_str = f"{subj_n} (Comisión {top_c.code}) con {top_qty} alumnos inscriptos"
|
||||
elif active_comms:
|
||||
top_c = max(active_comms, key=lambda c: (c.current_students or 0), default=None)
|
||||
if top_c:
|
||||
subj_n = top_c.subject.name if top_c.subject else top_c.code
|
||||
top_comm_str = f"{subj_n} (Comisión {top_c.code}) con {top_c.current_students or 0} alumnos"
|
||||
|
||||
lines.append(f"- Comisiones activas: {len(active_comms)}")
|
||||
lines.append(f"- Comisiones sin docente asignado: {unassigned_teacher_cnt}")
|
||||
if unassigned_teacher:
|
||||
sample_un = [f"{c.subject.name if c.subject else c.code} ({c.code})" for c in unassigned_teacher[:3]]
|
||||
lines.append(f" (Sin docente asignado: {', '.join(sample_un)})")
|
||||
lines.append(f"- Comisión con más alumnos: {top_comm_str}")
|
||||
|
||||
# Reservas
|
||||
total_res_today = (
|
||||
Reservation.query
|
||||
.filter(
|
||||
Reservation.start_time >= start_of_day,
|
||||
Reservation.start_time <= end_of_day,
|
||||
Reservation.status != 'CANCELLED'
|
||||
)
|
||||
.count()
|
||||
)
|
||||
pending_res_list = (
|
||||
Reservation.query
|
||||
.filter(Reservation.status == 'PENDING')
|
||||
.order_by(Reservation.start_time.asc())
|
||||
.limit(5)
|
||||
.all()
|
||||
)
|
||||
pending_cnt = Reservation.query.filter(Reservation.status == 'PENDING').count()
|
||||
lines.append(f"- Reservas programadas para hoy: {total_res_today}")
|
||||
lines.append(f"- Reservas pendientes de confirmación: {pending_cnt}")
|
||||
if pending_res_list:
|
||||
lines.append("DETALLE DE RESERVAS PENDIENTES:")
|
||||
for pr in pending_res_list:
|
||||
p_date = pr.start_time.strftime("%d/%m/%Y")
|
||||
p_time = f"{pr.start_time.strftime('%H:%M')} a {pr.end_time.strftime('%H:%M')}"
|
||||
solicitor = pr.user.name if pr.user else "Docente"
|
||||
room_desc = pr.classroom.location_display if pr.classroom else "Aula solicitada"
|
||||
lines.append(f"• ID {pr.id}: {pr.subject_name} ({p_date} {p_time} hs en {room_desc}) - Solicitó: {solicitor}")
|
||||
|
||||
lines.append(
|
||||
f"TOTALES ACADÉMICOS: {Career.query.count()} Carreras | "
|
||||
f"{Subject.query.filter_by(is_active=True).count()} Asignaturas | "
|
||||
f"{Commission.query.filter_by(active=True).count()} Comisiones | "
|
||||
f"{len(active_comms)} Comisiones | "
|
||||
f"{Classroom.query.filter_by(is_active=True).count()} Aulas"
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
lines.append(f"ESTADÍSTICAS OPERATIVAS: Consulta parcial ({str(e)}).")
|
||||
|
||||
except Exception as e:
|
||||
lines.append(f"DETALLE DE ROL: Error consultando datos específicos ({str(e)}).")
|
||||
@@ -496,15 +540,57 @@ class LiveContextService:
|
||||
# ---------------------------------------------------------
|
||||
if query and len(query.strip()) >= 3:
|
||||
try:
|
||||
q_lower = query.lower()
|
||||
|
||||
# A. Consulta de Clima, Ubicación o Cómo llegar a la Universidad
|
||||
weather_keywords = [
|
||||
'clima', 'temperatura', 'tiempo', 'llueve', 'lluvia', 'frio', 'calor',
|
||||
'grados', 'caba', 'pronostico', 'llegar', 'donde queda', 'ubicacion',
|
||||
'direccion', 'como llego', 'maps', 'mapa', 'tardo', 'distancia'
|
||||
]
|
||||
if any(w in q_lower for w in weather_keywords):
|
||||
w_info = WeatherService.get_university_weather()
|
||||
lines.append("\nCLIMA ACTUAL Y UBICACIÓN DE UNICABA:")
|
||||
lines.append(f"• Sede Central: {w_info['campus']} ({w_info['address']})")
|
||||
lines.append(f"• Clima actual en CABA: {w_info['summary']}")
|
||||
lines.append(f"• Cómo llegar en Google Maps: [Calcular ruta a UniCABA]({w_info['maps_url']})")
|
||||
lines.append("• Transporte público cercano: Subte B (Estación Florida), Subte D (Estación 9 de Julio / Diagonal Norte), Metrobus 9 de Julio.")
|
||||
|
||||
tokens = [
|
||||
w for w in re.findall(r'[a-zA-Z0-9áéíóúñÁÉÍÓÚÑ]+', query.lower())
|
||||
w for w in re.findall(r'[a-zA-Z0-9áéíóúñÁÉÍÓÚÑ]+', q_lower)
|
||||
if len(w) >= 3 and w not in {
|
||||
'donde', 'como', 'cuando', 'para', 'hola', 'buenas', 'cursar',
|
||||
'materia', 'materias', 'clase', 'clases', 'aula', 'aulas', 'que', 'cual'
|
||||
'materia', 'materias', 'clase', 'clases', 'aula', 'aulas', 'que', 'cual',
|
||||
'esta', 'estan', 'unos', 'algunos', 'ellos', 'tiene'
|
||||
}
|
||||
]
|
||||
|
||||
# B. Búsqueda de Docentes / Profesores por Nombre
|
||||
teacher_keywords = ['profesor', 'profesores', 'docente', 'docentes', 'llama', 'nombre', 'sergio']
|
||||
if any(w in q_lower for w in teacher_keywords) or any(len(tok) >= 4 for tok in tokens):
|
||||
all_docentes = User.query.filter(User.is_active == True, func.lower(User.role).like('%docent%')).all()
|
||||
meaningful_tokens = [
|
||||
tok for tok in tokens
|
||||
if tok not in {'profesor', 'profesores', 'docente', 'docentes', 'llamado', 'alguno', 'estan', 'registrados', 'cuantos', 'cual', 'quien', 'nombre'}
|
||||
]
|
||||
if meaningful_tokens:
|
||||
found_teachers = []
|
||||
for d in all_docentes:
|
||||
d_full = f"{d.name or ''} {d.first_name or ''} {d.last_name or ''}".lower()
|
||||
if any(mt in d_full for mt in meaningful_tokens):
|
||||
found_teachers.append(d)
|
||||
if found_teachers:
|
||||
lines.append("\nDOCENTES COINCIDENTES ENCONTRADOS:")
|
||||
for fd in found_teachers[:5]:
|
||||
c_list = [c.code for c in fd.taught_commissions if c.active]
|
||||
c_str = f"Comisiones: {', '.join(c_list)}" if c_list else "Sin comisiones activas"
|
||||
lines.append(f"• {fd.name} ({fd.email}) | {c_str}")
|
||||
elif any(len(mt) >= 4 for mt in meaningful_tokens):
|
||||
searched_name = meaningful_tokens[0].capitalize()
|
||||
lines.append(f"\nBÚSQUEDA DE DOCENTES: No se encontraron profesores registrados con el nombre '{searched_name}' entre los {len(all_docentes)} docentes activos.")
|
||||
|
||||
# C. Búsqueda de Asignaturas
|
||||
if tokens:
|
||||
# Buscar asignaturas coincidentes
|
||||
search_filter = or_(
|
||||
*[Subject.name.ilike(f"%{tok}%") for tok in tokens],
|
||||
*[Subject.code.ilike(f"%{tok}%") for tok in tokens]
|
||||
@@ -525,7 +611,7 @@ class LiveContextService:
|
||||
t_str = f"Prof: {sc.teacher_name}" if sc.teacher else "Docente a designar"
|
||||
lines.append(f" - Comisión {sc.code}: {sc.schedule or 'Horario a confirmar'} ({t_str})")
|
||||
|
||||
# Buscar aulas coincidentes si se menciona un código o número
|
||||
# D. Búsqueda de Aulas
|
||||
classroom_tokens = [w for w in tokens if w.isdigit() or 'lab' in w or 'virtual' in w]
|
||||
if classroom_tokens:
|
||||
c_filter = or_(*[Classroom.code.ilike(f"%{tok}%") for tok in classroom_tokens])
|
||||
|
||||
Reference in New Issue
Block a user