Feat Widget Tabla de Resultados Por Seccion
This commit is contained in:
@@ -16,6 +16,7 @@ import { ConcejalesTickerWidget } from './components/ConcejalesTickerWidget'
|
|||||||
import { DiputadosPorSeccionWidget } from './components/DiputadosPorSeccionWidget'
|
import { DiputadosPorSeccionWidget } from './components/DiputadosPorSeccionWidget'
|
||||||
import { SenadoresPorSeccionWidget } from './components/SenadoresPorSeccionWidget'
|
import { SenadoresPorSeccionWidget } from './components/SenadoresPorSeccionWidget'
|
||||||
import { ConcejalesPorSeccionWidget } from './components/ConcejalesPorSeccionWidget'
|
import { ConcejalesPorSeccionWidget } from './components/ConcejalesPorSeccionWidget'
|
||||||
|
import { ResultadosTablaDetalladaWidget } from './components/ResultadosTablaDetalladaWidget'
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
@@ -53,6 +54,8 @@ function App() {
|
|||||||
<MapaBsAsSecciones />
|
<MapaBsAsSecciones />
|
||||||
<hr className="border-gray-300" />
|
<hr className="border-gray-300" />
|
||||||
<TelegramaWidget />
|
<TelegramaWidget />
|
||||||
|
<hr className="border-gray-300" />
|
||||||
|
<ResultadosTablaDetalladaWidget />
|
||||||
</main>
|
</main>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// src/apiService.ts
|
// src/apiService.ts
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import type { ProyeccionBancas, MunicipioSimple, TelegramaData, CatalogoItem, CategoriaResumen, ResultadoTicker, ApiResponseResultadosPorSeccion } from './types/types';
|
import type { ApiResponseRankingSeccion, ApiResponseTablaDetallada, ProyeccionBancas, MunicipioSimple, TelegramaData, CatalogoItem, CategoriaResumen, ResultadoTicker, ApiResponseResultadosPorSeccion } from './types/types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL base para las llamadas a la API.
|
* URL base para las llamadas a la API.
|
||||||
@@ -191,3 +191,13 @@ export const getSeccionesElectoralesConCargos = async (): Promise<MunicipioSimpl
|
|||||||
const { data } = await apiClient.get<MunicipioSimple[]>('/resultados/secciones-electorales-con-cargos');
|
const { data } = await apiClient.get<MunicipioSimple[]>('/resultados/secciones-electorales-con-cargos');
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getResultadosTablaDetallada = async (seccionId: string): Promise<ApiResponseTablaDetallada> => {
|
||||||
|
const { data } = await apiClient.get(`/resultados/tabla-ranking-seccion/${seccionId}`);
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getRankingResultadosPorSeccion = async (seccionId: string): Promise<ApiResponseRankingSeccion> => {
|
||||||
|
const { data } = await apiClient.get(`/resultados/ranking-por-seccion/${seccionId}`);
|
||||||
|
return data;
|
||||||
|
};
|
||||||
@@ -15,8 +15,10 @@ import { ConcejalesTickerWidget } from './ConcejalesTickerWidget'
|
|||||||
import { DiputadosPorSeccionWidget } from './DiputadosPorSeccionWidget'
|
import { DiputadosPorSeccionWidget } from './DiputadosPorSeccionWidget'
|
||||||
import { SenadoresPorSeccionWidget } from './SenadoresPorSeccionWidget'
|
import { SenadoresPorSeccionWidget } from './SenadoresPorSeccionWidget'
|
||||||
import { ConcejalesPorSeccionWidget } from './ConcejalesPorSeccionWidget'
|
import { ConcejalesPorSeccionWidget } from './ConcejalesPorSeccionWidget'
|
||||||
|
import { ResultadosTablaDetalladaWidget } from './ResultadosTablaDetalladaWidget'
|
||||||
import '../App.css';
|
import '../App.css';
|
||||||
|
|
||||||
|
|
||||||
export const DevApp = () => {
|
export const DevApp = () => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -40,6 +42,7 @@ export const DevApp = () => {
|
|||||||
<MapaBsAs />
|
<MapaBsAs />
|
||||||
<MapaBsAsSecciones />
|
<MapaBsAsSecciones />
|
||||||
<TelegramaWidget />
|
<TelegramaWidget />
|
||||||
|
<ResultadosTablaDetalladaWidget />
|
||||||
</main>
|
</main>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,108 @@
|
|||||||
|
import { useState, useMemo, useEffect } from 'react';
|
||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import Select from 'react-select';
|
||||||
|
import { getSeccionesElectorales, getResultadosTablaDetallada } from '../apiService';
|
||||||
|
import type { MunicipioSimple, ApiResponseTablaDetallada } from '../types/types';
|
||||||
|
import './ResultadosTablaSeccionWidget.css';
|
||||||
|
|
||||||
|
const customSelectStyles = {
|
||||||
|
control: (base: any) => ({ ...base, minWidth: '200px', border: '1px solid #ced4da', boxShadow: 'none', '&:hover': { borderColor: '#86b7fe' } }),
|
||||||
|
menu: (base: any) => ({ ...base, zIndex: 10 }),
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatPercent = (porcentaje: number) => `${porcentaje.toFixed(2).replace('.', ',')}%`;
|
||||||
|
|
||||||
|
export const ResultadosTablaDetalladaWidget = () => {
|
||||||
|
const [secciones, setSecciones] = useState<MunicipioSimple[]>([]);
|
||||||
|
const [selectedSeccion, setSelectedSeccion] = useState<{ value: string; label: string } | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchSecciones = async () => {
|
||||||
|
const seccionesData = await getSeccionesElectorales();
|
||||||
|
if (seccionesData && seccionesData.length > 0) {
|
||||||
|
const orden = new Map([
|
||||||
|
['Capital', 0], ['Primera', 1], ['Segunda', 2], ['Tercera', 3],
|
||||||
|
['Cuarta', 4], ['Quinta', 5], ['Sexta', 6], ['Séptima', 7]
|
||||||
|
]);
|
||||||
|
const getOrden = (nombre: string) => {
|
||||||
|
const match = nombre.match(/Capital|Primera|Segunda|Tercera|Cuarta|Quinta|Sexta|Séptima/);
|
||||||
|
return match ? orden.get(match[0]) ?? 99 : 99;
|
||||||
|
};
|
||||||
|
seccionesData.sort((a, b) => getOrden(a.nombre) - getOrden(b.nombre));
|
||||||
|
setSecciones(seccionesData);
|
||||||
|
if (!selectedSeccion) {
|
||||||
|
setSelectedSeccion({ value: seccionesData[0].id, label: seccionesData[0].nombre });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fetchSecciones();
|
||||||
|
}, [selectedSeccion]);
|
||||||
|
|
||||||
|
const seccionOptions = useMemo(() => secciones.map(s => ({ value: s.id, label: s.nombre })), [secciones]);
|
||||||
|
|
||||||
|
const { data: tablaData, isLoading } = useQuery<ApiResponseTablaDetallada>({
|
||||||
|
queryKey: ['resultadosTablaDetallada', selectedSeccion?.value],
|
||||||
|
queryFn: () => getResultadosTablaDetallada(selectedSeccion!.value),
|
||||||
|
enabled: !!selectedSeccion,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="tabla-resultados-widget">
|
||||||
|
<div className="tabla-header">
|
||||||
|
<h3>Resultados por Sección Electoral</h3>
|
||||||
|
<Select
|
||||||
|
options={seccionOptions}
|
||||||
|
value={selectedSeccion}
|
||||||
|
onChange={(option) => setSelectedSeccion(option)}
|
||||||
|
isLoading={secciones.length === 0}
|
||||||
|
styles={customSelectStyles}
|
||||||
|
isSearchable={false}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tabla-container">
|
||||||
|
{isLoading ? <p>Cargando...</p> : !tablaData || tablaData.categorias.length === 0 ? <p>No hay datos disponibles.</p> : (
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th rowSpan={2} className="sticky-col municipio-header">Municipio</th>
|
||||||
|
{tablaData.categorias.map(cat => (
|
||||||
|
<th key={cat.id} colSpan={tablaData.partidosPorCategoria[cat.id]?.length || 1} className="categoria-header">
|
||||||
|
{cat.nombre}
|
||||||
|
</th>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
{tablaData.categorias.flatMap(cat =>
|
||||||
|
(tablaData.partidosPorCategoria[cat.id] || []).map(partido => (
|
||||||
|
<th key={`header-${cat.id}-${partido.id}`} className="partido-header">
|
||||||
|
<span>{partido.puesto}° {partido.nombre}</span>
|
||||||
|
<span className="porcentaje-total">{formatPercent(partido.porcentajeTotalSeccion)}</span>
|
||||||
|
</th>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{tablaData.resultadosPorMunicipio.map(municipio => (
|
||||||
|
<tr key={municipio.municipioId}>
|
||||||
|
<td className="sticky-col">{municipio.municipioNombre}</td>
|
||||||
|
{tablaData.categorias.flatMap(cat =>
|
||||||
|
(tablaData.partidosPorCategoria[cat.id] || []).map(partido => {
|
||||||
|
const porcentaje = municipio.celdas[cat.id]?.[partido.id];
|
||||||
|
return (
|
||||||
|
<td key={`${municipio.municipioId}-${cat.id}-${partido.id}`}>
|
||||||
|
{typeof porcentaje === 'number' ? formatPercent(porcentaje) : '-'}
|
||||||
|
</td>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
)}
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
/* ==========================================================================
|
||||||
|
ResultadosTablaSeccionWidget.css
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
.tabla-resultados-widget {
|
||||||
|
font-family: 'Roboto', sans-serif;
|
||||||
|
background-color: #ffffff;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 16px 20px;
|
||||||
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
|
||||||
|
border: 1px solid #e9ecef;
|
||||||
|
color: #333;
|
||||||
|
max-width: 100%;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabla-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
padding-bottom: 16px;
|
||||||
|
border-bottom: 1px solid #dee2e6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabla-header h3 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 1.25rem;
|
||||||
|
color: #212529;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabla-container {
|
||||||
|
width: 100%;
|
||||||
|
overflow-x: auto;
|
||||||
|
border: 1px solid #dee2e6;
|
||||||
|
border-radius: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabla-container table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --- Cabeceras (THEAD) --- */
|
||||||
|
.tabla-container thead th {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #495057;
|
||||||
|
padding: 12px 10px;
|
||||||
|
text-align: center; /* Centramos las cabeceras */
|
||||||
|
text-transform: uppercase;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
white-space: nowrap;
|
||||||
|
border-bottom: 2px solid #adb5bd; /* Línea inferior más gruesa */
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabla-container th.municipio-header {
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabla-container th.categoria-header {
|
||||||
|
border-bottom: 1px solid #dee2e6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabla-container th.partido-header {
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
text-transform: none;
|
||||||
|
white-space: normal;
|
||||||
|
line-height: 1.2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabla-container th.partido-header span {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabla-container th.partido-header .porcentaje-total {
|
||||||
|
font-weight: 700;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
color: #212529;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Línea divisoria vertical para las categorías */
|
||||||
|
.tabla-container thead th[colspan] {
|
||||||
|
border-right: 1px solid #ced4da;
|
||||||
|
}
|
||||||
|
.tabla-container thead th:last-child {
|
||||||
|
border-right: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --- Cuerpo de la Tabla (TBODY) --- */
|
||||||
|
.tabla-container tbody td {
|
||||||
|
padding: 10px 12px;
|
||||||
|
border-bottom: 1px solid #e9ecef;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabla-container tbody tr:last-child td {
|
||||||
|
border-bottom: none; /* Quita la línea de la última fila */
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabla-container tbody tr:nth-of-type(even) {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabla-container tbody tr:hover {
|
||||||
|
background-color: #e9ecef;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Primera columna (Municipios) */
|
||||||
|
.tabla-container td:first-child {
|
||||||
|
font-weight: 500;
|
||||||
|
color: #212529;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Columnas de porcentajes */
|
||||||
|
.tabla-container td:not(:first-child) {
|
||||||
|
text-align: left; /* Opcional: puedes poner 'center' si prefieres */
|
||||||
|
font-size: 0.85rem; /* Un poco más pequeño para que entre bien */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Línea divisoria vertical para las celdas de datos */
|
||||||
|
.tabla-container tbody td.category-divider {
|
||||||
|
border-right: 1px solid #ced4da;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Estilos para la columna fija (Sticky) */
|
||||||
|
.tabla-container th.sticky-col,
|
||||||
|
.tabla-container td.sticky-col {
|
||||||
|
position: sticky;
|
||||||
|
left: 0;
|
||||||
|
background-color: #ffffff; /* Fondo blanco para que tape el contenido */
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
.tabla-container thead th.sticky-col {
|
||||||
|
background-color: #f8f9fa; /* Mismo color que el resto de la cabecera */
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
.tabla-container tbody tr:nth-of-type(even) td.sticky-col {
|
||||||
|
background-color: #f8f9fa; /* Para que coincida con el fondo de la fila */
|
||||||
|
}
|
||||||
@@ -19,9 +19,10 @@ import { ConcejalesTickerWidget } from './components/ConcejalesTickerWidget'
|
|||||||
import { DiputadosPorSeccionWidget } from './components/DiputadosPorSeccionWidget'
|
import { DiputadosPorSeccionWidget } from './components/DiputadosPorSeccionWidget'
|
||||||
import { SenadoresPorSeccionWidget } from './components/SenadoresPorSeccionWidget'
|
import { SenadoresPorSeccionWidget } from './components/SenadoresPorSeccionWidget'
|
||||||
import { ConcejalesPorSeccionWidget } from './components/ConcejalesPorSeccionWidget'
|
import { ConcejalesPorSeccionWidget } from './components/ConcejalesPorSeccionWidget'
|
||||||
|
import { ResultadosTablaDetalladaWidget } from './components/ResultadosTablaDetalladaWidget';
|
||||||
import './index.css';
|
|
||||||
import { DevApp } from './components/DevApp';
|
import { DevApp } from './components/DevApp';
|
||||||
|
import './index.css';
|
||||||
|
|
||||||
|
|
||||||
const queryClient = new QueryClient();
|
const queryClient = new QueryClient();
|
||||||
|
|
||||||
@@ -43,6 +44,7 @@ const WIDGET_MAP: Record<string, React.ElementType> = {
|
|||||||
'diputados-por-seccion': DiputadosPorSeccionWidget,
|
'diputados-por-seccion': DiputadosPorSeccionWidget,
|
||||||
'senadores-por-seccion': SenadoresPorSeccionWidget,
|
'senadores-por-seccion': SenadoresPorSeccionWidget,
|
||||||
'concejales-por-seccion': ConcejalesPorSeccionWidget,
|
'concejales-por-seccion': ConcejalesPorSeccionWidget,
|
||||||
|
'resultados-tabla-detallada-por-seccion' : ResultadosTablaDetalladaWidget,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Vite establece `import.meta.env.DEV` a `true` cuando ejecutamos 'npm run dev'
|
// Vite establece `import.meta.env.DEV` a `true` cuando ejecutamos 'npm run dev'
|
||||||
|
|||||||
@@ -111,3 +111,96 @@ export interface ApiResponseResultadosPorSeccion {
|
|||||||
ultimaActualizacion: string;
|
ultimaActualizacion: string;
|
||||||
resultados: ResultadoTicker[];
|
resultados: ResultadoTicker[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ResultadoTablaAgrupacion {
|
||||||
|
id: string;
|
||||||
|
nombre: string;
|
||||||
|
nombreCorto: string | null;
|
||||||
|
porcentaje: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ResultadoTablaCategoria {
|
||||||
|
categoriaId: number;
|
||||||
|
categoriaNombre: string;
|
||||||
|
resultados: ResultadoTablaAgrupacion[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TablaDetalladaPartidoPrincipal {
|
||||||
|
id: string;
|
||||||
|
nombre: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TablaDetalladaResultadoPartido {
|
||||||
|
id: string;
|
||||||
|
porcentaje: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TablaDetalladaResultadoCategoria {
|
||||||
|
categoriaId: number;
|
||||||
|
partidos: TablaDetalladaResultadoPartido[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TablaDetalladaResultadoMunicipio {
|
||||||
|
municipioId: number;
|
||||||
|
municipioNombre: string;
|
||||||
|
resultadosPorCategoria: TablaDetalladaResultadoCategoria[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PartidoPrincipalDetalle {
|
||||||
|
puesto: number;
|
||||||
|
id: string;
|
||||||
|
nombre: string;
|
||||||
|
porcentajeTotalSeccion: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiResponseTablaDetallada {
|
||||||
|
categorias: { id: number; nombre: string }[];
|
||||||
|
partidosPorCategoria: { [catId: string]: PartidoPrincipalDetalle[] };
|
||||||
|
resultadosPorMunicipio: {
|
||||||
|
municipioId: number;
|
||||||
|
municipioNombre: string;
|
||||||
|
celdas: { [catId: string]: { [partidoId: string]: number } };
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TablaDetalladaPartidoPrincipal {
|
||||||
|
id: string;
|
||||||
|
nombre: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TablaDetalladaResultadoPartido {
|
||||||
|
id: string;
|
||||||
|
porcentaje: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TablaDetalladaResultadoCategoria {
|
||||||
|
categoriaId: number;
|
||||||
|
partidos: TablaDetalladaResultadoPartido[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TablaDetalladaResultadoMunicipio {
|
||||||
|
municipioId: number;
|
||||||
|
municipioNombre: string;
|
||||||
|
resultadosPorCategoria: TablaDetalladaResultadoCategoria[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RankingPartido {
|
||||||
|
nombreCorto: string;
|
||||||
|
porcentaje: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RankingCategoria {
|
||||||
|
categoriaId: number;
|
||||||
|
ranking: RankingPartido[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RankingMunicipio {
|
||||||
|
municipioId: number;
|
||||||
|
municipioNombre: string;
|
||||||
|
resultadosPorCategoria: RankingCategoria[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiResponseRankingSeccion {
|
||||||
|
categorias: { id: number; nombre: string }[];
|
||||||
|
resultados: RankingMunicipio[];
|
||||||
|
}
|
||||||
@@ -773,4 +773,105 @@ public class ResultadosController : ControllerBase
|
|||||||
|
|
||||||
return Ok(resultado);
|
return Ok(resultado);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// En src/Elecciones.Api/Controllers/ResultadosController.cs
|
||||||
|
|
||||||
|
[HttpGet("tabla-ranking-seccion/{seccionId}")]
|
||||||
|
public async Task<IActionResult> GetTablaRankingPorSeccion(string seccionId)
|
||||||
|
{
|
||||||
|
// 1. Obtener los ámbitos de los municipios de la sección
|
||||||
|
var municipios = await _dbContext.AmbitosGeograficos.AsNoTracking()
|
||||||
|
.Where(a => a.NivelId == 30 && a.SeccionProvincialId == seccionId)
|
||||||
|
.OrderBy(a => a.Nombre).Select(a => new { a.Id, a.Nombre }).ToListAsync();
|
||||||
|
|
||||||
|
if (!municipios.Any())
|
||||||
|
{
|
||||||
|
return Ok(new
|
||||||
|
{
|
||||||
|
Categorias = new List<object>(),
|
||||||
|
PartidosPrincipales = new Dictionary<int, List<object>>(),
|
||||||
|
ResultadosPorMunicipio = new List<object>()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var municipiosIds = municipios.Select(m => m.Id).ToList();
|
||||||
|
|
||||||
|
// 2. Obtener todos los resultados de votos para esos municipios en una sola consulta
|
||||||
|
var resultadosCrudos = await _dbContext.ResultadosVotos.AsNoTracking()
|
||||||
|
.Include(r => r.AgrupacionPolitica)
|
||||||
|
.Where(r => municipiosIds.Contains(r.AmbitoGeograficoId))
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
var categoriasMap = await _dbContext.CategoriasElectorales.AsNoTracking().ToDictionaryAsync(c => c.Id);
|
||||||
|
|
||||||
|
// 3. Determinar las categorías activas en la sección
|
||||||
|
var categoriasActivas = resultadosCrudos.Select(r => r.CategoriaId).Distinct()
|
||||||
|
.Select(id => categoriasMap.GetValueOrDefault(id)).Where(c => c != null)
|
||||||
|
.OrderBy(c => c!.Orden).Select(c => new { c!.Id, c.Nombre }).ToList();
|
||||||
|
|
||||||
|
// 4. Determinar los 2 partidos principales POR CATEGORÍA a nivel SECCIÓN
|
||||||
|
var partidosPorCategoria = categoriasActivas.ToDictionary(
|
||||||
|
c => c.Id,
|
||||||
|
c =>
|
||||||
|
{
|
||||||
|
var resultadosCategoriaSeccion = resultadosCrudos.Where(r => r.CategoriaId == c.Id);
|
||||||
|
var totalVotosSeccionCategoria = (decimal)resultadosCategoriaSeccion.Sum(r => r.CantidadVotos);
|
||||||
|
|
||||||
|
return resultadosCategoriaSeccion
|
||||||
|
// --- CAMBIO CLAVE: Agrupamos por el ID (string), no por el objeto ---
|
||||||
|
.GroupBy(r => r.AgrupacionPolitica.Id)
|
||||||
|
.Select(g => new
|
||||||
|
{
|
||||||
|
// g.Key ahora es el AgrupacionPoliticaId
|
||||||
|
// Tomamos la entidad completa del primer elemento del grupo
|
||||||
|
Agrupacion = g.First().AgrupacionPolitica,
|
||||||
|
TotalVotos = g.Sum(r => r.CantidadVotos)
|
||||||
|
})
|
||||||
|
.OrderByDescending(x => x.TotalVotos)
|
||||||
|
.Take(2)
|
||||||
|
.Select((x, index) => new
|
||||||
|
{
|
||||||
|
Puesto = index + 1,
|
||||||
|
x.Agrupacion.Id,
|
||||||
|
Nombre = x.Agrupacion.NombreCorto ?? x.Agrupacion.Nombre,
|
||||||
|
PorcentajeTotalSeccion = totalVotosSeccionCategoria > 0 ? (x.TotalVotos / totalVotosSeccionCategoria) * 100 : 0
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// 5. Construir los datos para las filas de la tabla (resultados por municipio)
|
||||||
|
var resultadosPorMunicipio = municipios.Select(municipio =>
|
||||||
|
{
|
||||||
|
var resultadosDelMunicipio = resultadosCrudos.Where(r => r.AmbitoGeograficoId == municipio.Id);
|
||||||
|
|
||||||
|
var celdas = resultadosDelMunicipio
|
||||||
|
.GroupBy(r => r.CategoriaId)
|
||||||
|
.ToDictionary(
|
||||||
|
g => g.Key, // CategoriaId
|
||||||
|
g =>
|
||||||
|
{
|
||||||
|
var totalVotosMunicipioCategoria = (decimal)g.Sum(r => r.CantidadVotos);
|
||||||
|
return g.ToDictionary(
|
||||||
|
r => r.AgrupacionPoliticaId, // PartidoId
|
||||||
|
r => totalVotosMunicipioCategoria > 0 ? (r.CantidadVotos / totalVotosMunicipioCategoria) * 100 : 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return new
|
||||||
|
{
|
||||||
|
MunicipioId = municipio.Id,
|
||||||
|
MunicipioNombre = municipio.Nombre,
|
||||||
|
Celdas = celdas
|
||||||
|
};
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
return Ok(new
|
||||||
|
{
|
||||||
|
Categorias = categoriasActivas,
|
||||||
|
PartidosPorCategoria = partidosPorCategoria,
|
||||||
|
ResultadosPorMunicipio = resultadosPorMunicipio
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("Elecciones.Api")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("Elecciones.Api")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8ce48b3a46c65b51238a04238228d86568680ac2")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ff6c2f29e74ad09bae72a857717e219dc3b937d3")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("Elecciones.Api")]
|
[assembly: System.Reflection.AssemblyProductAttribute("Elecciones.Api")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("Elecciones.Api")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("Elecciones.Api")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"GlobalPropertiesHash":"b5T/+ta4fUd8qpIzUTm3KyEwAYYUsU5ASo+CSFM3ByE=","FingerprintPatternsHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","PropertyOverridesHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","InputHashes":["TyIJk/eQMWjmB5LsDE\u002BZIJC9P9ciVxd7bnzRiTZsGt4=","t631p0kaOa0gMRIcaPzz1ZVPZ1kuq4pq4kYPWQgoPcM=","PA/Beu9jJpOBY5r5Y1CiSyqrARA2j7LHeWYUnEZpQO8=","E2ODTAlJxzsXY1iP1eB/02NIUK\u002BnQveGlWAOHY1cpgA=","6WTvWQ72AaZBYOVSmaxaci9tc1dW5p7IK9Kscjj2cb0=","vAy46VJ9Gp8QqG/Px4J1mj8jL6ws4/A01UKRmMYfYek=","cdgbHR/E4DJsddPc\u002BTpzoUMOVNaFJZm33Pw7AxU9Ees=","4r4JGR4hS5m4rsLfuCSZxzrknTBxKFkLQDXc\u002B2KbqTU=","yVoZ4UnBcSOapsJIi046hnn7ylD3jAcEBUxQ\u002Brkvj/4=","/GfbpJthEWmsuz0uFx1QLHM7gyM1wLLeQgAIl4SzUD4=","i5\u002B5LcfxQD8meRAkQbVf4wMvjxSE4\u002BjCd2/FdPtMpms=","AvSkxVPIg0GjnB1RJ4hDNyo9p9GONrzDs8uVuixH\u002BOE=","IgT9pOgRnK37qfILj2QcjFoBZ180HMt\u002BScgje2iYOo4=","ezUlOMzNZmyKDIe1wwXqvX\u002BvhwfB992xNVts7r2zcTc=","y2BV4WpkQuLfqQhfOQBtmuzh940c3s4LAopGKfztfTE=","lHTUEsMkDu8nqXtfTwl7FRfgocyyc7RI5O/edTHN1\u002B0=","A7nz7qgOtQ1CwZZLvNnr0b5QZB3fTi3y4i6y7rBIcxQ=","znnuRi2tsk7AACuYo4WSgj7NcLriG4PKVaF4L35SvDk=","GelE32odx/vTului267wqi6zL3abBnF9yvwC2Q66LoM=","TEsXImnzxFKTIq2f5fiDu7i6Ar/cbecW5MZ3z8Wb/a4=","5WogJu\u002BUPlF\u002BE5mq/ILtDXpVwqwmhHtsEB13nmT5JJk=","B5JL8yyHqNgMsFpbZP0qsuF4OLsILfK8gQJe8eGu3B0=","P8JRhYPpULTLMAydvl3Ky\u002B92/tYDIjui0l66En4aXuQ=","NNlKPM7/7JjN5EwDTVhjwjUKTnDOuh1gXx0T83PZFzk="],"CachedAssets":{},"CachedCopyCandidates":{}}
|
{"GlobalPropertiesHash":"b5T/+ta4fUd8qpIzUTm3KyEwAYYUsU5ASo+CSFM3ByE=","FingerprintPatternsHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","PropertyOverridesHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","InputHashes":["TyIJk/eQMWjmB5LsDE\u002BZIJC9P9ciVxd7bnzRiTZsGt4=","t631p0kaOa0gMRIcaPzz1ZVPZ1kuq4pq4kYPWQgoPcM=","PA/Beu9jJpOBY5r5Y1CiSyqrARA2j7LHeWYUnEZpQO8=","E2ODTAlJxzsXY1iP1eB/02NIUK\u002BnQveGlWAOHY1cpgA=","6WTvWQ72AaZBYOVSmaxaci9tc1dW5p7IK9Kscjj2cb0=","vAy46VJ9Gp8QqG/Px4J1mj8jL6ws4/A01UKRmMYfYek=","cdgbHR/E4DJsddPc\u002BTpzoUMOVNaFJZm33Pw7AxU9Ees=","4r4JGR4hS5m4rsLfuCSZxzrknTBxKFkLQDXc\u002B2KbqTU=","yVoZ4UnBcSOapsJIi046hnn7ylD3jAcEBUxQ\u002Brkvj/4=","/GfbpJthEWmsuz0uFx1QLHM7gyM1wLLeQgAIl4SzUD4=","i5\u002B5LcfxQD8meRAkQbVf4wMvjxSE4\u002BjCd2/FdPtMpms=","AvSkxVPIg0GjnB1RJ4hDNyo9p9GONrzDs8uVuixH\u002BOE=","IgT9pOgRnK37qfILj2QcjFoBZ180HMt\u002BScgje2iYOo4=","ezUlOMzNZmyKDIe1wwXqvX\u002BvhwfB992xNVts7r2zcTc=","y2BV4WpkQuLfqQhfOQBtmuzh940c3s4LAopGKfztfTE=","lHTUEsMkDu8nqXtfTwl7FRfgocyyc7RI5O/edTHN1\u002B0=","A7nz7qgOtQ1CwZZLvNnr0b5QZB3fTi3y4i6y7rBIcxQ=","znnuRi2tsk7AACuYo4WSgj7NcLriG4PKVaF4L35SvDk=","GelE32odx/vTului267wqi6zL3abBnF9yvwC2Q66LoM=","TEsXImnzxFKTIq2f5fiDu7i6Ar/cbecW5MZ3z8Wb/a4=","5WogJu\u002BUPlF\u002BE5mq/ILtDXpVwqwmhHtsEB13nmT5JJk=","uTr9qgRasEUmrcU7thdV3/6oH21r5OGtDP0nEXp3xYQ=","P8JRhYPpULTLMAydvl3Ky\u002B92/tYDIjui0l66En4aXuQ=","RmxhgDz17MFEPINl\u002B1yGj5\u002BUXoOKrnKpjtRGQZ8T2N0="],"CachedAssets":{},"CachedCopyCandidates":{}}
|
||||||
@@ -1 +1 @@
|
|||||||
{"GlobalPropertiesHash":"tJTBjV/i0Ihkc6XuOu69wxL8PBac9c9Kak6srMso4pU=","FingerprintPatternsHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","PropertyOverridesHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","InputHashes":["TyIJk/eQMWjmB5LsDE\u002BZIJC9P9ciVxd7bnzRiTZsGt4=","t631p0kaOa0gMRIcaPzz1ZVPZ1kuq4pq4kYPWQgoPcM=","PA/Beu9jJpOBY5r5Y1CiSyqrARA2j7LHeWYUnEZpQO8=","E2ODTAlJxzsXY1iP1eB/02NIUK\u002BnQveGlWAOHY1cpgA=","6WTvWQ72AaZBYOVSmaxaci9tc1dW5p7IK9Kscjj2cb0=","vAy46VJ9Gp8QqG/Px4J1mj8jL6ws4/A01UKRmMYfYek=","cdgbHR/E4DJsddPc\u002BTpzoUMOVNaFJZm33Pw7AxU9Ees=","4r4JGR4hS5m4rsLfuCSZxzrknTBxKFkLQDXc\u002B2KbqTU=","yVoZ4UnBcSOapsJIi046hnn7ylD3jAcEBUxQ\u002Brkvj/4=","/GfbpJthEWmsuz0uFx1QLHM7gyM1wLLeQgAIl4SzUD4=","i5\u002B5LcfxQD8meRAkQbVf4wMvjxSE4\u002BjCd2/FdPtMpms=","AvSkxVPIg0GjnB1RJ4hDNyo9p9GONrzDs8uVuixH\u002BOE=","IgT9pOgRnK37qfILj2QcjFoBZ180HMt\u002BScgje2iYOo4=","ezUlOMzNZmyKDIe1wwXqvX\u002BvhwfB992xNVts7r2zcTc=","y2BV4WpkQuLfqQhfOQBtmuzh940c3s4LAopGKfztfTE=","lHTUEsMkDu8nqXtfTwl7FRfgocyyc7RI5O/edTHN1\u002B0=","A7nz7qgOtQ1CwZZLvNnr0b5QZB3fTi3y4i6y7rBIcxQ=","znnuRi2tsk7AACuYo4WSgj7NcLriG4PKVaF4L35SvDk=","GelE32odx/vTului267wqi6zL3abBnF9yvwC2Q66LoM=","TEsXImnzxFKTIq2f5fiDu7i6Ar/cbecW5MZ3z8Wb/a4=","5WogJu\u002BUPlF\u002BE5mq/ILtDXpVwqwmhHtsEB13nmT5JJk=","B5JL8yyHqNgMsFpbZP0qsuF4OLsILfK8gQJe8eGu3B0=","P8JRhYPpULTLMAydvl3Ky\u002B92/tYDIjui0l66En4aXuQ=","NNlKPM7/7JjN5EwDTVhjwjUKTnDOuh1gXx0T83PZFzk="],"CachedAssets":{},"CachedCopyCandidates":{}}
|
{"GlobalPropertiesHash":"tJTBjV/i0Ihkc6XuOu69wxL8PBac9c9Kak6srMso4pU=","FingerprintPatternsHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","PropertyOverridesHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","InputHashes":["TyIJk/eQMWjmB5LsDE\u002BZIJC9P9ciVxd7bnzRiTZsGt4=","t631p0kaOa0gMRIcaPzz1ZVPZ1kuq4pq4kYPWQgoPcM=","PA/Beu9jJpOBY5r5Y1CiSyqrARA2j7LHeWYUnEZpQO8=","E2ODTAlJxzsXY1iP1eB/02NIUK\u002BnQveGlWAOHY1cpgA=","6WTvWQ72AaZBYOVSmaxaci9tc1dW5p7IK9Kscjj2cb0=","vAy46VJ9Gp8QqG/Px4J1mj8jL6ws4/A01UKRmMYfYek=","cdgbHR/E4DJsddPc\u002BTpzoUMOVNaFJZm33Pw7AxU9Ees=","4r4JGR4hS5m4rsLfuCSZxzrknTBxKFkLQDXc\u002B2KbqTU=","yVoZ4UnBcSOapsJIi046hnn7ylD3jAcEBUxQ\u002Brkvj/4=","/GfbpJthEWmsuz0uFx1QLHM7gyM1wLLeQgAIl4SzUD4=","i5\u002B5LcfxQD8meRAkQbVf4wMvjxSE4\u002BjCd2/FdPtMpms=","AvSkxVPIg0GjnB1RJ4hDNyo9p9GONrzDs8uVuixH\u002BOE=","IgT9pOgRnK37qfILj2QcjFoBZ180HMt\u002BScgje2iYOo4=","ezUlOMzNZmyKDIe1wwXqvX\u002BvhwfB992xNVts7r2zcTc=","y2BV4WpkQuLfqQhfOQBtmuzh940c3s4LAopGKfztfTE=","lHTUEsMkDu8nqXtfTwl7FRfgocyyc7RI5O/edTHN1\u002B0=","A7nz7qgOtQ1CwZZLvNnr0b5QZB3fTi3y4i6y7rBIcxQ=","znnuRi2tsk7AACuYo4WSgj7NcLriG4PKVaF4L35SvDk=","GelE32odx/vTului267wqi6zL3abBnF9yvwC2Q66LoM=","TEsXImnzxFKTIq2f5fiDu7i6Ar/cbecW5MZ3z8Wb/a4=","5WogJu\u002BUPlF\u002BE5mq/ILtDXpVwqwmhHtsEB13nmT5JJk=","uTr9qgRasEUmrcU7thdV3/6oH21r5OGtDP0nEXp3xYQ=","P8JRhYPpULTLMAydvl3Ky\u002B92/tYDIjui0l66En4aXuQ=","RmxhgDz17MFEPINl\u002B1yGj5\u002BUXoOKrnKpjtRGQZ8T2N0="],"CachedAssets":{},"CachedCopyCandidates":{}}
|
||||||
@@ -13,7 +13,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("Elecciones.Core")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("Elecciones.Core")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8ce48b3a46c65b51238a04238228d86568680ac2")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ff6c2f29e74ad09bae72a857717e219dc3b937d3")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("Elecciones.Core")]
|
[assembly: System.Reflection.AssemblyProductAttribute("Elecciones.Core")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("Elecciones.Core")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("Elecciones.Core")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("Elecciones.Database")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("Elecciones.Database")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8ce48b3a46c65b51238a04238228d86568680ac2")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ff6c2f29e74ad09bae72a857717e219dc3b937d3")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("Elecciones.Database")]
|
[assembly: System.Reflection.AssemblyProductAttribute("Elecciones.Database")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("Elecciones.Database")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("Elecciones.Database")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("Elecciones.Infrastructure")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("Elecciones.Infrastructure")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8ce48b3a46c65b51238a04238228d86568680ac2")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ff6c2f29e74ad09bae72a857717e219dc3b937d3")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("Elecciones.Infrastructure")]
|
[assembly: System.Reflection.AssemblyProductAttribute("Elecciones.Infrastructure")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("Elecciones.Infrastructure")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("Elecciones.Infrastructure")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
Reference in New Issue
Block a user