EMC NEMS Data Services Model Definitions
Model definitions for data services provided by the National Electricity Market of Singapore (NEMS) system of the Energy Market Company (EMC) of Singapore.
Definitions are based on the Data Services Specification for NEMS System document.
π Key Features
- Strongly typed classes representing EMC Download Reports and Submission messages submitted to or received from EMC Data Services.
- Use of enumerations to represent object properties that take on a finite set of
stringvalues. - EMC Download Reports classes can be serialised/deserialised using either their individual types or their report category types.
π Technical Documentation
The API reference guide has been generated using Sandcastle.
π Browse the Technical Documentation
Whatβs Inside?
- Namespaces & Classes: Full code architecture breakdown.
- Methods & Properties: Detailed parameter and return value info.
π¦ Installation
Install the package via the NuGet Package Manager Console, the Nuget Package Manager UI, the .NET CLI or by adding a package reference.
.NET CLI
dotnet add package Emc.SewPlus.Nems.Models.x.x.x.nupkg
Package Manager
Install-Package Emc.SewPlus.Nems.Models.x.x.x.nupkg
π οΈ Usage
All classes representing data elements in the EMC Data Services are marked as Serializable, thereby allowing themselves to participate in XML serialisation and deserialisation.
Deserialising XML Data Received From an EMC Web Service
Suppose the following real time price data is returned (as a XML string) and saved in a file RTP.xml:
<?xml version="1.0" encoding="UTF-8"?>
<list>
<RealTimePrice>
<period>25</period>
<reportType>REP</reportType>
<tradingDate>31-Jul-2022</tradingDate>
<demand>6101.455</demand>
<tcl>0.000</tcl>
<USEP>183.08</USEP>
<lcp>0.00</lcp>
<regulation>28.15</regulation>
<primaryReserve>1</primaryReserve>
<secondaryReserve/>
<contingencyReserve>20.16</contingencyReserve>
<eheur>-0.76</eheur>
<solar>22.540</solar>
<RUSEP>659.52</RUSEP>
<MAP>236.65</MAP>
<MAPT>591.75.00</MAPT>
<tpcApplied>N</tpcApplied>
<referenceRegulation>22.22</referenceRegulation>
<referencePrimaryReserve>69.69</referencePrimaryReserve>
<referenceContingencyReserve>50.44</referenceContingencyReserve>
</RealTimePrice>
<RealTimePrice>
<period>26</period>
<reportType>REP</reportType>
<tradingDate>31-Jul-2022</tradingDate>
<demand>6069.125</demand>
<tcl>0.000</tcl>
<USEP>160.15</USEP>
<lcp>0.00</lcp>
<regulation>10</regulation>
<primaryReserve>.14</primaryReserve>
<secondaryReserve/>
<contingencyReserve>2</contingencyReserve>
<eheur>-0.66</eheur>
<solar>22.540</solar>
<RUSEP>659.52</RUSEP>
<MAP>236.65</MAP>
<MAPT>591.75.00</MAPT>
<tpcApplied>N</tpcApplied>
<referenceRegulation>22.22</referenceRegulation>
<referencePrimaryReserve>69.69</referencePrimaryReserve>
<referenceContingencyReserve>50.44</referenceContingencyReserve>
</RealTimePrice>
</list>
To deserialise the XML data into a RealTimePrice object:
using Emc.SewPlus.Nems.Models.Reports.Cwr;
using System.Xml;
using System.Xml.Serialization;
public List<RealTimePrice> DeserializeRealTimePriceXml(string xmlFile)
{
XmlSerializer serializer = new XmlSerializer(typeof(List<RealTimePrice>), new XmlRootAttribute("list"));
using (FileStream fileStream = new FileStream(xmlFile, FileMode.Open, FileAccess.Read))
{
using (XmlReader xmlReader = XmlReader.Create(fileStream))
{
var results = serializer.Deserialize(xmlReader) as List<RealTimePrice>;
return results;
}
}
}
To deserialise the same data into the same object using the child elements:
using Emc.SewPlus.Nems.Models.Reports.Cwr;
using System.Linq;
using System.Xml.Linq;
public List<RealTimePrice> DeserializeRealTimePriceXml(string xmlFile)
{
XDocument doc = XDocument.Load(xmlFile);
var results = doc.Element("list").Elements("RealTimePrice")
.Select(n => new RealTimePrice()
{
Period = byte.Parse(n.Element("period").Value),
ReportType = n.Element("reportType").Value,
TradingDateString = n.Element("tradingDate").Value,
Demand = decimal.Parse(n.Element("demand").Value),
TotalCurtailedLoad = decimal.Parse(n.Element("tcl").Value),
Usep = decimal.Parse(n.Element("USEP").Value),
LoadCurtailmentPrice = decimal.Parse(n.Element("lcp").Value),
RegulationPrice = decimal.Parse(n.Element("regulation").Value),
PrimaryReservePrice = decimal.Parse(n.Element("primaryReserve").Value),
// property is nullable (defined as nillable in XSD)
SecondaryReservePrice = (n.Element("secondaryReserve").Value == null)? null : n.Element("secondaryReserve").Value,
ContingencyReservePrice = n.Element("contingencyReserve").Value,
Eheur = decimal.Parse(n.Element("eheur").Value),
SolarGenerationForecast = decimal.Parse(n.Element("solar").Value),
ReferenceUniformSingaporeEnergyPrice = decimal.Parse(n.Element("RUSEP").Value),
MovingAveragePrice = decimal.Parse(n.Element("MAP").Value),
MovingAveragePriceThreshold = decimal.Parse(n.Element("MAPT").Value),
TpcApplied = n.Element("tpcApplied").Value.Equals("Y") ? YesNoResponse.Yes
: (n.Element("tpcApplied").Value.Equals("N") ? YesNoResponse.No : YesNoResponse.NotDefined),
ReferenceRegulation = decimal.Parse(n.Element("referenceRegulation").Value),
ReferencePrimaryReserve = decimal.Parse(n.Element("referencePrimaryReserve").Value),
ReferenceContingencyReserve = decimal.Parse(n.Element("referenceContingencyReserve").Value)
}).ToList();
return results;
}
EMC Download Reports Category Classes
This package also offers a set of classes under the Emc.SewPlus.Nems.Models.Reports namespace that simplifies the deserialisation of XML data without having to specify the exact report class. Their names end with Reports:
Emc.SewPlus.Nems.Models.Reports.Cwr.CorporateWebsiteReportsrepresenting the set of Corporate Website Reports.Emc.SewPlus.Nems.Models.Reports.Mcr.MarketClearingRunReportsrepresenting the set of Market Clearing Run Reports.Emc.SewPlus.Nems.Models.Reports.Stl.SettlementReportsrepresenting the set of Settlement Reports.Emc.SewPlus.Nems.Models.Reports.Tsr.TradeSummaryReportsrepresenting the set of Trade Summary Reports.Emc.SewPlus.Nems.Models.Reports.Opr.OtherPublishedReportsrepresenting the set of Other Published Reports.
Using the same file RTP.xml, its contents can be deserialised using the CorporateWebsiteReports class since the corresponding Real Time Price report comes under the set of Corporate Website reports:
using Emc.SewPlus.Nems.Models.Reports.Cwr;
using System.Xml;
using System.Xml.Serialization;
public List<RealTimePrice> DeserializeRealTimePriceXml(string xmlFile)
{
// use the CorporateWebsiteReports class to deserialise the XML data instead of the RealTimePrice class
XmlSerializer serializer = new XmlSerializer(typeof(CorporateWebsiteReports));
using (FileStream fileStream = new FileStream(xmlFile, FileMode.Open, FileAccess.Read))
{
using (XmlReader xmlReader = XmlReader.Create(fileStream))
{
var results = serializer.Deserialize(xmlReader) as CorporateWebsiteReports;
return results.Items.Cast<Emc.SewPlus.Nems.Models.Reports.Cwr.RealTimePrice>().ToList();
}
}
}
Serialising XML Data for an EMC Web Service
To serialise an object of a class e.g. BidSubmission into XML to submit to EMC web services:
using Emc.SewPlus.Nems.Models.Submissions.Bids;
using System.Xml;
using System.Xml.Serialization;
public string SerializeBidSubmissionToXml(BidSubmission bidSubmission)
{
XmlSerializer serializer = new XmlSerializer(typeof(BidSubmission));
using (StringWriter writer = new StringWriter())
{
serializer.Serialize(writer, bidSubmission);
return writer.ToString();
}
}
π Target Frameworks
- .NET: Core 3.0, Core 3.1, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0
- .NET Framework: 4.0, 4.5, 4.5.2, 4.6.1, 4.6.2, 4.7.2, 4.8, 4.8.1
- .NET Standard: 2.0, 2.1
πΊοΈ Roadmap
- [] Planned: Incorporate JSON serialisation and deserialisation.
Have a feature request? Please open a feature suggestion.
π€ Feedback and Support
User feedbacks, bug reports and feature requests are welcome! Since the core codebase is private, please use the following channels to get in touch:
- Bug Reports & Feature Requests: Please open an issue directly on our GitHub Issues Tracker.
- Discussions and Questions: send me an e-mail.
π¨βπ» Author and Contact
- Maintainer: Jonathan Bong
- E-mail: jonbong1607@hotmail.com
π License
This project is licensed under the MIT License - see the LICENSE file for details.