Skip to content
Snippets Groups Projects
Commit 3bd4c27c authored by William Roberts's avatar William Roberts
Browse files

Improve comments and make url "url escaped"

parent 255053ee
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ import time ...@@ -9,6 +9,7 @@ import time
import sys import sys
import requests import requests
from datetime import timedelta from datetime import timedelta
from urllib.parse import urlencode
from metobscommon import influxdb from metobscommon import influxdb
from aosstower.level_00.parser import read_frames from aosstower.level_00.parser import read_frames
from metobscommon.util import calc from metobscommon.util import calc
...@@ -70,8 +71,9 @@ class Updater(object): ...@@ -70,8 +71,9 @@ class Updater(object):
self.submit_interval = submit_interval.total_seconds() self.submit_interval = submit_interval.total_seconds()
def rolling_average(self, record): 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) 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: for key in record:
if self.data.get(key) is None: if self.data.get(key) is None:
self.data[key] = np.array([]) self.data[key] = np.array([])
...@@ -130,35 +132,19 @@ def convert_to_influx_frame(record_gen, symbols, debug=False): ...@@ -130,35 +132,19 @@ def convert_to_influx_frame(record_gen, symbols, debug=False):
def construct_url(data): 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(): for key, val in data.items():
if val is None or isinstance(val, float) and np.isnan(val): if val is None or isinstance(val, float) and np.isnan(val):
data[key] = '' data[key] = ''
return ('http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?' # Makes url be "url escaped".
'ID={ID}&' return 'http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?' + urlencode(data)
'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)
def get_url_data(avg, wu_id, wu_pw): def get_url_data(avg, wu_id, wu_pw):
# Information on what paramaters that can be sent: # Information on what paramaters that can be sent:
# https://feedback.weather.com/customer/en/portal/articles/2924682-pws-upload-protocol?b_id=17298 # 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. # 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 = avg['wind_dir'][-1]
wind_dir_2m = avg['wind_dir_2m'][-1] wind_dir_2m = avg['wind_dir_2m'][-1]
rel_hum = avg['rel_hum'][-1] rel_hum = avg['rel_hum'][-1]
...@@ -178,7 +164,8 @@ def get_url_data(avg, wu_id, wu_pw): ...@@ -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, 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, 'windspeedmph': wind_speed, 'windspdmph_avg2m': wind_speed_2m, 'windgustmph': gust_1m,
'windgustmph_10m': gust_10m, 'humidity': rel_hum, 'tempf': air_temp, 'baromin': pressure, '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(): def main():
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment