diff options
author | Serghei Cebotari <serghei@cebotari.ru> | 2024-11-01 10:54:48 +0300 |
---|---|---|
committer | Serghei Cebotari <serghei@cebotari.ru> | 2024-11-01 10:54:48 +0300 |
commit | 6d3f2bf55c9242fb2eabb573fb6945a2a61d3065 (patch) | |
tree | 2820058a86dae7be85e2727b4c42d8ede71d3035 | |
parent | 38011f165e53997d7e76ffcfdf0b63506ae7f3a9 (diff) | |
parent | 8cb8f58714529cf138cf9b1bceee8c281f7e55c2 (diff) |
Merge pull request 'dev' (#2) from dev into master
Reviewed-on: https://gitea.cebotari.ru/chebser/RhSolutions-AddIn/pulls/2
-rw-r--r-- | RhSolutions.AddIn/Properties/AssemblyInfo.cs | 4 | ||||
-rw-r--r-- | RhSolutions.AddIn/Services/CouplingsCalculator.cs | 2 | ||||
-rw-r--r-- | RhSolutions.AddIn/Services/SleevesCalculator.cs | 152 | ||||
-rw-r--r-- | RhSolutions.Tests/CanFillCouplings.cs | 61 | ||||
-rw-r--r-- | RhSolutions.Tests/CanFillSleeves.cs | 16 | ||||
-rw-r--r-- | RhSolutions.Tests/TestWorkbooks/TestSpecificationCouplings.xlsx | bin | 358618 -> 358149 bytes | |||
-rw-r--r-- | RhSolutions.Tests/TestWorkbooks/TestSpecificationSleeves.xlsx | bin | 358970 -> 356040 bytes |
7 files changed, 114 insertions, 121 deletions
diff --git a/RhSolutions.AddIn/Properties/AssemblyInfo.cs b/RhSolutions.AddIn/Properties/AssemblyInfo.cs index 419c7f7..a71a4ad 100644 --- a/RhSolutions.AddIn/Properties/AssemblyInfo.cs +++ b/RhSolutions.AddIn/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.9.5.0")] -[assembly: AssemblyFileVersion("1.9.5.0")] +[assembly: AssemblyVersion("1.9.5.1")] +[assembly: AssemblyFileVersion("1.9.5.1")] diff --git a/RhSolutions.AddIn/Services/CouplingsCalculator.cs b/RhSolutions.AddIn/Services/CouplingsCalculator.cs index 79e72f5..1c500d2 100644 --- a/RhSolutions.AddIn/Services/CouplingsCalculator.cs +++ b/RhSolutions.AddIn/Services/CouplingsCalculator.cs @@ -42,7 +42,7 @@ public class CouplingsCalculator : IFittingsCalculator "20" => new Product("11080121001"), "25" => new Product("11080131001"), "32" => new Product("11080141001"), - "40" => new Product("11600151001"), + "40" => new Product("11080151001"), "50" => new Product("14563021001"), "63" => new Product("14563031001"), _ => throw new Exception($"Неизвестный диаметр {kvp.Key}") diff --git a/RhSolutions.AddIn/Services/SleevesCalculator.cs b/RhSolutions.AddIn/Services/SleevesCalculator.cs index 17a0aaa..13a60d1 100644 --- a/RhSolutions.AddIn/Services/SleevesCalculator.cs +++ b/RhSolutions.AddIn/Services/SleevesCalculator.cs @@ -4,82 +4,84 @@ namespace RhSolutions.Services; public class SleevesCalculator : IFittingsCalculator { - private const string doublePattern = - @"((?i)равнопроходная|угольник\s+90|угольник\s+45|Т-образная|Комплект\s+трубок(?i))(.+?\b(?<Sleeve>16|20|25|32|40|50|63)\b)+"; - private const string singlePattern = - @"((?i)муфта|тройник|переходник|угольник|штуцер|Г-образная|заглушка(?i))(.+?\b(?<Sleeve>16|20|25|32|40|50|63)\b)+"; + private const string doublePattern = + @"((?i)равнопроходная|угольник\s+90|угольник\s+45|Т-образная|Комплект\s+трубок(?i))(.+?\b(?<Sleeve>16|20|25|32|40|50|63)\b)+"; + private const string singlePattern = + @"((?i)муфта|тройник|переходник|угольник|штуцер|Г-образная|заглушка(?i))(.+?\b(?<Sleeve>16|20|25|32|40|50|63)\b)+"; - public Dictionary<Product, double> Calculate(Dictionary<Product, double> products) - { - Dictionary<string, double> result = new() - { - ["16"] = 0, - ["20"] = 0, - ["25"] = 0, - ["32"] = 0, - ["16PX"] = 0, - ["20PX"] = 0, - ["25PX"] = 0, - ["32PX"] = 0, - ["40"] = 0, - ["50"] = 0, - ["63"] = 0, - }; - var rautitanProducts = products.Where(kvp => kvp.Key.ProductLines.Contains("RAUTITAN")); + public Dictionary<Product, double> Calculate(Dictionary<Product, double> products) + { + Dictionary<string, double> result = new() + { + ["16"] = 0, + ["20"] = 0, + ["25"] = 0, + ["32"] = 0, + ["40"] = 0, + ["50"] = 0, + ["63"] = 0, + ["16PX"] = 0, + ["20PX"] = 0, + ["25PX"] = 0, + ["32PX"] = 0, + ["40PX"] = 0 + }; + var rautitanProducts = products.Where(kvp => kvp.Key.ProductLines.Contains("RAUTITAN")); - foreach (var kvp in rautitanProducts) - { - var doubleCollection = Regex.Matches(kvp.Key.Name, doublePattern); - if (doubleCollection.Count != 0) - { - CaptureCollection collection = doubleCollection[0].Groups["Sleeve"].Captures; - foreach (Capture sleeve in collection) - { - if (kvp.Key.Name.Contains("PX") && sleeve.Value != "40") - { - result[$"{sleeve.Value}PX"] += kvp.Value * 2; - } - else - { - result[sleeve.Value] += kvp.Value * 2; - } - } - continue; - } - var singleCollection = Regex.Matches(kvp.Key.Name, singlePattern); - if (singleCollection.Count != 0) - { - CaptureCollection collection = singleCollection[0].Groups["Sleeve"].Captures; - foreach (Capture sleeve in collection) - { - if (kvp.Key.Name.Contains("PX") && sleeve.Value != "40") - { - result[$"{sleeve.Value}PX"] += kvp.Value; - } - else - { - result[sleeve.Value] += kvp.Value; - } - } - } - } + foreach (var kvp in rautitanProducts) + { + var doubleCollection = Regex.Matches(kvp.Key.Name, doublePattern); + if (doubleCollection.Count != 0) + { + CaptureCollection collection = doubleCollection[0].Groups["Sleeve"].Captures; + foreach (Capture sleeve in collection) + { + if (kvp.Key.Name.Contains("PX")) + { + result[$"{sleeve.Value}PX"] += kvp.Value * 2; + } + else + { + result[sleeve.Value] += kvp.Value * 2; + } + } + continue; + } + var singleCollection = Regex.Matches(kvp.Key.Name, singlePattern); + if (singleCollection.Count != 0) + { + CaptureCollection collection = singleCollection[0].Groups["Sleeve"].Captures; + foreach (Capture sleeve in collection) + { + if (kvp.Key.Name.Contains("PX")) + { + result[$"{sleeve.Value}PX"] += kvp.Value; + } + else + { + result[sleeve.Value] += kvp.Value; + } + } + } + } - return result - .ToDictionary(kvp => - kvp.Key switch - { - "16" => new Product("11080011001"), - "20" => new Product("11080021001"), - "25" => new Product("11080031001"), - "32" => new Product("11080041001"), - "16PX" => new Product("11600011001"), - "20PX" => new Product("11600021001"), - "25PX" => new Product("11600031001"), - "32PX" => new Product("11600041001"), - "40" => new Product("11600051001"), - "50" => new Product("11397713002"), - "63" => new Product("11397813002"), - _ => throw new Exception($"Неизвестный диаметр {kvp.Key}") - }, kvp => kvp.Value); - } + return result + .ToDictionary(kvp => + kvp.Key switch + { + "16" => new Product("11080011001"), + "20" => new Product("11080021001"), + "25" => new Product("11080031001"), + "32" => new Product("11080041001"), + "40" => new Product("11080051001"), + "50" => new Product("11397713002"), + "63" => new Product("11397813002"), + "16PX" => new Product("11600011001"), + "20PX" => new Product("11600021001"), + "25PX" => new Product("11600031001"), + "32PX" => new Product("11600041001"), + "40PX" => new Product("11600051001"), + _ => throw new Exception($"Неизвестный диаметр {kvp.Key}") + }, kvp => kvp.Value); + } } diff --git a/RhSolutions.Tests/CanFillCouplings.cs b/RhSolutions.Tests/CanFillCouplings.cs index 5a57c32..2c6c0bb 100644 --- a/RhSolutions.Tests/CanFillCouplings.cs +++ b/RhSolutions.Tests/CanFillCouplings.cs @@ -5,38 +5,37 @@ namespace RhSolutions.Tests; [ExcelTestSettings(OutOfProcess = true)] public class CanFillCouplings : IDisposable { - private RhSolutionsAddIn _addIn; - private IFittingsCalculator _calculator; - private IReader _reader; - private IWriter _writer; - private Worksheet _worksheet; + private RhSolutionsAddIn _addIn; + private IFittingsCalculator _calculator; + private IReader _reader; + private IWriter _writer; + private Worksheet _worksheet; - public CanFillCouplings() - { - Environment.SetEnvironmentVariable("ISTESTING", "true"); - _addIn = new(); - _addIn.AutoOpen(); - _calculator = new CouplingsCalculator(); - _reader = new ExcelReader(Util.Application, RhSolutionsAddIn.Configuration); - _writer = new CurrentPriceWriter(Util.Application, RhSolutionsAddIn.Configuration); - _worksheet = Util.Workbook.Worksheets[1]; - } + public CanFillCouplings() + { + Environment.SetEnvironmentVariable("ISTESTING", "true"); + _addIn = new(); + _addIn.AutoOpen(); + _calculator = new CouplingsCalculator(); + _reader = new ExcelReader(Util.Application, RhSolutionsAddIn.Configuration); + _writer = new CurrentPriceWriter(Util.Application, RhSolutionsAddIn.Configuration); + _worksheet = Util.Workbook.Worksheets[1]; + } - [ExcelFact(Workbook = @"..\..\..\TestWorkbooks\TestSpecificationCouplings.xlsx")] - public void CanCalculateSleeves() - { - var products = _reader.ReadProducts(new[] { _worksheet }); - var couplings = _calculator.Calculate(products.First().Item2); - _writer.WriteProducts(couplings); + [ExcelFact(Workbook = @"..\..\..\TestWorkbooks\TestSpecificationCouplings.xlsx")] + public void CanCalculateSleeves() + { + var products = _reader.ReadProducts(new[] { _worksheet }); + var couplings = _calculator.Calculate(products.First().Item2); + _writer.WriteProducts(couplings); + for (int i = 2; i < 14; i++) + { + Assert.Equal(_worksheet.Range[$"F{i}"].Value, _worksheet.Range[$"E{i}"].Value); + } + } - Assert.Equal(7, _worksheet.Range["E2"].Value); - Assert.Equal(1, _worksheet.Range["E3"].Value); - Assert.Equal(1, _worksheet.Range["E5"].Value); - Assert.Equal(1, _worksheet.Range["E7"].Value); - } - - public void Dispose() - { - _addIn.AutoClose(); - } + public void Dispose() + { + _addIn.AutoClose(); + } } diff --git a/RhSolutions.Tests/CanFillSleeves.cs b/RhSolutions.Tests/CanFillSleeves.cs index 2fed50c..7d33294 100644 --- a/RhSolutions.Tests/CanFillSleeves.cs +++ b/RhSolutions.Tests/CanFillSleeves.cs @@ -28,18 +28,10 @@ public class CanFillSleeves : IDisposable var products = _reader.ReadProducts(new[] { _worksheet }); var sleeves = _calculator.Calculate(products.First().Item2); _writer.WriteProducts(sleeves); - - Assert.Equal(22, _worksheet.Range["E2"].Value); - Assert.Equal(12, _worksheet.Range["E3"].Value); - Assert.Equal(5, _worksheet.Range["E4"].Value); - Assert.Equal(6, _worksheet.Range["E5"].Value); - Assert.Equal(3, _worksheet.Range["E6"].Value); - Assert.Equal(3, _worksheet.Range["E7"].Value); - Assert.Equal(2, _worksheet.Range["E8"].Value); - Assert.Equal(2, _worksheet.Range["E9"].Value); - Assert.Equal(1, _worksheet.Range["E10"].Value); - Assert.Equal(3, _worksheet.Range["E11"].Value); - Assert.Equal(4, _worksheet.Range["E12"].Value); + for (int i = 2; i < 14; i++) + { + Assert.Equal(_worksheet.Range[$"F{i}"].Value, _worksheet.Range[$"E{i}"].Value); + } } public void Dispose() diff --git a/RhSolutions.Tests/TestWorkbooks/TestSpecificationCouplings.xlsx b/RhSolutions.Tests/TestWorkbooks/TestSpecificationCouplings.xlsx Binary files differindex 77335b9..21135d4 100644 --- a/RhSolutions.Tests/TestWorkbooks/TestSpecificationCouplings.xlsx +++ b/RhSolutions.Tests/TestWorkbooks/TestSpecificationCouplings.xlsx diff --git a/RhSolutions.Tests/TestWorkbooks/TestSpecificationSleeves.xlsx b/RhSolutions.Tests/TestWorkbooks/TestSpecificationSleeves.xlsx Binary files differindex f59a74c..13fcb4e 100644 --- a/RhSolutions.Tests/TestWorkbooks/TestSpecificationSleeves.xlsx +++ b/RhSolutions.Tests/TestWorkbooks/TestSpecificationSleeves.xlsx |