-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.889daa91.js
2 lines (2 loc) · 2.26 KB
/
index.889daa91.js
1
2
function e(e){let t=parseInt(e.datetime.substr(11,2)),n="dashboard";n+=t<6?"1":t>=6&&t<12?"2":t>=12&&t<18?"3":"4";let a=document.getElementById(n),d=document.createElement("div");d.className="bg-white shadow-2xl p-3 rounded-lg m-2",d.setAttribute("id","tarjeta"+t);let o=document.createElement("div");o.className="flex flex-col items-center";let r=document.createElement("h2");r.className="text-2xl font-bold text-center",r.innerText=(e.value/1e3).toFixed(4)+" €/kWh",r.setAttribute("id","precio"+t);let l=document.createElement("div");l.className="text-sm font-light",l.innerText=t+"h - "+(t+1)+"h",l.setAttribute("id","hora"+t),a.appendChild(d).appendChild(o).appendChild(r).appendChild(l)}function t(e){let t=[];for(let n in e)t.push(parseFloat((e[n].value/1e3).toFixed(4)));let n=Math.min(...t),a=Math.max(...t),d=t.reduce(((e,t,n,a)=>e+t/a.length),0),o=parseFloat(function(e){const t=e.length,n=e.reduce(((e,t)=>e+t))/t;return Math.sqrt(e.map((e=>Math.pow(e-n,2))).reduce(((e,t)=>e+t))/t)}(t).toFixed(4));d=parseFloat(d.toFixed(4));let r=t.indexOf(n),l=t.indexOf(a);document.getElementById("horaminima").innerText="Franja horaria: "+r+"h - "+(r+1)+"h",document.getElementById("horamaxima").innerText="Franja horaria: "+l+"h - "+(l+1)+"h",document.getElementById("preciomedio").innerText=d+" €/kWh",document.getElementById("preciominimo").innerText=n+" €/kWh",document.getElementById("preciomaximo").innerText=a+" €/kWh";for(let e=0;e<25;e++){let n=document.getElementById("tarjeta"+e),a=t[e];n.className=a<d-o?"bg-green-400 shadow-2xl p-3 rounded-lg m-2":a>d+o?"bg-red-400 shadow-2xl p-3 rounded-lg m-2":"bg-orange-400 shadow-2xl p-3 rounded-lg m-2"}}let n=document.getElementById("fechadehoy"),a=new Date(Date.now()),d=a.toLocaleDateString("es-ES",{weekday:"long"}),o=a.getDate(),r=a.toLocaleDateString("es-ES",{month:"long"}),l=a.getMonth()+1,i=a.getFullYear();n.innerText="Precios de la energía para hoy, "+d+" "+o+" de "+r+" del "+i;let m=[i,l,o].join("-")+"T00:00",c=[i,l,o].join("-")+"T23:59";fetch("https://apidatos.ree.es/es/datos/mercados/precios-mercados-tiempo-real?start_date="+m+"&end_date="+c+"&time_trunc=hour").then((e=>e.json())).then((n=>function(n){n.included[0].attributes.values.forEach(e),t(n.included[0].attributes.values)}(n)));
//# sourceMappingURL=index.889daa91.js.map