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
9749b866
Commit
9749b866
authored
5 years ago
by
William Roberts
Browse files
Options
Downloads
Patches
Plain Diff
Simplify and improve logic for 5 minute intervals
parent
1a5f5e3e
Branches
master
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aosstower/level_00/influxdb.py
+10
-41
10 additions, 41 deletions
aosstower/level_00/influxdb.py
with
10 additions
and
41 deletions
aosstower/level_00/influxdb.py
+
10
−
41
View file @
9749b866
...
...
@@ -70,55 +70,24 @@ class Updater(object):
def
rolling_average
(
self
,
record
):
self
.
start_time
=
self
.
start_time
if
self
.
start_time
else
record
[
'
timestamp
'
]
time_interval
=
(
record
[
'
timestamp
'
]
-
self
.
start_time
).
total_seconds
()
# Add in 5 minutes for cutoff
start
=
record
[
'
timestamp
'
]
-
timedelta
(
seconds
=
time_interval
%
300
)
end
=
self
.
start_time
+
timedelta
(
minutes
=
5
)
if
time_interval
>
300
:
for
key
in
record
:
if
key
==
'
timestamp
'
:
self
.
data
[
key
]
=
np
.
append
(
self
.
data
[
key
],
end
)
else
:
self
.
data
[
key
]
=
np
.
append
(
self
.
data
[
key
],
np
.
nan
)
else
:
for
key
in
record
:
if
self
.
data
.
get
(
key
)
is
None
:
self
.
data
[
key
]
=
np
.
array
([])
self
.
data
[
key
]
=
np
.
append
(
self
.
data
[
key
],
record
[
key
])
for
key
in
record
:
if
self
.
data
.
get
(
key
)
is
None
:
self
.
data
[
key
]
=
np
.
array
([])
self
.
data
[
key
]
=
np
.
append
(
self
.
data
[
key
],
record
[
key
])
# If 5 minutes of data are ready, average current data in dict. Holds up to 15 minutes.
# 60 * 5 seconds = 5 minutes.
if
time_interval
>=
300
:
if
time_interval
>=
300
or
(
record
[
'
timestamp
'
].
minute
%
5
==
0
and
record
[
'
timestamp
'
].
second
==
0
)
:
# Appending to a DataFrame is slow. Instead, this adds to a dict in chunks and passes it to the DataFrame.
frame
=
self
.
_calculate_averages
()
frame
.
fillna
(
value
=
np
.
nan
,
inplace
=
True
)
print
(
frame
[
'
rel_hum
'
])
print
(
frame
.
resample
(
'
5T
'
,
closed
=
'
right
'
).
mean
()[
'
rel_hum
'
])
print
(
frame
.
asfreq
(
'
5T
'
)[
'
rel_hum
'
])
# Keep data set within minimum window to improve speed.
# Wind gusts looks at 10 minute intervals, including the first data point which needs 2 minutes of data
# before it, totalling 12 minutes.
test
=
frame
.
asfreq
(
'
5T
'
)
if
len
(
test
.
index
)
>
3
:
new_frame
=
frame
.
copy
()
new_frame
[
'
timestamp
'
]
=
list
(
new_frame
.
index
)
data
=
new_frame
.
drop
(
new_frame
.
index
[:
new_frame
.
index
.
get_loc
(
test
.
index
[
-
3
])]).
to_dict
(
'
list
'
)
for
key
in
self
.
data
:
self
.
data
[
key
]
=
data
[
key
]
if
time_interval
>
300
:
for
key
in
record
:
if
key
==
'
timestamp
'
:
if
end
!=
start
:
self
.
data
[
key
]
=
np
.
array
([
start
])
else
:
if
end
!=
start
:
self
.
data
[
key
]
=
np
.
array
([
np
.
nan
])
self
.
start_time
=
self
.
data
[
'
timestamp
'
][
-
1
]
for
key
in
record
:
if
self
.
data
.
get
(
key
)
is
None
:
self
.
data
[
key
]
=
np
.
array
([])
self
.
data
[
key
]
=
np
.
append
(
self
.
data
[
key
],
record
[
key
])
else
:
self
.
start_time
=
self
.
data
[
'
timestamp
'
][
-
1
]
return
test
time_mask
=
frame
.
index
>
frame
.
index
[
-
1
]
-
timedelta
(
minutes
=
12
)
self
.
data
=
{
key
:
val
[
time_mask
]
for
key
,
val
in
self
.
data
.
items
()}
self
.
start_time
=
self
.
data
[
'
timestamp
'
][
-
1
]
if
record
[
'
timestamp
'
].
minute
%
5
==
0
and
record
[
'
timestamp
'
].
second
==
0
:
return
frame
def
_calculate_averages
(
self
):
KNOTS_9
=
calc
.
knots_to_mps
(
9.
)
...
...
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