本文整理汇总了Python中pyiso.LOGGER.error方法的典型用法代码示例。如果您正苦于以下问题:Python LOGGER.error方法的具体用法?Python LOGGER.error怎么用?Python LOGGER.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyiso.LOGGER
的用法示例。
在下文中一共展示了LOGGER.error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: latest_fuel_mix
# 需要导入模块: from pyiso import LOGGER [as 别名]
# 或者: from pyiso.LOGGER import error [as 别名]
def 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()
# test for valid content
if 'The page cannot be displayed' in response.text:
LOGGER.error('MISO: Error in source data for generation')
return pd.DataFrame()
# preliminary parsing
df = pd.read_csv(BytesIO(response.content), header=0, index_col=0, parse_dates=True)
# set index
df.index = self.utcify_index(df.index)
df.index.set_names(['timestamp'], inplace=True)
# set names and labels
df['fuel_name'] = df.apply(lambda x: self.fuels[x['CATEGORY']], axis=1)
df['gen_MW'] = df['ACT']
# return
return df[['fuel_name', 'gen_MW']]
示例2: handle_options
# 需要导入模块: from pyiso import LOGGER [as 别名]
# 或者: from pyiso.LOGGER import error [as 别名]
def handle_options(self, **kwargs):
"""
Process and store keyword argument options.
"""
super(EIAClient, self).handle_options(**kwargs)
if not hasattr(self, 'BA'):
LOGGER.error('Balancing authority not set.')
raise ValueError('Balancing authority not set.')
if 'market' not in self.options:
if self.options['forecast']:
self.options['market'] = self.MARKET_CHOICES.dam
elif self.options['sliceable'] and self.options['data'] == 'gen':
self.options['market'] = self.MARKET_CHOICES.dam
else:
self.options['market'] = self.MARKET_CHOICES.hourly
if 'freq' not in self.options:
if self.options['forecast']:
self.options['freq'] = self.FREQUENCY_CHOICES.hourly
elif self.options['sliceable'] and self.options['data'] == 'gen':
self.options['freq'] = self.FREQUENCY_CHOICES.hourly
else:
self.options['freq'] = self.FREQUENCY_CHOICES.hourly
if 'yesterday' not in self.options:
self.options['yesterday'] = False
示例3: latest_fuel_mix
# 需要导入模块: from pyiso import LOGGER [as 别名]
# 或者: from pyiso.LOGGER import error [as 别名]
def 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()
# test for valid content
if "The page cannot be displayed" in response.text:
LOGGER.error("MISO: Error in source data for generation")
return pd.DataFrame()
# preliminary parsing
df = pd.read_csv(StringIO(response.text), header=0, index_col=0, parse_dates=True)
# set index
df.index = self.utcify_index(df.index)
df.index.set_names(["timestamp"], inplace=True)
# set names and labels
df["fuel_name"] = df.apply(lambda x: self.fuels[x["CATEGORY"]], axis=1)
df["gen_MW"] = df["ACT"]
# return
return df[["fuel_name", "gen_MW"]]
示例4: time_from_soup
# 需要导入模块: from pyiso import LOGGER [as 别名]
# 或者: from pyiso.LOGGER import error [as 别名]
def time_from_soup(self, soup):
"""
Returns a UTC timestamp if one is found in the soup,
or None if an error was encountered.
"""
ts_elt = soup.find(class_='ts')
if not ts_elt:
LOGGER.error('PJM: Timestamp not found in soup:\n%s' % soup)
return None
return self.utcify(ts_elt.string)
示例5: fetch_oasis
# 需要导入模块: from pyiso import LOGGER [as 别名]
# 或者: from pyiso.LOGGER import error [as 别名]
def fetch_oasis(self, payload={}, return_all_files=False):
"""
Returns a list of report data elements, or an empty list if an error was encountered.
If return_all_files=False, returns only the content from the first file in the .zip -
this is the default behavior and was used in earlier versions of this function.
If return_all_files=True, will return an array representing the content from each file.
This is useful for processing LMP data or other fields where multiple price components are returned in a zip.
"""
# set up storage
raw_data = []
if return_all_files is True:
default_return_val = []
else:
default_return_val = ''
# try get
response = self.request(self.base_url_oasis, params=payload)
if not response:
return default_return_val
# read data from zip
# This will be an array of content if successful, and None if unsuccessful
content = self.unzip(response.content)
if not content:
return default_return_val
# check xml content for errors
soup = BeautifulSoup(content[0], 'lxml')
error = soup.find('m:error')
if error:
code = error.find('m:err_code')
desc = error.find('m:err_desc')
msg = 'XML error for CAISO OASIS with payload %s: %s %s' % (payload, code, desc)
LOGGER.error(msg)
return default_return_val
# return xml or csv data
if payload.get('resultformat', False) == 6:
# If we requested CSV files
if return_all_files:
return content
else:
return content[0]
else:
# Return XML content
if return_all_files:
raw_data = [BeautifulSoup(thisfile).find_all('report_data') for thisfile in content]
return raw_data
else:
raw_data = soup.find_all('report_data')
return raw_data
示例6: request
# 需要导入模块: from pyiso import LOGGER [as 别名]
# 或者: from pyiso.LOGGER import error [as 别名]
def request(self, url, mode='get', retry_sec=5, **kwargs):
"""
Get or post to a URL with the provided kwargs.
Returns the response, or None if an error was encountered.
If the mode is not 'get' or 'post', raises ValueError.
"""
# check args
allowed_modes = ['get', 'post']
if mode not in allowed_modes:
raise ValueError('Invalid request mode %s' % mode)
# check for session
try:
session = getattr(self, 'session')
except AttributeError:
self.session = requests.Session()
session = self.session
# carry out request
try:
response = getattr(session, mode)(url, verify=False,
timeout=self.TIMEOUT_SECONDS,
**kwargs)
# except requests.exceptions.ChunkedEncodingError as e:
# # JSON incomplete or not found
# msg = '%s: chunked encoding error for %s, %s:\n%s' % (self.NAME, url, kwargs, e)
# LOGGER.error(msg)
# return None
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout) as e:
# eg max retries exceeded
msg = '%s: connection error for %s, %s:\n%s' % (self.NAME, url, kwargs, e)
LOGGER.error(msg)
return None
# except requests.exceptions.RequestException:
# msg = '%s: request exception for %s, %s:\n%s' % (self.NAME, url, kwargs, e)
# LOGGER.error(msg)
# return None
if response.status_code == 200:
# success
LOGGER.debug('%s: request success for %s, %s with cache hit %s' % (self.NAME, url, kwargs, getattr(response, 'from_cache', None)))
elif response.status_code == 429:
# retry on throttle
LOGGER.warn('%s: retrying in %d seconds, throttled for %s, %s' % (self.NAME, retry_sec, url, kwargs))
sleep(retry_sec)
return self.request(url, mode=mode, retry_sec=retry_sec, **kwargs)
else:
# non-throttle error
LOGGER.error('%s: request failure with code %s for %s, %s' % (self.NAME, response.status_code, url, kwargs))
return response
示例7: handle_ba_limitations
# 需要导入模块: from pyiso import LOGGER [as 别名]
# 或者: from pyiso.LOGGER import error [as 别名]
def handle_ba_limitations(self):
"""Handle BA limitations"""
today = pytz.utc.localize(datetime.utcnow()).astimezone(pytz.timezone(self.TZ_NAME))
two_days_ago = today - timedelta(days=2)
load_not_supported_bas = ['DEAA', 'EEI', 'GRIF', 'GRMA', 'GWA',
'HGMA', 'SEPA', 'WWA', 'YAD']
delay_bas = ['AEC', 'DOPD', 'GVL', 'HST', 'NSB', 'PGE', 'SCL',
'TAL', 'TIDC', 'TPWR']
canada_mexico = ['IESO', 'BCTC', 'MHEB', 'AESO', 'HQT', 'NBSO',
'CFE', 'SPC']
if self.BA in delay_bas:
if self.options['end_at'] and self.options['end_at'] > two_days_ago:
LOGGER.error('No data for %s due to 2 day delay' % self.BA)
raise ValueError('No data: 2 day delay for this BA.')
elif self.options['yesterday']:
LOGGER.error('No data for %s due to 2 day delay' % self.BA)
raise ValueError('No data: 2 day delay for this BA.')
elif self.options['forecast']:
raise ValueError('No data: 2 day delay for this BA.')
if self.BA in load_not_supported_bas:
if self.options['data'] == 'load':
LOGGER.error('Load data not supported for %s' % self.BA)
raise ValueError('Load data not supported for this BA.')
if self.BA in canada_mexico:
LOGGER.error('Data not supported for %s' % self.BA)
raise ValueError('Data not currently supported for Canada and Mexico')
示例8: _assert_entries_1hr_apart
# 需要导入模块: from pyiso import LOGGER [as 别名]
# 或者: from pyiso.LOGGER import error [as 别名]
def _assert_entries_1hr_apart(self, result_ts):
prev_entry = None
for entry in result_ts:
if prev_entry:
seconds_delta = (entry['timestamp'] - prev_entry['timestamp']).total_seconds()
if seconds_delta > 3600:
LOGGER.error('prev_entry timestamp: ' + str(
prev_entry['timestamp'].astimezone(pytz.timezone(self.nbpower_client.TZ_NAME))
))
LOGGER.error('entry timestamp: ' + str(
entry['timestamp'].astimezone(pytz.timezone(self.nbpower_client.TZ_NAME))
))
self.assertEqual(3600, seconds_delta)
prev_entry = entry
示例9: get_latest_fuel_mix
# 需要导入模块: from pyiso import LOGGER [as 别名]
# 或者: from pyiso.LOGGER import error [as 别名]
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 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
示例10: _format_start_end
# 需要导入模块: from pyiso import LOGGER [as 别名]
# 或者: from pyiso.LOGGER import error [as 别名]
def _format_start_end(self, data):
formatted_sliced = []
if 'gen' not in self.options['data']:
formatted_sliced = [i for i in data if i['timestamp'] >= self.options['start_at'] and i['timestamp'] <= self.options['end_at']]
else:
try:
yesterday = (self.local_now() - timedelta(days=2)).replace(hour=0, minute=0,
second=0, microsecond=0)
tomorrow = (self.local_now() + timedelta(days=1)).replace(hour=23, minute=0,
second=0, microsecond=0)
assert ((self.options['start_at'] >= yesterday) and (self.options['end_at'] <= tomorrow))
formatted_sliced = [i for i in data if i['timestamp'] >= self.options['start_at'] and i['timestamp'] <= self.options['end_at']]
except:
LOGGER.error('Generation data error for %s' % self.BA)
raise ValueError('Generation data is available for the \
previous and current day.', self.options)
return formatted_sliced
示例11: val_from_soup
# 需要导入模块: from pyiso import LOGGER [as 别名]
# 或者: from pyiso.LOGGER import error [as 别名]
def val_from_soup(self, soup, key):
"""
Returns a float value if one is found in the soup for the provided key,
or None if an error was encountered.
"""
for elt in soup.find_all('td'):
try:
if elt.find('a').string == key:
# numbers may have commas in the thousands
val_str = elt.next_sibling.string.replace(',', '')
return float(val_str)
except AttributeError: # no 'a' child
continue
# no value found
LOGGER.error('PJM: Value for %s not found in soup:\n%s' % (key, soup))
return None
示例12: get_load
# 需要导入模块: from pyiso import LOGGER [as 别名]
# 或者: from pyiso.LOGGER import error [as 别名]
def get_load(self, latest=False, yesterday=False, start_at=False,
end_at=False, forecast=False, **kwargs):
"""
Scrape and parse load data.
"""
self.handle_options(data='load', latest=latest, start_at=start_at,
end_at=end_at, **kwargs)
self.handle_ba_limitations()
self.format_url()
result = self.request(self.url)
if result is not None:
result_json = json.loads(result.text)
result_formatted = self.format_result(result_json)
return result_formatted
else:
LOGGER.error('No results for %s' % self.BA)
return []
示例13: get_generation
# 需要导入模块: from pyiso import LOGGER [as 别名]
# 或者: from pyiso.LOGGER import error [as 别名]
def get_generation(self, latest=False, yesterday=False,
start_at=False, end_at=False, **kwargs):
"""
Scrape and parse generation fuel mix data.
Note: Generation may be quite low for HST and NSB BAs.
"""
self.handle_options(data='gen', latest=latest, yesterday=yesterday,
start_at=start_at, end_at=end_at, **kwargs)
self.handle_ba_limitations()
self.format_url()
result = self.request(self.url)
if result is not None:
result_json = json.loads(result.text)
result_formatted = self.format_result(result_json)
return result_formatted
else:
LOGGER.error('No results for %s' % self.BA)
return []
示例14: parse_oasis_renewable
# 需要导入模块: from pyiso import LOGGER [as 别名]
# 或者: from pyiso.LOGGER import error [as 别名]
def parse_oasis_renewable(self, raw_data):
"""Parse raw data output of fetch_oasis for renewables."""
# set up storage
preparsed_data = {}
parsed_data = []
# extract values from xml
for raw_soup_dp in raw_data:
# set up storage for timestamp
ts = self.utcify(raw_soup_dp.find('interval_start_gmt').string)
if ts not in preparsed_data:
preparsed_data[ts] = {'wind': 0, 'solar': 0}
# store generation value
try:
fuel_name = raw_soup_dp.find('renewable_type').string.lower()
gen_MW = float(raw_soup_dp.find('value').string)
preparsed_data[ts][fuel_name] += gen_MW
except TypeError:
LOGGER.error('Error in schema for CAISO OASIS result %s' % raw_soup_dp.prettify())
continue
# collect values into dps
freq = self.options.get('freq', self.FREQUENCY_CHOICES.hourly)
market = self.options.get('market', self.MARKET_CHOICES.hourly)
for ts, preparsed_dp in preparsed_data.items():
# set up base
base_parsed_dp = {'timestamp': ts,
'freq': freq,
'market': market,
'gen_MW': 0, 'ba_name': self.NAME}
# collect data
for fuel_name in ['wind', 'solar']:
parsed_dp = copy.deepcopy(base_parsed_dp)
parsed_dp['fuel_name'] = fuel_name
parsed_dp['gen_MW'] += preparsed_dp[fuel_name]
parsed_data.append(parsed_dp)
# return
return parsed_data
示例15: get_generation
# 需要导入模块: from pyiso import LOGGER [as 别名]
# 或者: from pyiso.LOGGER import error [as 别名]
def get_generation(self, latest=False, **kwargs):
# set args
self.handle_options(data='gen', **kwargs)
# get data
load_ts, load_val = self.fetch_edata_point('instLoad', 'PJM RTO Total')
imports_ts, imports_val = self.fetch_edata_point('tieFlow', 'PJM RTO')
wind_ts, wind_gen = self.fetch_edata_point('wind', 'RTO Wind Power')
# compute nonwind gen
try:
total_gen = load_val - imports_val
nonwind_gen = total_gen - wind_gen
except TypeError: # value was None
LOGGER.error('PJM: No timestamps found for options %s' % str(self.options))
return []
# choose best time to use
if load_ts:
ts = load_ts
elif imports_ts:
ts = imports_ts
elif wind_ts:
ts = wind_ts
else:
LOGGER.error('PJM: No timestamps found for options %s' % str(self.options))
return []
# set up storage
parsed_data = []
base_dp = {'timestamp': ts,
'freq': self.FREQUENCY_CHOICES.fivemin, 'market': self.MARKET_CHOICES.fivemin,
'gen_MW': 0, 'ba_name': self.NAME}
# collect data
for gen_MW, fuel_name in [(wind_gen, 'wind'), (nonwind_gen, 'nonwind')]:
parsed_dp = copy.deepcopy(base_dp)
parsed_dp['fuel_name'] = fuel_name
parsed_dp['gen_MW'] = gen_MW
parsed_data.append(parsed_dp)
# return
return parsed_data