| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- /**
- * 风场总图在 getAnomalyOverview 中的字段名。
- * 前端页面与 Node 报告必须共用,避免 Graph 字段映射漂移。
- */
- export const FARM_GRAPH_FIELD_BY_TEMPLATE = {
- wind_power_curve: "model1WindpwrPowercurveGraph",
- wind_power_scatter: "model1WindpwrScatterGraph",
- yaw_static: "model2YawStaticyawGraph",
- yaw_twist: "model2YawCabletwistGraph",
- yaw_error: "model2YawYawerrorGraph",
- yaw_count: "model2YawYawcountGraph",
- pitch_coord: "model3PitchPitchcoordGraph",
- pitch_regulation: "model3PitchPitchregulationGraph",
- pitch_min: "model3PitchMinpitchGraph",
- ctrl_power_quality: "model4CtrlparamPowerqualityGraph",
- ctrl_op_state: "model4CtrlparamOperationstateGraph",
- ctrl_deload: "model4CtrlparamDeloadGraph",
- aero_cp: "model5AerodynamicsCpGraph",
- aero_tsr: "model5AerodynamicsTsrGraph",
- aero_tsr_wind: "model5AerodynamicsCpTsrGraph",
- };
- function overviewRecords(overviewData) {
- if (!overviewData) return [];
- if (Array.isArray(overviewData)) return overviewData;
- if (Array.isArray(overviewData.list)) return overviewData.list;
- if (Array.isArray(overviewData.records)) return overviewData.records;
- if (Array.isArray(overviewData.data)) return overviewData.data;
- if (typeof overviewData === "object") return [overviewData];
- return [];
- }
- function normalizeGraphSource(raw) {
- if (raw == null || raw === "") return null;
- if (typeof raw === "object") return raw;
- const text = String(raw).trim();
- if (!text || text === "null" || text === "undefined" || text === "NULL") {
- return null;
- }
- return text;
- }
- /** 从 getAnomalyOverview 取出各检测器总图 JSON 地址或内嵌对象 */
- export function collectFarmGraphPaths(overviewData) {
- const paths = {};
- overviewRecords(overviewData).forEach((record) => {
- if (!record || typeof record !== "object") return;
- Object.entries(FARM_GRAPH_FIELD_BY_TEMPLATE).forEach(
- ([templateKey, graphField]) => {
- if (paths[templateKey]) return;
- const source = normalizeGraphSource(record[graphField]);
- if (source) paths[templateKey] = source;
- },
- );
- });
- return paths;
- }
- export function parseFarmGraphSource(source) {
- if (!source) return { kind: "empty", data: null, url: "" };
- if (typeof source === "object") {
- return { kind: "json", data: source, url: "" };
- }
- const text = String(source).trim();
- if (!text || text === "null" || text === "undefined" || text === "NULL") {
- return { kind: "empty", data: null, url: "" };
- }
- if (text.startsWith("{") || text.startsWith("[")) {
- try {
- return { kind: "json", data: JSON.parse(text), url: "" };
- } catch (_error) {
- return { kind: "empty", data: null, url: "" };
- }
- }
- return { kind: "url", data: null, url: text };
- }
|