免責事項:このライブラリは、さまざまな概念を実験するために書かれています。サブモジュールENTSOE_CLIENT.PARAMETERTYPESとENTESOE_CLIENT.QUERIESは簡単です。 Entsoe_client.parsersをリファクタリングするために、次のステップは、備品を確立し、XMLツリーの平坦化を標準化し、データフレームライブラリからレコードを分離することです。
読み取り可能なクエリを策定し、事前定義されたクエリの徹底的なセットを含むパンダのデータを処理します。
> >> import requests
> >> from lxml import objectify
> >> from lxml . etree import dump
> >> url = 'https://transparency.entsoe.eu/api?'
... 'documentType=A81&businessType=A95&psrType=A04&type_MarketAgreement.Type=A01&controlArea_Domain=10YNL----------L'
... f '&periodStart=202101010000&periodEnd=202104010000&securityToken={api_key}'
> >> response = requests . Session (). get ( url = url )
> >> element = objectify . fromstring ( response . content )
> >> dump ( element )
< Balancing_MarketDocument xmlns = "urn:iec62325.351:tc57wg16:451-6:balancingdocument:3:0" >
< mRID > 051 b91beed574b48b4548214e9001afc < / mRID >
< revisionNumber > 1 < / revisionNumber >
< type > A81 < / type >
< process . processType > A34 < / process . processType >
< sender_MarketParticipant . mRID codingScheme = "A01" > 10 X1001A1001A450 < / sender_MarketParticipant . mRID >
< sender_MarketParticipant . marketRole . type > A32 < / sender_MarketParticipant . marketRole . type >
< receiver_MarketParticipant . mRID codingScheme = "A01" > 10 X1001A1001A450 < / receiver_MarketParticipant . mRID >
< receiver_MarketParticipant . marketRole . type > A33 < / receiver_MarketParticipant . marketRole . type >
< createdDateTime > 2021 - 10 - 04 T18 : 12 : 43 Z < / createdDateTime >
< controlArea_Domain . mRID codingScheme = "A01" > 10 YNL - - - - - - - - - - L < / controlArea_Domain . mRID >
< period . timeInterval >
< start > 2020 - 12 - 31 T23 : 00 Z < / start >
< end > 2021 - 03 - 31 T22 : 00 Z < / end >
< / period . timeInterval >
< TimeSeries >
< mRID > 1 < / mRID >
< businessType > A95 < / businessType >
< type_MarketAgreement . type > A01 < / type_MarketAgreement . type >
< mktPSRType . psrType > A04 < / mktPSRType . psrType >
< flowDirection . direction > A03 < / flowDirection . direction >
< quantity_Measure_Unit . name > MAW < / quantity_Measure_Unit . name >
< curveType > A01 < / curveType >
< Period >
< timeInterval >
< start > 2020 - 12 - 31 T23 : 00 Z < / start >
< end > 2021 - 01 - 01 T23 : 00 Z < / end >
< / timeInterval >
< resolution > PT60M < / resolution >
< Point >
< position > 1 < / position >
< quantity > 44 < / quantity >
< / Point >
< Point >
< position > 2 < / position >
< quantity > 44 < / quantity >
[...]なります
> >> import entsoe_client as ec
> >> from entsoe_client . ParameterTypes import *
> >> client = ec . Client ( api_key )
> >> parser = ec . Parser
> >> query = ec . Query (
... documentType = DocumentType ( "Contracted reserves" ),
... psrType = PsrType ( "Generation" ),
... businessType = BusinessType ( "Frequency containment reserve" ),
... controlArea_Domain = Area ( "NL" ),
... type_MarketAgreementType = MarketAgreementType ( "Daily" ),
... periodStart = "2021-01-01T00:00" ,
... periodEnd = "2021-04-01T00:00"
... )
> >> response = client ( query )
> >> df = parser . parse ( response )
> >> df . iloc [:,: 3 ]. head ()
position quantity Period . timeInterval . start ...
2020 - 12 - 31 23 : 00 : 00 + 00 : 00 1 44 2020 - 12 - 31 T23 : 00 Z
2021 - 01 - 01 00 : 00 : 00 + 00 : 00 2 44 2020 - 12 - 31 T23 : 00 Z
2021 - 01 - 01 01 : 00 : 00 + 00 : 00 3 44 2020 - 12 - 31 T23 : 00 Z
2021 - 01 - 01 02 : 00 : 00 + 00 : 00 4 44 2020 - 12 - 31 T23 : 00 Z
2021 - 01 - 01 03 : 00 : 00 + 00 : 00 5 44 2020 - 12 - 31 T23 : 00 Z
...事前定義されたクエリは、generic Queryクラスのサブセットであり、Entso-E APIガイドのすべての例をカバーしています。
> >> predefined_query = ec . Queries . Balancing . AmountOfBalancingReservesUnderContract (
... controlArea_Domain = Area ( "NL" ),
... type_MarketAgreementType = MarketAgreementType ( "Daily" ),
... psrType = PsrType ( "Generation" ),
... periodStart = "2021-01-01T00:00" ,
... periodEnd = "2021-04-01T00:00"
... )
...
> >> predefined_query () == query ()
True主な貢献
これらによりDocumentType.A85 == DocumentType("Imbalance price")自然言語とGETリクエストに必要なコードの間のマッピングが可能になります。この機能により、ドキュメント間をジャンプしたりコメントを追加したりせずに、クエリを追跡できます。
Entso-E APIガイドは、APIコネクタが実装するためのミニールセットであり、Entso-E透明性プラットフォーム上のすべてのダッシュボードを反映しています。
応答ドキュメントには、Pandasデータフレームに解析できるXMLスキーマがあります。
実装:gl_marketdocuments、transmissionnetwork_marketdocuments、publication_marketdocuments、balancing_marketdocuments。
欠落:停止、混雑管理、システム運用。
それにもかかわらず、Entso-Eクライアントは、クエリからデータフレームに移行することを最小限にしようとしており、クエリを策定し、解析された応答のさまざまな列を解釈する方法に関するドメイン知識を必要とします。
Entso-Eは、多くのコード(タイプ)に依存して、目的のクエリにマッピングされます。タイプは、.help()関数を使用してenumクラスでエンコードされ、すべてをリストします。タイプ[コード]またはタイプ(文字列)を使用して対処でき、相互作用を簡単にすることができます。通常、HTTPリクエストと応答にはコードが必要ですが、クエリを読み取り可能な文字列として策定する必要があります。
ENTESOE_CLIENTインポートクエリから
Entsoe_client.parametertypesからインポート *
queries.transmission.capacityallocatedoutsideeu(
out_domain = area( 'sk')、
in_domain = area( 'ua_bei')、
MarketAgreementType = MarketAgreementType( 'Daily')、#Original Code:A01
auctionType = auctionType( 'expricit')、#original code:a02
auctioncategory = auctioncategory( 'hourly')、#original code:a04
classificationsequence_attributeinstancecomponent_position = 1、
lipingstart = 201601012300、
定期的な= 201601022300)
>>> parametertypes.documenttype ['a25'] == parametertypes.documentType( '割り当て結果ドキュメント') 真実 >>> ec.parametertypes.documenttype.help() --- documentType --- API_PARAMETER:説明 [...] A25:割り当て結果ドキュメント A71:生成予測 A72:貯水池の充填情報 A73:実際の生成 A85:不均衡価格 A86:不均衡量 [...] API_PARAMETER:説明 --- documentType --- >>> ec.parametertypes.businestype.help() --- BusinessType --- API_PARAMETER:説明 [...] A25:一般容量情報 A29:すでに割り当てられた容量(AAC) A97:手動の周波数修復リザーブ B08:総指名能力 C22:共有バランスリザーブ容量 C24:実際の予備容量 [...] API_PARAMETER:説明 --- BusinessType ---
#shortedened from sample_plot.py
ECとしてENTESOE_CLIENTをインポートします
設定からAPI_KEYをインポートします
#インスタンスクライアント、パーサー、クエリ。
client = ec.client(api_key)
parser = ec.parser()
query = ec.queries.generation.aggreatedgenerationpertype(
in_domain = ec.parametertypes.area( 'de_lu')、
lipingstart = 202109050200、
定期的な= 202109070200)
#データを抽出します。
response = client(query)
DF =パーサー(応答)
[...]
#データを変換します。
生産= df [〜Consumption_Mask] [['QUANTY'、 'TIMESERIES.MKTPSRTYPE.PSRTYPE']]]
## psrtype、例: `b01`:=` biomass `。
生産['GenerationType'] = Production ['Timeseries.mktpsrtype.psrtype']。
apply(lambda x:parametertypes.psrtype [x] .value)
production_by_type = pd.pivot_table(production、
index = production.index、
列= 'GenerationType'、
値= '数量')
[...]
#プロット。
production_by_type.plot.bar(title = "de-luの生成タイプによる生産"、
xlabel = "utc"、
ylabel = 'mwh'、
ax = ax、
** plot_params)
[...]
