면책 조항 :이 도서관은 다양한 개념을 실험하기 위해 작성되었습니다. 하위 모듈 entsoe_client.parametertypes 및 entsoe_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 >
[...]becomes
> >> 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
...사전 정의 된 쿼리는 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주요 기여
이를 통해 자연 언어와 GET 요청에 필요한 코드 (예 : DocumentType.A85 == DocumentType("Imbalance price") 간의 매핑이 허용됩니다. 이 기능을 사용하면 문서간에 점프하거나 댓글을 추가하지 않고 쿼리를 추적 할 수 있습니다.
Entso-E API Guide는 API 커넥터가 Entso-E Transparency 플랫폼의 모든 대시 보드를 구현하고 반영 할 수있는 미니얼 세트입니다.
응답 문서는 XML 스키마로 제공되어 Pandas 데이터 프레임으로 구문 분석 할 수 있습니다.
구현 : GL_MARKETDOCUMENTS, TRANSMISSIONNETWORT_MARKETDOCUMEMSES, PUBLICATION_MARKETDOCUMENTS 및 BALENCANCE_MARKETDOCUMENTS.
누락 : 정전, 혼잡 관리 및 시스템 운영.
그럼에도 불구하고 Entso-E 클라이언트는 쿼리에서 데이터 프레임으로 최소한으로 이동하려고 노력하고 있으며 쿼리를 공식화하고 구문 분석 된 응답의 다양한 열을 해석하는 방법에 대한 도메인 지식이 필요합니다.
Entso-e는 원하는 쿼리에 매핑하기 위해 많은 코드 (유형)에 의존합니다. 유형은 모든 것을 나열하기 위해 .help () 함수의 열거 클래스로 인코딩됩니다. 유형 [코드] 또는 유형 (문자열)을 통해 해결할 수있어 상호 작용을 쉽게 할 수 있습니다. HTTP 요청 및 응답에는 일반적으로 코드가 필요하지만 쿼리를 사람이 읽을 수있는 문자열로 공식화하려고합니다.
entsoe_client 가져 오기 쿼리에서
entsoe_client.parameterTypes import에서 *
Queries.Transmission.CapicationAlocatedOutsideEu (
out_domain = area ( 'sk'),
in_domain = area ( 'ua_bei'),
MarketAgreementType = MarketAgreementType ( 'Daily'), # Original Code : A01
auctionType = auctionType ( '명시 적'), # 원본 코드 : a02
AuctionCategory = AuctionCategory ( 'Hourly'), # Original Code : A04
ClassificationSequence_attrippeinstanceComponent_position = 1,
주기 스테이트 = 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.businesstype.help () --- 비즈니스 유형 --- API_PARAMETER : 설명 [...] A25 : 일반 용량 정보 A29 : 이미 할당 된 용량 (AAC) A97 : 수동 주파수 복원 준비금 B08 : 총 지명 용량 C22 : 공유 밸런싱 예비 용량 C24 : 실제 예비 용량 [...] API_PARAMETER : 설명 --- 비즈니스 유형 ---
#sample_plot.py에서 #shortened
ENTSOE_CLIENT를 EC로 가져옵니다
설정에서 API_KEY 가져 오기
# Instantiate Client, Parser 및 Query.
클라이언트 = EC.Client (API_KEY)
Parser = ec.parser ()
query = ec.queries.generation.aggregatedGenerationPertype (
in_domain = ec.parametertypes.area ( 'de_lu'),
주기 스테트 = 202109050200,
기간 = 202109070200)
# 데이터 추출.
응답 = 클라이언트 (쿼리)
DF = 파서 (응답)
[...]
# 데이터 변환.
생산 = df [~ 소비 _mask] [[ '수량', 'timeseries.mktpsrtype.prtype']]]]
## psrtype, 예를 들어`b01` : =`biomass '.
생산 [ 'GenerationType'] = 생산 [ 'TimesSeries.mktpsrtype.prtype'].
apply (lambda x : parametertypes.psrtype [x] .value) # map entso-e psrtypes를 사람이 읽을 수있는 문자열로 맵핑하십시오.
production_by_type = pd.pivot_table (Production,
index = production.index,
열 = 'GenerationType',
값 = '수량')
[...]
# 구성.
production_by_type.plot.bar (title = "de-lu의 생성 유형별 프로덕션",
xlabel = "utc",
ylabel = 'MWH',
도끼 = 도끼,
** plot_params)
[...]
