This commit is contained in:
2023-04-03 16:01:01 +02:00
parent a1b0f6bd31
commit 9a6a065882

View File

@@ -1,29 +1,58 @@
<template>
<div class="flex flex-center">
<h5 class="q-py-xl">{{ fecha }}</h5>
<q-btn
class="fixed-center"
color="deep-orange"
glossy
label="Calcular"
@click="calcular()"
></q-btn>
{{ data }}
</div>
</template>
<script setup>
import { ref, onMounted } from "vue";
import axios from "axios";
import { date } from "quasar";
const data = ref(null);
const humedad_relativa = ref(0);
const temp_max = ref(0);
const fecha = ref("");
const calcular = () => {
let valor = 0;
valor = temp_max.value - humedad_relativa.value * 0.2;
//console.log(Math.round(valor));
let hoy = new Date();
let newDate = date.addToDate(hoy, { days: Math.round(valor) });
fecha.value = newDate.toLocaleDateString("es-es", {
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
});
};
onMounted(() => {
console.log("gooooo");
axios
.get(
`https://api.openweathermap.org/data/2.5/forecast/daily?lat=44.34&lon=10.99&cnt=7&appid=1ce95ef35a6852cecee421a923fe4400`
`https://api.open-meteo.com/v1/forecast?latitude=39.55&longitude=-0.57&hourly=relativehumidity_2m&models=gfs_global&daily=temperature_2m_max,temperature_2m_min&timezone=Europe%2FLondon`
)
.then((res) => {
console.log(res);
//console.log("humedad relativa", res.data.hourly.relativehumidity_2m);
let suma_humedad = 0;
res.data.hourly.relativehumidity_2m.forEach((element) => {
suma_humedad += element;
});
humedad_relativa.value =
suma_humedad / res.data.hourly.relativehumidity_2m.length;
//console.log("temp máxima", res.data.daily.temperature_2m_max);
let suma_temp_max = 0;
res.data.daily.temperature_2m_max.forEach((element) => {
suma_temp_max += element;
});
temp_max.value = suma_temp_max / res.data.daily.temperature_2m_max.length;
});
});
</script>