diff --git a/aosstower/level_00/influxdb.py b/aosstower/level_00/influxdb.py index 512635c1118a58b2567e1defe2c92c5c93eba716..5610634909d60a1c1499719071e22d428ae28d8a 100644 --- a/aosstower/level_00/influxdb.py +++ b/aosstower/level_00/influxdb.py @@ -9,6 +9,7 @@ import time import sys import requests from datetime import timedelta +from urllib.parse import urlencode from metobscommon import influxdb from aosstower.level_00.parser import read_frames from metobscommon.util import calc @@ -70,8 +71,9 @@ class Updater(object): self.submit_interval = submit_interval.total_seconds() def rolling_average(self, record): - # Appending to a DataFrame is slow. Instead, this adds to a dict in chunks and passes it to the DataFrame. + # Keeps data within 12 minutes. time_mask = self.data['timestamp'] > record['timestamp'] - timedelta(minutes=12) + # Appending to a DataFrame is slow. Instead, this adds to a np array in chunks and passes it to the DataFrame. for key in record: if self.data.get(key) is None: self.data[key] = np.array([]) @@ -130,35 +132,19 @@ 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. for key, val in data.items(): if val is None or isinstance(val, float) and np.isnan(val): data[key] = '' - return ('http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?' - 'ID={ID}&' - 'PASSWORD={PASSWORD}&' - 'action=updateraw&' - 'dateutc={dateutc}&' - 'winddir={winddir}&' - 'winddir_avg2m={winddir_avg2m}&' - 'windspeedmph={windspeedmph}&' - 'windspdmph_avg2m={windspdmph_avg2m}&' - 'windgustmph={windgustmph}&' - 'windgustmph_10m={windgustmph_10m}&' - 'humidity={humidity}&' - 'tempf={tempf}&' - 'baromin={baromin}&' - 'dewptf={dewptf}&' - 'solarradiation={solarradiation}&' - 'rainin={rainin}&' - 'dailyrainin={dailyrainin}&' - 'softwaretype=SSEC-RIG').format(**data) + # Makes url be "url escaped". + return 'http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?' + urlencode(data) def get_url_data(avg, wu_id, wu_pw): # Information on what paramaters that can be sent: # https://feedback.weather.com/customer/en/portal/articles/2924682-pws-upload-protocol?b_id=17298 # For timestamp, want YYYY-MM-DD+hh:mm:ss of last dataset that was averaged, rounded up to nearest minute. - timestamp = avg.index[-1].isoformat('+') + timestamp = avg.index[-1] wind_dir = avg['wind_dir'][-1] wind_dir_2m = avg['wind_dir_2m'][-1] rel_hum = avg['rel_hum'][-1] @@ -178,7 +164,8 @@ def get_url_data(avg, wu_id, wu_pw): return {'ID': wu_id, 'PASSWORD': wu_pw, 'dateutc': timestamp, 'winddir': wind_dir, 'winddir_avg2m': wind_dir_2m, 'windspeedmph': wind_speed, 'windspdmph_avg2m': wind_speed_2m, 'windgustmph': gust_1m, 'windgustmph_10m': gust_10m, 'humidity': rel_hum, 'tempf': air_temp, 'baromin': pressure, - 'dewptf': dewpoint, 'solarradiation': solar_flux, 'rainin': precip, 'dailyrainin': accum_precip} + 'dewptf': dewpoint, 'solarradiation': solar_flux, 'rainin': precip, 'dailyrainin': accum_precip, + 'softwaretype': 'SSEC-RIG', 'action': 'updateraw'} def main():