|
@@ -702,26 +702,42 @@ export function a23MatrixOf(data, modelName) {
|
|
|
function legendLabelMap(chart) {
|
|
function legendLabelMap(chart) {
|
|
|
const byGroup = {};
|
|
const byGroup = {};
|
|
|
const byMetric = {};
|
|
const byMetric = {};
|
|
|
|
|
+ const byMetricGroup = {};
|
|
|
const entries = chart && Array.isArray(chart.legend_entries) ? chart.legend_entries : [];
|
|
const entries = chart && Array.isArray(chart.legend_entries) ? chart.legend_entries : [];
|
|
|
entries.forEach((entry) => {
|
|
entries.forEach((entry) => {
|
|
|
if (!entry || !entry.label) return;
|
|
if (!entry || !entry.label) return;
|
|
|
const gv = entry.group_values || [];
|
|
const gv = entry.group_values || [];
|
|
|
if (gv.length) byGroup[gv.map(String).join("|")] = entry.label;
|
|
if (gv.length) byGroup[gv.map(String).join("|")] = entry.label;
|
|
|
if (gv.length === 1) byGroup[String(gv[0])] = entry.label;
|
|
if (gv.length === 1) byGroup[String(gv[0])] = entry.label;
|
|
|
- if (entry.metric_key) byMetric[String(entry.metric_key)] = entry.label;
|
|
|
|
|
|
|
+ if (entry.metric_key) {
|
|
|
|
|
+ const mk = String(entry.metric_key);
|
|
|
|
|
+ byMetric[mk] = entry.label;
|
|
|
|
|
+ gv.forEach((g) => {
|
|
|
|
|
+ byMetricGroup[`${mk}|${String(g)}`] = entry.label;
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
- return { byGroup, byMetric };
|
|
|
|
|
|
|
+ return { byGroup, byMetric, byMetricGroup };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-/** 用 legend_entries 的更规范中文 label 替换系列名(优先按 metric_key,其次按 group_values)。 */
|
|
|
|
|
|
|
+/** 用 legend_entries 的更规范中文 label 替换系列名(优先 metric_key+分组,其次 metric_key,最后按系列名)。 */
|
|
|
function relabelSeries(option, labelMap) {
|
|
function relabelSeries(option, labelMap) {
|
|
|
if (!option || !Array.isArray(option.series)) return option;
|
|
if (!option || !Array.isArray(option.series)) return option;
|
|
|
const byGroup = (labelMap && labelMap.byGroup) || {};
|
|
const byGroup = (labelMap && labelMap.byGroup) || {};
|
|
|
const byMetric = (labelMap && labelMap.byMetric) || {};
|
|
const byMetric = (labelMap && labelMap.byMetric) || {};
|
|
|
|
|
+ const byMG = (labelMap && labelMap.byMetricGroup) || {};
|
|
|
if (!Object.keys(byGroup).length && !Object.keys(byMetric).length) return option;
|
|
if (!Object.keys(byGroup).length && !Object.keys(byMetric).length) return option;
|
|
|
const series = option.series.map((item) => {
|
|
const series = option.series.map((item) => {
|
|
|
const name = String(item && item.name != null ? item.name : "");
|
|
const name = String(item && item.name != null ? item.name : "");
|
|
|
- const label = (item && item.metricKey && byMetric[item.metricKey]) || byGroup[name];
|
|
|
|
|
|
|
+ const mk = item && item.metricKey;
|
|
|
|
|
+ // 残差类沿用 historyLines 里的中文名(如「支持期 去同期机群共性的日残差」),不被 legend_entries 覆盖
|
|
|
|
|
+ if (mk === "residual" || mk === "residual_c") return item;
|
|
|
|
|
+ let label = null;
|
|
|
|
|
+ if (item && item.metricKey && item.groupValue != null && byMG[`${item.metricKey}|${item.groupValue}`]) {
|
|
|
|
|
+ label = byMG[`${item.metricKey}|${item.groupValue}`];
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!label && item && item.metricKey) label = byMetric[item.metricKey];
|
|
|
|
|
+ if (!label) label = byGroup[name];
|
|
|
return label ? Object.assign({}, item, { name: label }) : item;
|
|
return label ? Object.assign({}, item, { name: label }) : item;
|
|
|
});
|
|
});
|
|
|
return Object.assign({}, option, { series });
|
|
return Object.assign({}, option, { series });
|
|
@@ -1002,7 +1018,7 @@ function buildDatasetChart(id, dataset, title, data, extras) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if (!isWindResourceChart(id, title)) {
|
|
if (!isWindResourceChart(id, title)) {
|
|
|
- const drawn = schemaChart(id, rows, keys, title, extras);
|
|
|
|
|
|
|
+ const drawn = schemaChart(id, rows, keys, title, extras, data);
|
|
|
if (drawn) return drawn;
|
|
if (drawn) return drawn;
|
|
|
}
|
|
}
|
|
|
const xKey = X_KEYS.find((key) => keys.includes(key));
|
|
const xKey = X_KEYS.find((key) => keys.includes(key));
|
|
@@ -1190,6 +1206,8 @@ function darkLineOption(series, extra) {
|
|
|
const guide = index === 0 ? opt.guide : null;
|
|
const guide = index === 0 ? opt.guide : null;
|
|
|
return {
|
|
return {
|
|
|
name: item.name,
|
|
name: item.name,
|
|
|
|
|
+ metricKey: item.metricKey,
|
|
|
|
|
+ groupValue: item.groupValue,
|
|
|
type: item.type || "line",
|
|
type: item.type || "line",
|
|
|
showSymbol: item.showSymbol != null ? item.showSymbol : item.type === "scatter",
|
|
showSymbol: item.showSymbol != null ? item.showSymbol : item.type === "scatter",
|
|
|
symbol: item.symbol || "circle",
|
|
symbol: item.symbol || "circle",
|
|
@@ -1278,7 +1296,7 @@ function isWindResourceChart(id, title) {
|
|
|
return /wind_frequency|rose_project_aggregate|rose_bins|relative_wind_monthly|wind_ratio_history|unit_wind_ratio_history|风速频率|风向玫瑰|风速比/.test(`${id} ${title || ""}`);
|
|
return /wind_frequency|rose_project_aggregate|rose_bins|relative_wind_monthly|wind_ratio_history|unit_wind_ratio_history|风速频率|风向玫瑰|风速比/.test(`${id} ${title || ""}`);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function schemaChart(id, rows, sourceKeys, title, extras) {
|
|
|
|
|
|
|
+function schemaChart(id, rows, sourceKeys, title, extras, data) {
|
|
|
const keys = [];
|
|
const keys = [];
|
|
|
rows.forEach((row) => {
|
|
rows.forEach((row) => {
|
|
|
Object.keys(row || {}).forEach((key) => {
|
|
Object.keys(row || {}).forEach((key) => {
|
|
@@ -1321,7 +1339,9 @@ function schemaChart(id, rows, sourceKeys, title, extras) {
|
|
|
return scatterOf(id, title, rows, "power_kw", "pitch_deg", "功率 kW", "桨距角 °");
|
|
return scatterOf(id, title, rows, "power_kw", "pitch_deg", "功率 kW", "桨距角 °");
|
|
|
}
|
|
}
|
|
|
if (has("month") && has("generator_rpm") && has("power_kw") && !has("wind_ms")) {
|
|
if (has("month") && has("generator_rpm") && has("power_kw") && !has("wind_ms")) {
|
|
|
- return monthPowerScatter(id, title, rows);
|
|
|
|
|
|
|
+ // 只展示当前查看月份(所选周期)的散点
|
|
|
|
|
+ const curMonth = data ? (data.month || (data.identity && data.identity.month) || "") : "";
|
|
|
|
|
+ return monthPowerScatter(id, title, rows, curMonth);
|
|
|
}
|
|
}
|
|
|
if (has("role") && has("month") && has("wind_ms") && has("power_kw")) {
|
|
if (has("role") && has("month") && has("wind_ms") && has("power_kw")) {
|
|
|
return monthContractScatter(id, title, rows);
|
|
return monthContractScatter(id, title, rows);
|
|
@@ -1833,18 +1853,27 @@ function monthContractScatter(id, title, rows) {
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function monthPowerScatter(id, title, rows) {
|
|
|
|
|
|
|
+function monthPowerScatter(id, title, rows, currentMonth) {
|
|
|
const months = uniqueValues(rows, "month");
|
|
const months = uniqueValues(rows, "month");
|
|
|
- const series = months.map((month, index) => {
|
|
|
|
|
- const data = rows.filter((row) => String(row.month) === month).map((row) => [
|
|
|
|
|
- Number(row.generator_rpm),
|
|
|
|
|
- Number(row.power_kw),
|
|
|
|
|
- ]).filter((point) => point.every(Number.isFinite));
|
|
|
|
|
- if (!data.length) return null;
|
|
|
|
|
- return { name: month, type: "scatter", symbolSize: 6, data, color: windColor(index, months.length) };
|
|
|
|
|
- }).filter(Boolean);
|
|
|
|
|
- if (!series.length) return null;
|
|
|
|
|
- return { id, title, option: darkLineOption(series, { xName: "转速 rpm", yName: "功率 kW", yMin: 0 }) };
|
|
|
|
|
|
|
+ // 只展示当前查看月份(所选周期)的散点;无法匹配时回退到数据里最新月份
|
|
|
|
|
+ const target = currentMonth && months.includes(currentMonth)
|
|
|
|
|
+ ? currentMonth
|
|
|
|
|
+ : (months.slice().sort().pop() || "");
|
|
|
|
|
+ if (!target) return null;
|
|
|
|
|
+ const data = rows
|
|
|
|
|
+ .filter((row) => String(row.month) === String(target))
|
|
|
|
|
+ .map((row) => [Number(row.generator_rpm), Number(row.power_kw)])
|
|
|
|
|
+ .filter((point) => point.every(Number.isFinite));
|
|
|
|
|
+ if (!data.length) return null;
|
|
|
|
|
+ return {
|
|
|
|
|
+ id,
|
|
|
|
|
+ title,
|
|
|
|
|
+ option: darkLineOption([{ name: target, type: "scatter", symbolSize: 6, data }], {
|
|
|
|
|
+ xName: "转速 rpm",
|
|
|
|
|
+ yName: "功率 kW",
|
|
|
|
|
+ yMin: 0,
|
|
|
|
|
+ }),
|
|
|
|
|
+ };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function contractRows(rows, extra) {
|
|
function contractRows(rows, extra) {
|
|
@@ -2052,11 +2081,13 @@ function historyLines(id, title, rows, extras) {
|
|
|
const groups = splitGroups(bundle.rows);
|
|
const groups = splitGroups(bundle.rows);
|
|
|
groups.forEach((group) => {
|
|
groups.forEach((group) => {
|
|
|
valueFields.forEach(([key, label]) => {
|
|
valueFields.forEach(([key, label]) => {
|
|
|
- const valueLabel = residual && key === "residual_c" ? "扣除同型机组共同变化后的温度偏差" : label;
|
|
|
|
|
- const groupName = residual && groups.length > 1 ? windowRoleLabel(group.name) : group.name;
|
|
|
|
|
- const item = pairSeries(group.rows, xKey, key, historyName(bundleName, residual ? groupName : group.name, valueLabel));
|
|
|
|
|
|
|
+ const valueLabel = key === "residual_c" ? "扣除同型机组共同变化后的温度偏差"
|
|
|
|
|
+ : (key === "residual" ? "去同期机群共性的日残差" : label);
|
|
|
|
|
+ const groupName = windowRoleLabel(group.name);
|
|
|
|
|
+ const item = pairSeries(group.rows, xKey, key, historyName(bundleName, groupName, valueLabel));
|
|
|
if (!item) return;
|
|
if (!item) return;
|
|
|
item.metricKey = key;
|
|
item.metricKey = key;
|
|
|
|
|
+ item.groupValue = group.name;
|
|
|
if (label === "EWMA") {
|
|
if (label === "EWMA") {
|
|
|
item.dash = true;
|
|
item.dash = true;
|
|
|
item.color = "#c29345";
|
|
item.color = "#c29345";
|
|
@@ -2066,15 +2097,16 @@ function historyLines(id, title, rows, extras) {
|
|
|
});
|
|
});
|
|
|
limitFields.forEach(([key, label]) => {
|
|
limitFields.forEach(([key, label]) => {
|
|
|
const limitLabel = residual && key === "threshold_c" ? "偏热判断线" : label;
|
|
const limitLabel = residual && key === "threshold_c" ? "偏热判断线" : label;
|
|
|
- const groupName = residual && groups.length > 1 ? windowRoleLabel(group.name) : group.name;
|
|
|
|
|
|
|
+ const groupName = windowRoleLabel(group.name);
|
|
|
const constVal = constantLimit(group.rows, key);
|
|
const constVal = constantLimit(group.rows, key);
|
|
|
if (constVal != null) {
|
|
if (constVal != null) {
|
|
|
guides.push({ y: constVal, label: `${limitLabel} ${formatGuide(constVal)}`, color: residual && key === "threshold_c" ? "#d08a3a" : "#e07070" });
|
|
guides.push({ y: constVal, label: `${limitLabel} ${formatGuide(constVal)}`, color: residual && key === "threshold_c" ? "#d08a3a" : "#e07070" });
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- const item = pairSeries(group.rows, xKey, key, historyName(bundleName, residual ? groupName : group.name, limitLabel));
|
|
|
|
|
|
|
+ const item = pairSeries(group.rows, xKey, key, historyName(bundleName, groupName, limitLabel));
|
|
|
if (!item) return;
|
|
if (!item) return;
|
|
|
item.metricKey = key;
|
|
item.metricKey = key;
|
|
|
|
|
+ item.groupValue = group.name;
|
|
|
item.dash = true;
|
|
item.dash = true;
|
|
|
item.color = residual && key === "threshold_c" ? "#d08a3a" : "#e07070";
|
|
item.color = residual && key === "threshold_c" ? "#d08a3a" : "#e07070";
|
|
|
item.limit = true;
|
|
item.limit = true;
|
|
@@ -2198,6 +2230,8 @@ function ambientHistoryChart(id, title, bundles, xKey) {
|
|
|
function windowRoleLabel(name) {
|
|
function windowRoleLabel(name) {
|
|
|
if (name === "prior") return "参考窗口";
|
|
if (name === "prior") return "参考窗口";
|
|
|
if (name === "detection") return "检测窗口";
|
|
if (name === "detection") return "检测窗口";
|
|
|
|
|
+ if (name === "support") return "支持期";
|
|
|
|
|
+ if (name === "current") return "本期";
|
|
|
return name || "";
|
|
return name || "";
|
|
|
}
|
|
}
|
|
|
|
|
|