@@ -22,6 +22,8 @@ def setUp(self):
22
22
self .today = datetime (2017 , 12 , 24 , 12 , 34 )
23
23
self .tomorrow = datetime (2017 , 12 , 25 , 12 , 34 )
24
24
self .last_month = datetime (2017 , 11 , 24 , 12 , 34 )
25
+
26
+ self .offset_hours = (pytz .timezone ('US/Pacific' ).localize (self .today ) - pytz .utc .localize (self .today )).total_seconds () / 3600 ;
25
27
self .now = pytz .utc .localize (datetime .utcnow ())
26
28
27
29
def test_idx2ts (self ):
@@ -83,6 +85,8 @@ def test_fetch_df_bad(self):
83
85
self .assertEqual (mode , 'error' )
84
86
85
87
def test_parse_load_today (self ):
88
+ local_hour = self .today .hour + self .offset_hours
89
+
86
90
with mock .patch .object (self .c , 'request' ) as mocker :
87
91
mocker .return_value = mock .Mock (status_code = 200 , content = self .one_day_response )
88
92
df , mode = self .c .fetch_df (self .today , url = 'http://mockurl' )
@@ -92,12 +96,13 @@ def test_parse_load_today(self):
92
96
data = self .c .parse_load (df , self .today )
93
97
94
98
# test
95
- self .assertEqual (len (data ), 18 )
96
- for idp , dp in enumerate (data ):
97
- self .assertEqual (dp ['market' ], 'RTHR' )
98
- self .assertEqual (dp ['freq' ], '1hr' )
99
- self .assertEqual (dp ['ba_name' ], 'NEVP' )
100
- self .assertEqual (dp ['load_MW' ], df .ix ['Actual System Load' , idp + 1 ])
99
+ self .assertEqual (len (data ), local_hour )
100
+
101
+ for idp , dp in enumerate (data ):
102
+ self .assertEqual (dp ['market' ], 'RTHR' )
103
+ self .assertEqual (dp ['freq' ], '1hr' )
104
+ self .assertEqual (dp ['ba_name' ], 'NEVP' )
105
+ self .assertEqual (dp ['load_MW' ], df .ix ['Actual System Load' , idp + 1 ])
101
106
102
107
def test_parse_load_tomorrow (self ):
103
108
with mock .patch .object (self .c , 'request' ) as mocker :
@@ -127,14 +132,16 @@ def test_parse_load_last_month(self):
127
132
data = self .c .parse_load (df , self .last_month )
128
133
129
134
# test
130
- self .assertEqual (len (data ), 18 )
135
+ self .assertEqual (len (data ), 24 )
131
136
for idp , dp in enumerate (data ):
132
137
self .assertEqual (dp ['market' ], 'RTHR' )
133
138
self .assertEqual (dp ['freq' ], '1hr' )
134
139
self .assertEqual (dp ['ba_name' ], 'NEVP' )
135
140
self .assertEqual (dp ['load_MW' ], df .ix ['Actual System Load' , idp + 1 ])
136
141
137
142
def test_parse_trade_today (self ):
143
+ local_hour = self .today .hour + self .offset_hours
144
+
138
145
with mock .patch .object (self .c , 'request' ) as mocker :
139
146
mocker .return_value = mock .Mock (status_code = 200 , content = self .one_day_response )
140
147
df , mode = self .c .fetch_df (self .today , url = 'http://mockurl' )
@@ -144,14 +151,14 @@ def test_parse_trade_today(self):
144
151
data = self .c .parse_trade (df , self .today )
145
152
146
153
# test
147
- self .assertEqual (len (data ), 18 * len (self .c .TRADE_BAS ))
154
+ self .assertEqual (len (data ), local_hour * len (self .c .TRADE_BAS ))
148
155
for idp , dp in enumerate (data ):
149
156
self .assertEqual (dp ['market' ], 'RTHR' )
150
157
self .assertEqual (dp ['freq' ], '1hr' )
151
158
self .assertIn (dp ['dest_ba_name' ], self .c .TRADE_BAS .values ())
152
159
153
160
dest = [k for k , v in self .c .TRADE_BAS .items () if v == dp ['dest_ba_name' ]][0 ]
154
- idx = idp % 18 + 1
161
+ idx = idp % local_hour + 1
155
162
self .assertEqual (dp ['export_MW' ], df .ix [dest , idx ])
156
163
157
164
def test_parse_trade_tomorrow (self ):
@@ -175,14 +182,14 @@ def test_parse_trade_last_month(self):
175
182
data = self .c .parse_trade (df , self .last_month )
176
183
177
184
# test
178
- self .assertEqual (len (data ), 18 * len (self .c .TRADE_BAS ))
185
+ self .assertEqual (len (data ), 24 * len (self .c .TRADE_BAS ))
179
186
for idp , dp in enumerate (data ):
180
187
self .assertEqual (dp ['market' ], 'RTHR' )
181
188
self .assertEqual (dp ['freq' ], '1hr' )
182
189
self .assertIn (dp ['dest_ba_name' ], self .c .TRADE_BAS .values ())
183
190
184
191
dest = [k for k , v in self .c .TRADE_BAS .items () if v == dp ['dest_ba_name' ]][0 ]
185
- idx = idp % 18 + 1
192
+ idx = idp % 24 + 1
186
193
self .assertEqual (dp ['export_MW' ], df .ix [dest , idx ])
187
194
188
195
def test_time_subset_latest (self ):
0 commit comments