Add Couplings calculator
This commit is contained in:
parent
d999a0b98a
commit
8a8fc397bf
@ -25,7 +25,7 @@ public sealed class RhSolutionsAddIn : IExcelAddIn
|
||||
.AddSingleton<IAddInConfiguration, AddInConfiguration>()
|
||||
.AddSingleton<IDatabaseClient, DatabaseClient>()
|
||||
.AddSingleton<ICurrencyClient, CurrencyClient>()
|
||||
.AddSingleton<ISleevesCalculator, SleevesCalculator>()
|
||||
.AddSingleton<IFittingsCalculator, SleevesCalculator>()
|
||||
.AddTransient<IFileDialog, FileDialog>();
|
||||
|
||||
Services.AddSingleton<WriterFactory>();
|
||||
|
9
RhSolutions.AddIn/Services/CouplingsCalculator.cs
Normal file
9
RhSolutions.AddIn/Services/CouplingsCalculator.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace RhSolutions.Services;
|
||||
|
||||
public class CouplingsCalculator : IFittingsCalculator
|
||||
{
|
||||
public Dictionary<Product, double> Calculate(Dictionary<Product, double> products)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
6
RhSolutions.AddIn/Services/IFittingsCalculator.cs
Normal file
6
RhSolutions.AddIn/Services/IFittingsCalculator.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace RhSolutions.Services;
|
||||
|
||||
public interface IFittingsCalculator
|
||||
{
|
||||
public Dictionary<Product, double> Calculate(Dictionary<Product, double> products);
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
namespace RhSolutions.Services;
|
||||
|
||||
public interface ISleevesCalculator
|
||||
{
|
||||
public Dictionary<Product, double> CalculateSleeves(Dictionary<Product, double> products);
|
||||
}
|
@ -2,14 +2,14 @@
|
||||
|
||||
namespace RhSolutions.Services;
|
||||
|
||||
public class SleevesCalculator : ISleevesCalculator
|
||||
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)+";
|
||||
|
||||
public Dictionary<Product, double> CalculateSleeves(Dictionary<Product, double> products)
|
||||
public Dictionary<Product, double> Calculate(Dictionary<Product, double> products)
|
||||
{
|
||||
Dictionary<string, double> result = new()
|
||||
{
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
internal class SleevesTool : Tool
|
||||
{
|
||||
private readonly ISleevesCalculator _sleevesCaluculator;
|
||||
private readonly IFittingsCalculator _sleevesCaluculator;
|
||||
|
||||
public SleevesTool(ReaderFactory readerFactory, WriterFactory writerFactory, ISleevesCalculator sleevesCaluculator) : base(readerFactory, writerFactory)
|
||||
public SleevesTool(ReaderFactory readerFactory, WriterFactory writerFactory, IFittingsCalculator sleevesCaluculator) : base(readerFactory, writerFactory)
|
||||
{
|
||||
_sleevesCaluculator = sleevesCaluculator;
|
||||
}
|
||||
@ -15,7 +15,7 @@ internal class SleevesTool : Tool
|
||||
Worksheet worksheet = app.ActiveWorkbook.ActiveSheet;
|
||||
_reader = _readerFactory.GetReader("Excel");
|
||||
var products = _reader.ReadProducts(new[] { worksheet });
|
||||
var sleeves = _sleevesCaluculator.CalculateSleeves(products.Select(p => p.Item2).First());
|
||||
var sleeves = _sleevesCaluculator.Calculate(products.Select(p => p.Item2).First());
|
||||
_writer = _writerFactory.GetWriter("CurrentPrice");
|
||||
_writer.WriteProducts(sleeves);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ internal class ToolFactory
|
||||
{
|
||||
static ReaderFactory readerFactory = RhSolutionsAddIn.ServiceProvider.GetService<ReaderFactory>();
|
||||
static WriterFactory writerFactory = RhSolutionsAddIn.ServiceProvider.GetService<WriterFactory>();
|
||||
static ISleevesCalculator sleevesCaluculator = RhSolutionsAddIn.ServiceProvider.GetService<ISleevesCalculator>();
|
||||
static IFittingsCalculator sleevesCaluculator = RhSolutionsAddIn.ServiceProvider.GetService<IFittingsCalculator>();
|
||||
|
||||
public Tool GetTool(string toolName)
|
||||
{
|
||||
|
@ -6,7 +6,7 @@ namespace RhSolutions.Tests;
|
||||
public class CanFillSleeves : IDisposable
|
||||
{
|
||||
private RhSolutionsAddIn _addIn;
|
||||
private ISleevesCalculator _calculator;
|
||||
private IFittingsCalculator _calculator;
|
||||
private IReader _reader;
|
||||
private IWriter _writer;
|
||||
private Worksheet _worksheet;
|
||||
@ -25,7 +25,7 @@ public class CanFillSleeves : IDisposable
|
||||
public void CanCalculateSleeves()
|
||||
{
|
||||
var products = _reader.ReadProducts(new[] { _worksheet });
|
||||
var sleeves = _calculator.CalculateSleeves(products.First().Item2);
|
||||
var sleeves = _calculator.Calculate(products.First().Item2);
|
||||
_writer.WriteProducts(sleeves);
|
||||
|
||||
Assert.Equal(25, _worksheet.Range["E2"].Value);
|
||||
|
Loading…
Reference in New Issue
Block a user