anomalyFarmGraphFields.mjs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * 风场总图在 getAnomalyOverview 中的字段名。
  3. * 前端页面与 Node 报告必须共用,避免 Graph 字段映射漂移。
  4. */
  5. export const FARM_GRAPH_FIELD_BY_TEMPLATE = {
  6. wind_power_curve: "model1WindpwrPowercurveGraph",
  7. wind_power_scatter: "model1WindpwrScatterGraph",
  8. yaw_static: "model2YawStaticyawGraph",
  9. yaw_twist: "model2YawCabletwistGraph",
  10. yaw_error: "model2YawYawerrorGraph",
  11. yaw_count: "model2YawYawcountGraph",
  12. pitch_coord: "model3PitchPitchcoordGraph",
  13. pitch_regulation: "model3PitchPitchregulationGraph",
  14. pitch_min: "model3PitchMinpitchGraph",
  15. ctrl_power_quality: "model4CtrlparamPowerqualityGraph",
  16. ctrl_op_state: "model4CtrlparamOperationstateGraph",
  17. ctrl_deload: "model4CtrlparamDeloadGraph",
  18. aero_cp: "model5AerodynamicsCpGraph",
  19. aero_tsr: "model5AerodynamicsTsrGraph",
  20. aero_tsr_wind: "model5AerodynamicsCpTsrGraph",
  21. };
  22. function overviewRecords(overviewData) {
  23. if (!overviewData) return [];
  24. if (Array.isArray(overviewData)) return overviewData;
  25. if (Array.isArray(overviewData.list)) return overviewData.list;
  26. if (Array.isArray(overviewData.records)) return overviewData.records;
  27. if (Array.isArray(overviewData.data)) return overviewData.data;
  28. if (typeof overviewData === "object") return [overviewData];
  29. return [];
  30. }
  31. function normalizeGraphSource(raw) {
  32. if (raw == null || raw === "") return null;
  33. if (typeof raw === "object") return raw;
  34. const text = String(raw).trim();
  35. if (!text || text === "null" || text === "undefined" || text === "NULL") {
  36. return null;
  37. }
  38. return text;
  39. }
  40. /** 从 getAnomalyOverview 取出各检测器总图 JSON 地址或内嵌对象 */
  41. export function collectFarmGraphPaths(overviewData) {
  42. const paths = {};
  43. overviewRecords(overviewData).forEach((record) => {
  44. if (!record || typeof record !== "object") return;
  45. Object.entries(FARM_GRAPH_FIELD_BY_TEMPLATE).forEach(
  46. ([templateKey, graphField]) => {
  47. if (paths[templateKey]) return;
  48. const source = normalizeGraphSource(record[graphField]);
  49. if (source) paths[templateKey] = source;
  50. },
  51. );
  52. });
  53. return paths;
  54. }
  55. export function parseFarmGraphSource(source) {
  56. if (!source) return { kind: "empty", data: null, url: "" };
  57. if (typeof source === "object") {
  58. return { kind: "json", data: source, url: "" };
  59. }
  60. const text = String(source).trim();
  61. if (!text || text === "null" || text === "undefined" || text === "NULL") {
  62. return { kind: "empty", data: null, url: "" };
  63. }
  64. if (text.startsWith("{") || text.startsWith("[")) {
  65. try {
  66. return { kind: "json", data: JSON.parse(text), url: "" };
  67. } catch (_error) {
  68. return { kind: "empty", data: null, url: "" };
  69. }
  70. }
  71. return { kind: "url", data: null, url: text };
  72. }