
import pandas as pd

cities_file = pd.read_csv('./ES CITIES.csv')
values_file = pd.read_csv('./ES VALUES.csv')

# global warming generated per bike (bike_factor)
bike_manufacturing = float(values_file['Bicycle manufacturing'][1])
print(bike_manufacturing)
maintenance = float(values_file['Maintenance'][1])
bike_disposal = float(values_file['Bicycle disposal'][1])
bike_factor = (bike_manufacturing + maintenance + bike_disposal)

# global warming generated per station (stations_factor)
stations_manufacturing = float(values_file['Station manufacturing'][1])
stations_disposal = float(values_file['Station disposal'][1])
stations_factor = (stations_manufacturing + stations_disposal)

# global warming generated per dock (docks_factor)
docks_manufacturing = float(values_file['Dock manufacturing'][1])
docks_disposal = float(values_file['Dock disposal'][1])
docks_factor = (docks_manufacturing + docks_disposal)

# rebalancing factor
rebalance_dock = float(values_file['Rebalancing'][1])
rebalance_dockless = float(values_file['Rebalancing'][15])


resultList = [9, "EmissionsCalculation"]
resultList_bikes = [10, "BikesEmmissionsCalculation"]
resultList_stations = [11, "StationsEmissionsCalculation"]
resultList_docks = [12, "DocksEmissionsCalculation"]
resultList_rebalance = [13, "RebalanceEmissionsCalculation"]

columns = cities_file.columns

# print('DOCK')
for i in range(2, 10):
    num_bikes = cities_file.iloc[0, i]
    num_bikes = float(num_bikes)
    num_stations = cities_file.iloc[1, i]
    num_stations = float(num_stations)
    num_docks = cities_file.iloc[2, i]
    num_docks = float(num_docks)
    total_distance = cities_file.iloc[5, i]
    total_distance = float(total_distance)

    # for loop that collects data for bikes, stations, docks, and total distance from each city
    gw_bikes = (num_bikes * bike_factor)

    # takes number of bikes in a city and multiplys it by global warming caused by each bike
    gw_stations = (stations_factor * num_stations)

    # takes number of stations in a city and multiplys it by global warming caused by each station
    gw_docks = (num_docks * docks_factor)

    # takes number of docks in a city and multiplys it by global warming caused by each dock
    gw_rebalance = (rebalance_dock * 259 * num_bikes)

    # Version 2.0
    gw_bikes_total = (gw_bikes / total_distance)

    gw_stations_total = (gw_stations / total_distance)

    gw_docks_total = (gw_docks / total_distance)

    gw_rebalance_total = (gw_rebalance / total_distance)

    # global warming caused by rebalancing a bike 1km X 259 km (over 10 years) X the number of bikes in a city
    gw_total = ((gw_bikes + gw_stations + gw_docks + gw_rebalance)/(total_distance))

    resultList.append(gw_total)
    resultList_bikes.append(gw_bikes_total)
    resultList_docks.append(gw_docks_total)
    resultList_stations.append(gw_stations_total)
    resultList_rebalance.append(gw_rebalance_total)
    # calculates global warming generated by BSS in a city divided by the total distance traveled using the BSS
    print(gw_total, 'Kg CO2 eq')


dl_bike_manufacturing = float(values_file['Bicycle manufacturing'][15])
dl_maintenance = float(values_file['Maintenance'][15])
dl_bike_disposal = float(values_file['Bicycle disposal'][15])
dl_bike_factor = (dl_bike_manufacturing + dl_maintenance + dl_bike_disposal)

# global warming generated per dockless bike
# print('DOCKLESS')
for i in range(9, 11):
    dl_num_bikes = cities_file.iloc[0, i]
    dl_num_bikes = float(dl_num_bikes)
    dl_total_distance = cities_file.iloc[5, i]
    dl_total_distance = float(dl_total_distance)
    # for loop that collects data for dockless bikes and total distance from each city
    dl_gw_bikes = (dl_num_bikes * dl_bike_factor)

    # takes number of dockless bikes in a city and multiplys it by global warming caused by each bike
    dl_gw_rebalance = (rebalance_dockless * 259 * num_bikes)

    # global warming caused by rebalancing a dockless bike 1km X 259 km (over 10 years) X the number of bikes in a city
    dl_gw_total = ((dl_gw_bikes + dl_gw_rebalance)/(dl_total_distance))
    resultList.append(dl_gw_total)
    resultList_bikes.append(dl_gw_bikes)
    resultList_docks.append(0)
    resultList_stations.append(0)
    resultList_rebalance.append(dl_gw_rebalance)

    # calculates global warming generated by dockless BSS in a city divided by the total distance traveled using the BSS
    print(dl_gw_total, 'Kg CO2 eq')

print(resultList)
df = pd.DataFrame([resultList], columns=cities_file.columns)
df1 = pd.DataFrame([resultList_bikes] , columns=cities_file.columns)
df2 = pd.DataFrame([resultList_docks] , columns=cities_file.columns)
df3 = pd.DataFrame([resultList_stations] , columns=cities_file.columns)
df4 = pd.DataFrame([resultList_rebalance] , columns=cities_file.columns)
print(df)

print(cities_file)

cities_file = cities_file.append(df, ignore_index=True)
cities_file = cities_file.append(df1, ignore_index=True)
cities_file = cities_file.append(df2, ignore_index=True)
cities_file = cities_file.append(df3, ignore_index=True)
cities_file = cities_file.append(df4, ignore_index=True)


print(cities_file)
cities_file.to_csv("./results.csv")
# cities_file.to_csv('C:/Users/bawr7/OneDrive/Desktop/ES CITIES.csv')
# values_file.to_csv('C:/Users/bawr7/OneDrive/Desktop/ES VALUES.csv')
