Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AossTower
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MetObs
AossTower
Commits
3bd4c27c
Commit
3bd4c27c
authored
5 years ago
by
William Roberts
Browse files
Options
Downloads
Patches
Plain Diff
Improve comments and make url "url escaped"
parent
255053ee
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aosstower/level_00/influxdb.py
+9
-22
9 additions, 22 deletions
aosstower/level_00/influxdb.py
with
9 additions
and
22 deletions
aosstower/level_00/influxdb.py
+
9
−
22
View file @
3bd4c27c
...
...
@@ -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
():
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment