Skip to the content.

EMC NEMS Data Services Model Definitions

GitHub Release NuGet Version (Emc.SewPlus.Nems.Models) NuGet Downloads GitHub License

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

πŸ“š Technical Documentation

The API reference guide has been generated using Sandcastle.

πŸ‘‰ Browse the Technical Documentation

What’s Inside?

πŸ“¦ 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:

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

πŸ—ΊοΈ Roadmap

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:

πŸ‘¨β€πŸ’» Author and Contact

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.