-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathprocessData.py
More file actions
100 lines (81 loc) · 3.58 KB
/
processData.py
File metadata and controls
100 lines (81 loc) · 3.58 KB
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
96
97
98
99
100
import time
class processData :
BUFFERING = 'BUFFERING'
LOG_PREV_SAME = 'LOG_PREV_SAME'
LOG_PREV_DIFF = 'LOG_PREV_DIFF'
INTERPOLATE = 'INTERPOLATE'
#--------------------------------------------------------------------------
def __init__( self, pvoutput):
# Processing class. This class converts the data from the Goodwe logging
# frequency of once every 10 min, to the log interval of 5 min of PVoutput
# by interpolating.
#
self.m_switch = {self.BUFFERING: self.buffering,
self.LOG_PREV_SAME: self.logging,
self.LOG_PREV_DIFF: self.logging,
self.INTERPOLATE: self.interpolate}
self.m_state = self.BUFFERING
self.m_prev_sample = None
self.m_pvoutput = pvoutput
#--------------------------------------------------------------------------
def state_to_string( self):
# Converts the state to a string
#
return self.m_state
#--------------------------------------------------------------------------
def update_state( self, sample):
# Updates the state.
#
if not self.m_prev_sample:
self.m_state == self.BUFFERING
else:
if sample.is_identical( self.m_prev_sample):
self.m_state = self.LOG_PREV_SAME
else:
if self.m_state == self.LOG_PREV_SAME:
self.m_state = self.INTERPOLATE
else:
self.m_state = self.LOG_PREV_DIFF
#--------------------------------------------------------------------------
def logging( self, sample):
# Processes the LOGGING state. This logs the m_prev_sample data
#
if self.m_pvoutput:
self.m_pvoutput.post_data( self.m_prev_sample)
t = time.localtime(time.time())
print "Logging: " + str(t.tm_hour).zfill(2) + ':' + str(t.tm_min).zfill(2) + "h " + self.m_prev_sample.to_short_string()
#--------------------------------------------------------------------------
def buffering( self, sample):
# Processes the BUFFERING state. Basically does nothing.
#
t = time.localtime(time.time())
print "Buffering: " + str(t.tm_hour).zfill(2) + ':' + str(t.tm_min).zfill(2) + "h " + sample.to_short_string()
#--------------------------------------------------------------------------
def interpolate( self, sample):
# Interpolates the current and the previous sample by using linear interpolation.
#
sample1 = sample.interpolate( self.m_prev_sample)
if self.m_pvoutput:
self.m_pvoutput.post_data( sample1)
t = time.localtime(time.time())
print "Interpol.: " + str(t.tm_hour).zfill(2) + ':' + str(t.tm_min).zfill(2) + "h " + sample1.to_short_string()
self.m_state = self.LOG_PREV_DIFF
#--------------------------------------------------------------------------
def reset( self):
# Resets the processing class when the inverter goes offline and logs the
# last sample.
#
# Flush the last dat apoint to PVoutput
if self.m_prev_sample:
self.logging( self.m_prev_sample)
self.m_state = self.BUFFERING
self.m_prev_sample = None
#--------------------------------------------------------------------------
def processSample( self, sample):
# This method processes the sample by calling the method associated with the
# current state
#
self.update_state( sample)
self.m_switch[self.m_state](sample)
self.m_prev_sample = sample
#---------------- End of file ------------------------------------------------