Skip to content

Commit

Permalink
update:d03
Browse files Browse the repository at this point in the history
  • Loading branch information
Danitaillefer committed May 13, 2024
2 parents 35d5d24 + 010ef58 commit e6dd5cc
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 43 deletions.
79 changes: 39 additions & 40 deletions back/api-top-richest/v2/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const API_BASE = "/api/v2";
import request from 'request';

let list = [
{ name: 'Elon Musk', net_worth: 240, bday_year: 1971, age: 51, nationality: 'South Africa' },
Expand All @@ -16,55 +17,48 @@ let list = [


function validarDatos(req, res, next) {
const json = req.body;

const esquema = {
'name': 'string',
'net_worth': 'number',
'bday_year': 'number',
'age': 'number',
'nationality': 'string',
};

const receivedKeys = Object.keys(json);
const expectedKeys = Object.keys(esquema);
const missingKeys = expectedKeys.filter(key => !receivedKeys.includes(key));


const extraKeys = receivedKeys.filter(key => !expectedKeys.includes(key));
if (extraKeys.length > 0) {
console.error(`There are more keys than expected: ${extraKeys.join(', ')}`);
return res.sendStatus(400, "Bad request");
}
const json = req.body;

const esquema = {
'name': 'string',
'net_worth': 'number',
'bday_year': 'number',
'age': 'number',
'nationality': 'string'
};

const receivedKeys = Object.keys(json);
const expectedKeys = Object.keys(esquema);

const missingKeys = expectedKeys.filter(key => !receivedKeys.includes(key));
if (missingKeys.length > 0) {
console.error(`There are missing keys: ${missingKeys.join(', ')}`);
return res.sendStatus(400, "Bad request");
}


if (missingKeys.length > 0) {
console.error(`There are missing keys: ${missingKeys.join(', ')}` );
return res.sendStatus(400, "Bad request");
}
const erroresTipo = [];


const erroresTipo = [];
expectedKeys.forEach(key => {
const tipoEsperado = esquema[key];
const valor = json[key];
if (valor === null || valor === undefined || valor === '') {
erroresTipo.push(`El valor de '${key}' está vacío`);
} else if (typeof valor !== tipoEsperado) {
erroresTipo.push(`El valor de '${key}' debe ser de tipo '${tipoEsperado}'`);
}
});

expectedKeys.forEach(key => {
const tipoEsperado = esquema[key];
const valor = json[key];
if (typeof valor !== tipoEsperado) {
erroresTipo.push(`El valor de '${key}' debe ser de tipo '${tipoEsperado}'`);
}
});
if (erroresTipo.length > 0) {
console.error(`Errores de tipo: ${erroresTipo.join(', ')}`);
return res.sendStatus(400, "Bad request");
}

if (erroresTipo.length > 0) {
console.error(`Errores de tipo: ${erroresTipo.join(', ')}`);
return res.sendStatus(400, "Bad request");
}
next();
next();
}





function LoadBackendTR2(app,dbtop100richest2) {

dbtop100richest2.insert(list);
Expand Down Expand Up @@ -282,6 +276,11 @@ dbtop100richest2.find( { name: personName }, (err,searchedPerson) => {
});
});

app.use('/proxyTR', function(req,res){
let url= 'https://sos2324-22.ew.r.appspot.com/api/v2/top-richest';
console.log('piped: ' + req.url);
req.pipe(request(url)).pipe(res);
});


};
Expand Down
Binary file added efforts/benvelben/detailed.pdf
Binary file not shown.
Binary file added efforts/benvelben/summary.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions front/src/routes/Integraciones-benvelben/crypto/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
<svelte:head>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<script src="https://code.highcharts.com/modules/treemap.js"></script>
<script src="https://code.highcharts.com/modules/bar.js"></script>
</svelte:head>

<script>
import { onMount } from 'svelte';
Expand Down
11 changes: 11 additions & 0 deletions front/src/routes/Integraciones-benvelben/music/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
<svelte:head>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<script src="https://code.highcharts.com/modules/scatter.js"></script>
</svelte:head>



<script>
import { onMount } from 'svelte';
Expand Down
9 changes: 8 additions & 1 deletion front/src/routes/Integraciones-benvelben/netW/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<svelte:head>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<script src="https://code.highcharts.com/modules/treemap.js"></script>
<script src="https://code.highcharts.com/modules/pie.js"></script>
</svelte:head>

<script>
Expand All @@ -8,7 +14,7 @@
let ms = [];
let API = "/api/v2/top-richest";
let API = "/proxyTR";
if (dev) {
API = "http://localhost:10000" + API;
Expand Down Expand Up @@ -77,6 +83,7 @@
}
function renderChart() {
console.log(ms);
const chartData = ms.map(millionaire => {
return {
name: millionaire.name,
Expand Down
98 changes: 98 additions & 0 deletions front/src/routes/Integraciones-benvelben/preciosABNB/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<svelte:head>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<script src="https://code.highcharts.com/modules/treemap.js"></script>
<script src="https://code.highcharts.com/modules/area.js"></script>
</svelte:head>

<script>
import { onMount } from 'svelte';
onMount(() => {
});
let selectedMonth = new Date().getMonth() + 1;
let chartData = [];
async function fetchData() {
const options = {
method: 'GET',
headers: {
'X-RapidAPI-Key': '744984621cmsha5593e77613e5d0p103591jsn5d3532ea0b8f',
'X-RapidAPI-Host': 'airbnb-listings.p.rapidapi.com'
}
};
try {
const response = await fetch(`https://airbnb-listings.p.rapidapi.com/v2/listingPrices?id=619966061834034729&year=2024&month=${selectedMonth}`, options);
const data = await response.json();
chartData = processData(data);
renderChart();
} catch (error) {
console.error('Error fetching data:', error);
}
}
function processData(data) {
return data.results.map(dayData => {
return [Date.parse(dayData.date), dayData.price];
});
}
function renderChart() {
Highcharts.chart('chart-container', {
chart: {
type: 'area'
},
title: {
text: `Precios de Airbnb por día en ${getMonthName(selectedMonth)} de 2024 en Atlantic Panorama Ocean front. Garden & salt pool`
},
xAxis: {
type: 'datetime',
labels: {
formatter: function () {
return Highcharts.dateFormat('%e', this.value);
}
}
},
yAxis: {
title: {
text: 'Precio'
}
},
series: [{
name: 'Precio',
data: chartData
}],
plotOptions: {
area: {
marker: {
enabled: false
}
}
},
credits: {
enabled: false
}
});
}
function getMonthName(month) {
const months = ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'];
return months[month - 1];
}
</script>

<main>
<h1>Selecciona un mes:</h1>
<select bind:value={selectedMonth} on:change={fetchData}>
{#each Array.from({ length: 12 }, (_, i) => i + 1) as month}
<option value={month}>{getMonthName(month)}</option>
{/each}
</select>
<div id="chart-container" style="height: 400px;"></div>
</main>
4 changes: 4 additions & 0 deletions front/src/routes/integrations/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@
<button>Uso API de conversion de moneda </button>
</a>

<a href="/Integraciones-benvelben/preciosABNB" style="text-decoration: none;">
<button>Uso API de precios AirBnB </button>
</a>




Expand Down
4 changes: 2 additions & 2 deletions front/src/routes/top-richest/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
let Msg = "";
let searchParams = {
name: "",
name: null,
net_worth: null,
bday_year: null,
age: null,
nationality: "",
nationality: null,
};
let searchResults = [];
Expand Down

0 comments on commit e6dd5cc

Please sign in to comment.