generated from enflujo/enflujo-plantilla-astro
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from enflujo/mostrar-todos-los-lugares
⚙️ Mostrar todos los lugares
- Loading branch information
Showing
8 changed files
with
224 additions
and
266 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"slug":"berlin","nombre":"Berlín","conteo":2},"geometry":{"type":"Point","coordinates":[13.259928,52.50673]}},{"type":"Feature","properties":{"slug":"bogota","nombre":"Bogotá","conteo":53},"geometry":{"type":"Point","coordinates":[-74.10378,4.64958]}},{"type":"Feature","properties":{"slug":"bucaramanga","nombre":"Bucaramanga","conteo":1},"geometry":{"type":"Point","coordinates":[-73.12099,7.11168]}},{"type":"Feature","properties":{"slug":"cali","nombre":"Cali","conteo":2},"geometry":{"type":"Point","coordinates":[-76.68155,3.39505]}},{"type":"Feature","properties":{"slug":"cambridge","nombre":"Cambridge","conteo":2},"geometry":{"type":"Point","coordinates":[0.04205,52.19881]}},{"type":"Feature","properties":{"slug":"honda","nombre":"Honda","conteo":1},"geometry":{"type":"Point","coordinates":[-74.84303,5.2104266]}},{"type":"Feature","properties":{"slug":"johannesburgo","nombre":"Johannesburgo","conteo":1},"geometry":{"type":"Point","coordinates":[27.9988,-26.17151]}},{"type":"Feature","properties":{"slug":"madrid","nombre":"Madrid","conteo":2},"geometry":{"type":"Point","coordinates":[-3.84434,40.43783]}},{"type":"Feature","properties":{"slug":"medellin","nombre":"Medellín","conteo":2},"geometry":{"type":"Point","coordinates":[-75.57667,6.216123]}},{"type":"Feature","properties":{"slug":"oakland","nombre":"Oakland","conteo":1},"geometry":{"type":"Point","coordinates":[-122.4001,37.7586]}},{"type":"Feature","properties":{"slug":"oregon","nombre":"Oregon","conteo":1},"geometry":{"type":"Point","coordinates":[-123.2223,44.1152]}},{"type":"Feature","properties":{"slug":"oxford","nombre":"Oxford","conteo":1},"geometry":{"type":"Point","coordinates":[-1.288787,51.75041]}},{"type":"Feature","properties":{"slug":"quibdo","nombre":"Quibdó","conteo":1},"geometry":{"type":"Point","coordinates":[-76.65319,5.68914]}},{"type":"Feature","properties":{"slug":"utrecht","nombre":"Utrecht","conteo":1},"geometry":{"type":"Point","coordinates":[5.00009,52.0841]}},{"type":"Feature","properties":{"slug":"viena","nombre":"Viena","conteo":1},"geometry":{"type":"Point","coordinates":[16.29727,48.22025]}},{"type":"Feature","properties":{"slug":"dubai","nombre":"Dubai","conteo":1},"geometry":{"type":"Point","coordinates":[55.24700319430791,25.1667024771733]}}]} | ||
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"slug":"berlin","nombre":"Berlín","tipo":"ciudades","conteo":2},"geometry":{"type":"Point","coordinates":[13.259928,52.50673]}},{"type":"Feature","properties":{"slug":"bogota","nombre":"Bogotá","tipo":"ciudades","conteo":53},"geometry":{"type":"Point","coordinates":[-74.10378,4.64958]}},{"type":"Feature","properties":{"slug":"bucaramanga","nombre":"Bucaramanga","tipo":"ciudades","conteo":1},"geometry":{"type":"Point","coordinates":[-73.12099,7.11168]}},{"type":"Feature","properties":{"slug":"cali","nombre":"Cali","tipo":"ciudades","conteo":2},"geometry":{"type":"Point","coordinates":[-76.68155,3.39505]}},{"type":"Feature","properties":{"slug":"cambridge","nombre":"Cambridge","tipo":"ciudades","conteo":2},"geometry":{"type":"Point","coordinates":[0.04205,52.19881]}},{"type":"Feature","properties":{"slug":"colombia","nombre":"Colombia","tipo":"paises","conteo":60},"geometry":{"type":"Point","coordinates":[-74.10378,4.64958]}},{"type":"Feature","properties":{"slug":"honda","nombre":"Honda","tipo":"ciudades","conteo":1},"geometry":{"type":"Point","coordinates":[-74.84303,5.2104266]}},{"type":"Feature","properties":{"slug":"johannesburgo","nombre":"Johannesburgo","tipo":"ciudades","conteo":1},"geometry":{"type":"Point","coordinates":[27.9988,-26.17151]}},{"type":"Feature","properties":{"slug":"madrid","nombre":"Madrid","tipo":"ciudades","conteo":2},"geometry":{"type":"Point","coordinates":[-3.84434,40.43783]}},{"type":"Feature","properties":{"slug":"medellin","nombre":"Medellín","tipo":"ciudades","conteo":2},"geometry":{"type":"Point","coordinates":[-75.57667,6.216123]}},{"type":"Feature","properties":{"slug":"oakland","nombre":"Oakland","tipo":"ciudades","conteo":1},"geometry":{"type":"Point","coordinates":[-122.4001,37.7586]}},{"type":"Feature","properties":{"slug":"oregon","nombre":"Oregon","tipo":"ciudades","conteo":1},"geometry":{"type":"Point","coordinates":[-123.2223,44.1152]}},{"type":"Feature","properties":{"slug":"oxford","nombre":"Oxford","tipo":"ciudades","conteo":1},"geometry":{"type":"Point","coordinates":[-1.288787,51.75041]}},{"type":"Feature","properties":{"slug":"quibdo","nombre":"Quibdó","tipo":"ciudades","conteo":1},"geometry":{"type":"Point","coordinates":[-76.65319,5.68914]}},{"type":"Feature","properties":{"slug":"utrecht","nombre":"Utrecht","tipo":"ciudades","conteo":1},"geometry":{"type":"Point","coordinates":[5.00009,52.0841]}},{"type":"Feature","properties":{"slug":"viena","nombre":"Viena","tipo":"ciudades","conteo":1},"geometry":{"type":"Point","coordinates":[16.29727,48.22025]}},{"type":"Feature","properties":{"slug":"alemania","nombre":"Alemania","tipo":"paises","conteo":2},"geometry":{"type":"Point","coordinates":[13.409434464984658,52.50245520250017]}},{"type":"Feature","properties":{"slug":"dubai","nombre":"Dubai","tipo":"ciudades","conteo":1},"geometry":{"type":"Point","coordinates":[55.24700319430791,25.1667024771733]}}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,152 +1,101 @@ | ||
import { getXlsxStream } from 'xlstream'; | ||
import slugificar from 'slug'; | ||
import type { Listas, Lugar } from '../src/tipos.js'; | ||
import type { Listas, Lugar, TiposLugares } from '../src/tipos.js'; | ||
import { guardarJSON } from './ayudas.js'; | ||
import type { Feature, FeatureCollection, Point } from 'geojson'; | ||
import type { ListasEgresados } from './egresados.js'; | ||
|
||
export async function procesarLugares(archivo: string, listas: Listas): Promise<void> { | ||
return new Promise(async (resolver) => { | ||
const flujoLugares = await getXlsxStream({ | ||
filePath: archivo, | ||
sheet: 'lugares', | ||
withHeader: false, | ||
ignoreEmpty: true | ||
}); | ||
|
||
let numeroFila = 1; | ||
const lugares: Lugar[] = []; | ||
const geojson: FeatureCollection = { type: 'FeatureCollection', features: [] }; | ||
|
||
flujoLugares.on('data', (fila) => { | ||
if (numeroFila > 2) { | ||
procesarLugar(fila.formatted.arr); | ||
} else { | ||
} | ||
|
||
numeroFila++; | ||
}); | ||
|
||
flujoLugares.on('close', () => { | ||
procesarDatosMapa(); | ||
guardarJSON(geojson, 'datosMapa.geo'); | ||
function procesarDatosMapa(lugares: Lugar[]) { | ||
const geojson: FeatureCollection = { type: 'FeatureCollection', features: [] }; | ||
|
||
resolver(); | ||
}); | ||
for (let lugar in lugares) { | ||
const datosLugar = lugares[lugar]; | ||
const conteo = datosLugar.conteo; | ||
|
||
function procesarLugar(fila: string[]) { | ||
const nombreLugar = fila[0].trim(); | ||
const slug = slugificar(nombreLugar); | ||
const longitud = fila[6]; | ||
const latitud = fila[5]; | ||
const lugar = listas.municipios.filter((elemento) => elemento.slug === slug); | ||
const conteo = lugar[0] ? lugar[0].conteo : 0; | ||
|
||
const respuesta: Lugar = { | ||
nombre: nombreLugar, | ||
slug: slug, | ||
lon: +longitud, | ||
lat: +latitud, | ||
const elemento: Feature<Point> = { | ||
type: 'Feature', | ||
properties: { | ||
slug: datosLugar.slug, | ||
nombre: datosLugar.nombre, | ||
tipo: datosLugar.tipo, | ||
conteo | ||
}; | ||
}, | ||
geometry: { type: 'Point', coordinates: [datosLugar.lon, datosLugar.lat] } | ||
}; | ||
|
||
if (respuesta.lon && respuesta.lat) { | ||
lugares.push(respuesta); | ||
} | ||
if (conteo > 0) { | ||
geojson.features.push(elemento); | ||
} | ||
} | ||
|
||
// Función para crear geojson con lugares y cantidad de proyectos por lugar | ||
function procesarDatosMapa() { | ||
for (let lugar in lugares) { | ||
const conteo = lugares[lugar].conteo; | ||
|
||
const elemento: Feature<Point> = { | ||
type: 'Feature', | ||
properties: { | ||
slug: lugares[lugar].slug, | ||
nombre: lugares[lugar].nombre, | ||
conteo | ||
}, | ||
geometry: { type: 'Point', coordinates: [lugares[lugar].lon, lugares[lugar].lat] } | ||
}; | ||
|
||
if (conteo > 0) { | ||
geojson.features.push(elemento); | ||
} | ||
} | ||
} | ||
}); | ||
return geojson; | ||
} | ||
|
||
function agregarLugarALista( | ||
nombre: string, | ||
slug: string, | ||
lon: number, | ||
lat: number, | ||
conteo: number, | ||
tipo: TiposLugares, | ||
lista: Lugar[] | ||
) { | ||
const respuesta: Lugar = { | ||
nombre, | ||
slug, | ||
lon, | ||
lat, | ||
conteo, | ||
tipo | ||
}; | ||
|
||
if (respuesta.lon && respuesta.lat) { | ||
lista.push(respuesta); | ||
} | ||
} | ||
|
||
export async function procesarLugaresEgresados(archivo: string, listas: ListasEgresados): Promise<void> { | ||
export async function procesarLugares(archivo: string, listas: Listas, listasE: ListasEgresados): Promise<void> { | ||
return new Promise(async (resolver) => { | ||
const flujoLugares = await getXlsxStream({ | ||
filePath: archivo, | ||
sheet: 'lugares', | ||
withHeader: false, | ||
withHeader: true, | ||
ignoreEmpty: true | ||
}); | ||
|
||
let numeroFila = 1; | ||
const lugares: Lugar[] = []; | ||
const geojson: FeatureCollection = { type: 'FeatureCollection', features: [] }; | ||
const lugaresProyectos: Lugar[] = []; | ||
const lugaresEgresados: Lugar[] = []; | ||
|
||
flujoLugares.on('data', (fila) => { | ||
if (numeroFila > 2) { | ||
procesarLugar(fila.formatted.arr); | ||
} else { | ||
} | ||
const datos = fila.formatted.arr; | ||
const nombreLugar = datos[0].trim(); | ||
const slug = slugificar(nombreLugar); | ||
const longitud = datos[6]; | ||
const latitud = datos[5]; | ||
|
||
const mun = listas.municipios.find((m) => m.slug === slug); | ||
if (mun) agregarLugarALista(nombreLugar, slug, +longitud, +latitud, mun.conteo, 'municipios', lugaresProyectos); | ||
|
||
const dep = listas.departamentos.find((d) => d.slug === slug); | ||
if (dep) | ||
agregarLugarALista(nombreLugar, slug, +longitud, +latitud, dep.conteo, 'departamentos', lugaresProyectos); | ||
|
||
const pais = listas.paises.find((p) => p.slug === slug); | ||
if (pais) agregarLugarALista(nombreLugar, slug, +longitud, +latitud, pais.conteo, 'paises', lugaresProyectos); | ||
|
||
numeroFila++; | ||
// Egresados | ||
const ciudad = listasE.ciudades.find((c) => c.slug === slug); | ||
if (ciudad) | ||
agregarLugarALista(nombreLugar, slug, +longitud, +latitud, ciudad.conteo, 'ciudades', lugaresEgresados); | ||
|
||
const paisE = listasE.paises.find((p) => p.slug === slug); | ||
if (paisE) agregarLugarALista(nombreLugar, slug, +longitud, +latitud, paisE.conteo, 'paises', lugaresEgresados); | ||
}); | ||
|
||
flujoLugares.on('close', () => { | ||
procesarDatosMapaEgresados(); | ||
guardarJSON(geojson, 'datosMapaEgresados.geo'); | ||
console.log('listo'); | ||
guardarJSON(procesarDatosMapa(lugaresProyectos), 'datosMapa.geo'); | ||
guardarJSON(procesarDatosMapa(lugaresEgresados), 'datosMapaEgresados.geo'); | ||
resolver(); | ||
}); | ||
|
||
function procesarLugar(fila: string[]) { | ||
const nombreLugar = fila[0].trim(); | ||
const slug = slugificar(nombreLugar); | ||
const longitud = fila[6]; | ||
const latitud = fila[5]; | ||
const lugar = listas.ciudades.filter((elemento) => elemento.slug === slug); | ||
const conteo = lugar[0] ? lugar[0].conteo : 0; | ||
|
||
const respuesta: Lugar = { | ||
nombre: nombreLugar, | ||
slug: slug, | ||
lon: +longitud, | ||
lat: +latitud, | ||
conteo | ||
}; | ||
|
||
if (respuesta.lon && respuesta.lat) { | ||
lugares.push(respuesta); | ||
} | ||
} | ||
|
||
// Función para crear geojson con lugares y cantidad de proyectos por lugar | ||
function procesarDatosMapaEgresados() { | ||
for (let lugar in lugares) { | ||
const conteo = lugares[lugar].conteo; | ||
|
||
const elemento: Feature<Point> = { | ||
type: 'Feature', | ||
properties: { | ||
slug: lugares[lugar].slug, | ||
nombre: lugares[lugar].nombre, | ||
conteo | ||
}, | ||
geometry: { type: 'Point', coordinates: [lugares[lugar].lon, lugares[lugar].lat] } | ||
}; | ||
|
||
if (conteo > 0) { | ||
geojson.features.push(elemento); | ||
} | ||
} | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.