更新遗传算法默认参数;更新漏损流量单位为m3/h
This commit is contained in:
@@ -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<Props> = ({ onResult }) => {
|
||||
dayjs().subtract(2, "hour"),
|
||||
);
|
||||
const [endTime, setEndTime] = useState<Dayjs | null>(dayjs());
|
||||
const [popSize, setPopSize] = useState<number>(50);
|
||||
const [maxGen, setMaxGen] = useState<number>(100);
|
||||
const [qSum, setQSum] = useState<number>(0.4);
|
||||
const [popSize, setPopSize] = useState<number>(10);
|
||||
const [maxGen, setMaxGen] = useState<number>(50);
|
||||
const [qSum, setQSum] = useState<number>(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<Props> = ({ 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<Props> = ({ onResult }) => {
|
||||
<Typography variant="subtitle2" className="mb-1 font-medium">
|
||||
DMA 数量
|
||||
</Typography>
|
||||
<TextField
|
||||
type="number"
|
||||
value={dmaCount}
|
||||
onChange={(e) => {
|
||||
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 个"
|
||||
/>
|
||||
<TextField
|
||||
type="number"
|
||||
value={dmaCount}
|
||||
onChange={(e) => {
|
||||
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 个"
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<LocalizationProvider
|
||||
@@ -171,7 +172,7 @@ const AnalysisParameters: React.FC<Props> = ({ onResult }) => {
|
||||
|
||||
<Box className="flex flex-col gap-2">
|
||||
<Typography variant="subtitle2" className="mb-1 font-medium">
|
||||
总漏损流量 (m3/s)
|
||||
总漏损流量 ({DMA_FLOW_DISPLAY_UNIT})
|
||||
</Typography>
|
||||
<TextField
|
||||
type="number"
|
||||
@@ -179,9 +180,9 @@ const AnalysisParameters: React.FC<Props> = ({ 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 }}
|
||||
/>
|
||||
<Box
|
||||
sx={{
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
} from "@mui/material";
|
||||
import { FormatListBulleted } from "@mui/icons-material";
|
||||
import dayjs from "dayjs";
|
||||
import { getAreaColor } from "./utils";
|
||||
import { DMA_FLOW_DISPLAY_UNIT, getAreaColor, toM3h } from "./utils";
|
||||
import { LeakageResultDetail } from "./types";
|
||||
|
||||
interface Props {
|
||||
@@ -125,11 +125,13 @@ const RecognitionResults: React.FC<Props> = ({ 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}`
|
||||
: "-";
|
||||
})()}
|
||||
</Typography>
|
||||
@@ -163,8 +165,9 @@ const RecognitionResults: React.FC<Props> = ({ 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}`
|
||||
: "-";
|
||||
})()}
|
||||
</Typography>
|
||||
@@ -212,7 +215,7 @@ const RecognitionResults: React.FC<Props> = ({ result }) => {
|
||||
align="right"
|
||||
sx={{ fontWeight: 600, color: "#64748b", py: 1.5, pr: 3 }}
|
||||
>
|
||||
漏损量 (m3/s)
|
||||
漏损量 ({DMA_FLOW_DISPLAY_UNIT})
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
@@ -244,7 +247,7 @@ const RecognitionResults: React.FC<Props> = ({ 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)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
|
||||
@@ -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<Props> = ({ onViewResult }) => {
|
||||
<Typography variant="caption" className="font-medium text-gray-900">
|
||||
{(() => {
|
||||
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}`
|
||||
: "-";
|
||||
})()}
|
||||
</Typography>
|
||||
</Box>
|
||||
@@ -218,8 +222,13 @@ const SchemeQuery: React.FC<Props> = ({ onViewResult }) => {
|
||||
<Typography variant="caption" className="font-medium text-gray-900">
|
||||
{(() => {
|
||||
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}`
|
||||
: "-";
|
||||
})()}
|
||||
</Typography>
|
||||
</Box>
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user