Feat Visual en Producción
This commit is contained in:
		| @@ -2,7 +2,7 @@ | ||||
| import React from 'react'; | ||||
| import ReactDOM from 'react-dom/client'; | ||||
| import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||||
|  | ||||
| /* | ||||
| import { BancasWidget } from './features/legislativas/provinciales/BancasWidget' | ||||
| import { CongresoWidget } from './features/legislativas/provinciales/CongresoWidget' | ||||
| import MapaBsAs from './features/legislativas/provinciales/MapaBsAs' | ||||
| @@ -21,16 +21,22 @@ import { SenadoresPorSeccionWidget } from './features/legislativas/provinciales/ | ||||
| import { ConcejalesPorSeccionWidget } from './features/legislativas/provinciales/ConcejalesPorSeccionWidget' | ||||
| import { ResultadosTablaDetalladaWidget } from './features/legislativas/provinciales/ResultadosTablaDetalladaWidget'; | ||||
| import { ResultadosRankingMunicipioWidget } from './features/legislativas/provinciales/ResultadosRankingMunicipioWidget'; | ||||
| */ | ||||
| //import { DevApp } from './components/common/DevApp'; | ||||
|  | ||||
| import { HomeCarouselWidget } from './features/legislativas/nacionales/HomeCarouselWidget'; | ||||
| import { PanelNacionalWidget } from './features/legislativas/nacionales/PanelNacionalWidget'; | ||||
| import { ResultadosNacionalesCardsWidget } from './features/legislativas/nacionales/ResultadosNacionalesCardsWidget'; | ||||
|  | ||||
| import './index.css'; | ||||
| import { DevAppLegislativas } from './features/legislativas/DevAppLegislativas'; | ||||
|  | ||||
|  | ||||
| const queryClient = new QueryClient(); | ||||
|  | ||||
| // Mapeamos el nombre del widget (del atributo data) al componente de React | ||||
| const WIDGET_MAP: Record<string, React.ElementType> = { | ||||
|     'resumen-senadores': SenadoresWidget, | ||||
|     // Widgets Legislativas Provinciales BsAs 2025 | ||||
|     /*'resumen-senadores': SenadoresWidget, | ||||
|     'resumen-diputados': DiputadosWidget, | ||||
|     'resumen-concejales': ConcejalesWidget, | ||||
|     'congreso-provincial': CongresoWidget, | ||||
| @@ -47,7 +53,12 @@ const WIDGET_MAP: Record<string, React.ElementType> = { | ||||
|     'senadores-por-seccion': SenadoresPorSeccionWidget, | ||||
|     'concejales-por-seccion': ConcejalesPorSeccionWidget, | ||||
|     'resultados-tabla-detallada-por-seccion' : ResultadosTablaDetalladaWidget, | ||||
|     'resultados-tabla-detallada-por-municipio' : ResultadosRankingMunicipioWidget, | ||||
|     'resultados-tabla-detallada-por-municipio' : ResultadosRankingMunicipioWidget,*/ | ||||
|      | ||||
|     // Widgets Legislativas Nacionales 2025 | ||||
|     'home-carousel': HomeCarouselWidget, | ||||
|     'panel-nacional': PanelNacionalWidget, | ||||
|     'resultados-nacionales-cards': ResultadosNacionalesCardsWidget, | ||||
| }; | ||||
|  | ||||
| // Vite establece `import.meta.env.DEV` a `true` cuando ejecutamos 'npm run dev' | ||||
|   | ||||
| @@ -146,7 +146,7 @@ public class ResultadosController : ControllerBase | ||||
|         .Where(l => l.EleccionId == eleccionId || l.EleccionId == 0) // Trae los de la elección actual y los de fallback | ||||
|         .ToListAsync(); | ||||
|  | ||||
|         // --- LÓGICA DE AGRUPACIÓN Y CÁLCULO CORREGIDA --- | ||||
|         // --- LÓGICA DE AGRUPACIÓN Y CÁLCULO --- | ||||
|         var resultadosAgrupados = resultadosPorMunicipio | ||||
|         .GroupBy(r => r.CategoriaId) | ||||
|         .Select(g => new | ||||
| @@ -465,7 +465,6 @@ public class ResultadosController : ControllerBase | ||||
|  | ||||
|     private async Task<IActionResult> GetComposicionDesdeProyecciones(Dictionary<string, string> config, int eleccionId) | ||||
|     { | ||||
|         // --- INICIO DE LA CORRECCIÓN --- | ||||
|         // 1. Obtenemos el ID del ámbito provincial para usarlo en el filtro. | ||||
|         var provincia = await _dbContext.AmbitosGeograficos.AsNoTracking() | ||||
|             .FirstOrDefaultAsync(a => a.NivelId == 10); | ||||
| @@ -480,7 +479,6 @@ public class ResultadosController : ControllerBase | ||||
|                 Senadores = new { Partidos = new List<object>() } | ||||
|             }); | ||||
|         } | ||||
|         // --- FIN DE LA CORRECCIÓN --- | ||||
|  | ||||
|         var bancasPorAgrupacion = await _dbContext.ProyeccionesBancas | ||||
|             .AsNoTracking() | ||||
| @@ -490,7 +488,6 @@ public class ResultadosController : ControllerBase | ||||
|             { | ||||
|                 AgrupacionId = g.Key.AgrupacionPoliticaId, | ||||
|                 CategoriaId = g.Key.CategoriaId, | ||||
|                 // Ahora la suma es correcta porque solo considera los registros a nivel provincial | ||||
|                 BancasTotales = g.Sum(p => p.NroBancas) | ||||
|             }) | ||||
|             .ToListAsync(); | ||||
| @@ -618,16 +615,12 @@ public class ResultadosController : ControllerBase | ||||
|             return Ok(new { UltimaActualizacion = DateTime.UtcNow, Resultados = new List<object>() }); | ||||
|         } | ||||
|  | ||||
|         // --- INICIO DE LA CORRECCIÓN DE LOGOS --- | ||||
|  | ||||
|         // 1. Buscamos logos que sean para esta categoría Y que sean generales (ámbito null). | ||||
|         var logosGenerales = await _dbContext.LogosAgrupacionesCategorias | ||||
|             .AsNoTracking() | ||||
|             .Where(l => l.CategoriaId == categoriaId && l.AmbitoGeograficoId == null) | ||||
|             .ToDictionaryAsync(l => l.AgrupacionPoliticaId); | ||||
|  | ||||
|         // --- FIN DE LA CORRECCIÓN DE LOGOS --- | ||||
|  | ||||
|         var resultadosMunicipales = await _dbContext.ResultadosVotos | ||||
|             .AsNoTracking() | ||||
|             .Include(r => r.AgrupacionPolitica) | ||||
| @@ -687,7 +680,6 @@ public class ResultadosController : ControllerBase | ||||
|             .GroupBy(r => r.AmbitoGeografico.SeccionProvincialId) | ||||
|             .Select(g => | ||||
|             { | ||||
|                 // --- INICIO DE LA CORRECCIÓN --- | ||||
|                 // Para cada sección, encontramos al partido con más votos. | ||||
|                 var ganador = g | ||||
|                     // CAMBIO CLAVE: Agrupamos por el ID de la agrupación, no por el objeto. | ||||
| @@ -700,7 +692,6 @@ public class ResultadosController : ControllerBase | ||||
|                     }) | ||||
|                     .OrderByDescending(x => x.TotalVotos) | ||||
|                     .FirstOrDefault(); | ||||
|                 // --- FIN DE LA CORRECCIÓN --- | ||||
|  | ||||
|                 // Buscamos el nombre de la sección | ||||
|                 var seccionInfo = _dbContext.AmbitosGeograficos | ||||
| @@ -1243,8 +1234,6 @@ public class ResultadosController : ControllerBase | ||||
|     { | ||||
|         if (string.IsNullOrEmpty(distritoId)) | ||||
|         { | ||||
|             // --- VISTA NACIONAL (LÓGICA CORRECTA Y ROBUSTA) --- | ||||
|  | ||||
|             // PASO 1: Agrupar y sumar los votos por provincia y partido directamente en la BD. | ||||
|             // Esto crea una lista con los totales, que es mucho más pequeña que los datos crudos. | ||||
|             var votosAgregadosPorProvincia = await _dbContext.ResultadosVotos | ||||
| @@ -1285,7 +1274,7 @@ public class ResultadosController : ControllerBase | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             // --- VISTA PROVINCIAL (SIN CAMBIOS, YA ERA EFICIENTE) --- | ||||
|             // --- VISTA PROVINCIAL --- | ||||
|             var votosAgregadosPorMunicipio = await _dbContext.ResultadosVotos | ||||
|                 .AsNoTracking() | ||||
|                 .Where(r => r.EleccionId == eleccionId | ||||
| @@ -1462,12 +1451,8 @@ List<CandidatoOverride> overrides, string agrupacionId, int categoriaId, int? am | ||||
|     ?? logos.FirstOrDefault(l => l.EleccionId == 0 && l.AgrupacionPoliticaId == agrupacionId && l.CategoriaId == categoriaId && l.AmbitoGeograficoId == ambitoId) | ||||
|     // Prioridad 4: Coincidencia de Fallback por Categoría (Elección y Ámbito genéricos) | ||||
|     ?? logos.FirstOrDefault(l => l.EleccionId == 0 && l.AgrupacionPoliticaId == agrupacionId && l.CategoriaId == categoriaId && l.AmbitoGeograficoId == null) | ||||
|      | ||||
|     // --- INICIO DE LA CORRECCIÓN --- | ||||
|     // Prioridad 5: LOGO GLOBAL. Coincidencia solo por Partido (Elección y Categoría genéricas) | ||||
|     // Se busca EleccionId = 0 y CategoriaId = 0 (en lugar de null) para que coincida con la lógica de los otros widgets. | ||||
|     ?? logos.FirstOrDefault(l => l.EleccionId == 0 && l.AgrupacionPoliticaId == agrupacionId && l.CategoriaId == 0 && l.AmbitoGeograficoId == null); | ||||
|     // --- FIN DE LA CORRECCIÓN --- | ||||
| } | ||||
|  | ||||
|     [HttpGet("resumen-por-provincia")] | ||||
| @@ -1483,8 +1468,6 @@ List<CandidatoOverride> overrides, string agrupacionId, int categoriaId, int? am | ||||
|         const int catSenadoresNac = 1; | ||||
|  | ||||
|         var provinciasQueRenuevanSenadores = new HashSet<string> { "01", "06", "08", "15", "16", "17", "22", "23" }; | ||||
|  | ||||
|         // --- CORRECCIÓN FINAL: Simplificar la carga de datos de soporte --- | ||||
|         var todasLasProyecciones = await _dbContext.ProyeccionesBancas.AsNoTracking().Where(p => p.EleccionId == eleccionId && (p.CategoriaId == catDiputadosNac || p.CategoriaId == catSenadoresNac)).ToDictionaryAsync(p => p.AmbitoGeograficoId + "_" + p.AgrupacionPoliticaId + "_" + p.CategoriaId); | ||||
|         var todosLosOverrides = await _dbContext.CandidatosOverrides.AsNoTracking().Where(c => c.EleccionId == eleccionId || c.EleccionId == 0).ToListAsync(); | ||||
|         var todosLosLogos = await _dbContext.LogosAgrupacionesCategorias.AsNoTracking().Where(l => l.EleccionId == eleccionId || l.EleccionId == 0).ToListAsync(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user