# CrossCompute
address_table_path = 'Simplified Table with average monthly savings(within 0.5 Mile) and tree count(within 0.5 Mile).csv'
search_radius_in_miles = 0.5
industry_select = """
Manufacturing
Manufacturing
Wholesale/Warehouse/Distribution
Commercial
Landlord
Public Benefit Corp
Other
"""
program_select = """
ICIP
City/State
ICAP
ICIP
IDA
Relocator
Tenant
"""
target_folder = '/tmp'
# Load inputs
import pandas as pd
df = pd.read_csv(address_table_path)
df.dropna(axis=0, subset=['Longitude','Latitude'], inplace = True)
df = df[['Latitude','Longitude','Periodic Savings']]
df
industry = industry_select.strip().splitlines()[0]
program = program_select.strip().splitlines()[0]
# Get longitude and latitude for each address
# from geopy import GoogleV3
# geocode = GoogleV3('AIzaSyDNqc0tWzXHx_wIp1w75-XTcCk4BSphB5w').geocode
# def get_longitude_latitude(row):
# location = geocode(row['Address'])
# row['Longitude'] = location.longitude
# row['Latitude'] = location.latitude
# return row
# df = df.apply(get_longitude_latitude, axis=1)
# df[:3]
# Prepare prediction dataset
prediction_table = df.copy()
# Prepare prediction dataset
prediction_table = df.copy()
# # Add "Average Monthly Savings of Buildings Within 0.5 Mile Radius" column
# prediction_table['Average Monthly Savings of Buildings Within 0.5 Mile Radius'] = [100, 200, 300]
# # Add "Tree Count Within 0.5 Mile Radius"
# prediction_table['Tree Count Within 0.5 Mile Radius'] = [10, 20, 30]
# # Load your model
# from pickle import load
# model = load(open('dummy-model.pkl', 'rb'))
# model
# # Run your model to add column "Monthly Savings"
#prediction_table['Monthly Savings'] = [1, 2, 3]
#X = prediction_table[['Periodic Savings within 0.5 Mile', 'Total Tree Count within 0.5 Mile']].values
## prediction_table['Monthly Savings'] = model.predict(X)
target_path = target_folder + '/savings.csv'
prediction_table.to_csv(target_path, index=False)
print(f'prediction_table_path = {target_path}')
target_path = target_folder + '/savings-map.csv'
map_table = prediction_table.copy()
map_table['RadiusInPixelsRange3-30'] = map_table['Periodic Savings']
map_table['FillColor'] = ['y' if index in df else 'b' for index in map_table.index]
map_table.to_csv(target_path, index=False)
print(f'prediction_geotable_path = {target_path}')
%matplotlib inline
axes = prediction_table[[
'Periodic Savings'
]].plot(kind='bar')
# Save file to target folder to include it in the result download
target_path = target_folder + '/c.png'
figure = axes.get_figure()
figure.savefig(target_path)
print(f'c_image_path = {target_path}')