diff options
| author | mo k <mo@mokhan.ca> | 2012-04-12 22:08:11 -0600 |
|---|---|---|
| committer | mo k <mo@mokhan.ca> | 2012-04-12 22:08:11 -0600 |
| commit | d04bc81d093a9ff5db247c154a649e91653964b8 (patch) | |
| tree | d3e13ed681bed034c22ca364ed00f14cc183750a | |
| parent | 4e2cb5a2d9c68bbdbf0ba24a5704ee5d6a13746a (diff) | |
split classes into separate files.
| -rw-r--r-- | src/domain/Commodity.cs | 54 | ||||
| -rw-r--r-- | src/domain/CommoditySplits.cs | 32 | ||||
| -rw-r--r-- | src/domain/DeclineCurve.cs | 33 | ||||
| -rw-r--r-- | src/domain/DrillSchedule.cs | 44 | ||||
| -rw-r--r-- | src/domain/Oppurtunity.cs | 37 | ||||
| -rw-r--r-- | src/domain/Production.cs | 26 | ||||
| -rw-r--r-- | src/domain/Quantity.cs | 61 | ||||
| -rw-r--r-- | src/domain/TypeCurve.cs | 20 | ||||
| -rw-r--r-- | src/domain/Well.cs | 271 | ||||
| -rwxr-xr-x | src/domain/domain.csproj | 8 |
10 files changed, 316 insertions, 270 deletions
diff --git a/src/domain/Commodity.cs b/src/domain/Commodity.cs new file mode 100644 index 0000000..e559efe --- /dev/null +++ b/src/domain/Commodity.cs @@ -0,0 +1,54 @@ +namespace domain +{ + using System; + using System.Collections.Generic; + using System.Linq; + + public class Gas : ICommodity + { + public Percent PercentageFrom(IComposition composition) + { + return composition.PercentageFor<Gas>(); + } + } + + public class Oil : ICommodity + { + public Percent PercentageFrom(IComposition composition) + { + return composition.PercentageFor<Oil>(); + } + } + + public class NGL : ICommodity + { + public Percent PercentageFrom(IComposition composition) + { + return composition.PercentageFor<NGL>(); + } + } + + public class Condensate : ICommodity + { + public Percent PercentageFrom(IComposition composition) + { + return composition.PercentageFor<Condensate>(); + } + } + + public class All : ICommodity + { + public Percent PercentageFrom(IComposition composition) + { + return composition.PercentageFor<Gas>() + .Plus(composition.PercentageFor<Oil>()) + .Plus(composition.PercentageFor<NGL>()) + .Plus(composition.PercentageFor<Condensate>()); + } + } + + public interface ICommodity + { + Percent PercentageFrom(IComposition composition); + } +} diff --git a/src/domain/CommoditySplits.cs b/src/domain/CommoditySplits.cs new file mode 100644 index 0000000..a88b681 --- /dev/null +++ b/src/domain/CommoditySplits.cs @@ -0,0 +1,32 @@ +namespace domain +{ + using System; + using System.Collections.Generic; + + public interface IComposition + { + void SplitFor<Commodity>(Percent percent) where Commodity : ICommodity; + IQuantity PercentageOf<Commodity>(IQuantity quantity) where Commodity : ICommodity, new(); + Percent PercentageFor<Commodity>() where Commodity : ICommodity; + } + + public class CommoditySplits : IComposition + { + IDictionary<Type, Percent> splits = new Dictionary<Type, Percent>(); + + public void SplitFor<Commodity>(Percent percent) where Commodity : ICommodity + { + splits[typeof (Commodity)] = percent; + } + + public IQuantity PercentageOf<Commodity>(IQuantity quantity) where Commodity : ICommodity, new() + { + return new Commodity().PercentageFrom(this).Reduce(quantity); + } + + public Percent PercentageFor<Commodity>() where Commodity : ICommodity + { + return splits.ContainsKey(typeof(Commodity)) ? splits[typeof (Commodity)] : Percent.Zero; + } + } +} diff --git a/src/domain/DeclineCurve.cs b/src/domain/DeclineCurve.cs new file mode 100644 index 0000000..6c02662 --- /dev/null +++ b/src/domain/DeclineCurve.cs @@ -0,0 +1,33 @@ +namespace domain +{ + using System; + using System.Collections.Generic; + using System.Linq; + + public class DeclineCurve + { + IDictionary<int, IQuantity> production = new Dictionary<int, IQuantity>(); + IComposition split = new CommoditySplits(); + + public void Add(int month, IQuantity quantity) + { + production[month] = quantity; + } + + public TypeCurve StartingOn(Month initialProductionMonth) + { + return new TypeCurve(CreateProductionFor(initialProductionMonth)); + } + + IEnumerable<Production> CreateProductionFor(Month initialProductionMonth) + { + foreach (var quantity in production) + yield return new Production(initialProductionMonth.Plus(quantity.Key), quantity.Value, split); + } + + public void Composition<Commodity>(Percent percent) where Commodity : ICommodity + { + split.SplitFor<Commodity>(percent); + } + } +} diff --git a/src/domain/DrillSchedule.cs b/src/domain/DrillSchedule.cs new file mode 100644 index 0000000..cbd2531 --- /dev/null +++ b/src/domain/DrillSchedule.cs @@ -0,0 +1,44 @@ +namespace domain +{ + using System; + using System.Collections.Generic; + using System.Linq; + + public class DrillSchedule + { + ICollection<IWell> wells = new List<IWell>(); + + public void Include(IWell well) + { + wells.Add(well); + } + + 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; + } + + 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; + } + + void Accept(Action<IWell> visitor ) + { + wells.Each(well => + { + visitor(well); + }); + } + } +} diff --git a/src/domain/Oppurtunity.cs b/src/domain/Oppurtunity.cs new file mode 100644 index 0000000..d3b2720 --- /dev/null +++ b/src/domain/Oppurtunity.cs @@ -0,0 +1,37 @@ +namespace domain +{ + using System.Collections.Generic; + using System.Linq; + + public class Oppurtunity + { + Percent workingInterest; + DeclineCurve declineCurve; + + public Oppurtunity() + { + workingInterest = 100m.Percent(); + } + + public void WorkingInterest(Percent percent) + { + workingInterest = percent; + } + + public void DeclinesUsing(DeclineCurve declineCurve) + { + this.declineCurve = declineCurve; + } + + public IWell BringOnlineOn(Month initialProductionMonth) + { + return new Well(initialProductionMonth, workingInterest, declineCurve.StartingOn(initialProductionMonth)); + } + + public IEnumerable<IWell> BringOnlineOn(Month initialProductionMonth, int numberOfWells) + { + for (var i = 0; i < numberOfWells; i++) + yield return BringOnlineOn(initialProductionMonth); + } + } +} diff --git a/src/domain/Production.cs b/src/domain/Production.cs new file mode 100644 index 0000000..8e32eaa --- /dev/null +++ b/src/domain/Production.cs @@ -0,0 +1,26 @@ +namespace domain +{ + public class Production + { + Month month; + IQuantity produced; + IComposition split; + + public Production(Month month, IQuantity produced, IComposition split) + { + this.month = month; + this.produced = produced; + this.split = split; + } + + public bool IsFor(Month otherMonth) + { + return month.Equals(otherMonth); + } + + public IQuantity ProductionOf<T>() where T : ICommodity, new() + { + return split.PercentageOf<T>(produced); + } + } +} diff --git a/src/domain/Quantity.cs b/src/domain/Quantity.cs new file mode 100644 index 0000000..9ff7109 --- /dev/null +++ b/src/domain/Quantity.cs @@ -0,0 +1,61 @@ +namespace domain +{ + public interface IQuantity + { + IQuantity Plus(IQuantity other); + IQuantity ConvertTo(IUnitOfMeasure units); + decimal Amount { get; } + IUnitOfMeasure Units { get; } + } + + public class Quantity : IQuantity + { + public Quantity(decimal amount, IUnitOfMeasure units) + { + Amount = amount; + Units = units; + } + + public decimal Amount { get;private set; } + + public IUnitOfMeasure Units { get; private set; } + + public IQuantity Plus(IQuantity other) + { + return new Quantity(Amount + other.ConvertTo(Units).Amount, Units); + } + + public IQuantity ConvertTo(IUnitOfMeasure unitOfMeasure) + { + return new Quantity(unitOfMeasure.Convert(Amount, this.Units), unitOfMeasure); + } + + public override string ToString() + { + return string.Format("{0} {1}", Amount, Units); + } + + public bool Equals(Quantity other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return other.Amount == Amount && Equals(other.Units, Units); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != typeof (Quantity)) return false; + return Equals((Quantity) obj); + } + + public override int GetHashCode() + { + unchecked + { + return (Amount.GetHashCode()*397) ^ (Units != null ? Units.GetHashCode() : 0); + } + } + } +} diff --git a/src/domain/TypeCurve.cs b/src/domain/TypeCurve.cs new file mode 100644 index 0000000..ba3d954 --- /dev/null +++ b/src/domain/TypeCurve.cs @@ -0,0 +1,20 @@ +namespace domain +{ + using System.Linq; + using System.Collections.Generic; + + public class TypeCurve + { + IEnumerable<Production> production; + + public TypeCurve(IEnumerable<Production> production) + { + this.production = production.ToList(); + } + + public IQuantity ProductionFor<Commodity>(Month month) where Commodity : ICommodity, new() + { + return production.Single(x => x.IsFor(month)).ProductionOf<Commodity>(); + } + } +} diff --git a/src/domain/Well.cs b/src/domain/Well.cs index f0400a5..69b5cd5 100644 --- a/src/domain/Well.cs +++ b/src/domain/Well.cs @@ -4,225 +4,6 @@ namespace domain using System.Collections.Generic; using System.Linq; - public class Gas : ICommodity - { - public Percent PercentageFrom(IComposition composition) - { - return composition.PercentageFor<Gas>(); - } - } - - public class Oil : ICommodity - { - public Percent PercentageFrom(IComposition composition) - { - return composition.PercentageFor<Oil>(); - } - } - - public class NGL : ICommodity - { - public Percent PercentageFrom(IComposition composition) - { - return composition.PercentageFor<NGL>(); - } - } - - public class Condensate : ICommodity - { - public Percent PercentageFrom(IComposition composition) - { - return composition.PercentageFor<Condensate>(); - } - } - - public class All : ICommodity - { - public Percent PercentageFrom(IComposition composition) - { - return composition.PercentageFor<Gas>() - .Plus(composition.PercentageFor<Oil>()) - .Plus(composition.PercentageFor<NGL>()) - .Plus(composition.PercentageFor<Condensate>()); - } - } - - public interface ICommodity - { - Percent PercentageFrom(IComposition composition); - } - - public class DrillSchedule - { - ICollection<IWell> wells = new List<IWell>(); - - public void Include(IWell well) - { - wells.Add(well); - } - - 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; - } - - 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; - } - - void Accept(Action<IWell> visitor ) - { - wells.Each(well => - { - visitor(well); - }); - } - } - - public interface IComposition - { - void SplitFor<Commodity>(Percent percent) where Commodity : ICommodity; - IQuantity PercentageOf<Commodity>(IQuantity quantity) where Commodity : ICommodity, new(); - Percent PercentageFor<Commodity>() where Commodity : ICommodity; - } - - public class DeclineCurve - { - IDictionary<int, IQuantity> production = new Dictionary<int, IQuantity>(); - IComposition split = new CommoditySplits(); - - public void Add(int month, IQuantity quantity) - { - production[month] = quantity; - } - - public TypeCurve StartingOn(Month initialProductionMonth) - { - return new TypeCurve(CreateProductionFor(initialProductionMonth)); - } - - IEnumerable<Production> CreateProductionFor(Month initialProductionMonth) - { - foreach (var quantity in production) - yield return new Production(initialProductionMonth.Plus(quantity.Key), quantity.Value, split); - } - - public void Composition<Commodity>(Percent percent) where Commodity : ICommodity - { - split.SplitFor<Commodity>(percent); - } - } - - public class CommoditySplits : IComposition - { - IDictionary<Type, Percent> splits = new Dictionary<Type, Percent>(); - - public void SplitFor<Commodity>(Percent percent) where Commodity : ICommodity - { - splits[typeof (Commodity)] = percent; - } - - public IQuantity PercentageOf<Commodity>(IQuantity quantity) where Commodity : ICommodity, new() - { - return new Commodity().PercentageFrom(this).Reduce(quantity); - } - - public Percent PercentageFor<Commodity>() where Commodity : ICommodity - { - return splits.ContainsKey(typeof(Commodity)) ? splits[typeof (Commodity)] : Percent.Zero; - } - } - - public class Production - { - Month month; - IQuantity produced; - IComposition split; - - public Production(Month month, IQuantity produced, IComposition split) - { - this.month = month; - this.produced = produced; - this.split = split; - } - - public bool IsFor(Month otherMonth) - { - return month.Equals(otherMonth); - } - - public IQuantity ProductionOf<T>() where T : ICommodity, new() - { - return split.PercentageOf<T>(produced); - } - } - - public class TypeCurve - { - IEnumerable<Production> production; - - public TypeCurve(IEnumerable<Production> production) - { - this.production = production.ToList(); - } - - public IQuantity ProductionFor<Commodity>(Month month) where Commodity : ICommodity, new() - { - return production.Single(x => x.IsFor(month)).ProductionOf<Commodity>(); - } - } - - public interface IQuantity - { - IQuantity Plus(IQuantity other); - IQuantity ConvertTo(IUnitOfMeasure units); - decimal Amount { get; } - IUnitOfMeasure Units { get; } - } - - public class Oppurtunity - { - Percent workingInterest; - DeclineCurve declineCurve; - - public Oppurtunity() - { - workingInterest = 100m.Percent(); - } - - public void WorkingInterest(Percent percent) - { - workingInterest = percent; - } - - public void DeclinesUsing(DeclineCurve declineCurve) - { - this.declineCurve = declineCurve; - } - - public IWell BringOnlineOn(Month initialProductionMonth) - { - return new Well(initialProductionMonth, workingInterest, declineCurve.StartingOn(initialProductionMonth)); - } - - public IEnumerable<IWell> BringOnlineOn(Month initialProductionMonth, int numberOfWells) - { - for (var i = 0; i < numberOfWells; i++) - yield return BringOnlineOn(initialProductionMonth); - } - } - public class Well : IWell { Month initialProductionMonth; @@ -405,61 +186,11 @@ namespace domain readonly string name = "BOED"; } - public class Quantity : IQuantity - { - public Quantity(decimal amount, IUnitOfMeasure units) - { - Amount = amount; - Units = units; - } - - public decimal Amount { get;private set; } - - public IUnitOfMeasure Units { get; private set; } - - public IQuantity Plus(IQuantity other) - { - return new Quantity(Amount + other.ConvertTo(Units).Amount, Units); - } - - public IQuantity ConvertTo(IUnitOfMeasure unitOfMeasure) - { - return new Quantity(unitOfMeasure.Convert(Amount, this.Units), unitOfMeasure); - } - - public override string ToString() - { - return string.Format("{0} {1}", Amount, Units); - } - - public bool Equals(Quantity other) - { - if (ReferenceEquals(null, other)) return false; - if (ReferenceEquals(this, other)) return true; - return other.Amount == Amount && Equals(other.Units, Units); - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != typeof (Quantity)) return false; - return Equals((Quantity) obj); - } - - public override int GetHashCode() - { - unchecked - { - return (Amount.GetHashCode()*397) ^ (Units != null ? Units.GetHashCode() : 0); - } - } - } - public interface IUnitOfMeasure { decimal Convert(decimal amount, IUnitOfMeasure units); } + public static class Iterating { public static void Each<T>(this IEnumerable<T> items, Action<T> visitor){ diff --git a/src/domain/domain.csproj b/src/domain/domain.csproj index 5b74a53..857af06 100755 --- a/src/domain/domain.csproj +++ b/src/domain/domain.csproj @@ -41,6 +41,14 @@ </ItemGroup>
<ItemGroup>
<Compile Include="Greeting.cs" />
+ <Compile Include="Commodity.cs" />
+ <Compile Include="CommoditySplits.cs" />
+ <Compile Include="DeclineCurve.cs" />
+ <Compile Include="DrillSchedule.cs" />
+ <Compile Include="Oppurtunity.cs" />
+ <Compile Include="Production.cs" />
+ <Compile Include="Quantity.cs" />
+ <Compile Include="TypeCurve.cs" />
<Compile Include="Well.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
|
