| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- var path = require('path');
- const dayjs = require('dayjs');
- const { getSubdirectories, getFilesInDirectory } = require('./folder_reader.js');
- async function getLastNewModel(degree) {
- let gfsList = null;
- let hourList = null;
- gfsList = await getSubdirectories(path.join(__dirname, `../../model/grib2/${degree}`));
- if (gfsList?.length) {
- let dates = [];
- for (let i = 0; i < gfsList.length; i++) {
- const filePath = gfsList[i].split("\\");
- dates.push({
- fileName: filePath[filePath.length - 1],
- path: gfsList[i],
- date: Number(filePath[filePath.length - 1].split(".")[1])
- });
- }
- dates.sort((a, b) => {
- return b.date - a.date;
- });
- hourList = await getSubdirectories(path.join(__dirname, `../../model/grib2/${degree}/${dates[0].fileName}`));
- if (hourList?.length) {
- let hours = [];
- for (let i = 0; i < hourList.length; i++) {
- const filePath = hourList[i].split("\\");
- hours.push({
- fileName: filePath[filePath.length - 1],
- path: hourList[i],
- date: Number(filePath[filePath.length - 1])
- });
- }
- hours.sort((a, b) => {
- return b.date - a.date;
- });
- const fileList = await getFilesInDirectory(hours[0].path);
- // return global.downloadManager.manager.getStatus();
- return {
- utcData: convertUtcDateForChinaDate(hours[0].path.split("gfs.")[1].split("\\")[0], hours[0].date - 8),
- chinaData: convertUtcDateForChinaDate(hours[0].path.split("gfs.")[1].split("\\")[0], hours[0].date),
- ...hours[0],
- list: fileList?.length ? fileList : []
- };
- }
- return [];
- }
- return [];
- }
- // utc 时间转中国时间
- function convertUtcDateForChinaDate(day, hour) {
- return dayjs(`${day} ${hour}:00`).add(8, 'hour').format("YYYY-MM-DD HH:mm:ss");
- }
- exports.test = async (req, res) => {
- const r = await getLastNewModel("gfs_1p00");
- res.rescc("成功", 200, r);
- }
|