duheng
2024-09-20 8a8983dd2053b631c559b257b1501d740bedf4a5
WinFrmUI/HStation.WinFrmUI.Xhs.Core/04-simulation/06-simulation/01-AutoMatching/02-AsstesFormCtrl/PumpMatchingCtrl.cs
@@ -11,72 +11,24 @@
        }
        private List<PumpMatchingViewModel> _allBindingList = null;
        private BLL.PumpMain _pumpMainBll = null;
        public List<PumpMatchingViewModel> SetBindingData(List<PumpMatchingViewModel> pumpMatchingViewModel, out List<PumpMatchingViewModel> errorList)
        public void SetBindingData(List<PumpMatchingViewModel> pumpMatchingViewModel)
        {
            _pumpMainBll = new BLL.PumpMain();
            errorList = null;
            _allBindingList = new List<PumpMatchingViewModel>();
            if (pumpMatchingViewModel == null)
                return null;
            var alllist = _pumpMainBll.GetAll().Result;
            const double speedTolerance = 100;
            const double flowTolerance = 10;
            const double headTolerance = 5;
            const double efficiencyTolerance = 0.05;
            foreach (var viewModel in pumpMatchingViewModel)
            {
                foreach (var pumpMain in alllist)
                {
                    // 尝试绝对匹配
                    var absoluteMatch = alllist.Where(item =>
                        viewModel.RatedN == item.RatedSpeed &&
                        viewModel.RatedQ == item.RatedFlow &&
                        viewModel.RatedH == item.RatedHead &&
                        viewModel.RatedP == item.RatedPower).ToList();
                    if (absoluteMatch != null)
                    {
                    }
                    else
                    {
                        // 尝试区间匹配
                        var rangeMatch = alllist.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) <= efficiencyTolerance)).ToList();
                        if (rangeMatch != null)
                        {
                            var vmo = new Vmo.PumpMainVmo();
                            int firstCount = 0;
                            foreach (var item in rangeMatch)
                            {
                                int commonCount = CountCommonCharacters(viewModel.ModelType, item.Name);
                                if (commonCount > firstCount)
                                {
                                    vmo = item;
                                    firstCount = commonCount;
                                }
                            }
                        }
                    }
                }
            }
            _allBindingList = pumpMatchingViewModel;
            this.pumpMatchingViewModelBindingSource.DataSource = _allBindingList;
            return new List<PumpMatchingViewModel>();
        }
        private static int CountCommonCharacters(string baseString, string comparisonString)
        public async Task<List<PumpMatchingViewModel>> SetMatching(List<PumpMatchingViewModel> pumpMatchingViewModel, List<PumpMainVmo> pumpMainVmos)
        {
            // 将字符串转换为字符集合
            HashSet<char> baseChars = new HashSet<char>(baseString);
            HashSet<char> comparisonChars = new HashSet<char>(comparisonString);
            // 计算两个集合的交集
            int commonCount = baseChars.Intersect(comparisonChars).Count();
            return commonCount;
            List<PumpMatchingViewModel> _allBindingList = new List<PumpMatchingViewModel>();
            if (pumpMatchingViewModel == null)
                return null;
            foreach (var item in pumpMatchingViewModel)
            {
                var result = await AsstesAutoMatchingHelper.PumpMatching(item, pumpMainVmos);
            }
            this.pumpMatchingViewModelBindingSource.ResetBindings(false);
            return _allBindingList;
        }
    }
}