generated from enflujo/enflujo-plantilla-vite-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧 Prueba básica de limpieza datos ruido
- Loading branch information
Showing
7 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { esNumero, guardarJSON, mensajes } from './utilidades/ayudas'; | ||
import { getXlsxStream } from 'xlstream'; | ||
type Ruido = [ | ||
/** Leq-1: contiene los niveles intermedios de ruido en esos 10 segundos de medición. Con este dato la experta menciona se puede comparar con la normativa de un máximo de 80db. En promedio se observó que los niveles de ruido son cercanos a 80db pero no superaron la normativa nacional. */ | ||
leq1: number | null, | ||
/** Lmax: contiene los niveles máximos de ruido captados en esos 10 segundos de medición. */ | ||
lmax1: number | null, | ||
]; | ||
const estructuras = { | ||
ruido: { | ||
archivo: 'Ruido_10 sec', | ||
nombreHoja: 'Sheet1', | ||
llaves: [ | ||
'ID', | ||
'Timestamp', | ||
'Leq-1', | ||
'Lmax-1', | ||
'Punto muestreado', | ||
'Name', | ||
'Jornada', | ||
'Date', | ||
'Longitud_X', | ||
'Latitud_Y', | ||
], | ||
}, | ||
}; | ||
|
||
async function inicio(): Promise<void> { | ||
const { ruido } = estructuras; | ||
const ruta = `./datos/${ruido.archivo}.xlsx`; | ||
const flujo = await getXlsxStream({ | ||
filePath: ruta, | ||
sheet: ruido.nombreHoja, | ||
withHeader: true, | ||
ignoreEmpty: true, | ||
}); | ||
|
||
let numeroFila = 2; | ||
let primeraFilaProcesada = false; | ||
const errataRuido: { fila: number; error: string }[] = []; | ||
const ruidoProcesados: Ruido[] = []; | ||
|
||
return new Promise((resolver) => { | ||
flujo.on('data', async ({ raw }) => { | ||
if (!primeraFilaProcesada) { | ||
// console.log(compararListas(Object.keys(raw.obj), ruido.llaves)); | ||
primeraFilaProcesada = true; | ||
} | ||
|
||
const [id, hora, leq1, lmax1, punto, nombre, jornada, lon, lat] = raw.arr; | ||
const filaProcesada: Ruido = [null, null]; | ||
|
||
if (esNumero(leq1)) { | ||
filaProcesada[0] = leq1; | ||
} else { | ||
errataRuido.push({ fila: numeroFila, error: `Leq-1 no es número, su valor es: ${leq1}` }); | ||
} | ||
|
||
if (esNumero(lmax1)) { | ||
filaProcesada[1] = lmax1; | ||
} else { | ||
errataRuido.push({ fila: numeroFila, error: `Lmax-1 no es número, su valor es: ${lmax1}` }); | ||
} | ||
|
||
ruidoProcesados.push(filaProcesada); | ||
numeroFila++; | ||
}); | ||
|
||
flujo.on('close', () => { | ||
mensajes.exito('FIN'); | ||
|
||
if (errataRuido.length) guardarJSON(errataRuido, 'errataRuido'); | ||
if (ruidoProcesados.length) { | ||
guardarJSON(ruidoProcesados, 'ruido'); | ||
} | ||
|
||
resolver(); | ||
}); | ||
|
||
flujo.on('error', (error) => { | ||
throw new Error(JSON.stringify(error, null, 2)); | ||
}); | ||
}); | ||
} | ||
|
||
inicio().catch(console.error); |
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { writeFileSync } from 'fs'; | ||
import colores from 'cli-color'; | ||
import { emojify } from 'node-emoji'; | ||
|
||
export const logError = colores.red.bold; | ||
export const logAviso = colores.bold.xterm(214); | ||
export const logBloque = colores.bgCyan.black; | ||
export const logCyan = colores.cyan.bold; | ||
export const logVerde = colores.greenBright; | ||
export const logNaranjaPulso = colores.xterm(214).blink; | ||
|
||
// https://raw.githubusercontent.com/omnidan/node-emoji/master/lib/emoji.json | ||
export const cadena = emojify(':link:'); | ||
export const conector = emojify(':electric_plug:'); | ||
export const gorila = emojify(':gorilla:'); | ||
export const chulo = emojify(':white_check_mark:'); | ||
|
||
export const mensajes = { | ||
proceso: (mensaje: string) => { | ||
console.log(gorila, logCyan(mensaje)); | ||
}, | ||
exito: (mensaje: string) => { | ||
console.log(chulo, logAviso(mensaje)); | ||
}, | ||
}; | ||
|
||
export const guardarJSON = (json: any, nombre: string) => { | ||
writeFileSync(`../www/estaticos/datos/${nombre}.json`, JSON.stringify(json)); | ||
}; | ||
|
||
export function ordenarListaObjetos(lista: any[], llave: string, descendente = false) { | ||
lista.sort((a, b) => { | ||
if (a[llave] < b[llave]) return descendente ? -1 : 1; | ||
else if (a[llave] > b[llave]) return descendente ? 1 : -1; | ||
return 0; | ||
}); | ||
} | ||
|
||
export const normalizar = (texto: string): string => { | ||
return texto | ||
.toLocaleLowerCase() | ||
.normalize('NFD') | ||
.replace(/[\u0300-\u036f]/g, ''); | ||
}; | ||
|
||
export const enMinusculas = (texto: string) => texto === texto.toLowerCase(); | ||
|
||
export function separarPartes(entrada: string, separador?: string) { | ||
const valores = entrada.trim(); | ||
const partes = separador ? valores.trim().split(separador) : valores.trim().split(','); | ||
return partes.map((p) => p.trim()); | ||
} | ||
|
||
export const compararListas = (a: any[], b: any[]) => | ||
a.length === b.length && a.every((element, index) => element === b[index]); | ||
|
||
export const esNumero = (valor: string | number): boolean => !isNaN(parseInt(`${valor}`)); |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<script setup lang="ts"> | ||
import Hola from './componentes/Hola.vue'; | ||
async function cargarDatos() { | ||
try { | ||
const ruido = await fetch('/datos/ruido.json').then((res) => res.json()); | ||
console.log(ruido); | ||
} catch (error) { | ||
console.error('Error descargando datos del ruido', error); | ||
} | ||
} | ||
cargarDatos().catch(console.error); | ||
</script> | ||
|
||
<template> | ||
<Hola /> | ||
</template> | ||
|
||
<style lang="scss" scoped> | ||
#main { | ||
background-color: yellow; | ||
} | ||
</style> |