def test_parse_data_kwh(self): response = JmaIrradiationResponse(self.csv_data, kwh=True) expected = [[0.70277, 1.930555555, 1.58611], [0.29722, 0.988888, 1.2611], [3.058333, 3.2444, 3.0388], [3.425, 3.41944, 3.2527], [1.75, 1.39444, 1.46388], [1.513888, 1.55, 1.4]] for i, row in enumerate(response.csv): self.assertAlmostEqual(row['Fukuoka'], expected[i][0], 3) self.assertAlmostEqual(row['Saga'], expected[i][1], 3) self.assertAlmostEqual(row['Nagasaki'], expected[i][2], 3)
def test_parse_data_lta_kwh(self): response = JmaIrradiationResponse(self.csv_data_with_lta, kwh=True) expected = [ [1.113888, 1.638888, 0.68333, 1.11111], [2.266666, 1.638888, 0.67777, 1.11111], ] for i, row in enumerate(response.csv): self.assertAlmostEqual(row['Morioka'], expected[i][0], 3) self.assertAlmostEqual(row['Morioka_LT'], expected[i][1], 3) self.assertAlmostEqual(row['Akita'], expected[i][2], 3) self.assertAlmostEqual(row['Akita_LT'], expected[i][3], 3)
def test_parse_data_lta(self): response = JmaIrradiationResponse(self.csv_data_with_lta) expected = [ [4.01, 5.9, 2.46, 4.0], [8.16, 5.9, 2.44, 4.0], ] for i, row in enumerate(response.csv): self.assertAlmostEqual(row['Morioka'], expected[i][0], 3) self.assertAlmostEqual(row['Morioka_LT'], expected[i][1], 3) self.assertAlmostEqual(row['Akita'], expected[i][2], 3) self.assertAlmostEqual(row['Akita_LT'], expected[i][3], 3)
def test_parse_data_incomplete_kwh(self): response = JmaIrradiationResponse(self.csv_data_incomplete, kwh=True) row0 = response.csv[0] row1 = response.csv[1] self.assertAlmostEqual(row0['Matsue'], 1.624999, 3) self.assertAlmostEqual(row1['Matsue'], 0.994444, 3) self.assertIsNone(row0['Matsue_LT']) self.assertIsNone(row1['Matsue_LT']) self.assertIsNone(row0['山口']) self.assertIsNone(row1['山口']) self.assertIsNone(row0['山口_LT']) self.assertIsNone(row1['山口_LT'])
def test_parse_data(self): response = JmaIrradiationResponse(self.csv_data) expected = [ [2.53, 6.95, 5.71], [1.07, 3.56, 4.54], [11.01, 11.68, 10.94], [12.33, 12.31, 11.71], [6.30, 5.02, 5.27], [5.45, 5.58, 5.04], ] for i, row in enumerate(response.csv): self.assertAlmostEqual(row['Fukuoka'], expected[i][0], 3) self.assertAlmostEqual(row['Saga'], expected[i][1], 3) self.assertAlmostEqual(row['Nagasaki'], expected[i][2], 3)
def get_daily_irradiation(self, start_date, end_date, stations, lta=False): """Download irradiation data in increments of 1 day. Args: start_date (datetime.date) - First date for which irradiation data will be downloaded end_date (datetime.date) - Last date (inclusive) for which irradiation data will be downloaded stations (List[JmaStation]) - Iterable of JmaStation lta (bool) - True if long-term average irradation should be included in results Returns: JmaIrradiationResponse """ date_arr = [ start_date.year, end_date.year, start_date.month, end_date.month, start_date.day, end_date.day, ] opts = '[["op1",0]]' if lta else [] params = { 'stationNumList': encode_list_for_jma([stn.value for stn in stations]), 'aggrgPeriod': 1, 'elementNumList': '[["610",""]]', 'interAnnualFlag': 1, 'ymdList': encode_list_for_jma(date_arr), 'optionNumList': opts, 'downloadFlag': True, 'rmkFlag': 0, 'disconnectFlag': 0, 'youbiFlag': 0, 'fukenFlag': 0, 'kijiFlag': 0, 'huukouFlag': 0, 'csvFlag': 0, 'jikantaiFlag': 0, 'jikantaiList': [], 'ymdLiteral': 1, 'PHPSESSID': self.php_sessid, } res = self._send_request(params) return JmaIrradiationResponse(res.text, kwh=self.kwh)
def test_parse_dates(self): response = JmaIrradiationResponse(self.csv_data) dates = [row['Date'] for row in response.csv] for i, date in enumerate(dates): self.assertEqual(f'2021-01-{i+1:02}', date)
def test_parse_headers_lta(self): response = JmaIrradiationResponse(self.csv_data_with_lta) expected = ['Date', 'Morioka', 'Morioka_LT', 'Akita', 'Akita_LT'] self.assertListEqual(expected, response.headers)
def test_parse_headers(self): response = JmaIrradiationResponse(self.csv_data) expected = ['Date', 'Fukuoka', 'Saga', 'Nagasaki'] self.assertListEqual(expected, response.headers)