Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MetObsAPI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
MetObsAPI
Commits
1b57f220
Unverified
Commit
1b57f220
authored
8 years ago
by
David Hoese
Browse files
Options
Downloads
Patches
Plain Diff
Replace original data api logic for short symbol names
When site and inst are specified don't use the whole symbol name
parent
aba7f006
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
metobsapi/data_api.py
+12
-8
12 additions, 8 deletions
metobsapi/data_api.py
metobsapi/tests/test_data_api.py
+3
-3
3 additions, 3 deletions
metobsapi/tests/test_data_api.py
with
15 additions
and
11 deletions
metobsapi/data_api.py
+
12
−
8
View file @
1b57f220
...
@@ -121,7 +121,7 @@ def calc_num_records(begin, end, interval):
...
@@ -121,7 +121,7 @@ def calc_num_records(begin, end, interval):
return
diff
/
data_responses
.
INTERVALS
[
interval
]
return
diff
/
data_responses
.
INTERVALS
[
interval
]
def
handle_csv
(
frame
,
symbols
,
epoch
,
sep
=
'
,
'
,
def
handle_csv
(
frame
,
epoch
,
sep
=
'
,
'
,
message
=
''
,
code
=
200
,
status
=
'
success
'
,
**
kwargs
):
message
=
''
,
code
=
200
,
status
=
'
success
'
,
**
kwargs
):
output
=
"""
# status: {status}
output
=
"""
# status: {status}
# code: {code:d}
# code: {code:d}
...
@@ -150,7 +150,7 @@ def handle_csv(frame, symbols, epoch, sep=',',
...
@@ -150,7 +150,7 @@ def handle_csv(frame, symbols, epoch, sep=',',
message
=
message
,
message
=
message
,
num_results
=
frame
.
shape
[
0
],
num_results
=
frame
.
shape
[
0
],
epoch_str
=
epoch_str
,
epoch_str
=
epoch_str
,
symbol_list
=
sep
.
join
(
symbol
s
),
symbol_list
=
sep
.
join
(
frame
.
column
s
),
symbol_data
=
"
\n
"
.
join
(
data_lines
),
symbol_data
=
"
\n
"
.
join
(
data_lines
),
)
)
...
@@ -158,7 +158,7 @@ def handle_csv(frame, symbols, epoch, sep=',',
...
@@ -158,7 +158,7 @@ def handle_csv(frame, symbols, epoch, sep=',',
@as_json_p
(
optional
=
True
)
@as_json_p
(
optional
=
True
)
def
handle_json
(
frame
,
symbols
,
epoch
,
order
=
'
columns
'
,
def
handle_json
(
frame
,
epoch
,
order
=
'
columns
'
,
message
=
''
,
code
=
200
,
status
=
'
success
'
,
**
kwargs
):
message
=
''
,
code
=
200
,
status
=
'
success
'
,
**
kwargs
):
output
=
{}
output
=
{}
output
[
'
status
'
]
=
status
output
[
'
status
'
]
=
status
...
@@ -177,16 +177,16 @@ def handle_json(frame, symbols, epoch, order='columns',
...
@@ -177,16 +177,16 @@ def handle_json(frame, symbols, epoch, order='columns',
package
[
'
timestamps
'
]
=
newStamps
package
[
'
timestamps
'
]
=
newStamps
if
order
==
'
column
'
:
if
order
==
'
column
'
:
package
[
'
data
'
]
=
dict
(
frame
[
symbols
]
)
package
[
'
data
'
]
=
dict
(
frame
)
else
:
else
:
package
[
'
symbols
'
]
=
symbol
s
package
[
'
symbols
'
]
=
frame
.
column
s
package
[
'
data
'
]
=
[
frame
.
iloc
[
i
].
values
for
i
in
range
(
frame
.
shape
[
0
])]
package
[
'
data
'
]
=
[
frame
.
iloc
[
i
].
values
for
i
in
range
(
frame
.
shape
[
0
])]
# package['data'] = frame.values
# package['data'] = frame.values
output
[
'
results
'
]
=
package
output
[
'
results
'
]
=
package
return
output
,
code
return
output
,
code
def
handle_xml
(
frame
,
symbols
,
epoch
,
sep
=
'
,
'
,
def
handle_xml
(
frame
,
epoch
,
sep
=
'
,
'
,
message
=
''
,
code
=
200
,
status
=
'
success
'
,
**
kwargs
):
message
=
''
,
code
=
200
,
status
=
'
success
'
,
**
kwargs
):
doc
=
Document
()
doc
=
Document
()
header
=
'
metobs
'
header
=
'
metobs
'
...
@@ -276,9 +276,11 @@ def modify_data(fmt, begin, end, site, inst, symbols, interval,
...
@@ -276,9 +276,11 @@ def modify_data(fmt, begin, end, site, inst, symbols, interval,
if
site
and
inst
:
if
site
and
inst
:
# shorthand for symbols that all use the same site and inst
# shorthand for symbols that all use the same site and inst
symbols
=
[
"
{}.{}.{}
"
.
format
(
site
,
inst
,
s
)
for
s
in
symbols
.
split
(
'
:
'
)]
short_symbols
=
symbols
.
split
(
'
:
'
)
symbols
=
[
"
{}.{}.{}
"
.
format
(
site
,
inst
,
s
)
for
s
in
short_symbols
]
elif
not
site
and
not
inst
:
elif
not
site
and
not
inst
:
# each symbol is fully qualified with site.inst.symbol
# each symbol is fully qualified with site.inst.symbol
short_symbols
=
None
symbols
=
symbols
.
split
(
'
:
'
)
symbols
=
symbols
.
split
(
'
:
'
)
else
:
else
:
return
handle_error
(
fmt
,
'
missing_site_inst
'
)
return
handle_error
(
fmt
,
'
missing_site_inst
'
)
...
@@ -304,8 +306,10 @@ def modify_data(fmt, begin, end, site, inst, symbols, interval,
...
@@ -304,8 +306,10 @@ def modify_data(fmt, begin, end, site, inst, symbols, interval,
# order the resulting symbols the way the user requested
# order the resulting symbols the way the user requested
# assume time is the first column
# assume time is the first column
frame
=
frame
[
symbols
]
frame
=
frame
[
symbols
]
if
site
:
frame
.
columns
=
short_symbols
handler
=
RESPONSE_HANDLERS
[
fmt
]
handler
=
RESPONSE_HANDLERS
[
fmt
]
return
handler
(
frame
,
symbols
,
epoch
,
return
handler
(
frame
,
epoch
,
sep
=
sep
,
order
=
order
,
sep
=
sep
,
order
=
order
,
status
=
status
,
code
=
code
,
message
=
message
)
status
=
status
,
code
=
code
,
message
=
message
)
This diff is collapsed.
Click to expand it.
metobsapi/tests/test_data_api.py
+
3
−
3
View file @
1b57f220
...
@@ -117,7 +117,7 @@ class TestDataAPI(unittest.TestCase):
...
@@ -117,7 +117,7 @@ class TestDataAPI(unittest.TestCase):
res
=
json
.
loads
(
res
.
data
.
decode
())
res
=
json
.
loads
(
res
.
data
.
decode
())
self
.
assertEqual
(
res
[
'
code
'
],
200
)
self
.
assertEqual
(
res
[
'
code
'
],
200
)
self
.
assertEqual
(
res
[
'
num_results
'
],
9
)
self
.
assertEqual
(
res
[
'
num_results
'
],
9
)
self
.
assertListEqual
(
res
[
'
results
'
][
'
symbols
'
],
[
'
aoss.tower.
air_temp
'
])
self
.
assertListEqual
(
res
[
'
results
'
][
'
symbols
'
],
[
'
air_temp
'
])
self
.
assertEqual
(
len
(
res
[
'
results
'
][
'
timestamps
'
]),
9
)
self
.
assertEqual
(
len
(
res
[
'
results
'
][
'
timestamps
'
]),
9
)
self
.
assertEqual
(
len
(
res
[
'
results
'
][
'
data
'
]),
9
)
self
.
assertEqual
(
len
(
res
[
'
results
'
][
'
data
'
]),
9
)
self
.
assertEqual
(
len
(
res
[
'
results
'
][
'
data
'
][
0
]),
1
)
self
.
assertEqual
(
len
(
res
[
'
results
'
][
'
data
'
][
0
]),
1
)
...
@@ -130,8 +130,8 @@ class TestDataAPI(unittest.TestCase):
...
@@ -130,8 +130,8 @@ class TestDataAPI(unittest.TestCase):
res
=
json
.
loads
(
res
.
data
.
decode
())
res
=
json
.
loads
(
res
.
data
.
decode
())
self
.
assertEqual
(
res
[
'
code
'
],
200
)
self
.
assertEqual
(
res
[
'
code
'
],
200
)
self
.
assertEqual
(
res
[
'
num_results
'
],
9
)
self
.
assertEqual
(
res
[
'
num_results
'
],
9
)
self
.
assertIn
(
'
aoss.tower.
air_temp
'
,
res
[
'
results
'
][
'
data
'
])
self
.
assertIn
(
'
air_temp
'
,
res
[
'
results
'
][
'
data
'
])
self
.
assertEqual
(
len
(
res
[
'
results
'
][
'
data
'
][
'
aoss.tower.
air_temp
'
]),
9
)
self
.
assertEqual
(
len
(
res
[
'
results
'
][
'
data
'
][
'
air_temp
'
]),
9
)
self
.
assertEqual
(
len
(
res
[
'
results
'
][
'
timestamps
'
]),
9
)
self
.
assertEqual
(
len
(
res
[
'
results
'
][
'
timestamps
'
]),
9
)
@mock.patch
(
'
metobsapi.data_api.query
'
)
@mock.patch
(
'
metobsapi.data_api.query
'
)
...
...
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