-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader.py
76 lines (53 loc) · 2.2 KB
/
loader.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
from __future__ import annotations
import csv
import numpy as np
import pandas as pd
dataset_dir = 'dataset/'
output_dir = 'outputs/'
Genome = dict[int, tuple[int, int]]
def load_demand_points(year: int) -> pd.DataFrame:
historic = pd.read_csv(dataset_dir + 'Demand_History.csv')
prophet_predictions = pd.read_csv(dataset_dir + 'v2_ensemble_2019_2020.csv')
if year == 2019:
predictions = prophet_predictions.drop(
['2020'], axis=1).rename(columns={'2019': 'value'})
elif year == 2020:
predictions = prophet_predictions.drop(
['2019'], axis=1).rename(columns={'2020': 'value'})
predictions.insert(1, 'x', historic.x_coordinate)
predictions.insert(2, 'y', historic.y_coordinate)
return predictions
def load_infrastructure() -> pd.DataFrame:
existing = pd.read_csv(dataset_dir + 'exisiting_EV_infrastructure_2018.csv')
return existing.rename(
{
'x_coordinate': 'x',
'y_coordinate': 'y',
'existing_num_SCS': 'scs',
'existing_num_FCS': 'fcs'
},
axis=1)
def load_distance() -> np.ndarray:
return np.load(dataset_dir + 'distance.npy')
def load_rev_proximity() -> np.ndarray:
return np.load(dataset_dir + 'reverse_proximity.npy')
def load_previous_chargers(year: int) -> Genome:
if year == 2019:
existing_infra = load_infrastructure()
elif year == 2020:
existing_infra = pd.read_csv(output_dir + 'chargers_2019.csv')
else:
raise ValueError('Invalid year')
return {ind: (int(x.scs), int(x.fcs)) for ind, x in existing_infra.iterrows()}
def load_chargers(year: int) -> pd.DataFrame:
return pd.read_csv(output_dir + f'chargers_{year}.csv')
def load_ds(year: int) -> np.ndarray:
return np.load(output_dir + f'ds_{year}.npy')
def output_chargers(supply_chargers: Genome, year: int) -> None:
with open(output_dir + f'chargers_{year}.csv', 'w', newline='') as f:
writer = csv.writer(f)
writer.writerow(['scs', 'fcs'])
for _, (scs, fcs) in supply_chargers.items():
writer.writerow([scs, fcs])
def output_distribution(ds: np.ndarray, year: int) -> None:
np.save(output_dir + f'ds_{year}.npy', ds)