-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
96 lines (71 loc) · 2.87 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 20 11:32:12 2020
@authors: Katherine Collett and Sivapriya Bhagavathy
"""
#Import Python core modules
import os
import pandas as pd
import numpy as np
#Import custom modules
import dataextract
import analyzer
path=os.getcwd()
os.chdir(path)
#defining file names
netVehicleDataFile = 'veh0122.xlsx'
evDataFile = 'veh0132.xlsx'
countyDataFile = 'CountyDistricts.xlsx'
la2CountyFile = 'LA2County.xlsx'
#set year and quarter
year = "2021"
Quarter = "Q1"
#Opening files
netVehicleData = dataextract.Dataextract(netVehicleDataFile)
netVehicleData.openfile(sheet=0, sheet_type = 'xlsx')
electricVehicleData = dataextract.Dataextract(evDataFile)
electricVehicleData.openfile(sheet=2,sheet_type = 'xlsx')
countyData = dataextract.Dataextract(countyDataFile)
countyData.openfile(sheet=1,sheet_type = 'xlsx')
la2CountyData = dataextract.Dataextract(la2CountyFile)
la2CountyData.openfile(sheet=1,sheet_type = 'xlsx')
#cleaning Data
netVehicleData.cleanseVehData(countyData = countyData.rawdf)
electricVehicleData.cleanseEVData(countyData = la2CountyData.rawdf)
#analysis and prepping for csv
regions = netVehicleData.rawdf.columns
historic_data_Qs = netVehicleData.rawdf.index
test_matching = electricVehicleData.rawdf.index
if (test_matching == historic_data_Qs).all() == False:
print("Quarters do not match")
data_to_save_historic = pd.DataFrame()
data_to_save_S_curve = pd.DataFrame()
index_year = 2011
index_Q = 4
S_curve_index = [None]*520
for n in range(520):
S_curve_index[n] = f"{index_year} Q{index_Q}"
if index_Q == 4:
index_Q = 1
index_year += 1
else: index_Q += 1
for place in regions:
sCurveData = analyzer.analyzer(electricVehicleData.rawdf,netVehicleData.rawdf)
sCurveData.analyseDataforSCurveCumulative(place)
data_to_save_historic['Quarter'] = historic_data_Qs
header_2 = str(place + '_total_vehicles')
data_to_save_historic[header_2] = netVehicleData.rawdf[place].values.tolist()
header_3 = str(place + '_EVs')
data_to_save_historic[header_3] = electricVehicleData.rawdf[place].values.tolist()
header_1 = str(place + '_historic_percent_EV')
data_to_save_historic[header_1] = np.around(sCurveData.region_EVHistoricData,5)
data_to_save_S_curve['Quarter'] = S_curve_index
header_4 = str(place + '_S_curve')
data_to_save_S_curve[header_4] = np.around(sCurveData.s_region_series, 5)
length = 354 #to select data until 2100 Q1
data_to_save_S_curve = data_to_save_S_curve[:length]
title_historic = "Percent_cumulative_EVs_historic_" + year + '_' + Quarter + ".xlsx"
title_S_curve = "Percent_cumulative_EVs_S_curve_" + year + '_' + Quarter + ".xlsx"
data_to_save_historic.to_excel(title_historic,index=False, sheet_name = year + '_' + Quarter)
data_to_save_S_curve.to_excel(title_S_curve,index=False, sheet_name = year + '_' + Quarter)