-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
117 additions
and
118 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const PARTIDOS_TOTALES = 14 | ||
|
||
export default function calcularParcial (arrayEquipos) { | ||
return arrayEquipos.map(infoEquipo => { | ||
const { nombre, puntosTotales, partidosJugados } = infoEquipo | ||
|
||
const porcentajeActual = parseFloat((puntosTotales / (partidosJugados * 3)).toFixed(2)) | ||
const puntosEstimados = parseInt((PARTIDOS_TOTALES - partidosJugados) * 3 * porcentajeActual) | ||
|
||
return { | ||
nombre, | ||
porcentajeActual, | ||
puntosEstimados | ||
} | ||
}) | ||
} |
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,25 @@ | ||
import calcularParcial from './calcularParcial.js' | ||
|
||
export default function calcularTotal (tablaGeneral, zonaA, zonaB) { | ||
const unificado = [...calcularParcial(zonaA), ...calcularParcial(zonaB)] | ||
|
||
const datos = tablaGeneral.map(equipo => { | ||
const equipoEncontrado = unificado.find(eq => eq.nombre === equipo.nombre) | ||
const puntosFinalesEstimados = equipo.puntosTotales + equipoEncontrado.puntosEstimados | ||
|
||
return { | ||
...equipo, | ||
porcentajeActual: equipoEncontrado.porcentajeActual, | ||
puntosFinalesEstimados | ||
} | ||
}) | ||
|
||
return datos | ||
.sort((a, b) => b.puntosFinalesEstimados - a.puntosFinalesEstimados) | ||
.map((equipoInfo, index) => { | ||
return { | ||
posicion: index + 1, | ||
...equipoInfo | ||
} | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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,19 @@ | ||
import { extract } from '@extractus/article-extractor' | ||
import * as cheerio from 'cheerio' | ||
|
||
export default async function extraerDatosConCheerio (URL) { | ||
const { content } = await extract(URL) | ||
|
||
const $ = cheerio.load(content) | ||
|
||
const tablaAnual = $("p:contains('Tabla Anual 2023 (Copas+Descenso)')") | ||
const zonaA = $("p:contains('ZONA A')") | ||
const zonaB = $("p:contains('ZONA B')") | ||
|
||
return { | ||
$, | ||
tablaAnual, | ||
zonaA, | ||
zonaB | ||
} | ||
} |
This file was deleted.
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,25 @@ | ||
export default function formatearInfo (tablaDatos, datosGenerales) { | ||
const buffer = [] | ||
|
||
if (tablaDatos.length > 0) { | ||
tablaDatos.find('tbody tr').each((_, row) => { | ||
const columnas = datosGenerales(row).find('td') | ||
|
||
const nombre = columnas.eq(1).text().trim() | ||
const puntosTotales = parseInt(columnas.eq(2).text(), 10) | ||
const partidosJugados = parseInt(columnas.eq(3).text(), 10) | ||
|
||
const datosEquipo = { | ||
nombre, | ||
puntosTotales, | ||
partidosJugados | ||
} | ||
|
||
buffer.push(datosEquipo) | ||
}) | ||
|
||
return buffer | ||
} else { | ||
return [] | ||
} | ||
} |
This file was deleted.
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,15 +1,15 @@ | ||
import getTableData from './getData.js' | ||
import calculateTotal from './calculateTotal.js' | ||
import useCheerio from './useCheerio.js' | ||
import obtenerDatos from './obtenerDatos.js' | ||
import calcularTotal from './calcularTotal.js' | ||
import extraerDatosConCheerio from './extraerDatosConCheerio.js' | ||
|
||
const URL = 'https://www.promiedos.com.ar/copadeliga' | ||
|
||
export default async function main () { | ||
const { $, yearTable, groupATable, groupBTable } = await useCheerio(URL) | ||
const { $, tablaAnual, zonaA, zonaB } = await extraerDatosConCheerio(URL) | ||
|
||
const tablaAnual = getTableData(yearTable, $) | ||
const zonaA = getTableData(groupATable, $) | ||
const zonaB = getTableData(groupBTable, $) | ||
const datosTablaAnual = obtenerDatos(tablaAnual, $) | ||
const datosZonaA = obtenerDatos(zonaA, $) | ||
const datosZonaB = obtenerDatos(zonaB, $) | ||
|
||
return calculateTotal(tablaAnual, zonaA, zonaB) | ||
return calcularTotal(datosTablaAnual, datosZonaA, datosZonaB) | ||
} |
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,19 @@ | ||
import formatearInfo from './formatear.js' | ||
|
||
export default function obtenerDatos (tablaDatos, datosGenerales) { | ||
let datosFormateados | ||
|
||
if (tablaDatos.length > 0) { | ||
const tabla = tablaDatos.next('table') | ||
|
||
if (tabla.length > 0) { | ||
datosFormateados = formatearInfo(tabla, datosGenerales) | ||
} else { | ||
console.log('No se encontró la tabla hermana.') | ||
} | ||
} else { | ||
console.log('No se encontró el párrafo específico.') | ||
} | ||
|
||
return datosFormateados | ||
} |
This file was deleted.
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