From f10f00cf1739b49fe51abfbb96093a2a2f66a65c Mon Sep 17 00:00:00 2001 From: duheng <2784771470@qq.com> Date: 星期日, 19 一月 2025 17:56:36 +0800 Subject: [PATCH] 赋值问题报错修改 --- WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/07-matching/00-core/AssetsMatchingHelper.cs | 240 ++++++++++++++++++++++++++++++++++++------------------------ 1 files changed, 144 insertions(+), 96 deletions(-) diff --git a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/07-matching/00-core/AssetsMatchingHelper.cs b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/07-matching/00-core/AssetsMatchingHelper.cs index 3041280..f64a335 100644 --- a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/07-matching/00-core/AssetsMatchingHelper.cs +++ b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/07-matching/00-core/AssetsMatchingHelper.cs @@ -1,10 +1,4 @@ -锘縰sing HStation.WinFrmUI.PhartRelation; -using Swashbuckle.AspNetCore.SwaggerGen; -using System.Linq; -using System.Windows.Input; -using Yw.WinFrmUI.Q3d; - -namespace HStation.WinFrmUI +锘縩amespace HStation.WinFrmUI { public class AssetsMatchingHelper { @@ -117,7 +111,7 @@ } } - //鍠峰ご鍖归厤 + //鍐峰嵈濉斿尮閰� foreach (var item in assetsAutoMatchingView.Coolings) { if (Matching(item, allCoolingMain)) @@ -237,9 +231,9 @@ { // 灏濊瘯鍖洪棿鍖归厤 var rangeMatch = AssetsPumpMainVmos.Where(item => - (InputModel.RatedN.HasValue ? Math.Abs(InputModel.RatedN.Value - item.RatedSpeed) <= _speedTolerance : true) && - (InputModel.RatedQ.HasValue ? Math.Abs(InputModel.RatedQ.Value - item.RatedFlow) <= _flowTolerance : true) && - (InputModel.RatedH.HasValue ? Math.Abs(InputModel.RatedH.Value - item.RatedHead) <= _headTolerance : true) && + (InputModel.RatedN > 0 ? Math.Abs(InputModel.RatedN - item.RatedSpeed) <= _speedTolerance : true) && + (InputModel.RatedQ > 0 ? Math.Abs(InputModel.RatedQ - item.RatedFlow) <= _flowTolerance : true) && + (InputModel.RatedH > 0 ? Math.Abs(InputModel.RatedH - item.RatedHead) <= _headTolerance : true) && (Math.Abs(InputModel.RatedP - item.RatedPower) <= _powerTolerance)).ToList(); if (rangeMatch != null && rangeMatch.Count != 0) { @@ -390,7 +384,7 @@ } //鏍囩 - int flagWeight = 1; + int flagWeight = 1000;//涓存椂淇敼,涔嬪墠涓�1 foreach (var item in valveMainVmos) { if (item.Flags != null && item.Flags.Count > 0) @@ -401,7 +395,6 @@ } } } - var valve = dict.OrderBy(x => x.Value).LastOrDefault().Key; input.MatchingDbId = valve.ID.ToString(); if (string.IsNullOrEmpty(input.ModelType)) @@ -424,6 +417,7 @@ { input.MatchingValveSetting = valve.ValveSetting; } + input.MatchingValveType = eValveType.TCV; if (input.CurveDbId == null) { var list = Task.Run(async () => @@ -433,26 +427,21 @@ var def = list.OrderByDescending(x => x.Importance).First(); input.MatchingCurveDbId = def.ID.ToString(); var curve = def.Diagram.GraphList[0].GetFeatPointList(); - if (valve.ValveType == HStation.Assets.eValveType.GPV) + input.MatchingCurveQL = new List<HydroCurvePointViewModel>(); + /* foreach (var item in curve) + { + input.MatchingCurveQL.Add(new HydroCurvePointViewModel(item.X, item.Y)); + }*/ + + input.MatchingCurveOL = new List<HydroCurvePointViewModel>(); + foreach (var item in curve) { - input.MatchingCurveQL = new List<HydroCurvePointViewModel>(); - foreach (var item in curve) - { - input.MatchingCurveQL.Add(new HydroCurvePointViewModel(item.X, item.Y)); - } - } - else if (valve.ValveType == HStation.Assets.eValveType.TCV) - { - input.MatchingCurveOL = new List<HydroCurvePointViewModel>(); - foreach (var item in curve) - { - input.MatchingCurveOL.Add(new HydroCurvePointViewModel(item.X, item.Y)); - } + input.MatchingCurveOL.Add(new HydroCurvePointViewModel(item.X, item.Y)); } } + return true; } - - return true; + return false; } //绠¢亾鍖归厤 @@ -539,7 +528,7 @@ } //鏍囩 - int flagWeight = 1; + int flagWeight = 1000; foreach (var item in pipeLineMainVmos) { if (item.Flags != null && item.Flags.Count > 0) @@ -557,17 +546,14 @@ { input.MatchingModelType = pipe.Name; } - if (input.Roughness == 0) - { - input.MatchingRoughness = pipe.Hazen; - } + if (string.IsNullOrEmpty(input.Material)) { input.MatchingMaterial = pipe.Material; } if (input.MinorLoss < 0) { - input.MatchingMinorLoss = pipe.MinorLoss; + input.MatchingMinorLoss = pipe.Hazen; } return true; @@ -625,14 +611,14 @@ //鍙e緞 int caliberWeight = 1; - if (input.Caliber.HasValue) + if (input.Caliber > 0) { foreach (var item in threelinkVmos) { if (item.Caliber.HasValue) { - var diff = Math.Abs(item.Caliber.Value - input.Caliber.Value); - dict[item] += diff / input.Caliber.Value * 100 * caliberWeight; + var diff = Math.Abs(item.Caliber.Value - input.Caliber); + dict[item] += diff / input.Caliber * 100 * caliberWeight; } } } @@ -657,7 +643,7 @@ } //鏍囩 - int flagWeight = 1; + int flagWeight = 1000; foreach (var item in threelinkVmos) { if (item.Flags != null && item.Flags.Count > 0) @@ -679,19 +665,16 @@ { input.MatchingMaterial = threelink.Material; } - if (!input.Caliber.HasValue || input.Caliber.Value <= 0) + if (input.Caliber <= 0) { - input.Caliber = threelink.Caliber; + input.Caliber = threelink.Caliber ?? 0; } - if (!input.MinorLoss.HasValue) - { - input.MatchingMinorLoss = threelink.MinorLoss; - } - if (!input.RunningThroughLoss.HasValue) + + if (input.RunningThroughLoss <= 0) { input.MatchingRunningThroughLoss = threelink.RunThroughMinorLoss; } - if (!input.MatchingBranchThroughLoss.HasValue) + if (input.MatchingBranchThroughLoss <= 0) { input.MatchingBranchThroughLoss = threelink.BranchThroughMinorLoss; } @@ -751,14 +734,14 @@ //鍙e緞 int caliberWeight = 1; - if (input.Caliber.HasValue) + if (input.Caliber > 0) { foreach (var item in fourLinkVmos) { if (item.Caliber.HasValue) { - var diff = Math.Abs(item.Caliber.Value - input.Caliber.Value); - dict[item] += diff / input.Caliber.Value * 100 * caliberWeight; + var diff = Math.Abs(item.Caliber.Value - input.Caliber); + dict[item] += diff / input.Caliber * 100 * caliberWeight; } } } @@ -783,7 +766,7 @@ } //鏍囩 - int flagWeight = 1; + int flagWeight = 1000; foreach (var item in fourLinkVmos) { if (item.Flags != null && item.Flags.Count > 0) @@ -805,11 +788,11 @@ { input.MatchingMaterial = fourlink.Material; } - if (!input.Caliber.HasValue || input.Caliber.Value <= 0) + if (input.Caliber <= 0) { - input.Caliber = fourlink.Caliber; + input.Caliber = fourlink.Caliber ?? 0; } - if (!input.MinorLoss.HasValue) + if (input.MinorLoss <= 0) { input.MatchingMinorLoss = fourlink.MinorLoss; } @@ -869,14 +852,14 @@ //鍙e緞 int caliberWeight = 1; - if (input.Caliber.HasValue) + if (input.Caliber > 0) { foreach (var item in sprinklerVmos) { if (item.Caliber.HasValue) { - var diff = Math.Abs(item.Caliber.Value - input.Caliber.Value); - dict[item] += diff / input.Caliber.Value * 100 * caliberWeight; + var diff = Math.Abs(item.Caliber.Value - input.Caliber); + dict[item] += diff / input.Caliber * 100 * caliberWeight; } } } @@ -901,7 +884,7 @@ } //鏍囩 - int flagWeight = 1; + int flagWeight = 1000; foreach (var item in sprinklerVmos) { if (item.Flags != null && item.Flags.Count > 0) @@ -923,13 +906,13 @@ { input.MatchingMaterial = sprinkler.Material; } - if (!input.Caliber.HasValue || input.Caliber.Value <= 0) + if (input.Caliber <= 0) { - input.Caliber = sprinkler.Caliber; + input.Caliber = sprinkler.Caliber ?? 0; } - if (!input.MinorLoss.HasValue) + if (input.MinorLoss <= 0) { - input.MatchingMinorLoss = sprinkler.MinorLoss; + input.MatchingMinorLoss = sprinkler.FlowMinorLoss; } return true; @@ -1019,7 +1002,7 @@ } //鏍囩 - int flagWeight = 1; + int flagWeight = 1000; foreach (var item in allExchangerList) { if (item.Flags != null && item.Flags.Count > 0) @@ -1158,7 +1141,7 @@ } //鏍囩 - int flagWeight = 1; + int flagWeight = 1000; foreach (var item in allCompressorList) { if (item.Flags != null && item.Flags.Count > 0) @@ -1265,14 +1248,14 @@ //鍙e緞 int caliberWeight = 1; - if (input.Caliber.HasValue) + if (input.Caliber > 0) { foreach (var item in bluntheadVmos) { if (item.Caliber.HasValue) { - var diff = Math.Abs(item.Caliber.Value - input.Caliber.Value); - dict[item] += diff / input.Caliber.Value * 100 * caliberWeight; + var diff = Math.Abs(item.Caliber.Value - input.Caliber); + dict[item] += diff / input.Caliber * 100 * caliberWeight; } } } @@ -1297,7 +1280,7 @@ } //鏍囩 - int flagWeight = 1; + int flagWeight = 1000; foreach (var item in bluntheadVmos) { if (item.Flags != null && item.Flags.Count > 0) @@ -1319,9 +1302,9 @@ { input.MatchingMaterial = blunthead.Material; } - if (!input.Caliber.HasValue || input.Caliber.Value <= 0) + if (input.Caliber <= 0) { - input.Caliber = blunthead.Caliber; + input.Caliber = blunthead.Caliber ?? 0; } if (input.MinorLoss < 0) { @@ -1382,7 +1365,7 @@ } //鏍囩 - int flagWeight = 1; + int flagWeight = 1000; foreach (var item in tankVmos) { if (item.Flags != null && item.Flags.Count > 0) @@ -1488,7 +1471,7 @@ } //鏍囩 - int flagWeight = 10; + int flagWeight = 1000; foreach (var item in allMeterList) { if (item.Flags != null && item.Flags.Count > 0) @@ -1565,7 +1548,7 @@ } //鏍囩 - int flagWeight = 10; + int flagWeight = 1000; foreach (var item in allFlowmeterList) { if (item.Flags != null && item.Flags.Count > 0) @@ -1643,14 +1626,14 @@ //鍙e緞 int caliberWeight = 1; - if (input.Caliber.HasValue) + if (input.Caliber > 0) { foreach (var item in hydrantVmos) { if (item.Caliber.HasValue) { - var diff = Math.Abs(item.Caliber.Value - input.Caliber.Value); - dict[item] += diff / input.Caliber.Value * 100 * caliberWeight; + var diff = Math.Abs(item.Caliber.Value - input.Caliber); + dict[item] += diff / input.Caliber * 100 * caliberWeight; } } } @@ -1675,7 +1658,7 @@ } //鏍囩 - int flagWeight = 1; + int flagWeight = 1000; foreach (var item in hydrantVmos) { if (item.Flags != null && item.Flags.Count > 0) @@ -1697,9 +1680,9 @@ { input.MatchingMaterial = hydrant.Material; } - if (!input.Caliber.HasValue || input.Caliber.Value <= 0) + if (input.Caliber <= 0) { - input.Caliber = hydrant.Caliber; + input.Caliber = hydrant.Caliber ?? 0; } if (input.MinorLoss < 0) { @@ -1723,7 +1706,7 @@ { return false; } - + allElbowList = allElbowList.Where(x => x.Angle == 90).ToList(); //鏉冮噸瀛楀吀 var dict = new Dictionary<AssetsElbowMainVmo, double>(); foreach (var item in allElbowList) @@ -1744,7 +1727,40 @@ } } } - + //鍙e緞 + int caliberWeight = 1; + if (input.Caliber > 0) + { + foreach (var item in allElbowList) + { + if (item.Caliber.HasValue) + { + var diff = Math.Abs(item.Caliber.Value - input.Caliber); + dict[item] += diff / input.Caliber * 100 * caliberWeight; + } + } + } + // 瑙掑害 + int angleWeight = 1000; + if (input.BendingAngle > 0) + { + foreach (var item in allElbowList) + { + if (item.Angle > 0) + { + var count = Math.Abs(item.Angle.Value - input.BendingAngle); + if (count != 0) + { + dict[item] += (1.0 / count) * angleWeight; + } + else + { + // 濡傛灉 count 涓� 0锛岃〃绀哄畬鍏ㄥ尮閰嶏紝缁欎簣鏈�澶ф潈閲� + dict[item] += angleWeight * 100; + } + } + } + } // 鍏抽敭瀛� int keywordWeight = 1; foreach (var item in allElbowList) @@ -1760,7 +1776,7 @@ } //鏍囩 - int flagWeight = 10; + int flagWeight = 1000; foreach (var item in allElbowList) { if (item.Flags != null && item.Flags.Count > 0) @@ -1786,13 +1802,18 @@ { input.MatchingBendingAngle = elbow.Angle; } - input.MatchingElbowType = (Yw.WinFrmUI.eElbowType)(int)elbow.ElbowType; + if (elbow.ElbowType != null) + { + input.MatchingElbowType = (Yw.WinFrmUI.eElbowType)(int)elbow.ElbowType; + } if (input.Material == null || input.Material == string.Empty) { input.MatchingMaterial = elbow.Material; } - if (!input.Caliber.HasValue) + if (input.Caliber <= 0) + { input.MatchingCaliber = elbow.Caliber; + } return true; } @@ -1847,7 +1868,7 @@ } //鏍囩 - int flagWeight = 1; + int flagWeight = 1000; foreach (var item in pressmeterVmos) { if (item.Flags != null && item.Flags.Count > 0) @@ -1909,6 +1930,37 @@ } } + // 涓婃父鍜屼笅娓哥洿寰� + int diameterWeight = 100; + if (input.StartDiameter > 0 && input.EndDiameter > 0) + { + foreach (var item in translationVmos) + { + if (item.StartDiameter > 0 && item.EndDiameter > 0) + { + var startCount = Math.Abs(item.StartDiameter - input.StartDiameter); + var endCount = Math.Abs(item.EndDiameter - input.EndDiameter); + + if (startCount == 0 && endCount == 0) + { + // 濡傛灉 startCount 鍜� endCount 閮戒负 0锛岃〃绀哄畬鍏ㄥ尮閰嶏紝缁欎簣鏈�澶ф潈閲� + dict[item] += diameterWeight * 100; + } + else + { + // 鍚﹀垯锛屽垎鍒绠楁潈閲� + if (startCount != 0) + { + dict[item] += (1.0 / startCount) * diameterWeight; + } + if (endCount != 0) + { + dict[item] += (1.0 / endCount) * diameterWeight; + } + } + } + } + } //鏉愯川 int materialWeight = 5; if (!string.IsNullOrEmpty(input.Material)) @@ -1943,7 +1995,7 @@ } //鏍囩 - int flagWeight = 1; + int flagWeight = 1000; foreach (var item in translationVmos) { if (item.Flags != null && item.Flags.Count > 0) @@ -1980,10 +2032,6 @@ if (input.StartDiameter < 0) { input.MatchingStartDiameter = translation.StartDiameter; - } - if (input.Diameter < 0) - { - input.MatchingDiameter = translation.Diameter; } return true; @@ -2041,14 +2089,14 @@ //鍙e緞 int caliberWeight = 1; - if (input.Caliber.HasValue) + if (input.Caliber > 0) { foreach (var item in allCoolingList) { if (item.Caliber.HasValue) { - var diff = Math.Abs(item.Caliber.Value - input.Caliber.Value); - dict[item] += diff / input.Caliber.Value * 100 * caliberWeight; + var diff = Math.Abs(item.Caliber.Value - input.Caliber); + dict[item] += diff / input.Caliber * 100 * caliberWeight; } } } @@ -2073,7 +2121,7 @@ } //鏍囩 - int flagWeight = 1; + int flagWeight = 1000; foreach (var item in allCoolingList) { if (item.Flags != null && item.Flags.Count > 0) @@ -2095,9 +2143,9 @@ { input.MatchingMaterial = cooling.Material; } - if (!input.Caliber.HasValue || input.Caliber.Value <= 0) + if (input.Caliber <= 0) { - input.Caliber = cooling.Caliber; + input.Caliber = cooling.Caliber ?? 0; } if (input.Coefficient <= 1) { -- Gitblit v1.9.3