From 3100c32b0f2023cf0229a2cd109326a5bdbe4723 Mon Sep 17 00:00:00 2001 From: wroberts <wroberts4@wisc.edu> Date: Mon, 16 Sep 2019 10:43:47 -0500 Subject: [PATCH] Fix mask being called in incorrect place --- aosstower/level_00/influxdb.py | 17 ++++++++--------- aosstower/tests/test_influxdb.py | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 aosstower/tests/test_influxdb.py diff --git a/aosstower/level_00/influxdb.py b/aosstower/level_00/influxdb.py index 541281b..434850e 100644 --- a/aosstower/level_00/influxdb.py +++ b/aosstower/level_00/influxdb.py @@ -92,8 +92,8 @@ class Updater(object): return self._calculate_averages() def _calculate_averages(self): - frame = pd.DataFrame(self.data) - frame = frame.set_index('timestamp').mask(frame == -99999.) + frame = pd.DataFrame(self.data).set_index('timestamp') + frame = frame.mask(frame == -99999.) # Add wind direction components so we can average wind direction properly. frame['wind_east'], frame['wind_north'], _ = calc.wind_vector_components(frame['wind_speed'], frame['wind_dir']) @@ -137,7 +137,7 @@ def convert_to_influx_frame(record_gen, symbols, debug=False): def construct_url(data): - # Sends data as empty string to show that recording worked, but that the data is nonexistent. + # Sends null data as empty string to show that recording worked, but that the data is nonexistent. for key, val in data.items(): if val is None or isinstance(val, float) and np.isnan(val): data[key] = '' @@ -241,13 +241,12 @@ def main(): # Record is in a list of size 1, but want just the record. avg = updater.rolling_average(record[0]) # Once every 5 minutes: 0 through 295 seconds inclusive in 5 second intervals. - if avg is not None: + if wu_pw and args.ldmp and avg is not None: url = construct_url(get_url_data(avg, args.wu_id, wu_pw)) - if wu_pw and args.ldmp: - resp = requests.post(url) - if resp.status_code != 200: - warnings.warn('Data failed to upload to {0} with status code {1}: {2}'.format( - url, resp.status_code, resp.text)) + resp = requests.post(url) + if resp.status_code != 200: + warnings.warn('Data failed to upload to {0} with status code {1}: {2}'.format( + url, resp.status_code, resp.text)) if args.sleep_interval: time.sleep(args.sleep_interval) diff --git a/aosstower/tests/test_influxdb.py b/aosstower/tests/test_influxdb.py new file mode 100644 index 0000000..9f9206a --- /dev/null +++ b/aosstower/tests/test_influxdb.py @@ -0,0 +1,23 @@ +import unittest + + +class TestInfluxdb(unittest.TestCase): + def setUp(self): + self.test_cases = [] + + def tearDown(self): + return + + + + +def suite(): + """The test suite for test_wind_functions.""" + loader = unittest.TestLoader() + mysuite = unittest.TestSuite() + mysuite.addTest(loader.loadTestsFromTestCase(TestInfluxdb)) + return mysuite + + +if __name__ == "__main__": + unittest.main() -- GitLab