ykzz-web/src/views/TestLine/watersTools.js

34 lines
1.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import moment from "moment";
/**
* 使用滑动窗口获取水文数据批次
* @param {Array} data - 后端返回的数据数组
* @returns {Array} - 返回数组每个元素包含600个点的数据
*/
export const getAllHydroBatches = (data) => {
if (!Array.isArray(data) || data.length < 600) {
return [];
}
const batches = [];
let startIndex = 0;
// 当剩余数据量大于等于600时继续处理
while (startIndex + 600 <= data.length) {
const slicedData = data.slice(startIndex, startIndex + 600);
batches.push({
rains: slicedData.map(item => item.rains),
waters: slicedData.map(item => item.waters),
lastTm: slicedData[599].tm // 记录第600个点的时间
});
// 每次向后移动1个位置
startIndex += 1;
}
return batches;
};
export const responseData = new Array(800).fill(0).map((item,index) => ({
rains: (Math.random() * 1).toFixed(2),
waters: (Math.random() * 100).toFixed(2),
tm:moment().clone().add(index, 'hours').format("YYYY-MM-DD HH:00:00")
}))