-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
code-recipes
committed
Aug 11, 2017
1 parent
515c911
commit bca1780
Showing
17 changed files
with
341 additions
and
11 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
xDGA.CORE/Algorithms/RogersRatios/RogersRatiosAlgorithm.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2017 Carlos Gamez | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
using System; | ||
using xDGA.CORE.Models; | ||
|
||
namespace xDGA.CORE.Algorithms | ||
{ | ||
public class RogersRatiosAlgorithm : AbstractAlgorithm | ||
{ | ||
public override string Version => "Rogers Ratios as described in IEEE C57.104"; | ||
|
||
/// <summary> | ||
/// The Dissolved Gas Analysis that will be used in the assessment. | ||
/// </summary> | ||
public DissolvedGasAnalysis DGA { get; internal set; } | ||
|
||
/// <summary> | ||
/// Creates a new RogersRatioAlgorithm instance. | ||
/// </summary> | ||
/// <param name="dga">The JSON serialsed DGA data.</param> | ||
public RogersRatiosAlgorithm(string dga) | ||
{ | ||
DGA = new DissolvedGasAnalysis(dga); | ||
} | ||
|
||
public override void Execute() | ||
{ | ||
var dga = DGA; | ||
DissolvedGasAnalysis prevDga = null; | ||
var outputs = Outputs; | ||
|
||
Rules.Add(new ApplyDetectionLimitsRule()); | ||
Rules.Add(new RogersRatiosRule()); | ||
|
||
// Create a Title output | ||
outputs.Add(new Output() { Name = "Title", Description = $"Interpretation of Dissolved Gas Analysis as per {Version}" }); | ||
|
||
foreach (var rule in Rules) | ||
{ | ||
rule.Execute(ref dga, ref prevDga, ref outputs); | ||
} | ||
|
||
Outputs = outputs; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2017 Carlos Gamez | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
using System.Collections.Generic; | ||
using xDGA.CORE.Interfaces; | ||
using xDGA.CORE.Models; | ||
using Helper = xDGA.CORE.Algorithms.AlgorithmHelperCalculations; | ||
using Ratio = xDGA.CORE.Models.GasRatios.Ratio; | ||
|
||
namespace xDGA.CORE.Algorithms | ||
{ | ||
public class RogersRatiosRule : IRule | ||
{ | ||
private Dictionary<Ratio, double> _Ratios { get; set; } = new Dictionary<Ratio, double>(); | ||
public FailureType.Code FailureCode { get; set; } = FailureType.Code.NA; | ||
|
||
public void Execute(ref DissolvedGasAnalysis currentDga, ref DissolvedGasAnalysis previousDga, ref List<IOutput> outputs) | ||
{ | ||
CalculateRatios(currentDga); | ||
FailureCode = CalculateFailureCode(); | ||
outputs.Add(new Output() { Name = GasRatios.Description[Ratio.AcetyleneToEthylene], Description = _Ratios[Ratio.AcetyleneToEthylene].ToString("0.000") }); | ||
outputs.Add(new Output() { Name = GasRatios.Description[Ratio.MethaneToHydrogen], Description = _Ratios[Ratio.MethaneToHydrogen].ToString("0.000") }); | ||
outputs.Add(new Output() { Name = GasRatios.Description[Ratio.EthyleneToEthane], Description = _Ratios[Ratio.EthyleneToEthane].ToString("0.000") }); | ||
outputs.Add(new Output() { Name = "Rogers Ratio Failure Code", Description = FailureType.Description[FailureCode] }); | ||
} | ||
|
||
public bool IsApplicable(DissolvedGasAnalysis currentDga, DissolvedGasAnalysis previousDga, List<IOutput> outputs) | ||
{ | ||
return currentDga != null && currentDga.Ethylene != null && currentDga.Hydrogen != null && currentDga.Methane != null && currentDga.Ethane != null && currentDga.Acetylene != null; | ||
} | ||
|
||
private void CalculateRatios(DissolvedGasAnalysis dga) | ||
{ | ||
_Ratios.Clear(); | ||
_Ratios.Add(Ratio.AcetyleneToEthylene, (double)Helper.GasRatio(dga.Acetylene, dga.Ethylene)); | ||
_Ratios.Add(Ratio.MethaneToHydrogen, (double)Helper.GasRatio(dga.Methane, dga.Hydrogen)); | ||
_Ratios.Add(Ratio.EthyleneToEthane, (double)Helper.GasRatio(dga.Ethylene, dga.Ethane)); | ||
} | ||
|
||
private FailureType.Code CalculateFailureCode() | ||
{ | ||
var code = FailureType.Code.NA; | ||
|
||
if (_Ratios[Ratio.AcetyleneToEthylene] < 0.1 && _Ratios[Ratio.MethaneToHydrogen] > 0.1 && _Ratios[Ratio.MethaneToHydrogen] < 1.0 && _Ratios[Ratio.EthyleneToEthane] < 1.0) code = FailureType.Code.N; | ||
|
||
if (_Ratios[Ratio.AcetyleneToEthylene] < 0.1 && _Ratios[Ratio.MethaneToHydrogen] < 0.1 && _Ratios[Ratio.EthyleneToEthane] < 1.0) code = FailureType.Code.PD; | ||
|
||
if (_Ratios[Ratio.AcetyleneToEthylene] >= 0.1 && _Ratios[Ratio.AcetyleneToEthylene] <= 3.0 && _Ratios[Ratio.MethaneToHydrogen] >= 0.1 && _Ratios[Ratio.MethaneToHydrogen] <= 1.0 && _Ratios[Ratio.EthyleneToEthane] > 3.0) code = FailureType.Code.D2; | ||
|
||
if (_Ratios[Ratio.AcetyleneToEthylene] < 0.1 && _Ratios[Ratio.MethaneToHydrogen] > 0.1 && _Ratios[Ratio.MethaneToHydrogen] < 1.0 && _Ratios[Ratio.EthyleneToEthane] >= 1.0 && _Ratios[Ratio.EthyleneToEthane] <= 3.0) code = FailureType.Code.T1; | ||
|
||
if (_Ratios[Ratio.AcetyleneToEthylene] < 0.1 && _Ratios[Ratio.MethaneToHydrogen] > 0.1 && _Ratios[Ratio.EthyleneToEthane] >= 1.0 && _Ratios[Ratio.EthyleneToEthane] <= 3.0) code = FailureType.Code.T2; | ||
|
||
if (_Ratios[Ratio.AcetyleneToEthylene] < 0.1 && _Ratios[Ratio.MethaneToHydrogen] > 0.1 && _Ratios[Ratio.EthyleneToEthane] >= 3.0) code = FailureType.Code.T3; | ||
|
||
return code; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2017 Carlos Gamez | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace xDGA.CORE.Models | ||
{ | ||
public static class GasRatios | ||
{ | ||
public enum Ratio | ||
{ | ||
HydrogenToMethane, | ||
HydrogenToEthane, | ||
HydrogenToEthylene, | ||
HydrogenToAcetylene, | ||
MethaneToHydrogen, | ||
MethaneToEthane, | ||
MethaneToEthylene, | ||
MethaneToAcetylene, | ||
EthaneToHydrogen, | ||
EthaneToMethane, | ||
EthaneToEthylene, | ||
EthaneToAcetylene, | ||
EthyleneToHydrogen, | ||
EthyleneToMethane, | ||
EthyleneToEthane, | ||
EthyleneToAcetylene, | ||
AcetyleneToHydrogen, | ||
AcetyleneToMethane, | ||
AcetyleneToEthane, | ||
AcetyleneToEthylene, | ||
CarbonMonoxideToCarbonDioxide, | ||
CarbonDioxideToCarbonMonoxide, | ||
NitrogenToOxygen, | ||
OxygenToNitrogen | ||
} | ||
|
||
public static Dictionary<Ratio, string> Description | ||
{ | ||
get | ||
{ | ||
return new Dictionary<Ratio, string>() | ||
{ | ||
{ Ratio.HydrogenToMethane, "H2/CH4" }, | ||
{ Ratio.HydrogenToEthane, "H2/C2H6" }, | ||
{ Ratio.HydrogenToEthylene, "H2/C2H4" }, | ||
{ Ratio.HydrogenToAcetylene, "H2/C2H2" }, | ||
{ Ratio.MethaneToHydrogen, "CH4/H2" }, | ||
{ Ratio.MethaneToEthane, "CH4/C2H6" }, | ||
{ Ratio.MethaneToEthylene, "CH4/C2H4" }, | ||
{ Ratio.MethaneToAcetylene, "CH4/C2H2" }, | ||
{ Ratio.EthaneToHydrogen, "C2H6/H2" }, | ||
{ Ratio.EthaneToMethane, "C2H6/CH4" }, | ||
{ Ratio.EthaneToEthylene, "C2H6/C2H4" }, | ||
{ Ratio.EthaneToAcetylene, "C2H6/C2H2" }, | ||
{ Ratio.EthyleneToHydrogen, "C2H4/H2" }, | ||
{ Ratio.EthyleneToMethane, "C2H4/CH4" }, | ||
{ Ratio.EthyleneToEthane, "C2H4/C2H6" }, | ||
{ Ratio.EthyleneToAcetylene, "C2H4/C2H2" }, | ||
{ Ratio.AcetyleneToHydrogen, "C2H2/H2" }, | ||
{ Ratio.AcetyleneToMethane, "C2H2/CH4" }, | ||
{ Ratio.AcetyleneToEthane, "C2H2/C2H6" }, | ||
{ Ratio.AcetyleneToEthylene, "C2H2/C2H4" }, | ||
{ Ratio.CarbonMonoxideToCarbonDioxide, "CO/CO2" }, | ||
{ Ratio.CarbonDioxideToCarbonMonoxide, "CO2/CO" }, | ||
{ Ratio.NitrogenToOxygen, "N2/O2" }, | ||
{ Ratio.OxygenToNitrogen, "O2/N2" } | ||
}; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.