+page.js 1.06 KB
export const ssr = false;

export async function load({ fetch }) {
  const [pobRes, ubigeoRes] = await Promise.all([
    fetch('/poblacion.csv').then(r => r.text()),
    fetch('/api/ubigeo-todo?gestion=2025').then(r => r.json())
  ]);

  const poblacionMap = {};
  pobRes.split('\n').slice(1).forEach(line => {
    const [cod, , gestion, pob] = line.split(',');
    if (parseInt(gestion) === 2025) {
      poblacionMap[cod] = parseInt(pob);
    }
  });

  const resumen = (ubigeoRes || [])
    .filter(d => d.ubigeo !== '0.0.0' && !d.ubigeo.endsWith('.0') && !/multimunicipal/i.test(d.desc_ubigeo) && !/multiprovincial/i.test(d.desc_ubigeo) && !/desconocido/i.test(d.desc_ubigeo))
    .map(d => ({
      codigo: d.ubigeo,
      desc: d.desc_ubigeo,
      gestion: d.gestion,
      devengado: d.monto,
      ranking: d.ranking,
      per_capita: d.per_capita,
      departamento: d.desc_departamento
    }));

  const gestiones = [2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025];

  return {
    resumen,
    poblacionMap,
    gestiones,
    gestionInicial: 2025
  };
}