Skip to content

Instantly share code, notes, and snippets.

@mcowger
Created June 19, 2015 23:24
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 mcowger/b1b99b8901376cf093fd to your computer and use it in GitHub Desktop.
Save mcowger/b1b99b8901376cf093fd to your computer and use it in GitHub Desktop.
__author__ = 'mcowger'
import csv
import pprint
from datetime import datetime
data = []
sell_rate = 0.03
yearly_increase_rate = 1.029
def get_rate(date_object,year_ahead=0):
base = 0
if date_object.month in [5,6,7,8,9,10]: #Summer
base = .42781 #peak
if date_object.hour in [23,24,0,1,2,3,4,5,6]: #off peak
base = .09992
if date_object.hour in [7,8,9,10,11,12,13]: #part peak
base = 0.22554
else:
base = .29378 #peak
if date_object.hour in [23,24,0,1,2,3,4,5,6]: #off peak
base = .17360
if date_object.hour in [7,8,9,10,11,12,13]: #part peak
base = .17360
#return base
#Now correct for increases in PGE rates, assuming 2.9%
for x in range(1,year_ahead):
base = base * (1+yearly_increase_rate)
return base
with open('pge.csv', newline='') as csvfile:
power_reader = csv.DictReader(csvfile)
for row in power_reader:
data.append(row)
raw_production_data = [row for row in csv.DictReader(open("pvwatts_hourly.csv"))]
production_data = {}
for row in raw_production_data:
date_object = datetime(2015,int(row['Month']),int(row['Day']),int(row['Hour']))
row['date_object'] = date_object
#pprint.pprint(row)
production_data[date_object] = row
bill = 0
pge_bill = 0
for row in data:
date = row['DATE']
starttime = row['START TIME']
combo = "{} {}".format(date,starttime)
date_object = datetime.strptime(combo, '%Y-%m-%d %H:00')
date_object = date_object.replace(year=2015)
row['date_object'] = date_object
kwh = float(row['USAGE'].replace("$",""))
cost = float(row['COST'].replace("$",""))
rate = round(cost/kwh,3)
pge_bill += cost
solar_out_kwh = round(float(production_data[date_object]['AC System Output (W)']) / 1000,2)
buy_from_util = round(max(kwh - solar_out_kwh,0),2)
sell_to_util = round(max(solar_out_kwh - kwh, 0),2)
buy_cost = round(get_rate(date_object) * buy_from_util,2)
sell_value = -1 * round(sell_rate * sell_to_util,2)
print("{date} \t Consumed: {kwh}\t Produced: {prod}\t Buy From Util@{rate}:{buy}(${buy_cost})\t Sell To Util:{sell}(${sell_value})".format(
date = date_object,
kwh=kwh,
prod=solar_out_kwh,
buy=buy_from_util,
rate=get_rate(date_object),
sell=sell_to_util,
buy_cost=buy_cost,
sell_value=sell_value
))
bill += buy_cost
bill += sell_value
bill = round(bill,2)
pge_bill = round(pge_bill,2)
years = 30
for x in range(0,years-1):
print()
increase_multiplier = yearly_increase_rate**x
print("Year {}".format(2015+x))
print("PGE Power Bill (no Solar) for Year: ${}".format(pge_bill * increase_multiplier))
print("PGE Bill With 5.75kW System: ${}".format(bill * increase_multiplier))
print("Yearly Cost of System $21K amortized 10yr: ${}".format(21000/(years)))
print("Cost of Solar System: ${}".format(21000/years + bill * increase_multiplier))
print("Money Saved: {}".format( -1 * ((21000/years + bill * increase_multiplier) - (pge_bill * increase_multiplier)) ))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment