Openmeteo page update (not working)

This commit is contained in:
pswsm 2023-03-06 19:07:39 +01:00
pare 537a1a3729
commit f04d95ff84

Veure arxiu

@ -14,13 +14,50 @@ export function load(): object {
// return [ latlon.longitude, latlon.latitude ];
})
.then( (res) => {
let forecastData: object = res.hourly;
let fmtForecastData: { title: string, data: [Date, number] | [] } = { title: 'Temps', data: [] };
let regex: RegExp = /(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/
forecastData.time.forEach( (elem, idx) => {
fmtForecastData.data.push([Date.parse(elem), forecastData.temperature_2m[idx]])
let yAxis: object[] = [];
let temps: object[] = [];
["hourly", "six_hourly", "three_hourly", "daily"].forEach(function (section, index) {
if (!(section in res)) {
return
}
Object.entries(res[section]||[]).forEach(function(k){
if (k[0] == "time" || k[0] == "sunrise" || k[0] == "sunset") {
return
}
let hourly_starttime = (res[section].time[0] + res.utc_offset_seconds) * 1000;
let pointInterval = (res[section].time[1] - res[section].time[0]) * 1000;
let unit = res[`${section}_units`][k[0]];
var axisId = null;
for (let i = 0; i < yAxis.length; i++) {
if (yAxis[i].title.text == unit) {
axisId = i;
}
}
if (axisId == null) {
yAxis.push({title: {text: unit}});
axisId = yAxis.length-1;
}
var ser = {
name: k[0],
res: k[1],
yAxis: axisId,
pointStart:hourly_starttime,
pointInterval: pointInterval,
type: (unit == 'mm' || unit == 'cm' || unit == 'inch' || unit == 'MJ/m²') ? 'column' : 'line',
tooltip: {
valueSuffix: " " + unit,
},
dataGrouping: {groupPixelWidth: 12}
/*dataGrouping: {
enabled: true,
forced: true,
units: [['year',[1]]]
}*/
};
temps.push(ser);
});
});
return fmtForecastData;
return temps;
} )
return { ubicacio, temps }