From 9beba1cf6f83e9c186d249e0fa9136365cee93ff Mon Sep 17 00:00:00 2001 From: JIANG Date: Fri, 6 Mar 2026 14:13:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=81=97=E4=BC=A0=E7=AE=97?= =?UTF-8?q?=E6=B3=95=E9=BB=98=E8=AE=A4=E5=8F=82=E6=95=B0=EF=BC=9B=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=BC=8F=E6=8D=9F=E6=B5=81=E9=87=8F=E5=8D=95=E4=BD=8D?= =?UTF-8?q?=E4=B8=BAm3/h?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DMALeakDetection/AnalysisParameters.tsx | 57 ++++++++++--------- .../DMALeakDetection/RecognitionResults.tsx | 21 ++++--- .../olmap/DMALeakDetection/SchemeQuery.tsx | 15 ++++- .../olmap/DMALeakDetection/utils.ts | 17 ++++++ 4 files changed, 70 insertions(+), 40 deletions(-) diff --git a/src/components/olmap/DMALeakDetection/AnalysisParameters.tsx b/src/components/olmap/DMALeakDetection/AnalysisParameters.tsx index 6489ec5..1c45f16 100644 --- a/src/components/olmap/DMALeakDetection/AnalysisParameters.tsx +++ b/src/components/olmap/DMALeakDetection/AnalysisParameters.tsx @@ -20,6 +20,7 @@ import { useNotification } from "@refinedev/core"; import { api } from "@/lib/api"; import { NETWORK_NAME, config } from "@config/config"; import { LeakageResultDetail } from "./types"; +import { DMA_FLOW_DISPLAY_UNIT, toM3s } from "./utils"; interface Props { onResult: (result: LeakageResultDetail) => void; @@ -33,15 +34,15 @@ const AnalysisParameters: React.FC = ({ onResult }) => { dayjs().subtract(2, "hour"), ); const [endTime, setEndTime] = useState(dayjs()); - const [popSize, setPopSize] = useState(50); - const [maxGen, setMaxGen] = useState(100); - const [qSum, setQSum] = useState(0.4); + const [popSize, setPopSize] = useState(10); + const [maxGen, setMaxGen] = useState(50); + const [qSum, setQSum] = useState(1440); const [advancedOpen, setAdvancedOpen] = useState(false); const [running, setRunning] = useState(false); const isValid = useMemo(() => { if (!schemeName.trim() || !startTime || !endTime) return false; - return startTime.isBefore(endTime) && qSum >= 0.1; + return startTime.isBefore(endTime) && qSum >= 360; }, [schemeName, startTime, endTime, qSum]); const handleRun = async () => { @@ -67,9 +68,9 @@ const AnalysisParameters: React.FC = ({ onResult }) => { scada_end: endTime.toISOString(), pop_size: popSize, max_gen: maxGen, - q_sum: qSum, + q_sum: toM3s(qSum, DMA_FLOW_DISPLAY_UNIT), q_sum_unit: "m3/s", - output_flow_unit: "m3/s", + output_flow_unit: DMA_FLOW_DISPLAY_UNIT, }, ); onResult(response.data as LeakageResultDetail); @@ -115,25 +116,25 @@ const AnalysisParameters: React.FC = ({ onResult }) => { DMA 数量 - { - const value = Number.parseInt(e.target.value, 10); - // Limit between 3 and 10 - if (Number.isNaN(value)) { - setDmaCount(5); - } else if (value > 10) { - setDmaCount(10); - } else { - setDmaCount(Math.max(3, value)); - } - }} - fullWidth - size="small" - inputProps={{ min: 3, max: 10, step: 1 }} - helperText="DMA 数量限制为 3-10 个" - /> + { + const value = Number.parseInt(e.target.value, 10); + // Limit between 3 and 10 + if (Number.isNaN(value)) { + setDmaCount(5); + } else if (value > 10) { + setDmaCount(10); + } else { + setDmaCount(Math.max(3, value)); + } + }} + fullWidth + size="small" + inputProps={{ min: 3, max: 10, step: 1 }} + helperText="DMA 数量限制为 3-10 个" + /> = ({ onResult }) => { - 总漏损流量 (m3/s) + 总漏损流量 ({DMA_FLOW_DISPLAY_UNIT}) = ({ onResult }) => { value={qSum} onChange={(e) => { const value = Number(e.target.value); - setQSum(Number.isNaN(value) ? 0.4 : Math.max(0.1, value)); + setQSum(Number.isNaN(value) ? 1440 : Math.max(360, value)); }} - inputProps={{ min: 0.1, step: 0.1 }} + inputProps={{ min: 360, step: 10 }} /> = ({ result }) => { {(() => { const val = (result.scheme_detail as any)?.algorithm_params ?.q_sum; - const unit = + const unit = String( (result.scheme_detail as any)?.algorithm_params?.q_sum_unit || - "m3/s"; - return val !== undefined - ? `${Number(val).toFixed(3)} ${unit}` + "m3/s", + ); + const qSumM3h = toM3h(Number(val), unit); + return Number.isFinite(qSumM3h) + ? `${qSumM3h.toFixed(3)} ${DMA_FLOW_DISPLAY_UNIT}` : "-"; })()} @@ -163,8 +165,9 @@ const RecognitionResults: React.FC = ({ result }) => { {(() => { const maxL = (result.scheme_detail as any)?.result_summary ?.max_leakage; - return maxL !== undefined - ? `${Number(maxL).toFixed(3)} m3/s` + const maxLeakageM3h = toM3h(Number(maxL), "m3/s"); + return Number.isFinite(maxLeakageM3h) + ? `${maxLeakageM3h.toFixed(3)} ${DMA_FLOW_DISPLAY_UNIT}` : "-"; })()} @@ -212,7 +215,7 @@ const RecognitionResults: React.FC = ({ result }) => { align="right" sx={{ fontWeight: 600, color: "#64748b", py: 1.5, pr: 3 }} > - 漏损量 (m3/s) + 漏损量 ({DMA_FLOW_DISPLAY_UNIT}) @@ -244,7 +247,7 @@ const RecognitionResults: React.FC = ({ result }) => { align="right" sx={{ pr: 3, py: 1.2, fontWeight: 500, color: "#334155" }} > - {row.LeakageFlow_m3_per_s.toFixed(3)} + {toM3h(Number(row.LeakageFlow_m3_per_s), "m3/s").toFixed(3)} ))} diff --git a/src/components/olmap/DMALeakDetection/SchemeQuery.tsx b/src/components/olmap/DMALeakDetection/SchemeQuery.tsx index e7c6f91..70c403e 100644 --- a/src/components/olmap/DMALeakDetection/SchemeQuery.tsx +++ b/src/components/olmap/DMALeakDetection/SchemeQuery.tsx @@ -24,6 +24,7 @@ import { useNotification } from "@refinedev/core"; import { api } from "@/lib/api"; import { NETWORK_NAME, config } from "@config/config"; import { LeakageResultDetail, LeakageSchemeRecord } from "./types"; +import { DMA_FLOW_DISPLAY_UNIT, toM3h } from "./utils"; interface Props { onViewResult: (result: LeakageResultDetail) => void; @@ -207,7 +208,10 @@ const SchemeQuery: React.FC = ({ onViewResult }) => { {(() => { const value = Number((scheme.scheme_detail as any)?.result_summary?.max_leakage); - return Number.isFinite(value) ? `${value.toFixed(3)} m3/s` : "-"; + const maxLeakageM3h = toM3h(value, "m3/s"); + return Number.isFinite(maxLeakageM3h) + ? `${maxLeakageM3h.toFixed(3)} ${DMA_FLOW_DISPLAY_UNIT}` + : "-"; })()} @@ -218,8 +222,13 @@ const SchemeQuery: React.FC = ({ onViewResult }) => { {(() => { const value = Number((scheme.scheme_detail as any)?.algorithm_params?.q_sum); - const unit = String((scheme.scheme_detail as any)?.algorithm_params?.q_sum_unit || "m3/s"); - return Number.isFinite(value) ? `${value.toFixed(3)} ${unit}` : "-"; + const unit = String( + (scheme.scheme_detail as any)?.algorithm_params?.q_sum_unit || "m3/s", + ); + const qSumM3h = toM3h(value, unit); + return Number.isFinite(qSumM3h) + ? `${qSumM3h.toFixed(3)} ${DMA_FLOW_DISPLAY_UNIT}` + : "-"; })()} diff --git a/src/components/olmap/DMALeakDetection/utils.ts b/src/components/olmap/DMALeakDetection/utils.ts index bd46411..c38ee6f 100644 --- a/src/components/olmap/DMALeakDetection/utils.ts +++ b/src/components/olmap/DMALeakDetection/utils.ts @@ -11,6 +11,9 @@ export const AREA_COLORS = [ "#be123c", ]; +export const DMA_FLOW_DISPLAY_UNIT = "m3/h"; +const M3H_FACTOR = 3600; + export const getAreaColor = (areaId: string | number | undefined) => { const text = String(areaId ?? ""); let hash = 0; @@ -19,3 +22,17 @@ export const getAreaColor = (areaId: string | number | undefined) => { } return AREA_COLORS[hash % AREA_COLORS.length]; }; + +export const toM3h = (value: number, sourceUnit: string = "m3/s") => { + if (!Number.isFinite(value)) return Number.NaN; + const normalizedUnit = sourceUnit.trim().toLowerCase(); + if (normalizedUnit === "m3/h") return value; + return value * M3H_FACTOR; +}; + +export const toM3s = (value: number, sourceUnit: string = "m3/h") => { + if (!Number.isFinite(value)) return Number.NaN; + const normalizedUnit = sourceUnit.trim().toLowerCase(); + if (normalizedUnit === "m3/s") return value; + return value / M3H_FACTOR; +};