test-data-completeness-api.mjs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * 联调 getDataCompleteness
  3. * 用法:
  4. * node scripts/test-data-completeness-api.mjs [fieldCode] [datatime] [dataType]
  5. * 示例:
  6. * node scripts/test-data-completeness-api.mjs SVLgVZfi 2026-08-18 min
  7. */
  8. import "dotenv/config";
  9. import { fetchAnomalyDataCompleteness } from "../src/server/reportService/analyseApiClient.js";
  10. import { buildDataCompletenessHeatmapData } from "../src/server/reportService/anomalyReportMapper.js";
  11. const fieldCode = process.argv[2] || "SVLgVZfi";
  12. const datatime = process.argv[3] || "2026-08-18";
  13. const dataType = process.argv[4] || "min";
  14. console.log("ANALYSE_API_BASE_URL =", process.env.ANALYSE_API_BASE_URL || "(未配置)");
  15. console.log("请求参数:", { fieldCode, datatime, dataType });
  16. try {
  17. const rows = await fetchAnomalyDataCompleteness(
  18. { fieldCode, datatime, dataType },
  19. {},
  20. );
  21. console.log("code=200, records =", rows.length);
  22. if (rows[0]) {
  23. console.log("首条样例:", JSON.stringify(rows[0], null, 2));
  24. }
  25. const valueKey =
  26. dataType === "sec" ? "secondDataCompleteness" : "minuteDataCompleteness";
  27. const nonNull = rows.filter((row) => row?.[valueKey] != null && row[valueKey] !== "");
  28. console.log(`${valueKey} 非空条数:`, nonNull.length);
  29. const heatmap = buildDataCompletenessHeatmapData(rows, valueKey);
  30. console.log(
  31. "热力图矩阵:",
  32. `${heatmap.yLabels.length} 行(机组) × ${heatmap.xLabels.length} 列(日期)`,
  33. );
  34. if (heatmap.yLabels.length && heatmap.xLabels.length) {
  35. const max = Math.max(...heatmap.matrix.flat());
  36. console.log("矩阵最大值(%):", max);
  37. }
  38. } catch (error) {
  39. console.error("调用失败:", error.message);
  40. process.exit(1);
  41. }