/** * 联调 getDataCompleteness * 用法: * node scripts/test-data-completeness-api.mjs [fieldCode] [datatime] [dataType] * 示例: * node scripts/test-data-completeness-api.mjs SVLgVZfi 2026-08-18 min */ import "dotenv/config"; import { fetchAnomalyDataCompleteness } from "../src/server/reportService/analyseApiClient.js"; import { buildDataCompletenessHeatmapData } from "../src/server/reportService/anomalyReportMapper.js"; const fieldCode = process.argv[2] || "SVLgVZfi"; const datatime = process.argv[3] || "2026-08-18"; const dataType = process.argv[4] || "min"; console.log("ANALYSE_API_BASE_URL =", process.env.ANALYSE_API_BASE_URL || "(未配置)"); console.log("请求参数:", { fieldCode, datatime, dataType }); try { const rows = await fetchAnomalyDataCompleteness( { fieldCode, datatime, dataType }, {}, ); console.log("code=200, records =", rows.length); if (rows[0]) { console.log("首条样例:", JSON.stringify(rows[0], null, 2)); } const valueKey = dataType === "sec" ? "secondDataCompleteness" : "minuteDataCompleteness"; const nonNull = rows.filter((row) => row?.[valueKey] != null && row[valueKey] !== ""); console.log(`${valueKey} 非空条数:`, nonNull.length); const heatmap = buildDataCompletenessHeatmapData(rows, valueKey); console.log( "热力图矩阵:", `${heatmap.yLabels.length} 行(机组) × ${heatmap.xLabels.length} 列(日期)`, ); if (heatmap.yLabels.length && heatmap.xLabels.length) { const max = Math.max(...heatmap.matrix.flat()); console.log("矩阵最大值(%):", max); } } catch (error) { console.error("调用失败:", error.message); process.exit(1); }