-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataLoader.py
80 lines (75 loc) · 2.68 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
from __future__ import annotations
from typing import *
from datetime import datetime, timedelta
import numpy as np
if len(__name__.split("."))==1:
from calc import PowerData, Period
else:
from .calc import PowerData, Period
class dataloader():
def load_prod(self, path : str, startDate : Optional[datetime] = None) -> PowerData:
#expecting a csv mm/dd/yyyy hh:mm:ss,"12,34"
with open(path) as inp:
first_line = True
dates = []
power = []
for line in inp:
if first_line or line.strip() == '':
first_line = False
continue
splittedLine = line.split('"')
if (len(splittedLine) == 1):
splittedLine = line.split(",")
date = datetime.strptime(splittedLine[0].strip(","), "%m/%d/%Y %H:%M:%S")
if (startDate != None and date < startDate):
continue
dates.append(date)
power.append(float(splittedLine[1].replace(",", ".")))
return PowerData(dates, np.array(power))
def load_one_user(self, path : str, startDate : Optional[datetime] = None) -> PowerData:
#expecting a csv mm/dd/yyyy hh:mm:ss,"12,34"
with open(path) as inp:
first_line = True
dates = []
power = []
for line in inp:
if first_line or line.strip() == '':
first_line = False
continue
splittedLine = line.split(';')
date = datetime.strptime(splittedLine[0][:16], "%Y-%m-%dT%H:%M")
date -= timedelta(hours = int(splittedLine[0].split("+")[1][:2]))
if (startDate != None and date < startDate):
continue
dates.append(date)
power.append(float(splittedLine[1]))
return PowerData(dates, np.array(power))
def load_solar_panel_prod(self, path : str, startDate : Optional[datetime] = None) -> PowerData:
#expecting a csv mm/dd/yyyy hh:mm:ss,"12,34"
with open(path) as inp:
dates = []
power = []
for line in inp:
splittedLine = line.split(';')
date = datetime.strptime(splittedLine[0], "%Y-%m-%d:%H")
if (startDate != None and date < startDate):
continue
dates.append(date)
power.append(float(splittedLine[1]))
return PowerData(dates, np.array(power))
def load_wind_prod(self, path : str, startDate : Optional[datetime] = None, index : int = 2, skip : bool = True) -> PowerData:
#expecting a csv mm/dd/yyyy hh:mm:ss,"12,34"
with open(path) as inp:
dates = []
power = []
for line in inp:
if (skip):
skip = False
continue
splittedLine = line.split(';')
date = datetime.strptime(splittedLine[0][:13], "%Y-%m-%d %H")
if (startDate != None and date < startDate):
continue
dates.append(date)
power.append(float(splittedLine[index].replace(",", ".")))
return PowerData(dates, np.array(power))