ข้อจำกัดความรับผิดชอบ: ห้องสมุดนี้เขียนขึ้นเพื่อทดลองกับแนวคิดต่าง ๆ submodules entsoe_client.parametertypes และ entsoe_client.queries ตรงไปตรงมา ในการ refactor entsoe_client.parsers ขั้นตอนต่อไปคือการสร้างการติดตั้งสร้างมาตรฐานการแบนของต้นไม้ XML และแยกบันทึกจากไลบรารี DataFrame
กำหนดคิวรีที่อ่านได้และจัดการข้อมูลในแพนด้ารวมถึงชุดคิวรีที่กำหนดไว้ล่วงหน้า
> >> 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
...การสืบค้นที่กำหนดไว้ล่วงหน้าเป็นส่วนย่อยของคลาสการสืบค้นทั่วไปซึ่งครอบคลุมตัวอย่างทั้งหมดของคู่มือ INTESO-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") คุณสมบัตินี้ช่วยให้สามารถติดตามการสืบค้นได้โดยไม่ต้องกระโดดระหว่างเอกสารหรือเพิ่มความคิดเห็น
INTESO-E API Guide เป็นชุดเล็กสำหรับตัวเชื่อมต่อ API ใด ๆ ที่จะนำไปใช้และสะท้อนแดชบอร์ดทั้งหมดบนแพลตฟอร์มความโปร่งใส ENTESO-E
เอกสารการตอบสนองมาใน Schema XML ซึ่งสามารถแยกวิเคราะห์ลงใน pandas dataframes
นำไปใช้: GL_MARKETDOCUMENTS, TransmissionNetWork_MarketDocuments, Publication_MarketDocuments และ Balancing_marketDocuments
ขาดหายไป: การหยุดทำงานการจัดการความแออัดและการดำเนินงานระบบ
อย่างไรก็ตามไคลเอนต์ INTESO-E พยายามน้อยที่สุดที่จะเปลี่ยนจากการสืบค้นไปยัง DataFrame และต้องใช้ความรู้โดเมนเกี่ยวกับวิธีการกำหนดค่าการสืบค้นและตีความคอลัมน์ต่าง ๆ ของการตอบสนองที่แยกวิเคราะห์
entso-e ขึ้นอยู่กับรหัสจำนวนมาก (พิมพ์) เพื่อทำแผนที่ไปยังการสืบค้นที่ต้องการ ประเภทจะถูกเข้ารหัสในคลาส enum ด้วยฟังก์ชัน. help () เพื่อแสดงรายการทั้งหมด สามารถแก้ไขได้ผ่านประเภท [รหัส] หรือประเภท (สตริง) ทำให้การโต้ตอบง่าย การร้องขอและการตอบกลับ HTTP มักจะต้องใช้รหัสในขณะที่เราต้องการกำหนดแบบสอบถามเป็นสตริงที่มนุษย์อ่านได้
จาก entsoe_client import Queries
จาก entsoe_client.parametertypes นำเข้า *
Queries.transmission.capacityallocatedoutesideeu (
out_domain = พื้นที่ ('sk')
in_domain = พื้นที่ ('ua_bei')
MarketagreementType = MarketagreementType ('Daily'), # รหัสต้นฉบับ: A01
AuctionType = AuctionType ('Explicit'), # รหัสต้นฉบับ: A02
AuctionCategory = AuctionCategory ('ชั่วโมง'), # รหัสต้นฉบับ: A04
classification sequence_attributeInstancecomponent_position = 1,
Periodstart = 201601012300
PeriodEnd = 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 ()
--- BusinessType ---
api_parameter: คำอธิบาย
-
A25: ข้อมูลความจุทั่วไป
A29: ความสามารถที่จัดสรรแล้ว (AAC)
A97: สำรองการฟื้นฟูความถี่ด้วยตนเอง
B08: กำลังการผลิตที่ได้รับการเสนอชื่อทั้งหมด
C22: กำลังการผลิตสำรองสมดุลร่วมกัน
C24: ความสามารถในการสำรองจริง
-
api_parameter: คำอธิบาย
--- BusinessType ---
#Shortened จาก sample_plot.py
นำเข้า entsoe_client เป็น EC
จากการตั้งค่านำเข้า api_key
# อินสแตนซ์ไคลเอนต์ตัวแยกวิเคราะห์และการสืบค้น
client = ec.client (api_key)
parser = ec.parser ()
Query = Ec.queries.generation.aggregatedGenerationerType (
in_domain = ec.parametertypes.area ('de_lu')
Periodstart = 202109050200
PeriodEnd = 202109070200)
# แยกข้อมูล
Response = Client (Query)
df = parser (การตอบสนอง)
-
# แปลงข้อมูล
การผลิต = df [~ ensumption_mask] [['ปริมาณ', 'Timeseries.mktpsrtype.psrtype']]]
## psrtype เช่น `b01`: =` ชีวมวล '
การผลิต ['GenerationType'] = การผลิต ['Timeseries.mktpsrtype.psrtype'] -
ใช้ (Lambda X: ParameterTypes.psrtype [x] .Value) # แผนที่ entso-e psrtypes ลงในสตริงที่มนุษย์อ่านได้
production_by_type = pd.pivot_table (การผลิต
index = production.index
คอลัมน์ = 'GenerationType'
ค่า = 'ปริมาณ')
-
# พล็อต.
production_by_type.plot.bar (title = "การผลิตตามประเภทการสร้างใน de-lu"
xlabel = "utc"
ylabel = 'mWh'
ขวาน = ขวาน
** plot_params)
-
