Energy is a small library of utilities that are useful in the energy industry.
Follow the instructions below to install this NuGet package into your project:
dotnet add package Relay.Energy
Install-Package Relay.Energy
Latest releases and package version history can be found on NuGet.
Follow the instructions below to build and test this project:
dotnet build
dotnet test
The data structures in this library represent energy dimensions. An energy dimension is an attribute pertaining to a record in a system built for the energy industry. Since these dimensions are fundamental to the business and used so frequently, it makes sense to standardize the way they are represented. Each energy dimension exposes the same set of properties which are derived from parsing an input string provided to the constructor. Some more fun facts about energy dimensions:
- The dimensions are standardized, immutable, lightweight structs
- String interpretation is flexible
- Different variations of the same data are considered when parsing input strings.
- This is valuable when a system interacts with several different vendors that represent the same attribute in different ways. For example, one vendor may represent an Electric account as 'E', while another uses 'Electric'.
- There are standard sets of static values exposed by each structure that represent valid values
- For example, the Commodity structure exposes static instances that represent Electric, Gas, Solar and Unrecognized (Unrecognized is available for all energy dimensions as a representation of an input string that couldn't be parsed).
- This allows you to use the structs similarly to the way you would use an enum
- Comparison amongst instances is simple
- The equivalency operators are overloaded for each dimension to support comparing dimensions of the same type to each other, and for comparing strings to a dimension.
Each dimension contains everything needed to parse an input string and return it's standardized constituents.
private void StandardizedFieldsAreExposedForInstances()
{
var accountClass = new AccountClass("Residential");
Console.WriteLine(accountClass.Name);
Console.WriteLine(accountClass.Code);
Console.WriteLine(accountClass.DisplayName);
}
Each dimension will sensibly parse the input string to account for variations in representation from different vendors.
private void InterpretationIsFlexibleForInputStrings()
{
var accountClass1 = new AccountClass("R");
var accountClass2 = new AccountClass("res");
var accountClass3 = new AccountClass("Resi");
var accountClass4 = new AccountClass("resi.");
Console.WriteLine(accountClass1.Name);
Console.WriteLine(accountClass2.Name);
Console.WriteLine(accountClass3.Name);
Console.WriteLine(accountClass4.Name);
}
Each dimension exposes static instances for quick comparison and assignment.
private void StaticValuesRepresentValidValues()
{
AccountClass accountClassResidential = AccountClass.Residential;
AccountClass accountClassSmallCommercial = AccountClass.SmallCommercial;
AccountClass accountClassLargeCommercial = AccountClass.LargeCommercial;
Console.WriteLine(accountClassResidential.Name);
Console.WriteLine(accountClassSmallCommercial.Name);
Console.WriteLine(accountClassLargeCommercial.Name);
}
Each dimension can be compared for equality.
private void CompareForEquality()
{
AccountClass accountClassResidential1 = new AccountClass("Residential");
AccountClass accountClassResidential2 = new AccountClass("Residential");
AccountClass accountClassSmallCommercial = new AccountClass("Small Commercial");
bool isResidentialResidentialEquivalent = (accountClassResidential1 == accountClassResidential2);
bool isResidentialSmallCommercialEquivalent = (accountClassResidential1 == accountClassSmallCommercial);
Console.WriteLine("Is Residential Residential equivalent?: {0}", isResidentialResidentialEquivalent);
Console.WriteLine("Is Residential SmallCommercial equivalent?: {0}", isResidentialSmallCommercialEquivalent);
}
Each dimension can also be compared for equality using strings.
private void CompareForEqualityFromStrings()
{
AccountClass accountClassResidential1 = new AccountClass("Residential");
AccountClass accountClassResidential2 = new AccountClass("Residential");
AccountClass accountClassSmallCommercial = new AccountClass("Small Commercial");
bool isResidentialResidentialEquivalent = (accountClassResidential1 == "Residential");
bool isResidentialSmallCommercialEquivalent = (accountClassResidential2 == "Small Commercial");
bool isSmallCommercialSmallCommercialAbbreviationEquivalent = (accountClassSmallCommercial == "SC");
Console.WriteLine("Is Residential Residential equivalent?: {0}", isResidentialResidentialEquivalent);
Console.WriteLine("Is Residential SmallCommercial equivalent?: {0}", isResidentialSmallCommercialEquivalent);
Console.WriteLine("Is SmallCommercial SmallCommercial equivalent?: {0}", isSmallCommercialSmallCommercialAbbreviationEquivalent);
}
All dimensions can be returned as a collection.
private void AllDimensionsCanBeReturnedAsACollection()
{
IEnumerable<AccountClass> accountClasses = new EnergyDimensionService()
.GetAllAccountClasses();
foreach (AccountClass accountClass in accountClasses)
{
Console.WriteLine(accountClass);
}
}
There are several other variations not documented here. You can find a Console Application with these samples here.
When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.