إخلاء المسئولية: تمت كتابة هذه المكتبة لتجربة مفاهيم مختلفة. النطاق الفرعي 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
...الاستعلامات المحددة مسبقًا هي مجموعة فرعية من فئة الاستعلام العامة ، وتغطي جميع الأمثلة على دليل 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") . تتيح هذه الميزة تتبع الاستعلامات دون القفز بين المستندات أو إضافة التعليقات.
Entso-E API Guide هو مجموعة مصغرة لأي موصل API لتنفيذ جميع لوحات المعلومات على منصة الشفافية Entso-E.
تأتي مستندات الاستجابة في مخطط XML الذي يمكن تحليله في إطارات بيانات Pandas.
المنفذ: GL_MarketDocuments ، transmissionnetwork_marketdocuments ، publication_marketdocuments و calancing_marketdocuments.
مفقود: انقطاع ، إدارة الازدحام وعمليات النظام.
ومع ذلك ، يسعى عميل Entso-E إلى أن يكون الحد الأدنى من الاستعلام إلى DataFrame ويتطلب معرفة المجال حول كيفية صياغة الاستعلامات وتفسير الأعمدة المختلفة للاستجابة المحلية.
يعتمد Entso-E على العديد من الرموز (النوع) لتعيين الاستعلامات المطلوبة. يتم تشفير الأنواع في فئات التعداد مع دالة .help () لسرد الكل. يمكن معالجتها من خلال النوع [رمز] أو نوع (سلسلة) ، مما يجعل التفاعل سهلًا. عادة ما تتطلب طلبات HTTP والاستجابات رمزًا ، في حين نريد صياغة الاستعلام كسلسلة قابلة للقراءة الإنسان.
من entsoe_client استيراد الاستعلامات
من entsoe_client.parametertypes استيراد *
Queries.Transmission.CapacityAllocatedoutsideeu (
out_domain = المنطقة ('SK') ،
in_domain = المنطقة ('UA_BEI') ،
MarketagreementType = MarketagreementType ('Daily') ، # الكود الأصلي: A01
AuctionType = AuctionType ("صريح") ، # الكود الأصلي: A02
AuctionCategory = AuctionCategory ('Clyly') ، # الكود الأصلي: A04
ClassificeSexence_attributeInstanceComponent_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 ()
--- BusinessType ---
api_parameter: الوصف
[...]
A25: معلومات السعة العامة
A29: السعة المخصصة بالفعل (AAC)
A97: احتياطي استعادة التردد اليدوي
B08: إجمالي السعة المرشح
C22: قدرة الاحتياطي الموازنة المشتركة
C24: القدرة الاحتياطية الفعلية
[...]
api_parameter: الوصف
--- BusinessType ---
#shortened من sample_plot.py
استيراد entsoe_client مثل EC
من الإعدادات استيراد api_key
# عميل مثبتة ، محلل واستعلام.
العميل = ec.client (api_key)
محلل = ec.parser ()
Query = ec.queries.generation.aggregatedGenerationPertype (
in_domain = ec.parametertypes.area ('de_lu') ،
فترة التشغيل = 202109050200 ،
الدور = 202109070200)
# استخراج البيانات.
استجابة = عميل (استعلام)
df = محلل (استجابة)
[...]
# تحويل البيانات.
الإنتاج = df [~ consumpt_mask] [['Quantity' ، '
## psrtype ، على سبيل المثال b01`: = "الكتلة الحيوية".
الإنتاج ['genertype'] = الإنتاج ['timeseries.mktpsrtype.psrtype'].
قم بتطبيق (lambda x: parametertypes.psrtype [x] .value) # map entso-e psrtypes في سلسلة قابلة للقراءة البشرية.
production_by_type = pd.pivot_table (الإنتاج ،
الفهرس = production.index ،
الأعمدة = 'GeneryType' ،
القيم = 'الكمية')
[...]
# حبكة.
production_by_type.plot.bar (title = "الإنتاج حسب نوع الجيل في de-lu" ،
xlabel = "UTC" ،
ylabel = 'mwh' ،
الفأس = الفأس ،
** plot_params)
[...]
