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
54cf52dc
Verified
Commit
54cf52dc
authored
7 years ago
by
David Hoese
Browse files
Options
Downloads
Patches
Plain Diff
Add loggernet parsing to influxdb injector
parent
eec24620
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aosstower/level_00/influxdb.py
+14
-2
14 additions, 2 deletions
aosstower/level_00/influxdb.py
aosstower/level_00/parser.py
+15
-1
15 additions, 1 deletion
aosstower/level_00/parser.py
with
29 additions
and
3 deletions
aosstower/level_00/influxdb.py
+
14
−
2
View file @
54cf52dc
...
@@ -16,6 +16,7 @@ LOG = logging.getLogger(__name__)
...
@@ -16,6 +16,7 @@ LOG = logging.getLogger(__name__)
STATIONS
=
{
STATIONS
=
{
"
AOSS Tower
"
:
{
"
inst
"
:
"
tower
"
,
"
site
"
:
"
aoss
"
},
"
AOSS Tower
"
:
{
"
inst
"
:
"
tower
"
,
"
site
"
:
"
aoss
"
},
}
}
# parser symbols to influxdb symbols
SYMBOL_CONVERSIONS
=
{
SYMBOL_CONVERSIONS
=
{
'
stamp
'
:
'
timestamp
'
,
'
stamp
'
:
'
timestamp
'
,
'
box_temp
'
:
'
box_temp
'
,
'
box_temp
'
:
'
box_temp
'
,
...
@@ -46,6 +47,7 @@ SYMBOL_CONVERSIONS = {
...
@@ -46,6 +47,7 @@ SYMBOL_CONVERSIONS = {
}
}
SYMBOLS
=
list
(
SYMBOL_CONVERSIONS
.
values
())
SYMBOLS
=
list
(
SYMBOL_CONVERSIONS
.
values
())
def
main
():
def
main
():
import
argparse
import
argparse
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
,
formatter_class
=
argparse
.
ArgumentDefaultsHelpFormatter
)
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
,
formatter_class
=
argparse
.
ArgumentDefaultsHelpFormatter
)
...
@@ -53,6 +55,10 @@ def main():
...
@@ -53,6 +55,10 @@ def main():
parser
.
add_argument
(
'
-t
'
,
'
--tail
'
,
action
=
'
store_true
'
,
parser
.
add_argument
(
'
-t
'
,
'
--tail
'
,
action
=
'
store_true
'
,
help
=
(
'
Tail file forever, not returning. This will start at the end
'
help
=
(
'
Tail file forever, not returning. This will start at the end
'
'
of the file and insert any new data added after starting
'
))
'
of the file and insert any new data added after starting
'
))
parser
.
add_argument
(
'
--ldmp
'
,
action
=
'
store_true
'
,
help
=
'
Treat `src` file as a station name and read records from LoggerNet LDMP server (port: 1024)
'
)
parser
.
add_argument
(
'
--tables
'
,
nargs
=
'
*
'
,
default
=
[
'
RIGTower
'
],
help
=
"
LoggerNet LDMP tables to read in
"
)
parser
.
add_argument
(
"
--host
"
,
default
=
influxdb
.
DB_HOST
,
parser
.
add_argument
(
"
--host
"
,
default
=
influxdb
.
DB_HOST
,
help
=
"
Hostname of database connection
"
)
help
=
"
Hostname of database connection
"
)
parser
.
add_argument
(
"
--port
"
,
default
=
influxdb
.
DB_PORT
,
parser
.
add_argument
(
"
--port
"
,
default
=
influxdb
.
DB_PORT
,
...
@@ -74,10 +80,16 @@ def main():
...
@@ -74,10 +80,16 @@ def main():
LOG
.
info
(
"
source: %s
"
,
args
.
src
)
LOG
.
info
(
"
source: %s
"
,
args
.
src
)
LOG
.
info
(
"
tail: %s
"
,
args
.
tail
)
LOG
.
info
(
"
tail: %s
"
,
args
.
tail
)
station_tags
=
STATIONS
[
args
.
station
]
station_tags
=
STATIONS
[
args
.
station
]
src
=
open
(
args
.
src
,
"
r
"
)
symbols
=
SYMBOL_CONVERSIONS
symbols
=
SYMBOL_CONVERSIONS
for
idx
,
record
in
enumerate
(
read_frames
(
src
,
tail
=
args
.
tail
)):
if
args
.
ldmp
:
from
aosstower.level_00.parser
import
ldmp_generator
record_gen
=
ldmp_generator
(
args
.
src
,
args
.
tables
)
else
:
src
=
open
(
args
.
src
,
"
r
"
)
record_gen
=
read_frames
(
src
,
tail
=
args
.
tail
)
for
idx
,
record
in
enumerate
(
record_gen
):
LOG
.
info
(
"
Inserting records for frame %d
"
,
idx
)
LOG
.
info
(
"
Inserting records for frame %d
"
,
idx
)
record
=
{
symbols
[
k
]
or
k
:
v
for
k
,
v
in
record
.
items
()
if
k
in
symbols
}
record
=
{
symbols
[
k
]
or
k
:
v
for
k
,
v
in
record
.
items
()
if
k
in
symbols
}
lines
=
influxdb
.
frame_records
(
record
,
**
station_tags
)
lines
=
influxdb
.
frame_records
(
record
,
**
station_tags
)
...
...
This diff is collapsed.
Click to expand it.
aosstower/level_00/parser.py
+
15
−
1
View file @
54cf52dc
...
@@ -145,7 +145,8 @@ class ParserV1V2(object):
...
@@ -145,7 +145,8 @@ class ParserV1V2(object):
def
maybe_mine
(
line
):
def
maybe_mine
(
line
):
return
re
.
search
(
'
^\d,\d{4},\d{1,3}
'
,
line
)
is
not
None
return
re
.
search
(
'
^\d,\d{4},\d{1,3}
'
,
line
)
is
not
None
def
_get_stamp
(
self
,
parts
):
@staticmethod
def
_get_stamp
(
parts
):
year
=
int
(
parts
[
1
])
year
=
int
(
parts
[
1
])
doy
=
int
(
parts
[
2
])
doy
=
int
(
parts
[
2
])
dt
=
datetime
.
strptime
(
'
{:d}.{:03d}
'
.
format
(
int
(
year
),
int
(
doy
)),
'
%Y.%j
'
)
dt
=
datetime
.
strptime
(
'
{:d}.{:03d}
'
.
format
(
int
(
year
),
int
(
doy
)),
'
%Y.%j
'
)
...
@@ -212,3 +213,16 @@ def read_frames(source, error_handler=lambda *a: None, tail=False):
...
@@ -212,3 +213,16 @@ def read_frames(source, error_handler=lambda *a: None, tail=False):
# exactly what I need, it only executes if `break` does not execute
# exactly what I need, it only executes if `break` does not execute
else
:
else
:
error_handler
(
idx
+
1
,
line
,
RuntimeError
(
"
no parser found
"
,
line
))
error_handler
(
idx
+
1
,
line
,
RuntimeError
(
"
no parser found
"
,
line
))
def
loggernet_to_tower
(
rec_dict
):
"""
Convert loggernet record dictionary to our standard naming
"""
return
_make_frame
(
zip
(
ParserV1V2
.
names
,
rec_dict
.
values
()))
def
ldmp_generator
(
station_name
,
tables
):
from
metobscommon.archive.loggernet_receiver
import
dict_records
,
ldmp_receiver
receiver
=
ldmp_receiver
()
# This should be generated OrderedDicts
dict_rec_gen
=
dict_records
(
receiver
,
station_name
,
tables
)
return
(
loggernet_to_tower
(
x
)
for
x
in
dict_rec_gen
)
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