-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.555c4775.js
2 lines (2 loc) · 3.12 KB
/
index.555c4775.js
1
2
!function(){function e(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function t(t){if(Array.isArray(t))return e(t)}function n(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function r(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function a(t,n){if(t){if("string"==typeof t)return e(t,n);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?e(t,n):void 0}}function o(e){return t(e)||n(e)||a(e)||r()}function i(e){var t=parseInt(e.datetime.substr(11,2)),n="dashboard";n+=t<6?"1":t>=6&&t<12?"2":t>=12&&t<18?"3":"4";var r=document.getElementById(n),a=document.createElement("div");a.className="bg-white shadow-2xl p-3 rounded-lg m-2",a.setAttribute("id","tarjeta"+t);var o=document.createElement("div");o.className="flex flex-col items-center";var i=document.createElement("h2");i.className="text-2xl font-bold text-center",i.innerText=(e.value/1e3).toFixed(4)+" €/kWh",i.setAttribute("id","precio"+t);var d=document.createElement("div");d.className="text-sm font-light",d.innerText=t+"h - "+(t+1)+"h",d.setAttribute("id","hora"+t),r.appendChild(a).appendChild(o).appendChild(i).appendChild(d)}function d(e){var t,n,r=[];for(var a in e)r.push(parseFloat((e[a].value/1e3).toFixed(4)));var i,d,l,u=(t=Math).min.apply(t,o(r)),c=(n=Math).max.apply(n,o(r)),m=r.reduce((function(e,t,n,r){return e+t/r.length}),0),s=parseFloat((i=r,d=i.length,l=i.reduce((function(e,t){return e+t}))/d,Math.sqrt(i.map((function(e){return Math.pow(e-l,2)})).reduce((function(e,t){return e+t}))/d)).toFixed(4));m=parseFloat(m.toFixed(4));var h=r.indexOf(u),p=r.indexOf(c);document.getElementById("horaminima").innerText="Franja horaria: "+h+"h - "+(h+1)+"h",document.getElementById("horamaxima").innerText="Franja horaria: "+p+"h - "+(p+1)+"h",document.getElementById("preciomedio").innerText=m+" €/kWh",document.getElementById("preciominimo").innerText=u+" €/kWh",document.getElementById("preciomaximo").innerText=c+" €/kWh";for(var f=0;f<25;f++){var g=document.getElementById("tarjeta"+f),x=r[f];g.className=x<m-s?"bg-green-400 shadow-2xl p-3 rounded-lg m-2":x>m+s?"bg-red-400 shadow-2xl p-3 rounded-lg m-2":"bg-orange-400 shadow-2xl p-3 rounded-lg m-2"}}var l=document.getElementById("fechadehoy"),u=new Date(Date.now()),c=u.toLocaleDateString("es-ES",{weekday:"long"}),m=u.getDate(),s=u.toLocaleDateString("es-ES",{month:"long"}),h=u.getMonth()+1,p=u.getFullYear();l.innerText="Precios de la energía para hoy, "+c+" "+m+" de "+s+" del "+p;var f=[p,h,m].join("-")+"T00:00",g=[p,h,m].join("-")+"T23:59";fetch("https://apidatos.ree.es/es/datos/mercados/precios-mercados-tiempo-real?start_date="+f+"&end_date="+g+"&time_trunc=hour").then((function(e){return e.json()})).then((function(e){return function(e){e.included[0].attributes.values.forEach(i),d(e.included[0].attributes.values)}(e)}))}();
//# sourceMappingURL=index.555c4775.js.map