|
|
@@ -112,102 +112,7 @@ const handleChartGeneration = async (
|
|
|
* @param {function} onParsed - 解析成功回调,返回解析后的数据
|
|
|
* @param {function} onError - 出错时的回调
|
|
|
*/
|
|
|
-// const fetchCsvAndParse = async (
|
|
|
-// req,
|
|
|
-// res,
|
|
|
-// onParsed,
|
|
|
-// onError,
|
|
|
-// successMessage,
|
|
|
-// additionalParams = {}
|
|
|
-// ) => {
|
|
|
-// try {
|
|
|
-// const {
|
|
|
-// fileAddr,
|
|
|
-// bucketName,
|
|
|
-// objectName,
|
|
|
-// fieldInfo,
|
|
|
-// chartType,
|
|
|
-// engineTypeCode,
|
|
|
-// } = req.body;
|
|
|
-// if (!fileAddr) {
|
|
|
-// return errorResponse(res, "缺少数据URL", 400);
|
|
|
-// }
|
|
|
-
|
|
|
-// const response = await axios.get(fileAddr, { responseType: "text" });
|
|
|
-// const csvText = response.data;
|
|
|
-// console.log(req.body, "req.body");
|
|
|
-// Papa.parse(csvText, {
|
|
|
-// header: true,
|
|
|
-// complete: async (result) => {
|
|
|
-// const data = result.data
|
|
|
-// .filter((row) => Object.keys(row).length)
|
|
|
-// .slice(0, result.data.length - 1);
|
|
|
-// console.log(data, "csv data 数据");
|
|
|
-// // 调用 onParsed 函数并确保只发送一次响应
|
|
|
-// try {
|
|
|
-// let imageUrl = "";
|
|
|
-// let imageUrls = [];
|
|
|
-// if (typeof onParsed === "function") {
|
|
|
-// if (chartType === "radar") {
|
|
|
-// const results = await Promise.all(
|
|
|
-// data &&
|
|
|
-// data.map((val) =>
|
|
|
-// onParsed(
|
|
|
-// val,
|
|
|
-// data,
|
|
|
-// bucketName,
|
|
|
-// objectName,
|
|
|
-// fieldInfo,
|
|
|
-// engineTypeCode,
|
|
|
-// additionalParams
|
|
|
-// ).catch((err) => {
|
|
|
-// console.error("getRadarCharts failed:", err);
|
|
|
-// return null;
|
|
|
-// })
|
|
|
-// )
|
|
|
-// );
|
|
|
-// imageUrls.push(...results); // 如果你还需要存入 imageUrls
|
|
|
-// console.log(imageUrls, "img");
|
|
|
-// } else {
|
|
|
-// imageUrl = await onParsed(
|
|
|
-// data,
|
|
|
-// bucketName,
|
|
|
-// objectName,
|
|
|
-// fieldInfo,
|
|
|
-// additionalParams
|
|
|
-// );
|
|
|
-// }
|
|
|
-// }
|
|
|
-// successResponse(res, { data, imageUrl, imageUrls }, successMessage);
|
|
|
-// } catch (error) {
|
|
|
-// console.error("处理解析数据时出错:", error);
|
|
|
-// errorResponse(res, "处理数据失败", 500);
|
|
|
-// }
|
|
|
-// },
|
|
|
-// error: (error) => {
|
|
|
-// console.error("CSV 解析错误:", error);
|
|
|
-// if (onError) {
|
|
|
-// onError(error);
|
|
|
-// }
|
|
|
-// errorResponse(res, "CSV 解析失败", 500); // 发送错误响应
|
|
|
-// },
|
|
|
-// });
|
|
|
-// } catch (error) {
|
|
|
-// console.error("获取 CSV 错误:", error);
|
|
|
-
|
|
|
-// if (error.response) {
|
|
|
-// errorResponse(
|
|
|
-// res,
|
|
|
-// `获取数据失败: ${error.response.status}`,
|
|
|
-// error.response.status
|
|
|
-// );
|
|
|
-// } else {
|
|
|
-// errorResponse(res, "获取 CSV 失败", 500);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// };
|
|
|
-
|
|
|
-const text = () => {};
|
|
|
+
|
|
|
const fetchCsvAndParse = async (
|
|
|
req,
|
|
|
res,
|
|
|
@@ -284,11 +189,33 @@ const handleParsedResult = async (
|
|
|
engineTypeCode,
|
|
|
additionalParams
|
|
|
) => {
|
|
|
- const data = result.data
|
|
|
- .filter((row) => Object.keys(row).length)
|
|
|
- .slice(0, result.data.length - 1);
|
|
|
-
|
|
|
- // console.log(data, "csv data 数据");
|
|
|
+ // chartType==="faultUnitChart"?
|
|
|
+ const data =
|
|
|
+ chartType === "faultUnitChart"
|
|
|
+ ? result.data
|
|
|
+ .filter((row) => {
|
|
|
+ return Object.keys(row).length;
|
|
|
+ })
|
|
|
+ .slice(0, result.data.length - 1)
|
|
|
+ .map((item) => ({
|
|
|
+ ...item,
|
|
|
+ count: Number(item.count),
|
|
|
+ fault_time: (Number(item.fault_time) / 3600).toFixed(2),
|
|
|
+ }))
|
|
|
+ .sort((a, b) => Number(b.fault_time) - Number(a.fault_time))
|
|
|
+ : chartType === "faultAllChart"
|
|
|
+ ? result.data
|
|
|
+ .filter((row) => Object.keys(row).length)
|
|
|
+ .slice(0, result.data.length - 1)
|
|
|
+ .map((item) => ({
|
|
|
+ ...item,
|
|
|
+ count: Number(item.count),
|
|
|
+ fault_time_sum: (Number(item.fault_time_sum) / 3600).toFixed(2),
|
|
|
+ }))
|
|
|
+ .sort((a, b) => Number(b.fault_time_sum) - Number(a.fault_time_sum))
|
|
|
+ : result.data
|
|
|
+ .filter((row) => Object.keys(row).length)
|
|
|
+ .slice(0, result.data.length - 1);
|
|
|
|
|
|
try {
|
|
|
let imageUrl = "";
|