Page 1 of 1

How to use PAIRS with ENTSOE multiple Timeseries

Posted: Thursday 11 April 2024 10:30
by Wilop91
Hello
This topic is related with the following topic I created earlier:
https://www.domoticz.com/forum/viewtopic.php?t=42104

I had to write 2 different dzVents scripts:
- one when ENTSOE returns a set of data containing a single Timeserie
- one when ENTSOE returns a set of data containing multiple Timeseries

Here is a link which shows a dataset with a single Timeseries
https://web-api.tp.entsoe.eu/api?securi ... 2404092300

And this is a link which shows a dataset with multiple Timeseries
https://web-api.tp.entsoe.eu/api?securi ... 2404092300

In both cases I retrieve the amount of MWH generated in France per hour and per "Generation Type" for a selected day (typically yesterday)

I use the following syntax to find the Timeseries in the received XML dataset:

Code: Select all

for key, value in pairs (item.xml.GL_MarketDocument.TimeSeries) do idx = idx + 1 end
When there are multiple Timeseries, this returns the number of Timeseries found.
However when there is only a single Timeserie, this do not return 1 as I would expect but the number of Tags in GL_MarketDocument (8 in this case)

While having 2 scripts is not really a problem, I just would like to know if there is a solution (PAIRS or something else) which allows to determine for both cases the number of Timeseries so that I can have a single script that handles both cases.

Thanks a lot in advance

Willy

Re: How to use PAIRS with ENTSOE multiple Timeseries

Posted: Thursday 11 April 2024 23:41
by waltervl
This is more Lua then dzvents. Search your answer in Lua references.

Btw, the examples do not work, perhaps post them in original text (perhaps limited if large series)

Re: How to use PAIRS with ENTSOE multiple Timeseries

Posted: Friday 12 April 2024 9:50
by Wilop91
Hello waltervl, thanks for your reply.
Actually I replaced PAIRS by this code

Code: Select all

idxMax = 0
for myKey, myValue in next, (item.xml.Publication_MarketDocument) do if (myKey == "TimeSeries") then idxMax = idxMax + 1 end end
This seems to work but still when processing the Timeseries I need to do this:

Code: Select all

if (idxMax == 1 ) then --dataset has only 1 Timeseries
	enumerate_timeseries(1, item.xml.Publication_MarketDocument.TimeSeries)
else -- the dataset has several Timeseries
	for idx = 1, idxMax do --Loop trough all the Timeseries
       		enumerate_timeseries(idx, item.xml.Publication_MarketDocument.TimeSeries[idx])
    	end
end
I'm still testing...and progressing slowly in LUA coding...

PS: in the ENTSOE links you need to enter your API token.

BR

Willy