FEat Widgets Tablas
This commit is contained in:
@@ -17,6 +17,7 @@ import { DiputadosPorSeccionWidget } from './components/DiputadosPorSeccionWidge
|
|||||||
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 { ResultadosTablaDetalladaWidget } from './components/ResultadosTablaDetalladaWidget'
|
||||||
|
import { ResultadosRankingMunicipioWidget } from './components/ResultadosRankingMunicipioWidget'
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
@@ -56,6 +57,8 @@ function App() {
|
|||||||
<TelegramaWidget />
|
<TelegramaWidget />
|
||||||
<hr className="border-gray-300" />
|
<hr className="border-gray-300" />
|
||||||
<ResultadosTablaDetalladaWidget />
|
<ResultadosTablaDetalladaWidget />
|
||||||
|
<hr className="border-gray-300" />
|
||||||
|
<ResultadosRankingMunicipioWidget />
|
||||||
</main>
|
</main>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// src/apiService.ts
|
// src/apiService.ts
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import type { ApiResponseRankingSeccion, ApiResponseTablaDetallada, ProyeccionBancas, MunicipioSimple, TelegramaData, CatalogoItem, CategoriaResumen, ResultadoTicker, ApiResponseResultadosPorSeccion } from './types/types';
|
import type { ApiResponseRankingMunicipio, 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.
|
||||||
@@ -200,4 +200,9 @@ export const getResultadosTablaDetallada = async (seccionId: string): Promise<Ap
|
|||||||
export const getRankingResultadosPorSeccion = async (seccionId: string): Promise<ApiResponseRankingSeccion> => {
|
export const getRankingResultadosPorSeccion = async (seccionId: string): Promise<ApiResponseRankingSeccion> => {
|
||||||
const { data } = await apiClient.get(`/resultados/ranking-por-seccion/${seccionId}`);
|
const { data } = await apiClient.get(`/resultados/ranking-por-seccion/${seccionId}`);
|
||||||
return data;
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getRankingMunicipiosPorSeccion = async (seccionId: string): Promise<ApiResponseRankingMunicipio> => {
|
||||||
|
const { data } = await apiClient.get(`/resultados/ranking-municipios-por-seccion/${seccionId}`);
|
||||||
|
return data;
|
||||||
};
|
};
|
||||||
@@ -16,6 +16,7 @@ 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 { ResultadosTablaDetalladaWidget } from './ResultadosTablaDetalladaWidget'
|
||||||
|
import { ResultadosRankingMunicipioWidget } from './ResultadosRankingMunicipioWidget'
|
||||||
import '../App.css';
|
import '../App.css';
|
||||||
|
|
||||||
|
|
||||||
@@ -42,7 +43,8 @@ export const DevApp = () => {
|
|||||||
<MapaBsAs />
|
<MapaBsAs />
|
||||||
<MapaBsAsSecciones />
|
<MapaBsAsSecciones />
|
||||||
<TelegramaWidget />
|
<TelegramaWidget />
|
||||||
<ResultadosTablaDetalladaWidget />
|
<ResultadosTablaDetalladaWidget />
|
||||||
|
<ResultadosRankingMunicipioWidget />
|
||||||
</main>
|
</main>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,129 @@
|
|||||||
|
import { useState, useMemo, useEffect } from 'react';
|
||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import Select from 'react-select';
|
||||||
|
import { getSeccionesElectorales, getRankingMunicipiosPorSeccion } from '../apiService';
|
||||||
|
import type { MunicipioSimple, ApiResponseRankingMunicipio } from '../types/types';
|
||||||
|
import './ResultadosTablaSeccionWidget.css'; // Reutilizamos el mismo estilo
|
||||||
|
|
||||||
|
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 ResultadosRankingMunicipioWidget = () => {
|
||||||
|
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: rankingData, isLoading } = useQuery<ApiResponseRankingMunicipio>({
|
||||||
|
queryKey: ['rankingMunicipiosPorSeccion', selectedSeccion?.value],
|
||||||
|
queryFn: () => getRankingMunicipiosPorSeccion(selectedSeccion!.value),
|
||||||
|
enabled: !!selectedSeccion,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="tabla-resultados-widget">
|
||||||
|
<div className="tabla-header">
|
||||||
|
<h3>Resultados por Municipio</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> : !rankingData || rankingData.categorias.length === 0 ? <p>No hay datos.</p> : (
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
{/* --- Fila 1: Nombres de Categorías --- */}
|
||||||
|
<tr>
|
||||||
|
<th rowSpan={2} className="sticky-col municipio-header">Municipio</th>
|
||||||
|
{rankingData.categorias.map(cat => (
|
||||||
|
// Cada categoría ahora ocupa 4 columnas (1° Partido, 1° %, 2° Partido, 2° %)
|
||||||
|
<th key={cat.id} colSpan={4} className="categoria-header">
|
||||||
|
{cat.nombre}
|
||||||
|
</th>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
{/* --- Fila 2: Puestos y % --- */}
|
||||||
|
<tr>
|
||||||
|
{rankingData.categorias.flatMap(cat => [
|
||||||
|
<th key={`${cat.id}-p1`} colSpan={2} className="puesto-header">1° Puesto</th>,
|
||||||
|
<th key={`${cat.id}-p2`} colSpan={2} className="puesto-header category-divider-header">2° Puesto</th>
|
||||||
|
])}
|
||||||
|
</tr>
|
||||||
|
{/* --- Fila 3: Partido y % --- */}
|
||||||
|
<tr>
|
||||||
|
<th className="sticky-col"></th> {/* Celda vacía para alinear con Municipio */}
|
||||||
|
{rankingData.categorias.flatMap(cat => [
|
||||||
|
<th key={`${cat.id}-p1-partido`} className="sub-header">Partido</th>,
|
||||||
|
<th key={`${cat.id}-p1-porc`} className="sub-header">%</th>,
|
||||||
|
<th key={`${cat.id}-p2-partido`} className="sub-header category-divider-header">Partido</th>,
|
||||||
|
<th key={`${cat.id}-p2-porc`} className="sub-header">%</th>
|
||||||
|
])}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{rankingData.resultados.map(municipio => (
|
||||||
|
<tr key={municipio.municipioId}>
|
||||||
|
<td className="sticky-col">{municipio.municipioNombre}</td>
|
||||||
|
{rankingData.categorias.flatMap(cat => {
|
||||||
|
const resCategoria = municipio.resultadosPorCategoria[cat.id];
|
||||||
|
const primerPuesto = resCategoria?.ranking[0];
|
||||||
|
const segundoPuesto = resCategoria?.ranking[1];
|
||||||
|
|
||||||
|
return [
|
||||||
|
// --- Celdas para el 1° Puesto ---
|
||||||
|
<td key={`${municipio.municipioId}-${cat.id}-p1-partido`} className="cell-partido">
|
||||||
|
{primerPuesto?.nombreCorto || '-'}
|
||||||
|
</td>,
|
||||||
|
<td key={`${municipio.municipioId}-${cat.id}-p1-porc`} className="cell-porcentaje">
|
||||||
|
{primerPuesto ? formatPercent(primerPuesto.porcentaje) : '-'}
|
||||||
|
</td>,
|
||||||
|
// --- Celdas para el 2° Puesto ---
|
||||||
|
<td key={`${municipio.municipioId}-${cat.id}-p2-partido`} className="cell-partido category-divider">
|
||||||
|
{segundoPuesto?.nombreCorto || '-'}
|
||||||
|
</td>,
|
||||||
|
<td key={`${municipio.municipioId}-${cat.id}-p2-porc`} className="cell-porcentaje">
|
||||||
|
{segundoPuesto ? formatPercent(segundoPuesto.porcentaje) : '-'}
|
||||||
|
</td>
|
||||||
|
];
|
||||||
|
})}
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -42,67 +42,93 @@
|
|||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --- Cabeceras (THEAD) --- */
|
/* --- CABECERAS (THEAD) --- */
|
||||||
.tabla-container thead th {
|
.tabla-container thead th {
|
||||||
background-color: #f8f9fa;
|
background-color: #f8f9fa;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: #495057;
|
color: #495057;
|
||||||
padding: 12px 10px;
|
padding: 8px 10px;
|
||||||
text-align: center; /* Centramos las cabeceras */
|
text-align: center;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
font-size: 0.75rem;
|
font-size: 0.75rem;
|
||||||
letter-spacing: 0.5px;
|
letter-spacing: 0.5px;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
border-bottom: 2px solid #adb5bd; /* Línea inferior más gruesa */
|
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
}
|
border-right: 1px solid #dee2e6;
|
||||||
|
|
||||||
.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 {
|
.tabla-container thead th:last-child {
|
||||||
border-right: none;
|
border-right: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --- Cuerpo de la Tabla (TBODY) --- */
|
/* Fila 1: Categorías (SENADORES, CONCEJALES) */
|
||||||
|
.tabla-container th.categoria-header {
|
||||||
|
border-bottom: 1px solid #adb5bd;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fila 2: Puestos (1° Puesto, 2° Puesto) */
|
||||||
|
.tabla-container th.puesto-header {
|
||||||
|
border-bottom: 1px solid #adb5bd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fila 3: Sub-cabeceras (Partido, %) */
|
||||||
|
.tabla-container th.sub-header {
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 0.7rem;
|
||||||
|
color: #6c757d;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --- CUERPO DE LA TABLA (TBODY) --- */
|
||||||
.tabla-container tbody td {
|
.tabla-container tbody td {
|
||||||
padding: 10px 12px;
|
padding: 10px 12px;
|
||||||
border-bottom: 1px solid #e9ecef;
|
border-bottom: 1px solid #e9ecef;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
vertical-align: middle;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tabla-container tbody tr:last-child td {
|
.tabla-container tbody tr:last-child td {
|
||||||
border-bottom: none; /* Quita la línea de la última fila */
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
.tabla-container tbody tr:nth-of-type(even) {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
}
|
||||||
|
.tabla-container tbody tr:hover {
|
||||||
|
background-color: #e2e6ea;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tabla-container tbody tr:nth-of-type(even) {
|
/* Celdas específicas */
|
||||||
|
.tabla-container .cell-partido {
|
||||||
|
text-align: left;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
}
|
||||||
|
.tabla-container .cell-porcentaje {
|
||||||
|
text-align: right;
|
||||||
|
font-family: 'Roboto Mono', 'Courier New', monospace;
|
||||||
|
font-weight: 500;
|
||||||
|
border-right: 1px solid #dee2e6;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Líneas divisorias entre categorías */
|
||||||
|
.tabla-container .category-divider-header {
|
||||||
|
border-left: 2px solid #adb5bd; /* Línea más gruesa en la cabecera */
|
||||||
|
}
|
||||||
|
.tabla-container .category-divider {
|
||||||
|
border-left: 2px solid #adb5bd; /* Línea más gruesa en las celdas */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Columna fija de Municipio */
|
||||||
|
.tabla-container th.sticky-col,
|
||||||
|
.tabla-container td.sticky-col {
|
||||||
|
position: sticky;
|
||||||
|
left: 0;
|
||||||
|
background-color: #ffffff;
|
||||||
|
z-index: 1;
|
||||||
|
border-right: 2px solid #adb5bd; /* Línea divisoria gruesa para la columna fija */
|
||||||
|
}
|
||||||
|
.tabla-container thead th.sticky-col {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
.tabla-container tbody tr:nth-of-type(even) td.sticky-col {
|
||||||
background-color: #f8f9fa;
|
background-color: #f8f9fa;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { DiputadosPorSeccionWidget } from './components/DiputadosPorSeccionWidge
|
|||||||
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 { ResultadosTablaDetalladaWidget } from './components/ResultadosTablaDetalladaWidget';
|
||||||
|
import { ResultadosRankingMunicipioWidget } from './components/ResultadosRankingMunicipioWidget';
|
||||||
import { DevApp } from './components/DevApp';
|
import { DevApp } from './components/DevApp';
|
||||||
import './index.css';
|
import './index.css';
|
||||||
|
|
||||||
@@ -45,6 +46,7 @@ const WIDGET_MAP: Record<string, React.ElementType> = {
|
|||||||
'senadores-por-seccion': SenadoresPorSeccionWidget,
|
'senadores-por-seccion': SenadoresPorSeccionWidget,
|
||||||
'concejales-por-seccion': ConcejalesPorSeccionWidget,
|
'concejales-por-seccion': ConcejalesPorSeccionWidget,
|
||||||
'resultados-tabla-detallada-por-seccion' : ResultadosTablaDetalladaWidget,
|
'resultados-tabla-detallada-por-seccion' : ResultadosTablaDetalladaWidget,
|
||||||
|
'resultados-tabla-detallada-por-municipio' : ResultadosRankingMunicipioWidget,
|
||||||
};
|
};
|
||||||
|
|
||||||
// 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'
|
||||||
|
|||||||
@@ -194,13 +194,27 @@ export interface RankingCategoria {
|
|||||||
ranking: RankingPartido[];
|
ranking: RankingPartido[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RankingMunicipio {
|
|
||||||
municipioId: number;
|
|
||||||
municipioNombre: string;
|
|
||||||
resultadosPorCategoria: RankingCategoria[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ApiResponseRankingSeccion {
|
export interface ApiResponseRankingSeccion {
|
||||||
categorias: { id: number; nombre: string }[];
|
categorias: { id: number; nombre: string }[];
|
||||||
resultados: RankingMunicipio[];
|
resultados: RankingMunicipio[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RankingPartido {
|
||||||
|
nombreCorto: string;
|
||||||
|
porcentaje: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RankingCategoria {
|
||||||
|
ranking: RankingPartido[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RankingMunicipio {
|
||||||
|
municipioId: number;
|
||||||
|
municipioNombre: string;
|
||||||
|
resultadosPorCategoria: { [catId: string]: RankingCategoria };
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiResponseRankingMunicipio {
|
||||||
|
categorias: { id: number; nombre: string }[];
|
||||||
|
resultados: RankingMunicipio[];
|
||||||
}
|
}
|
||||||
@@ -874,4 +874,83 @@ public class ResultadosController : ControllerBase
|
|||||||
ResultadosPorMunicipio = resultadosPorMunicipio
|
ResultadosPorMunicipio = resultadosPorMunicipio
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("ranking-municipios-por-seccion/{seccionId}")]
|
||||||
|
public async Task<IActionResult> GetRankingMunicipiosPorSeccion(string seccionId)
|
||||||
|
{
|
||||||
|
// 1. Obtener 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 List<object>());
|
||||||
|
}
|
||||||
|
|
||||||
|
var municipiosIds = municipios.Select(m => m.Id).ToList();
|
||||||
|
|
||||||
|
// 2. Obtener todos los resultados de esos municipios en una sola consulta
|
||||||
|
var resultadosCrudos = await _dbContext.ResultadosVotos.AsNoTracking()
|
||||||
|
.Include(r => r.AgrupacionPolitica)
|
||||||
|
.Where(r => municipiosIds.Contains(r.AmbitoGeograficoId))
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
// 3. Procesar los datos por cada municipio
|
||||||
|
var resultadosPorMunicipio = municipios.Select(municipio =>
|
||||||
|
{
|
||||||
|
// Filtramos los resultados solo para el municipio actual
|
||||||
|
var resultadosDelMunicipio = resultadosCrudos.Where(r => r.AmbitoGeograficoId == municipio.Id);
|
||||||
|
|
||||||
|
// Agrupamos por categoría (Senadores, Concejales, etc.)
|
||||||
|
var resultadosPorCategoria = resultadosDelMunicipio
|
||||||
|
.GroupBy(r => r.CategoriaId)
|
||||||
|
.Select(g =>
|
||||||
|
{
|
||||||
|
var totalVotosCategoria = (decimal)g.Sum(r => r.CantidadVotos);
|
||||||
|
|
||||||
|
// Obtenemos los 2 partidos con más votos para esta categoría EN ESTE MUNICIPIO
|
||||||
|
var ranking = g
|
||||||
|
.OrderByDescending(r => r.CantidadVotos)
|
||||||
|
.Take(2)
|
||||||
|
.Select(r => new
|
||||||
|
{
|
||||||
|
NombreCorto = r.AgrupacionPolitica.NombreCorto ?? r.AgrupacionPolitica.Nombre,
|
||||||
|
Porcentaje = totalVotosCategoria > 0 ? (r.CantidadVotos / totalVotosCategoria) * 100 : 0
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
return new
|
||||||
|
{
|
||||||
|
CategoriaId = g.Key,
|
||||||
|
Ranking = ranking
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.ToDictionary(r => r.CategoriaId); // Lo convertimos a diccionario para fácil acceso
|
||||||
|
|
||||||
|
return new
|
||||||
|
{
|
||||||
|
MunicipioId = municipio.Id,
|
||||||
|
MunicipioNombre = municipio.Nombre,
|
||||||
|
ResultadosPorCategoria = resultadosPorCategoria
|
||||||
|
};
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
// Devolvemos las categorías que tuvieron resultados en esta sección para construir la cabecera
|
||||||
|
var categoriasMap = await _dbContext.CategoriasElectorales.AsNoTracking().ToDictionaryAsync(c => c.Id);
|
||||||
|
var categoriasActivas = resultadosCrudos
|
||||||
|
.Select(r => r.CategoriaId).Distinct()
|
||||||
|
.Select(id => categoriasMap.GetValueOrDefault(id)).Where(c => c != null)
|
||||||
|
.OrderBy(c => c!.Orden)
|
||||||
|
.Select(c => new { Id = c!.Id, Nombre = c.Nombre })
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
return Ok(new
|
||||||
|
{
|
||||||
|
Categorias = categoriasActivas,
|
||||||
|
Resultados = 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+ff6c2f29e74ad09bae72a857717e219dc3b937d3")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+f41b4eaa1c7c6dbfbb2e39df540430cca2707997")]
|
||||||
[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=","uTr9qgRasEUmrcU7thdV3/6oH21r5OGtDP0nEXp3xYQ=","P8JRhYPpULTLMAydvl3Ky\u002B92/tYDIjui0l66En4aXuQ=","RmxhgDz17MFEPINl\u002B1yGj5\u002BUXoOKrnKpjtRGQZ8T2N0="],"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=","snxr5B4h1JuC8zeKEobJW\u002B0ShSJJ7TjIbeEC9BXUNyQ=","P8JRhYPpULTLMAydvl3Ky\u002B92/tYDIjui0l66En4aXuQ=","njFw1781eb3KkWTyICHD6vWcMAY4bH2NaKz52wjO9Tk="],"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=","uTr9qgRasEUmrcU7thdV3/6oH21r5OGtDP0nEXp3xYQ=","P8JRhYPpULTLMAydvl3Ky\u002B92/tYDIjui0l66En4aXuQ=","RmxhgDz17MFEPINl\u002B1yGj5\u002BUXoOKrnKpjtRGQZ8T2N0="],"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=","snxr5B4h1JuC8zeKEobJW\u002B0ShSJJ7TjIbeEC9BXUNyQ=","P8JRhYPpULTLMAydvl3Ky\u002B92/tYDIjui0l66En4aXuQ=","njFw1781eb3KkWTyICHD6vWcMAY4bH2NaKz52wjO9Tk="],"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+ff6c2f29e74ad09bae72a857717e219dc3b937d3")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+f41b4eaa1c7c6dbfbb2e39df540430cca2707997")]
|
||||||
[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+ff6c2f29e74ad09bae72a857717e219dc3b937d3")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+f41b4eaa1c7c6dbfbb2e39df540430cca2707997")]
|
||||||
[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+ff6c2f29e74ad09bae72a857717e219dc3b937d3")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+f41b4eaa1c7c6dbfbb2e39df540430cca2707997")]
|
||||||
[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