Penafian: Perpustakaan ini ditulis untuk bereksperimen dengan berbagai konsep. Submodules entsoe_client.parametertypes dan entsoe_client.queries lurus ke depan. Untuk refactor entsoe_client.parsers, langkah selanjutnya adalah membuat perlengkapan, membakukan perataan pohon XML dan memisahkan catatan dari perpustakaan DataFrame.
Merumuskan kueri yang dapat dibaca dan menangani data dalam panda, termasuk satu set pertanyaan yang sudah ditentukan sebelumnya.
> >> 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 >
[...]menjadi
> >> 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
...Kueri yang telah ditentukan adalah subset dari kelas kueri generik, mencakup semua contoh panduan API entso-e.
> >> 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 ()
TrueKontribusi utama
Ini memungkinkan pemetaan antara bahasa alami dan kode yang diperlukan untuk mendapatkan permintaan, misalnya DocumentType.A85 == DocumentType("Imbalance price") . Fitur ini memungkinkan melacak kueri tanpa melompat di antara dokumen atau menambahkan komentar.
Panduan API ENTSO-E adalah set minial untuk setiap konektor API untuk mengimplementasikan dan mencerminkan semua dasbor pada platform transparansi Entso-E.
Dokumen respons datang dalam skema XML yang dapat diuraikan ke dalam data panda.
Diimplementasikan: GL_MarketDocuments, TransmissionNetwork_MarketDocuments, publikasi_marketdocuments dan balancing_marketdocuments.
Hilang: Pemadaman, manajemen kemacetan dan operasi sistem.
Namun demikian, klien Entso-E berusaha menjadi minimal untuk beralih dari kueri ke dataframe dan membutuhkan pengetahuan domain tentang cara merumuskan kueri dan menafsirkan berbagai kolom dari respons yang diuraikan.
Entso-E mengandalkan banyak kode (jenis) untuk memetakan pertanyaan yang diinginkan. Jenis dikodekan dalam kelas enum dengan fungsi .help () untuk mencantumkan semua. Mereka dapat diatasi melalui tipe [kode] atau ketik (string), membuat interaksi mudah. Permintaan dan tanggapan HTTP biasanya memerlukan kode, sedangkan kami ingin merumuskan kueri sebagai string yang dapat dibaca manusia.
dari kueri impor entsoe_client
dari entsoe_client.parametertypes impor *
Queries.transmission.capacityAllocatedOutseSeEu (
out_domain = area ('sk'),
in_domain = area ('ua_bei'),
MarketAgreementType = MarketAgreementType ('Daily'), # Kode Asli: A01
AuctionType = AucticleType ('Explicit'), # Kode Asli: A02
AuctionCategory = AuctionCategory ('jam'), # Kode Asli: A04
CLASSIFICATIONSECHENCE_ATtributeInstanceComponent_position = 1,
PeriodStart = 201601012300,
Periodend = 201601022300)
>>> ParameterTypes.DocumentType ['A25'] == ParameterTypes.DocumentType ('Dokumen Hasil Alokasi')
BENAR
>>> ec.parametertypes.documenttype.help ()
--- DocumentType ---
API_PARAMETER: Deskripsi
[...]
A25: Dokumen Hasil Alokasi
A71: Prakiraan Generasi
A72: Informasi Pengisian Reservoir
A73: generasi aktual
A85: Harga ketidakseimbangan
A86: Volume ketidakseimbangan
[...]
API_PARAMETER: Deskripsi
--- DocumentType ---
>>> ec.parametertypes.businesstype.help ()
--- BusinessType ---
API_PARAMETER: Deskripsi
[...]
A25: Informasi Kapasitas Umum
A29: Sudah dialokasikan Kapasitas (AAC)
A97: Cagar Restorasi Frekuensi Manual
B08: Total kapasitas yang dinominasikan
C22: Kapasitas Cadangan Balancing Bersama
C24: Kapasitas Cadangan Aktual
[...]
API_PARAMETER: Deskripsi
--- BusinessType ---
#shortened dari sample_plot.py
Impor entsoe_client sebagai EC
Dari Pengaturan Impor API_Key
# Instantiate Client, Parser dan Query.
Client = EC.Client (API_KEY)
parser = ec.parser ()
kueri = ec.queries.generation.agregatedGenerationPerType (
in_domain = ec.parametertypes.area ('de_lu'),
PeriodStart = 202109050200,
Periodend = 202109070200)
# Ekstrak data.
respons = klien (kueri)
df = parser (respons)
[...]
# Mengubah data.
produksi = df [~ konsumsi_mask] [['kuantitas', 'timeseries.mktpsrtype.psrtype']]
## psrtype, misalnya `b01`: =` biomassa`.
produksi ['generasi'] = produksi ['timeSeries.mktpsrtype.psrtype'].
Terapkan (lambda x: parameterTypes.psrtype [x] .value) # peta entso-e psrtypes ke dalam string yang dapat dibaca manusia.
produksi_by_type = pd.pivot_table (produksi,
index = produksi.index,
kolom = 'generasi',
nilai = 'kuantitas')
[...]
# Plot.
Production_by_type.plot.bar (title = "Produksi oleh generasi tipe di de-lu",
xlabel = "UTC",
ylabel = 'mwh',
kapak = kapak,
** plot_params)
[...]
