diff options
| author | mo k <mo@mokhan.ca> | 2012-04-23 18:58:39 -0600 |
|---|---|---|
| committer | mo k <mo@mokhan.ca> | 2012-04-23 18:58:39 -0600 |
| commit | 497942c67ac3c176db5bddc2c5b08c8486a27534 (patch) | |
| tree | 26a7bdbdaa2f41dadd14baab07d939c6fefe8949 | |
| parent | 071efd4c0a83e6f30d52e2cd3bc746425b3a8c2f (diff) | |
move summation and capacity to separate files.
| -rw-r--r-- | src/domain/Capacity.cs | 56 | ||||
| -rw-r--r-- | src/domain/DrillSchedule.cs | 14 | ||||
| -rw-r--r-- | src/domain/GasPlant.cs | 80 | ||||
| -rw-r--r-- | src/domain/Month.cs | 8 | ||||
| -rw-r--r-- | src/domain/Months.cs | 54 | ||||
| -rw-r--r-- | src/domain/Summation.cs | 16 | ||||
| -rwxr-xr-x | src/domain/domain.csproj | 3 |
7 files changed, 135 insertions, 96 deletions
diff --git a/src/domain/Capacity.cs b/src/domain/Capacity.cs new file mode 100644 index 0000000..9c9c1a2 --- /dev/null +++ b/src/domain/Capacity.cs @@ -0,0 +1,56 @@ +namespace domain +{ + using System.Collections.Generic; + + public class Capacity + { + IList<Increase> increases; + + public Capacity(IQuantity initialCapacity):this(initialCapacity, Month.Now()) + { + } + + public Capacity(IQuantity initialCapacity, Month month) + { + this.increases = new List<Increase>(); + this.IncreaseCapacity(initialCapacity, month); + } + + public void IncreaseCapacity(IQuantity quantity, Month month) + { + this.increases.Add(new Increase(quantity, month)); + } + + public IQuantity AvailableFor(Month month) + { + return new Quantity(0, new BOED()); + //return this + //.increases + //.Where(x => x.IsBeforeOrOn(month)) + //.Sum(x => x.IncreasedCapacity()); + return null; + } + + class Increase + { + IQuantity quantity; + Month month; + + public Increase(IQuantity quantity, Month month) + { + this.quantity = quantity; + this.month = month; + } + + public bool IsBeforeOrOn(Month other) + { + return month.IsBefore(other) || month.Equals(other); + } + + public IQuantity IncreasedCapacity() + { + return this.quantity; + } + } + } +} diff --git a/src/domain/DrillSchedule.cs b/src/domain/DrillSchedule.cs index a59dff0..5b56d61 100644 --- a/src/domain/DrillSchedule.cs +++ b/src/domain/DrillSchedule.cs @@ -16,22 +16,12 @@ namespace domain public IQuantity EstimatedGrossProductionFor<Commodity>(Month month) where Commodity : ICommodity, new() { - IQuantity result = new Quantity(0, new BOED()); - Accept(well => - { - result = result.Plus(well.GrossProductionFor<Commodity>(month)); - }); - return result; + return wells.Select(well => well.GrossProductionFor<Commodity>(month)).Sum(); } public IQuantity EstimatedNetProductionFor<Commodity>(Month month) where Commodity : ICommodity, new() { - IQuantity result = new Quantity(0, new BOED()); - Accept(well => - { - result = result.Plus(well.NetProductionFor<Commodity>(month)); - }); - return result; + return wells.Select(well => well.NetProductionFor<Commodity>(month)).Sum(); } public void Accept(IVisitor<IWell> visitor ) diff --git a/src/domain/GasPlant.cs b/src/domain/GasPlant.cs index faa4e18..e104c24 100644 --- a/src/domain/GasPlant.cs +++ b/src/domain/GasPlant.cs @@ -36,92 +36,20 @@ namespace domain var results = new List<Month>(); months.Accept(month => { - if(IsOverCapacity(month)){ + if(IsOverCapacity(month)) results.Add(month); - } }); return results; } bool IsOverCapacity(Month month) { - var production = TotalProductionFor(month); - if( capacity.AvailableFor(month).IsGreaterThan(production) ){ - return true; - } - return false; + return capacity.AvailableFor(month).IsGreaterThan(TotalProductionFor(month)); } - IQuantity TotalProductionFor(Month month) - { - IQuantity result = new Quantity(0, new BOED()); - wells.Each(x => - { - result = result.Plus( x.GrossProductionFor<Gas>(month)); - }); - return result; - } - } - - public class Capacity - { - IList<Increase> increases; - public Capacity(IQuantity initialCapacity):this(initialCapacity, Month.Now()) - { - } - - public Capacity(IQuantity initialCapacity, Month month) - { - this.increases = new List<Increase>(); - this.IncreaseCapacity(initialCapacity, month); - } - - public void IncreaseCapacity(IQuantity quantity, Month month) - { - this.increases.Add(new Increase(quantity, month)); - } - - public IQuantity AvailableFor(Month month) - { - return new Quantity(0, new BOED()); - //return this - //.increases - //.Where(x => x.IsBeforeOrOn(month)) - //.Sum(x => x.IncreasedCapacity()); - return null; - } - - class Increase - { - IQuantity quantity; - Month month; - - public Increase(IQuantity quantity, Month month) - { - this.quantity = quantity; - this.month = month; - } - - public bool IsBeforeOrOn(Month other) - { - return month.IsBefore(other) || month.Equals(other); - } - - public IQuantity IncreasedCapacity() - { - return this.quantity; - } - } - } - public static class Summation - { - static public IQuantity Sum(this IEnumerable<IQuantity> items) + IQuantity TotalProductionFor(Month month) { - var result = 0m.BOED(); - foreach (var item in items) { - result = result.Plus(item); - } - return result; + return wells.Select(well => well.GrossProductionFor<Gas>(month)).Sum(); } } } diff --git a/src/domain/Month.cs b/src/domain/Month.cs index 617f33a..6bc9359 100644 --- a/src/domain/Month.cs +++ b/src/domain/Month.cs @@ -70,12 +70,4 @@ namespace domain return string.Format("{0} {1}", date.Year, date.Month); } } - - public static class Months - { - public static Month January(this int year) - { - return new Month(year,01); - } - } } diff --git a/src/domain/Months.cs b/src/domain/Months.cs new file mode 100644 index 0000000..1652ad6 --- /dev/null +++ b/src/domain/Months.cs @@ -0,0 +1,54 @@ +namespace domain +{ + public static class Months + { + public static Month January(this int year) + { + return new Month(year,01); + } + public static Month February(this int year) + { + return new Month(year,2); + } + public static Month March(this int year) + { + return new Month(year,3); + } + public static Month April(this int year) + { + return new Month(year,04); + } + public static Month May(this int year) + { + return new Month(year,05); + } + public static Month June(this int year) + { + return new Month(year,06); + } + public static Month July(this int year) + { + return new Month(year,07); + } + public static Month August(this int year) + { + return new Month(year,08); + } + public static Month September(this int year) + { + return new Month(year,09); + } + public static Month October(this int year) + { + return new Month(year,10); + } + public static Month November(this int year) + { + return new Month(year,11); + } + public static Month December(this int year) + { + return new Month(year,12); + } + } +} diff --git a/src/domain/Summation.cs b/src/domain/Summation.cs new file mode 100644 index 0000000..0a3e889 --- /dev/null +++ b/src/domain/Summation.cs @@ -0,0 +1,16 @@ +namespace domain +{ + using System.Collections.Generic; + + public static class Summation + { + static public IQuantity Sum(this IEnumerable<IQuantity> items) + { + var result = 0m.BOED(); + foreach (var item in items) { + result = result.Plus(item); + } + return result; + } + } +} diff --git a/src/domain/domain.csproj b/src/domain/domain.csproj index 8c5b85d..d0386dc 100755 --- a/src/domain/domain.csproj +++ b/src/domain/domain.csproj @@ -43,6 +43,7 @@ <Compile Include="Greeting.cs" />
<Compile Include="BOED.cs" />
<Compile Include="Clock.cs" />
+ <Compile Include="Capacity.cs" />
<Compile Include="Commodity.cs" />
<Compile Include="CommoditySplits.cs" />
<Compile Include="DeclineCurve.cs" />
@@ -50,11 +51,13 @@ <Compile Include="EstimatedNetProductionFor.cs" />
<Compile Include="GasPlant.cs" />
<Compile Include="Month.cs" />
+ <Compile Include="Months.cs" />
<Compile Include="Oppurtunity.cs" />
<Compile Include="Percent.cs" />
<Compile Include="Production.cs" />
<Compile Include="Quantity.cs" />
<Compile Include="Range.cs" />
+ <Compile Include="Summation.cs" />
<Compile Include="TypeCurve.cs" />
<Compile Include="Units.cs" />
<Compile Include="Well.cs" />
|
