Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor bugs #90

Merged
merged 5 commits into from
Jul 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions docs/source/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,26 @@ Specifically, here are the included balancing authorities and their respective d
============================= ======================================== ============
balancing authority abbrev. balancing authority name/region data source
============================= ======================================== ============
BPA Bonneville Power Administration (Pac NW) BPA
CAISO California ISO CAISO
ERCOT Texas ERCOT
EU European Union ENTSO
ISONE ISO New England ISONE
MISO Midcontinent ISO MISO
NEVP Nevada Power NVEnergy
NYISO New York ISO NYISO
PJM Mid-Atlantic PJM
SPPC Sierra Pacific Power (NV) NVEnergy
AZPS Arizona Public Service SVERI
BPA Bonneville Power Administration (Pac NW) BPA
CAISO California ISO CAISO
DEAA DECA Arlington Valley (AZ) SVERI
ELE El Paso Electric SVERI
ERCOT Texas ERCOT
EU European Union ENTSO
HGMA Harquahala Generation Maricopa Arizona SVERI
IID Imperial Irrigation District (CA) SVERI
ISONE ISO New England ISONE
GRIF Griffith Energy (AZ) SVERI
MISO Midcontinent ISO MISO
NEVP Nevada Power NVEnergy
NYISO New York ISO NYISO
PJM Mid-Atlantic PJM
PNM Public Service Co New Mexico SVERI
SPPC Sierra Pacific Power (NV) NVEnergy
SRP Salt River Project (AZ) SVERI
TEPC Tuscon Electric Power Co SVERI
WALC WAPA Desert Southwest (NV, AZ) SVERI
============================= ======================================== ============


Expand Down
2 changes: 2 additions & 0 deletions docs/source/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ method ``latest`` ``start_at`` and ``end_at`` pair ``yeste
``PJM.get_load`` yes yes no yes
``PJM.get_trade`` yes no no no
``PJM.get_lmp`` yes yes no no
``SVERI.get_generation`` yes yes no no
``SVERI.get_load`` yes yes no no
======================== ========== =================================== ============== ============
23 changes: 18 additions & 5 deletions pyiso/miso.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def get_generation(self, latest=False, **kwargs):

# get data
if self.options['latest']:
data = self.latest_fuel_mix()
content = self.get_latest_fuel_mix()
data = self.parse_latest_fuel_mix(content)
extras = {
'ba_name': self.NAME,
'market': self.MARKET_CHOICES.fivemin,
Expand Down Expand Up @@ -95,25 +96,37 @@ def get_trade(self, latest=False, **kwargs):
# return
return self.serialize_faster(data, extras=extras)

def latest_fuel_mix(self):
def get_latest_fuel_mix(self):
# set up request
url = self.base_url + '/ria/FuelMix.aspx?CSV=True'

# carry out request
response = self.request(url)
if not response:
return pd.DataFrame()
return None

# test for valid content
if 'The page cannot be displayed' in response.text:
LOGGER.error('MISO: Error in source data for generation')
return None

# return good
return response.content

def parse_latest_fuel_mix(self, content):
# handle bad input
if not content:
return pd.DataFrame()

# preliminary parsing
df = pd.read_csv(BytesIO(response.content), header=0, index_col=0, parse_dates=True)
df = pd.read_csv(BytesIO(content), header=0, index_col=0, parse_dates=True)

# set index
df.index = self.utcify_index(df.index)
try:
df.index = self.utcify_index(df.index)
except AttributeError:
LOGGER.error('MISO: Error in source data for generation %s' % content)
return pd.DataFrame()
df.index.set_names(['timestamp'], inplace=True)

# set names and labels
Expand Down
4 changes: 4 additions & 0 deletions tests/test_miso.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ def test_utcify(self):
self.assertEqual(ts.minute, 45)
self.assertEqual(ts.tzinfo, pytz.utc)

def test_parse_latest_fuel_mix_bad(self):
bad_content = b'header1,header2\nnotadate,2016-01-01'
data = self.c.parse_latest_fuel_mix(bad_content)
self.assertEqual(len(data), 0)