Skip to content

Commit

Permalink
US-SEC: fetch production from EIA
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Aug 3, 2019
1 parent 3c029af commit b35f32e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
25 changes: 21 additions & 4 deletions parsers/EIA.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
'US-IPC': 'EBA.IPCO-ALL.DF.H'
}

PRODUCTION = {
'US-SEC': 'EBA.SEC-ALL.NG.H'
}

EXCHANGES = {
'MX-BC->US-CA': 'EBA.CISO-CFE.ID.H',
'US-BPA->US-IPC': 'EBA.BPAT-IPCO.ID.H',
Expand All @@ -32,16 +36,28 @@

def fetch_consumption_forecast(zone_key, session=None, target_datetime=None,
logger=None):
return _fetch_production_or_consumption(
zone_key, DAY_AHEAD[zone_key], session=session,
target_datetime=target_datetime, logger=logger)


def fetch_production(zone_key, session=None, target_datetime=None,
logger=None):
return _fetch_production_or_consumption(
zone_key, PRODUCTION[zone_key], session=session,
target_datetime=target_datetime, logger=logger)


series_id = DAY_AHEAD[zone_key]
def _fetch_production_or_consumption(zone_key, series_id, session=None,
target_datetime=None, logger=None):
s = session or requests.Session()
forecast_series = Series(series_id=series_id, session=s)
series = Series(series_id=series_id, session=s)

if target_datetime:
raw_data = forecast_series.last_from(24, end=target_datetime)
raw_data = series.last_from(24, end=target_datetime)
else:
# Get the last 24 hours available.
raw_data = forecast_series.last(24)
raw_data = series.last(24)

# UTC timestamp with no offset returned.

Expand Down Expand Up @@ -102,4 +118,5 @@ def fetch_exchange(zone_key1, zone_key2, session=None, target_datetime=None, log
"Main method, never used by the Electricity Map backend, but handy for testing."

print(fetch_consumption_forecast('US-NY'))
print(fetch_production('US-SEC'))
print(fetch_exchange('MX-BC', 'US-CA'))
20 changes: 19 additions & 1 deletion parsers/US_SEC.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@

import pandas as pd

import EIA


def fetch_production(zone_key='US-SEC', session=None,
target_datetime=None, logger=logging.getLogger(__name__)):
"""Requests the last known production mix (in MW) of a given country
See example.py for details.
"""
data = EIA.fetch_production(zone_key=zone_key, session=session,
target_datetime=target_datetime, logger=logger)
for hour in data:
hour['production'] = {'unknown': hour.pop('value')}

return data


def fetch_solar(session=None, logger=logging.getLogger(__name__)):
url = 'http://apps.seminole.coop/db/cs/render.ashx?ItemPath=/Applications/Solar+Dashboard/Cooperative+Solar+-+Data&Format=EXCEL&rptHDInterval=Day&rptHDOffset=0'
Expand All @@ -27,6 +43,8 @@ def fetch_solar(session=None, logger=logging.getLogger(__name__)):
if __name__ == '__main__':
"""Main method, not used by the ElectricityMap backend, just for testing."""

import json, pprint
import pprint
print('fetch_production() ->')
print(pprint.pprint(fetch_production(target_datetime='20190705T22Z')))
print('fetch_solar() ->')
print(pprint.pprint(fetch_solar()))

0 comments on commit b35f32e

Please sign in to comment.