Skip to content

Commit

Permalink
Resolved issue when exactly n*4 quarters are given
Browse files Browse the repository at this point in the history
  • Loading branch information
Pluimvee committed Oct 12, 2024
1 parent 2e5bab1 commit 60e593f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
6 changes: 3 additions & 3 deletions custom_components/entsoe/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ def process_PT15M_points(self, period: Element, start_time: datetime):

# now calculate hourly averages based on available points
data = {}
last_position = max(positions.keys())
last_price = positions.get(0, 0)
last_hour = (max(positions.keys()) + 3) // 4
last_price = 0

for hour in range((last_position // 4) + 1):
for hour in range(last_hour):
sum_prices = 0
for idx in range(hour * 4 + 1, hour * 4 + 5):
last_price = positions.get(idx, last_price)
Expand Down
49 changes: 49 additions & 0 deletions custom_components/entsoe/test/datasets/BE_15M_exact4.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<Publication_MarketDocument xmlns="urn:iec62325.351:tc57wg16:451-3:publicationdocument:7:3">
<mRID>64e2af3a87c2404cbea80edc067a1b6f</mRID>
<revisionNumber>1</revisionNumber>
<type>A44</type>
<sender_MarketParticipant.mRID codingScheme="A01">10X1001A1001A450</sender_MarketParticipant.mRID>
<sender_MarketParticipant.marketRole.type>A32</sender_MarketParticipant.marketRole.type>
<receiver_MarketParticipant.mRID codingScheme="A01">10X1001A1001A450</receiver_MarketParticipant.mRID>
<receiver_MarketParticipant.marketRole.type>A33</receiver_MarketParticipant.marketRole.type>
<createdDateTime>2024-10-07T14:36:40Z</createdDateTime>
<period.timeInterval>
<start>2024-10-05T22:00Z</start>
<end>2024-10-06T22:00Z</end>
</period.timeInterval>
<TimeSeries>
<mRID>1</mRID>
<auction.type>A01</auction.type>
<businessType>A62</businessType>
<in_Domain.mRID codingScheme="A01">10YBE----------2</in_Domain.mRID>
<out_Domain.mRID codingScheme="A01">10YBE----------2</out_Domain.mRID>
<contract_MarketAgreement.type>A01</contract_MarketAgreement.type>
<currency_Unit.name>EUR</currency_Unit.name>
<price_Measure_Unit.name>MWH</price_Measure_Unit.name>
<curveType>A03</curveType>
<Period>
<timeInterval>
<start>2024-10-05T22:00Z</start>
<end>2024-10-05T23:00Z</end>
</timeInterval>
<resolution>PT15M</resolution>
<Point>
<position>1</position>
<price.amount>55.35</price.amount>
</Point>
<Point>
<position>2</position>
<price.amount>44.22</price.amount>
</Point>
<Point>
<position>3</position>
<price.amount>40.32</price.amount>
</Point>
<Point>
<position>4</position>
<price.amount>31.86</price.amount>
</Point>
</Period>
</TimeSeries>
</Publication_MarketDocument>
13 changes: 13 additions & 0 deletions custom_components/entsoe/test/test_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,19 @@ def test_be_15M_avg(self):
},
)

def test_be_exact4(self):
with open("./datasets/BE_15M_exact4.xml") as f:
data = f.read()

self.maxDiff = None
self.assertDictEqual(
self.client.parse_price_document(data),
{
# part 1 - 15M resolution
datetime.fromisoformat("2024-10-05T22:00:00Z"): 42.94, # average
},
)


if __name__ == "__main__":
unittest.main()

0 comments on commit 60e593f

Please # to comment.