From 88c13046c69ebeb0bc323c8d81501f5933f5a81f Mon Sep 17 00:00:00 2001
From: duheng <2784771470@qq.com>
Date: 星期四, 26 九月 2024 16:19:08 +0800
Subject: [PATCH] 修改匹配细节

---
 WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs |  173 +++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 113 insertions(+), 60 deletions(-)

diff --git a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs
index 5070d38..5672274 100644
--- a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs
+++ b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs
@@ -1,4 +1,6 @@
-锘縩amespace HStation.WinFrmUI
+锘縰sing HStation.WinFrmUI.PhartRelation;
+
+namespace HStation.WinFrmUI
 {
     public class AssetsMatchingHelper
     {
@@ -73,21 +75,21 @@
         }
 
         //娉靛尮閰�
-        public static async Task<bool> MatchingPumps(PumpMatchingViewModel viewModel, List<Vmo.PumpMainVmo> pumpMainVmos)
+        public static async Task<bool> MatchingPumps(PumpMatchingViewModel InputModel, List<Vmo.PumpMainVmo> pumpMainVmos)
         {
             Vmo.PumpMainVmo vmo = null;
             int startCount = 0;
             // 灏濊瘯缁濆鍖归厤
             var absoluteMatch = pumpMainVmos.Where(item =>
-            (viewModel.RatedN == null || viewModel.RatedN == item.RatedSpeed) &&
-            (viewModel.RatedQ == null || viewModel.RatedQ == item.RatedFlow) &&
-            (viewModel.RatedH == null || viewModel.RatedH == item.RatedHead) &&
-            (viewModel.RatedP == item.RatedPower)).ToList();
+            (InputModel.RatedN == null || InputModel.RatedN == item.RatedSpeed) &&
+            (InputModel.RatedQ == null || InputModel.RatedQ == item.RatedFlow) &&
+            (InputModel.RatedH == null || InputModel.RatedH == item.RatedHead) &&
+            (InputModel.RatedP == item.RatedPower)).ToList();
             if (absoluteMatch != null && absoluteMatch.Count != 0)
             {
                 foreach (var item in absoluteMatch)
                 {
-                    int commonCount = CountCommonCharacters(viewModel.ModelType, item.Name);
+                    int commonCount = GetIntersect(InputModel.ModelType, item.Name);
                     if (commonCount > startCount)
                     {
                         vmo = item;
@@ -99,15 +101,15 @@
             {
                 // 灏濊瘯鍖洪棿鍖归厤
                 var rangeMatch = pumpMainVmos.Where(item =>
-                   (viewModel.RatedN.HasValue ? Math.Abs(viewModel.RatedN.Value - item.RatedSpeed) <= _speedTolerance : true) &&
-                   (viewModel.RatedQ.HasValue ? Math.Abs(viewModel.RatedQ.Value - item.RatedFlow) <= _flowTolerance : true) &&
-                   (viewModel.RatedH.HasValue ? Math.Abs(viewModel.RatedH.Value - item.RatedHead) <= _headTolerance : true) &&
-                   (Math.Abs(viewModel.RatedP - item.RatedPower) <= _powerTolerance)).ToList();
+                   (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) &&
+                   (Math.Abs(InputModel.RatedP - item.RatedPower) <= _powerTolerance)).ToList();
                 if (rangeMatch != null && rangeMatch.Count != 0)
                 {
                     foreach (var item in rangeMatch)
                     {
-                        int commonCount = CountCommonCharacters(viewModel.ModelType, item.Name);
+                        int commonCount = GetIntersect(InputModel.ModelType, item.Name);
                         if (commonCount > startCount)
                         {
                             vmo = item;
@@ -121,7 +123,7 @@
             {
                 foreach (var item in pumpMainVmos)
                 {
-                    int commonCount = CountCommonCharacters(viewModel.ModelType, item.Name);
+                    int commonCount = GetIntersect(InputModel.ModelType, item.Name);
                     if (commonCount > startCount)
                     {
                         vmo = item;
@@ -131,15 +133,46 @@
             }
             if (vmo != null)
             {
-                viewModel.MatchingRatedH = vmo.RatedHead;
-                viewModel.MatchingRatedN = vmo.RatedSpeed;
-                viewModel.MatchingRatedQ = vmo.RatedFlow;
-                viewModel.MatchingRatedP = vmo.RatedPower;
-                viewModel.MatchingDbId = vmo.ID.ToString();
+                InputModel.MatchingRatedH = vmo.RatedHead;
+                InputModel.MatchingRatedN = vmo.RatedSpeed;
+                InputModel.MatchingRatedQ = vmo.RatedFlow;
+                InputModel.MatchingRatedP = vmo.RatedPower;
+                InputModel.MatchingDbId = vmo.ID.ToString();
+                InputModel.MatchingModelType = vmo.Name;
                 var list = await new BLL.XhsPumpMainPhartMappingExtensions().GetByPumpMainID(vmo.ID);
                 if (list != null && list.Count > 0)
                 {
-                    viewModel.MatchingCurveDbId = list.First().ID.ToString();
+                    InputModel.MatchingCurveDbId = list.First().ID.ToString();
+                    var graph_qh = list.First().Diagram.GraphList.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQH);
+                    var graph_qe = list.First().Diagram.GraphList.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQE);
+                    var graph_qp = list.First().Diagram.GraphList.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQP);
+                    if (graph_qh != null)
+                    {
+                        var points_qh = PhartPerformCurveHelper.GetFeatPointList(graph_qh.GraphType, graph_qh.GeometryInfo, 100, null);
+                        InputModel.MatchingCurveQH = new List<CurvePointMatchingViewModel>();
+                        foreach (var item in points_qh)
+                        {
+                            InputModel.MatchingCurveQH.Add(new CurvePointMatchingViewModel(item.X, item.Y));
+                        }
+                    }
+                    if (graph_qe != null)
+                    {
+                        var points_qe = PhartPerformCurveHelper.GetFeatPointList(graph_qe.GraphType, graph_qe.GeometryInfo, 100, null);
+                        InputModel.MatchingCurveQE = new List<CurvePointMatchingViewModel>();
+                        foreach (var item in points_qe)
+                        {
+                            InputModel.MatchingCurveQE.Add(new CurvePointMatchingViewModel(item.X, item.Y));
+                        }
+                    }
+                    if (graph_qp != null)
+                    {
+                        var points_qp = PhartPerformCurveHelper.GetFeatPointList(graph_qp.GraphType, graph_qp.GeometryInfo, 100, null);
+                        InputModel.MatchingCurveQP = new List<CurvePointMatchingViewModel>();
+                        foreach (var item in points_qp)
+                        {
+                            InputModel.MatchingCurveQP.Add(new CurvePointMatchingViewModel(item.X, item.Y));
+                        }
+                    }
                 }
                 return true;
             }
@@ -160,7 +193,7 @@
             {
                 foreach (var range in absoluteMatch)
                 {
-                    int commonCount = CountCommonCharacters(input.ModelType, range.Name);
+                    int commonCount = GetIntersect(input.ModelType, range.Name);
                     if (commonCount > firstCount)
                     {
                         vmo = range;
@@ -173,7 +206,7 @@
                 //鍖洪棿鍖归厤
                 var rangeMatch = adaptingManageVmos.Where(item =>
                 {
-                    if (item.Caliber != null && input.Diameter != null)
+                    if (item.Caliber.HasValue)
                     {
                         return Math.Abs(Convert.ToInt64(item.Caliber - input.Diameter)) <= _caliberTolerance;
                     }
@@ -199,7 +232,7 @@
                         }
                         else
                         {
-                            int commonCount = CountCommonCharacters(input.Material, range.Material);
+                            int commonCount = GetIntersect(input.Material, range.Material);
                             if (commonCount > firstCount)
                             {
                                 materialList.Add(range);
@@ -211,7 +244,7 @@
                     firstCount = 0;
                     foreach (var material in materialList)
                     {
-                        int commonCount = CountCommonCharacters(input.ModelType, material.Name);
+                        int commonCount = GetIntersect(input.ModelType, material.Name);
                         if (commonCount > firstCount)
                         {
                             vmo = material;
@@ -226,7 +259,7 @@
             {
                 foreach (var item in adaptingManageVmos)
                 {
-                    int commonCount = CountCommonCharacters(input.ModelType, item.Name);
+                    int commonCount = GetIntersect(input.ModelType, item.Name);
                     if (commonCount > firstCount)
                     {
                         vmo = item;
@@ -237,6 +270,12 @@
             if (vmo != null)
             {
                 input.MatchingMinorLoss = vmo.Coefficient;
+                input.MatchingDbId = vmo.ID.ToString();
+                input.MatchingDiameter = vmo.Caliber;
+                input.MatchingMaterial = vmo.Material;
+                input.MatchingModelType = vmo.Name;
+                //  input.MatchingValveSetting =
+                input.MatchingValveType = vmo.Type.ToString();
                 return true;
             }
             return false;
@@ -256,7 +295,7 @@
             {
                 foreach (var range in absoluteMatch)
                 {
-                    int commonCount = CountCommonCharacters(input.ModelType, range.Name);
+                    int commonCount = GetIntersect(input.ModelType, range.Name);
                     if (commonCount > StartCount)
                     {
                         vmo = range;
@@ -281,7 +320,7 @@
                     foreach (var range in rangeMatch)
                     {
                         //浠ユ潗鏂欎负鏉′欢寮�濮嬪尮閰�
-                        int commonCount = CountCommonCharacters(input.Material, range.Material);
+                        int commonCount = GetIntersect(input.Material, range.Material);
                         if (commonCount > StartCount)
                         {
                             vmo = range;
@@ -295,7 +334,7 @@
             {
                 foreach (var item in pipeLineManageVmos)
                 {
-                    int commonCount = CountCommonCharacters(input.ModelType, item.Name);
+                    int commonCount = GetIntersect(input.ModelType, item.Name);
                     if (commonCount > StartCount)
                     {
                         vmo = item;
@@ -308,21 +347,25 @@
                 switch (input.eAlgorithmType)
                 {
                     case HStation.Assets.eAlgorithmType.Hazen:
-                        input.MatchingMinorLoss = vmo.Hazen;
+                        input.MatchingRoughness = vmo.Hazen;
                         break;
 
                     case HStation.Assets.eAlgorithmType.Manning:
-                        input.MatchingMinorLoss = vmo.Manning;
+                        input.MatchingRoughness = vmo.Manning;
                         break;
 
                     case HStation.Assets.eAlgorithmType.Darcy:
-                        input.MatchingMinorLoss = vmo.Darcy;
+                        input.MatchingRoughness = vmo.Darcy;
                         break;
 
                     default:
-                        input.MatchingMinorLoss = vmo.Hazen;
+                        input.MatchingRoughness = vmo.Hazen;
                         break;
                 }
+                input.MatchingDbId = vmo.ID.ToString();
+                input.MatchingMaterial = vmo.Material;
+                input.MatchingModelType = vmo.Name;
+                input.MatchingMinorLoss = vmo.Coefficient;
                 return true;
             }
             return false;
@@ -342,7 +385,7 @@
             {
                 foreach (var range in absoluteMatch)
                 {
-                    int commonCount = CountCommonCharacters(input.ModelType, range.Name);
+                    int commonCount = GetIntersect(input.ModelType, range.Name);
                     if (commonCount > firstCount)
                     {
                         vmo = range;
@@ -381,7 +424,7 @@
                         }
                         else
                         {
-                            int commonCount = CountCommonCharacters(input.Material, range.Material);
+                            int commonCount = GetIntersect(input.Material, range.Material);
                             if (commonCount > firstCount)
                             {
                                 materialList.Add(range);
@@ -393,7 +436,7 @@
                     firstCount = 0;
                     foreach (var material in materialList)
                     {
-                        int commonCount = CountCommonCharacters(input.ModelType, material.Name);
+                        int commonCount = GetIntersect(input.ModelType, material.Name);
                         if (commonCount > firstCount)
                         {
                             vmo = material;
@@ -408,7 +451,7 @@
             {
                 foreach (var item in adaptingManageVmos)
                 {
-                    int commonCount = CountCommonCharacters(input.ModelType, item.Name);
+                    int commonCount = GetIntersect(input.ModelType, item.Name);
                     if (commonCount > firstCount)
                     {
                         vmo = item;
@@ -419,6 +462,9 @@
             if (vmo != null)
             {
                 input.MatchingMinorLoss = vmo.Coefficient;
+                input.MatchingDbId = vmo.ID.ToString();
+                input.MatchingMaterial = vmo.Material;
+                input.MatchingModelType = vmo.Name;
                 return true;
             }
             return false;
@@ -438,7 +484,7 @@
             {
                 foreach (var range in absoluteMatch)
                 {
-                    int commonCount = CountCommonCharacters(input.ModelType, range.Name);
+                    int commonCount = GetIntersect(input.ModelType, range.Name);
                     if (commonCount > firstCount)
                     {
                         vmo = range;
@@ -477,7 +523,7 @@
                         }
                         else
                         {
-                            int commonCount = CountCommonCharacters(input.Material, range.Material);
+                            int commonCount = GetIntersect(input.Material, range.Material);
                             if (commonCount > firstCount)
                             {
                                 materialList.Add(range);
@@ -489,7 +535,7 @@
                     firstCount = 0;
                     foreach (var material in materialList)
                     {
-                        int commonCount = CountCommonCharacters(input.ModelType, material.Name);
+                        int commonCount = GetIntersect(input.ModelType, material.Name);
                         if (commonCount > firstCount)
                         {
                             vmo = material;
@@ -504,7 +550,7 @@
             {
                 foreach (var item in adaptingManageVmos)
                 {
-                    int commonCount = CountCommonCharacters(input.ModelType, item.Name);
+                    int commonCount = GetIntersect(input.ModelType, item.Name);
                     if (commonCount > firstCount)
                     {
                         vmo = item;
@@ -515,6 +561,9 @@
             if (vmo != null)
             {
                 input.MatchingMinorLoss = vmo.Coefficient;
+                input.MatchingDbId = vmo.ID.ToString();
+                input.MatchingMaterial = vmo.Material;
+                input.MatchingModelType = vmo.Name;
                 return true;
             }
             return false;
@@ -534,7 +583,7 @@
             {
                 foreach (var range in absoluteMatch)
                 {
-                    int commonCount = CountCommonCharacters(input.ModelType, range.Name);
+                    int commonCount = GetIntersect(input.ModelType, range.Name);
                     if (commonCount > firstCount)
                     {
                         vmo = range;
@@ -573,7 +622,7 @@
                         }
                         else
                         {
-                            int commonCount = CountCommonCharacters(input.Material, range.Material);
+                            int commonCount = GetIntersect(input.Material, range.Material);
                             if (commonCount > firstCount)
                             {
                                 materialList.Add(range);
@@ -585,7 +634,7 @@
                     firstCount = 0;
                     foreach (var material in materialList)
                     {
-                        int commonCount = CountCommonCharacters(input.ModelType, material.Name);
+                        int commonCount = GetIntersect(input.ModelType, material.Name);
                         if (commonCount > firstCount)
                         {
                             vmo = material;
@@ -600,7 +649,7 @@
             {
                 foreach (var item in adaptingManageVmos)
                 {
-                    int commonCount = CountCommonCharacters(input.ModelType, item.Name);
+                    int commonCount = GetIntersect(input.ModelType, item.Name);
                     if (commonCount > firstCount)
                     {
                         vmo = item;
@@ -611,25 +660,29 @@
             if (vmo != null)
             {
                 input.MatchingMinorLoss = vmo.Coefficient;
+                input.MatchingDbId = vmo.ID.ToString();
+                input.MatchingMaterial = vmo.Material;
+                input.MatchingModelType = vmo.Name;
                 return true;
             }
             return false;
         }
 
-        //杩斿洖涓や釜瀛楃涓蹭箣闂寸浉鍚岀殑瀛楃涓暟
-        private static int CountCommonCharacters(string baseString, string compareString)
-        {
-            // 灏嗗瓧绗︿覆杞崲涓哄瓧绗﹂泦鍚�
-            if (baseString == string.Empty || baseString == null || compareString == string.Empty || compareString == null)
-            {
-                return 0;
-            }
-            HashSet<char> baseChars = new HashSet<char>(baseString);
-            HashSet<char> comparisonChars = new HashSet<char>(compareString);
-            // 璁$畻涓や釜闆嗗悎鐨勪氦闆�
-            int commonCount = baseChars.Intersect(comparisonChars).Count();
-            return commonCount;
-        }
+        /*
+                //杩斿洖涓や釜瀛楃涓蹭箣闂寸浉鍚岀殑瀛楃涓暟
+                private static int GetIntersect(string baseString, string compareString)
+                {
+                    // 灏嗗瓧绗︿覆杞崲涓哄瓧绗﹂泦鍚�
+                    if (baseString == string.Empty || baseString == null || compareString == string.Empty || compareString == null)
+                    {
+                        return 0;
+                    }
+                    HashSet<char> baseChars = new HashSet<char>(baseString);
+                    HashSet<char> comparisonChars = new HashSet<char>(compareString);
+                    // 璁$畻涓や釜闆嗗悎鐨勪氦闆�
+                    int commonCount = baseChars.Intersect(comparisonChars).Count();
+                    return commonCount;
+                }*/
 
         /// <summary>
         /// 鑾峰彇涓や釜瀛楃涓茬殑鎵�鏈変氦闆�
@@ -637,11 +690,11 @@
         /// <param name="str1"></param>
         /// <param name="str2"></param>
         /// <returns></returns>
-        public static string GetIntersect(string str1, string str2)
+        public static int GetIntersect(string str1, string str2)
         {
-            if (str1 == null || str2 == null) return null;
+            if (str1 == null || str2 == null) return 0;
 
-            return string.Join("", str1.Intersect(str2));
+            return string.Join("", str1.Intersect(str2)).Count();
         }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3