Skip to content

Commit

Permalink
Adhere to PEP 8 style guide
Browse files Browse the repository at this point in the history
 - max line width of 80 characters
 - avoid backslashes
  • Loading branch information
Marko Bastovanovic committed Feb 21, 2018
1 parent 0efb8da commit 75b0a14
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions emr_cost_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def __init__(self, region):
self.emr_prices = {}
for sku in sku_to_instance_type.keys():
instance_type = sku_to_instance_type.get(sku)
price = float(emr_pricing['terms']['OnDemand'][sku].itervalues().next()['priceDimensions'].itervalues().next()['pricePerUnit']['USD'])
price = float(emr_pricing['terms']['OnDemand'][sku].itervalues().next()['priceDimensions']
.itervalues().next()['pricePerUnit']['USD'])
self.emr_prices[instance_type] = price

ec2_regions_response = requests.get(url_base + index['offers']['AmazonEC2']['currentRegionIndexUrl'])
Expand All @@ -102,8 +103,8 @@ def __init__(self, region):
ec2_sku_to_instance_type = {}
for sku in ec2_pricing['products']:
try:
if ec2_pricing['products'][sku]['attributes']['tenancy'] == 'Shared' \
and ec2_pricing['products'][sku]['attributes']['operatingSystem'] == 'Linux':
if (ec2_pricing['products'][sku]['attributes']['tenancy'] == 'Shared' and
ec2_pricing['products'][sku]['attributes']['operatingSystem'] == 'Linux'):
ec2_sku_to_instance_type[sku] = ec2_pricing['products'][sku]['attributes']['instanceType']

except KeyError:
Expand All @@ -112,7 +113,8 @@ def __init__(self, region):
self.ec2_prices = {}
for sku in ec2_sku_to_instance_type.keys():
instance_type = ec2_sku_to_instance_type.get(sku)
price = float(ec2_pricing['terms']['OnDemand'][sku].itervalues().next()['priceDimensions'].itervalues().next()['pricePerUnit']['USD'])
price = float(ec2_pricing['terms']['OnDemand'][sku].itervalues().next()['priceDimensions']
.itervalues().next()['pricePerUnit']['USD'])
self.ec2_prices[instance_type] = price

def get_emr_price(self, instance_type):
Expand Down Expand Up @@ -204,8 +206,8 @@ def _get_instance_cost(self, instance, availability_zone):
instance.instance_type, availability_zone, instance.creation_ts, instance.termination_ts)

elif instance.market_type == "ON_DEMAND":
return self.ec2_emr_pricing.get_ec2_price(instance.instance_type) * \
((instance.termination_ts - instance.creation_ts).total_seconds() / 3600)
ec2_price = self.ec2_emr_pricing.get_ec2_price(instance.instance_type)
return ec2_price * ((instance.termination_ts - instance.creation_ts).total_seconds() / 3600)

def _get_cluster_list(self, created_after, created_before):
"""
Expand Down Expand Up @@ -297,8 +299,8 @@ def _populate_all_prices_if_needed(self, instance_id, availability_zone, start_t

if (instance_id, availability_zone) in self.all_prices:
prices = self.all_prices[(instance_id, availability_zone)]
if end_time - sorted(prices.keys())[-1] < datetime.timedelta(days=1, hours=1) \
and sorted(prices.keys())[0] < start_time:
if (end_time - sorted(prices.keys())[-1] < datetime.timedelta(days=1, hours=1) and
sorted(prices.keys())[0] < start_time):
# this means we already have requested dates. Nothing to do
return
else:
Expand Down

0 comments on commit 75b0a14

Please sign in to comment.