OpenLEADR / openleadr-python

Python library for OpenADR
https://openleadr.org/docs
Apache License 2.0
133 stars 51 forks source link

Registering multiple reports with one reportSpecifierID #80

Closed 00javad00 closed 2 years ago

00javad00 commented 3 years ago

Making reportSpecifierID = None will result to a unique random reportSpecifierID for each report during the registration. It is recommended to register reporting with multiple oadrReportDescription under one reportSpecifierID, i.e.:

<oadr:oadrPayload xmlns:oadr="http://openadr.org/oadr-2.0b/2012/07">
  <oadr:oadrSignedObject oadr:Id="oadrSignedObject" xmlns:oadr="http://openadr.org/oadr-2.0b/2012/07">
    <oadr:oadrRegisterReport ei:schemaVersion="2.0b" xmlns:ei="http://docs.oasis-open.org/ns/energyinterop/201110">
      <requestID xmlns="http://docs.oasis-open.org/ns/energyinterop/201110/payloads">66b5d936-62c1-4806-b7bd-f4f0480dacf8</requestID>
      <oadrReport>
        <duration xmlns="urn:ietf:params:xml:ns:icalendar-2.0">
          <duration>PT2H</duration>
        </duration>
        <oadrReportDescription>
          <ei:rID>resource1_energy</ei:rID>
          <ei:reportDataSource>
            <ei:resourceID>resource1</ei:resourceID>
          </ei:reportDataSource>
          <ei:reportType>usage</ei:reportType>
          <energyReal xmlns="http://docs.oasis-open.org/ns/emix/2011/06/power">
            <itemDescription>RealEnergy</itemDescription>
            <itemUnits>Wh</itemUnits>
            <siScaleCode xmlns="http://docs.oasis-open.org/ns/emix/2011/06/siscale">n</siScaleCode>
          </energyReal>
          <ei:readingType>Direct Read</ei:readingType>
          <marketContext xmlns="http://docs.oasis-open.org/ns/emix/2011/06">http://MarketContext1</marketContext>
          <oadrSamplingRate>
            <oadrMinPeriod>PT1M</oadrMinPeriod>
            <oadrMaxPeriod>PT1M</oadrMaxPeriod>
            <oadrOnChange>false</oadrOnChange>
          </oadrSamplingRate>
        </oadrReportDescription>
        <oadrReportDescription>
          <ei:rID>resource1_power</ei:rID>
          <ei:reportDataSource>
            <ei:resourceID>resource1</ei:resourceID>
          </ei:reportDataSource>
          <ei:reportType>usage</ei:reportType>
          <powerReal xmlns="http://docs.oasis-open.org/ns/emix/2011/06/power">
            <itemDescription>RealPower</itemDescription>
            <itemUnits>W</itemUnits>
            <siScaleCode xmlns="http://docs.oasis-open.org/ns/emix/2011/06/siscale">n</siScaleCode>
            <powerAttributes>
              <hertz>60</hertz>
              <voltage>110</voltage>
              <ac>false</ac>
            </powerAttributes>
          </powerReal>
          <ei:readingType>Direct Read</ei:readingType>
          <marketContext xmlns="http://docs.oasis-open.org/ns/emix/2011/06">http://MarketContext1</marketContext>
          <oadrSamplingRate>
            <oadrMinPeriod>PT1M</oadrMinPeriod>
            <oadrMaxPeriod>PT1M</oadrMaxPeriod>
            <oadrOnChange>false</oadrOnChange>
          </oadrSamplingRate>
        </oadrReportDescription>
        <ei:reportRequestID>0</ei:reportRequestID>
        <ei:reportSpecifierID>789ed6cd4e</ei:reportSpecifierID>
        <ei:reportName>METADATA_HISTORY_USAGE</ei:reportName>
        <ei:createdDateTime>2020-07-20T18:00:51.8855009Z</ei:createdDateTime>
      </oadrReport>
      <ei:venID>VEN0</ei:venID>
    </oadr:oadrRegisterReport>
  </oadr:oadrSignedObject>
</oadr:oadrPayload>

If this has already addressed would you please provide an example showing how to register one report (one reportSpecifierID) with multiple parameters?

stan-janssen commented 3 years ago

Making reportSpecifierID = None will result to a unique random reportSpecifierID for each report during the registration.

This should not be the case, so if you are seeing this behaviour, I'd like to know what is going wrong. Could you provide an example of how you are adding the reports to your client?

Reports with the same report_name already get grouped under the same report_specifier_id, if you don't provide a report_specifier_id yourself. For example, having a client like this (example adapted and verified from this testcase:

client = OpenADRClient(ven_name='myven', vtn_url='http://localhost:8080/OpenADR2/Simple/2.0b',)

# Add 4 reports
client.add_report(callback=collect_data,
                  resource_id='Device001',
                  measurement='current',
                  unit='A')
client.add_report(callback=collect_data,
                  resource_id='Device002',
                  measurement='current',
                  unit='A')
client.add_report(callback=collect_data,
                  resource_id='Device001',
                  measurement='voltage',
                  unit='V')
client.add_report(callback=collect_data,
                  resource_id='Device002',
                  measurement='voltage',
                  unit='V')

Results in the following oadrRegisterReport XML document:

<oadr:oadrPayload xmlns:oadr="http://openadr.org/oadr-2.0b/2012/07">
    <oadr:oadrSignedObject oadr:Id="oadrSignedObject" xmlns:oadr="http://openadr.org/oadr-2.0b/2012/07">
        <oadr:oadrRegisterReport ei:schemaVersion="2.0b" xmlns:ei="http://docs.oasis-open.org/ns/energyinterop/201110">
            <requestID xmlns="http://docs.oasis-open.org/ns/energyinterop/201110/payloads">0a662464-8a64-4d82-9ce7-5715da80afee</requestID>
            <oadr:oadrReport xmlns:strm="urn:ietf:params:xml:ns:icalendar-2.0:stream" xmlns:xcal="urn:ietf:params:xml:ns:icalendar-2.0">
                <ei:eiReportID/>
                <oadr:oadrReportDescription xmlns:emix="http://docs.oasis-open.org/ns/emix/2011/06" xmlns:power="http://docs.oasis-open.org/ns/emix/2011/06/power">
                    <ei:rID>c4be6dd0-486e-44bc-98c6-b63142a4a48b</ei:rID>
                    <ei:reportDataSource>
                        <ei:resourceID>Device001</ei:resourceID>
                    </ei:reportDataSource>
                    <ei:reportType>reading</ei:reportType>
                    <oadr:current xmlns:power="http://docs.oasis-open.org/ns/emix/2011/06/power" xmlns:scale="http://docs.oasis-open.org/ns/emix/2011/06/siscale">
                        <oadr:itemDescription>Current</oadr:itemDescription>
                        <oadr:itemUnits>A</oadr:itemUnits>
                        <scale:siScaleCode>none</scale:siScaleCode>
                    </oadr:current>
                    <ei:readingType>Direct Read</ei:readingType>
                    <oadr:oadrSamplingRate>
                        <oadr:oadrMinPeriod>PT10S</oadr:oadrMinPeriod>
                        <oadr:oadrMaxPeriod>P1D</oadr:oadrMaxPeriod>
                        <oadr:oadrOnChange>false</oadr:oadrOnChange>
                    </oadr:oadrSamplingRate>
                </oadr:oadrReportDescription>
                <oadr:oadrReportDescription xmlns:emix="http://docs.oasis-open.org/ns/emix/2011/06" xmlns:power="http://docs.oasis-open.org/ns/emix/2011/06/power">
                    <ei:rID>8495e070-2c41-4eaa-9451-e9f8860c1f5b</ei:rID>
                    <ei:reportDataSource>
                        <ei:resourceID>Device002</ei:resourceID>
                    </ei:reportDataSource>
                    <ei:reportType>reading</ei:reportType>
                    <oadr:current xmlns:power="http://docs.oasis-open.org/ns/emix/2011/06/power" xmlns:scale="http://docs.oasis-open.org/ns/emix/2011/06/siscale">
                        <oadr:itemDescription>Current</oadr:itemDescription>
                        <oadr:itemUnits>A</oadr:itemUnits>
                        <scale:siScaleCode>none</scale:siScaleCode>
                    </oadr:current>
                    <ei:readingType>Direct Read</ei:readingType>
                    <oadr:oadrSamplingRate>
                        <oadr:oadrMinPeriod>PT10S</oadr:oadrMinPeriod>
                        <oadr:oadrMaxPeriod>P1D</oadr:oadrMaxPeriod>
                        <oadr:oadrOnChange>false</oadr:oadrOnChange>
                    </oadr:oadrSamplingRate>
                </oadr:oadrReportDescription>
                <oadr:oadrReportDescription xmlns:emix="http://docs.oasis-open.org/ns/emix/2011/06" xmlns:power="http://docs.oasis-open.org/ns/emix/2011/06/power">
                    <ei:rID>4edbaff1-1fcb-4f15-bd22-a1d3472eca92</ei:rID>
                    <ei:reportDataSource>
                        <ei:resourceID>Device001</ei:resourceID>
                    </ei:reportDataSource>
                    <ei:reportType>reading</ei:reportType>
                    <power:voltage xmlns:power="http://docs.oasis-open.org/ns/emix/2011/06/power" xmlns:scale="http://docs.oasis-open.org/ns/emix/2011/06/siscale">
                        <power:itemDescription>Voltage</power:itemDescription>
                        <power:itemUnits>V</power:itemUnits>
                        <scale:siScaleCode>none</scale:siScaleCode>
                    </power:voltage>
                    <ei:readingType>Direct Read</ei:readingType>
                    <oadr:oadrSamplingRate>
                        <oadr:oadrMinPeriod>PT10S</oadr:oadrMinPeriod>
                        <oadr:oadrMaxPeriod>P1D</oadr:oadrMaxPeriod>
                        <oadr:oadrOnChange>false</oadr:oadrOnChange>
                    </oadr:oadrSamplingRate>
                </oadr:oadrReportDescription>
                <oadr:oadrReportDescription xmlns:emix="http://docs.oasis-open.org/ns/emix/2011/06" xmlns:power="http://docs.oasis-open.org/ns/emix/2011/06/power">
                    <ei:rID>3e6ab27d-da0a-4b8d-a93e-79df345d8f7e</ei:rID>
                    <ei:reportDataSource>
                        <ei:resourceID>Device002</ei:resourceID>
                    </ei:reportDataSource>
                    <ei:reportType>reading</ei:reportType>
                    <power:voltage xmlns:power="http://docs.oasis-open.org/ns/emix/2011/06/power" xmlns:scale="http://docs.oasis-open.org/ns/emix/2011/06/siscale">
                        <power:itemDescription>Voltage</power:itemDescription>
                        <power:itemUnits>V</power:itemUnits>
                        <scale:siScaleCode>none</scale:siScaleCode>
                    </power:voltage>
                    <ei:readingType>Direct Read</ei:readingType>
                    <oadr:oadrSamplingRate>
                        <oadr:oadrMinPeriod>PT10S</oadr:oadrMinPeriod>
                        <oadr:oadrMaxPeriod>P1D</oadr:oadrMaxPeriod>
                        <oadr:oadrOnChange>false</oadr:oadrOnChange>
                    </oadr:oadrSamplingRate>
                </oadr:oadrReportDescription>
                <ei:reportRequestID/>
                <ei:reportSpecifierID>c9b77df5-4ce2-4de7-bde9-dff7e04e568c</ei:reportSpecifierID>
                <ei:reportName>METADATA_TELEMETRY_USAGE</ei:reportName>
                <ei:createdDateTime>2021-07-04T09:20:16.160754Z</ei:createdDateTime>
            </oadr:oadrReport>
            <ei:venID>1234</ei:venID>
            <ei:reportRequestID>0</ei:reportRequestID>
        </oadr:oadrRegisterReport>
    </oadr:oadrSignedObject>
</oadr:oadrPayload>

If you want maunal control over the grouping of reports, you can provide your own report_specifier_id explicitely like in that mentioned testcase, like this:


# Create a client
client = OpenADRClient(ven_name='myven', vtn_url='http://localhost:8080/OpenADR2/Simple/2.0b',)

# Add 4 reports
client.add_report(callback=collect_data,
                  report_specifier_id='CurrentReport',
                  resource_id='Device001',
                  measurement='current',
                  unit='A')
client.add_report(callback=collect_data,
                  report_specifier_id='CurrentReport',
                  resource_id='Device002',
                  measurement='current',
                  unit='A')
client.add_report(callback=collect_data,
                  report_specifier_id='VoltageReport',
                  resource_id='Device001',
                  measurement='voltage',
                  unit='V')
client.add_report(callback=collect_data,
                  report_specifier_id='VoltageReport',
                  resource_id='Device002',
                  measurement='voltage',
                  unit='V')

which results in the following oadrRegisterReport document:


<oadr:oadrPayload xmlns:oadr="http://openadr.org/oadr-2.0b/2012/07">
    <oadr:oadrSignedObject oadr:Id="oadrSignedObject" xmlns:oadr="http://openadr.org/oadr-2.0b/2012/07">
        <oadr:oadrRegisterReport ei:schemaVersion="2.0b" xmlns:ei="http://docs.oasis-open.org/ns/energyinterop/201110">
            <requestID xmlns="http://docs.oasis-open.org/ns/energyinterop/201110/payloads">13172262-12df-4530-a8d1-bd805880f31d</requestID>
            <oadr:oadrReport xmlns:strm="urn:ietf:params:xml:ns:icalendar-2.0:stream" xmlns:xcal="urn:ietf:params:xml:ns:icalendar-2.0">
                <ei:eiReportID/>
                <oadr:oadrReportDescription xmlns:emix="http://docs.oasis-open.org/ns/emix/2011/06" xmlns:power="http://docs.oasis-open.org/ns/emix/2011/06/power">
                    <ei:rID>33c231c0-a00d-4842-8d3b-9b24cdd74e28</ei:rID>
                    <ei:reportDataSource>
                        <ei:resourceID>Device001</ei:resourceID>
                    </ei:reportDataSource>
                    <ei:reportType>reading</ei:reportType>
                    <oadr:current xmlns:power="http://docs.oasis-open.org/ns/emix/2011/06/power" xmlns:scale="http://docs.oasis-open.org/ns/emix/2011/06/siscale">
                        <oadr:itemDescription>Current</oadr:itemDescription>
                        <oadr:itemUnits>A</oadr:itemUnits>
                        <scale:siScaleCode>none</scale:siScaleCode>
                    </oadr:current>
                    <ei:readingType>Direct Read</ei:readingType>
                    <oadr:oadrSamplingRate>
                        <oadr:oadrMinPeriod>PT10S</oadr:oadrMinPeriod>
                        <oadr:oadrMaxPeriod>P1D</oadr:oadrMaxPeriod>
                        <oadr:oadrOnChange>false</oadr:oadrOnChange>
                    </oadr:oadrSamplingRate>
                </oadr:oadrReportDescription>
                <oadr:oadrReportDescription xmlns:emix="http://docs.oasis-open.org/ns/emix/2011/06" xmlns:power="http://docs.oasis-open.org/ns/emix/2011/06/power">
                    <ei:rID>66ddfee8-03f5-42e7-a686-030f551999e4</ei:rID>
                    <ei:reportDataSource>
                        <ei:resourceID>Device002</ei:resourceID>
                    </ei:reportDataSource>
                    <ei:reportType>reading</ei:reportType>
                    <oadr:current xmlns:power="http://docs.oasis-open.org/ns/emix/2011/06/power" xmlns:scale="http://docs.oasis-open.org/ns/emix/2011/06/siscale">
                        <oadr:itemDescription>Current</oadr:itemDescription>
                        <oadr:itemUnits>A</oadr:itemUnits>
                        <scale:siScaleCode>none</scale:siScaleCode>
                    </oadr:current>
                    <ei:readingType>Direct Read</ei:readingType>
                    <oadr:oadrSamplingRate>
                        <oadr:oadrMinPeriod>PT10S</oadr:oadrMinPeriod>
                        <oadr:oadrMaxPeriod>P1D</oadr:oadrMaxPeriod>
                        <oadr:oadrOnChange>false</oadr:oadrOnChange>
                    </oadr:oadrSamplingRate>
                </oadr:oadrReportDescription>
                <ei:reportRequestID/>
                <ei:reportSpecifierID>CurrentReport</ei:reportSpecifierID>
                <ei:reportName>METADATA_TELEMETRY_USAGE</ei:reportName>
                <ei:createdDateTime>2021-07-04T09:25:13.149227Z</ei:createdDateTime>
            </oadr:oadrReport>
            <oadr:oadrReport xmlns:strm="urn:ietf:params:xml:ns:icalendar-2.0:stream" xmlns:xcal="urn:ietf:params:xml:ns:icalendar-2.0">
                <ei:eiReportID/>
                <oadr:oadrReportDescription xmlns:emix="http://docs.oasis-open.org/ns/emix/2011/06" xmlns:power="http://docs.oasis-open.org/ns/emix/2011/06/power">
                    <ei:rID>2d1fdc19-b114-4cb6-8c6c-4d1089458eb9</ei:rID>
                    <ei:reportDataSource>
                        <ei:resourceID>Device001</ei:resourceID>
                    </ei:reportDataSource>
                    <ei:reportType>reading</ei:reportType>
                    <power:voltage xmlns:power="http://docs.oasis-open.org/ns/emix/2011/06/power" xmlns:scale="http://docs.oasis-open.org/ns/emix/2011/06/siscale">
                        <power:itemDescription>Voltage</power:itemDescription>
                        <power:itemUnits>V</power:itemUnits>
                        <scale:siScaleCode>none</scale:siScaleCode>
                    </power:voltage>
                    <ei:readingType>Direct Read</ei:readingType>
                    <oadr:oadrSamplingRate>
                        <oadr:oadrMinPeriod>PT10S</oadr:oadrMinPeriod>
                        <oadr:oadrMaxPeriod>P1D</oadr:oadrMaxPeriod>
                        <oadr:oadrOnChange>false</oadr:oadrOnChange>
                    </oadr:oadrSamplingRate>
                </oadr:oadrReportDescription>
                <oadr:oadrReportDescription xmlns:emix="http://docs.oasis-open.org/ns/emix/2011/06" xmlns:power="http://docs.oasis-open.org/ns/emix/2011/06/power">
                    <ei:rID>30b0fb29-b871-4115-8701-062a5257f082</ei:rID>
                    <ei:reportDataSource>
                        <ei:resourceID>Device002</ei:resourceID>
                    </ei:reportDataSource>
                    <ei:reportType>reading</ei:reportType>
                    <power:voltage xmlns:power="http://docs.oasis-open.org/ns/emix/2011/06/power" xmlns:scale="http://docs.oasis-open.org/ns/emix/2011/06/siscale">
                        <power:itemDescription>Voltage</power:itemDescription>
                        <power:itemUnits>V</power:itemUnits>
                        <scale:siScaleCode>none</scale:siScaleCode>
                    </power:voltage>
                    <ei:readingType>Direct Read</ei:readingType>
                    <oadr:oadrSamplingRate>
                        <oadr:oadrMinPeriod>PT10S</oadr:oadrMinPeriod>
                        <oadr:oadrMaxPeriod>P1D</oadr:oadrMaxPeriod>
                        <oadr:oadrOnChange>false</oadr:oadrOnChange>
                    </oadr:oadrSamplingRate>
                </oadr:oadrReportDescription>
                <ei:reportRequestID/>
                <ei:reportSpecifierID>VoltageReport</ei:reportSpecifierID>
                <ei:reportName>METADATA_TELEMETRY_USAGE</ei:reportName>
                <ei:createdDateTime>2021-07-04T09:25:13.149498Z</ei:createdDateTime>
            </oadr:oadrReport>
            <ei:venID>1234</ei:venID>
            <ei:reportRequestID>0</ei:reportRequestID>
        </oadr:oadrRegisterReport>
    </oadr:oadrSignedObject>
</oadr:oadrPayload>
00javad00 commented 3 years ago

Thanks for the delineated response, just to close the ticket and for the sake of other users, what I have done to group multiple Metadata (telemetry_usage, and history_usage) reports with a dedicated reportSpecifierID:

client = OpenADRClient(ven_name='myven', vtn_url='http://localhost:8080/OpenADR2/Simple/2.0b',)

telemetry_usage_specifier_id = str(uuid.uuid4().hex[:10]) + "_telemetry_usage"
history_usage_specifier_id = str(uuid.uuid4().hex[:10]) + "_history_usage"

# Add 4 reports with different Metadata

client.add_report(callback=collect_data,
                  resource_id='Device001',
                  measurement='current',
                  unit='A',
                  report_specifier_id = telemetry_usage_specifier_id)
client.add_report(callback=collect_data,
                  resource_id='Device002',
                  measurement='current',
                  unit='A',
                  report_specifier_id = telemetry_usage_specifier_id)
client.add_report(callback=collect_data,
                  resource_id='Device001',
                  measurement='voltage',
                  unit='V',
                  report_specifier_id = history_usage_specifier_id)
client.add_report(callback=collect_data,
                  resource_id='Device002',
                  measurement='voltage',
                  unit='V',
                  report_specifier_id = history_usage_specifier_id)
stan-janssen commented 3 years ago

Did you find out why it was not working before?

00javad00 commented 3 years ago

By leaving report_specifier_id = None I was not able to generate and group report in three oadrReports. The Test harness's was asking for three oadrReport payload of: oadrReport#1) includes one report for METADATA_TELEMETRY_STATUS, oadrReport#2) includes two reports for METADATA_TELEMETRY_USAGE and oadrReport#3) includes two reports for METADATA_HISTORY_USAGE, where I made and group them manually (as I mentioned in above).

00javad00 commented 3 years ago

I realized the mandatory duration attribute is also missing in oadrReport despite the fact that it is already implemented in the template:

      {% if report.duration is defined and report.duration is not none %}
      <xcal:duration>
        <xcal:duration>{{ report.duration|timedeltaformat }}</xcal:duration>
      </xcal:duration>
      {% endif %}

oadrReport:duration element communicates the amount of history that can be buffered. This element MUST be included in Metadata reports. Seems you should consider this parameter also in client.add_report function.