-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataLoader.py
82 lines (56 loc) · 2.09 KB
/
dataLoader.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
import csv
from model.day import Day
from model.household import Household
# methods for loading data from csv
def load_all_data(file):
customer = []
with open(file) as solarData:
readCSV = csv.reader(solarData, delimiter=',')
# skip first line with comment in file
next(readCSV)
# skip headers
next(readCSV)
# store for households
customers = []
current_household = Household(1)
last_date = None
current_day = None
last_id = 1
lines = 0
for day in readCSV:
lines += 1
current_id = int(day[0])
day_energy = []
category = day[3]
current_date = day[4]
# day is separated to 48 30-mins period
for period in range(5, 53):
day_energy.append(float(day[period]))
if last_id < current_id:
# append last day
current_household.year.append(current_day)
# next customer
customers.append(current_household)
print('processed customer: ', current_id)
#set up new customer
current_household = Household(current_id)
current_household.generator_capacity = float(day[1])
last_id = current_id
last_date = None
if last_date == current_date:
# day exist - add data
current_day.add_data(category, day_energy)
elif (last_date != current_date) or (last_date is None):
if last_date is not None:
# add day to household
current_household.year.append(current_day)
# create new day
current_day = Day(current_date)
last_date = current_date
# add daily data
current_day.add_data(category, day_energy)
print('lines: ', lines)
# append last day
current_household.year.append(current_day)
customers.append(current_household)
return customers