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 ]; // return [ latlon.longitude, latlon.latitude ];
}) })
.then( (res) => { .then( (res) => {
let forecastData: object = res.hourly; let yAxis: object[] = [];
let fmtForecastData: { title: string, data: [Date, number] | [] } = { title: 'Temps', data: [] }; let temps: object[] = [];
let regex: RegExp = /(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/ ["hourly", "six_hourly", "three_hourly", "daily"].forEach(function (section, index) {
forecastData.time.forEach( (elem, idx) => { if (!(section in res)) {
fmtForecastData.data.push([Date.parse(elem), forecastData.temperature_2m[idx]]) 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 } return { ubicacio, temps }