Skip to content

Instantly share code, notes, and snippets.

@michaelhays
Last active October 28, 2019 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelhays/c8a01b740b790fe674a68c2870b50db9 to your computer and use it in GitHub Desktop.
Save michaelhays/c8a01b740b790fe674a68c2870b50db9 to your computer and use it in GitHub Desktop.
Demonstration of Awesome Power Texas plan extraction/calculation
def calculate_plan_cost(charges, rates, kwh_usage):
charge_index = len(charges) - 1
for index, array in enumerate(charges):
if kwh_usage < array[0]:
charge_index = index - 1
break
charge = charges[charge_index][1]
rate_index = len(rates) - 1
for index, array in enumerate(rates):
if kwh_usage <= array[0]:
rate_index = index - 1
break
rate_total = 0
for index in range(rate_index + 1):
if index < rate_index:
rate_total += rates[index][1] * (rates[index + 1][0] - rates[index][0])
else:
rate_total += rates[index][1] * (kwh_usage - rates[index][0])
plan_cost = charge + rate_total
return plan_cost
# Example plan: https://drive.google.com/file/d/1BiL4wQl63d5fZuTY9g0Ac1Kl1Spi6EGb/view
charges = [
[0, 0],
[500, 0.5],
[1001, 44.5],
]
rates = [
[0, 0.149],
[500, 0],
[1001, 0.119],
]
calculate_plan_cost(charges, rates, 343) # 51.107
calculate_plan_cost(charges, rates, 528) # 75.0
calculate_plan_cost(charges, rates, 997) # 75.0
calculate_plan_cost(charges, rates, 1003) # 119.357
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment