feat: 前端新增雨量预测准确率
This commit is contained in:
parent
0caa1da229
commit
d78bfd381b
@ -170,20 +170,23 @@ const WeatherApp = {
|
||||
try {
|
||||
const hexID = WeatherUtils.decimalToHex(decimalId);
|
||||
const stationID = `RS485-${hexID}`;
|
||||
const endPlus3Str = (() => {
|
||||
try {
|
||||
const d = new Date(endTime);
|
||||
if (!isNaN(d)) {
|
||||
const d2 = new Date(d.getTime() + 3 * 60 * 60 * 1000);
|
||||
return WeatherUtils.formatDatetimeLocal(d2).replace('T', ' ') + ':00';
|
||||
}
|
||||
} catch (e) {}
|
||||
return endTime.replace('T', ' ') + ':00';
|
||||
})();
|
||||
// 将预报查询范围按小时对齐:from 向下取整到整点;to 向上取整到整点,再 +3h
|
||||
const parseLocal = (s) => { try { return new Date(s); } catch { return null; } };
|
||||
const floorHour = (d) => { const t = new Date(d); t.setMinutes(0,0,0); return t; };
|
||||
const ceilHour = (d) => { const t = new Date(d); if (t.getMinutes()||t.getSeconds()||t.getMilliseconds()) { t.setHours(t.getHours()+1); } t.setMinutes(0,0,0); return t; };
|
||||
const fmt = (d) => {
|
||||
const y=d.getFullYear(); const m=String(d.getMonth()+1).padStart(2,'0'); const da=String(d.getDate()).padStart(2,'0');
|
||||
const h=String(d.getHours()).padStart(2,'0'); const mi='00'; const s='00';
|
||||
return `${y}-${m}-${da} ${h}:${mi}:${s}`;
|
||||
};
|
||||
const startD = parseLocal(startTime);
|
||||
const endD = parseLocal(endTime);
|
||||
const fromStr = startD && !isNaN(startD) ? fmt(floorHour(startD)) : startTime.replace('T',' ') + ':00';
|
||||
const toStr = endD && !isNaN(endD) ? fmt(new Date(ceilHour(endD).getTime() + 3*60*60*1000)) : endTime.replace('T',' ') + ':00';
|
||||
const forecastParams = new URLSearchParams({
|
||||
station_id: stationID,
|
||||
from: startTime.replace('T', ' ') + ':00',
|
||||
to: endPlus3Str,
|
||||
from: fromStr,
|
||||
to: toStr,
|
||||
provider: forecastProvider,
|
||||
versions: '3'
|
||||
});
|
||||
@ -250,4 +253,4 @@ window.WeatherApp = WeatherApp;
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
WeatherApp.init();
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user