Skip to content

Commit

Permalink
🚧 Prueba básica de limpieza datos ruido
Browse files Browse the repository at this point in the history
  • Loading branch information
1cgonza committed Aug 30, 2024
1 parent 7b58434 commit f2c5a01
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
Binary file added aplicaciones/procesador/datos/Ruido_10 sec.xlsx
Binary file not shown.
86 changes: 86 additions & 0 deletions aplicaciones/procesador/fuente/aplicacion.ts
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);
57 changes: 57 additions & 0 deletions aplicaciones/procesador/fuente/utilidades/ayudas.ts
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}`));
1 change: 1 addition & 0 deletions aplicaciones/www/estaticos/datos/ruido.json

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions aplicaciones/www/src/Aplicacion.vue
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>

0 comments on commit f2c5a01

Please sign in to comment.