WSL/SLF GitLab Repository
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
snow-models
meteoio
Commits
1ad25e72
Commit
1ad25e72
authored
Feb 21, 2017
by
Mathias Bavay
Browse files
Parsing more elements out of the JSON
parent
eea956b2
Changes
1
Hide whitespace changes
Inline
Side-by-side
meteoio/plugins/DBO.cc
View file @
1ad25e72
...
...
@@ -296,6 +296,48 @@ void DBO::readMeteoData(const Date& dateStart, const Date& dateEnd,
readData
(
dateStart
,
dateEnd
,
vecMeteo
[
ii
],
ii
);
}
void
getTsProperties
(
picojson
::
value
&
v
)
{
std
::
vector
<
picojson
::
value
>
results
;
goToJSONPath
(
"$.properties.timeseries"
,
v
,
results
);
for
(
size_t
ii
=
0
;
ii
<
results
.
size
();
ii
++
)
{
if
(
results
[
ii
].
is
<
picojson
::
array
>
()){
const
picojson
::
array
&
array
=
results
[
ii
].
get
<
picojson
::
array
>
();
for
(
size_t
jj
=
0
;
jj
<
array
.
size
();
jj
++
)
{
if
(
!
array
[
jj
].
is
<
picojson
::
null
>
())
{
std
::
string
code
,
agg_type
;
double
ts_id
;
unsigned
int
interval
;
Date
since
,
until
;
const
picojson
::
value
::
object
&
obj
=
array
[
jj
].
get
<
picojson
::
object
>
();
for
(
picojson
::
value
::
object
::
const_iterator
it
=
obj
.
begin
();
it
!=
obj
.
end
();
++
it
)
{
if
(
it
->
first
==
"code"
&&
it
->
second
.
is
<
std
::
string
>
())
{
code
=
it
->
second
.
get
<
std
::
string
>
();
code
=
code
.
substr
(
0
,
code
.
find
(
'_'
));
}
if
(
it
->
first
==
"id"
&&
it
->
second
.
is
<
double
>
())
ts_id
=
it
->
second
.
get
<
double
>
();
if
(
it
->
first
==
"since"
&&
it
->
second
.
is
<
std
::
string
>
())
IOUtils
::
convertString
(
since
,
it
->
second
.
get
<
std
::
string
>
(),
0.
);
if
(
it
->
first
==
"until"
&&
it
->
second
.
is
<
std
::
string
>
())
IOUtils
::
convertString
(
until
,
it
->
second
.
get
<
std
::
string
>
(),
0.
);
if
(
it
->
first
==
"aggregationInterval"
&&
it
->
second
.
is
<
std
::
string
>
())
{
unsigned
int
hour
,
minute
,
second
;
if
(
sscanf
(
it
->
second
.
get
<
std
::
string
>
().
c_str
(),
"%u:%u:%u"
,
&
hour
,
&
minute
,
&
second
)
==
3
)
{
interval
=
hour
*
3600
+
minute
*
60
+
second
;
}
else
throw
ConversionFailedException
(
"Could not read aggregation interval '"
+
it
->
second
.
get
<
std
::
string
>
()
+
"'"
,
AT
);
}
if
(
it
->
first
==
"aggregationType"
&&
it
->
second
.
is
<
std
::
string
>
())
agg_type
=
it
->
second
.
get
<
std
::
string
>
();
}
std
::
cout
<<
code
<<
" ("
<<
ts_id
<<
") since "
<<
since
.
toString
(
Date
::
ISO
)
<<
" every "
<<
interval
<<
" seconds ("
<<
agg_type
<<
")
\n
"
;
}
}
}
}
}
void
DBO
::
fillStationMeta
()
{
vecMeta
.
clear
();
...
...
@@ -305,7 +347,7 @@ void DBO::fillStationMeta()
if
(
station_id
.
find
(
':'
)
==
std
::
string
::
npos
)
station_id
=
"IMIS::"
+
station_id
;
const
std
::
string
request
(
metadata_endpoint
+
"name="
+
IOUtils
::
strToLower
(
station_id
)
);
stringstream
ss
;
std
::
stringstream
ss
;
if
(
curl_read
(
request
,
ss
))
{
if
(
ss
.
str
().
empty
())
throw
UnknownValueException
(
"Station not found: '"
+
station_id
+
"'"
,
AT
);
...
...
@@ -324,9 +366,7 @@ void DBO::fillStationMeta()
vecMeta
.
push_back
(
sd
);
//select proper time series
const
std
::
vector
<
std
::
string
>
ts_codes
(
getStrings
(
"$.properties.timeseries.code"
,
v
)
);
for
(
size_t
jj
=
0
;
jj
<
ts_codes
.
size
();
jj
++
)
std
::
cout
<<
"Found "
<<
ts_codes
[
jj
]
<<
"
\n
"
;
getTsProperties
(
v
);
}
else
{
if
(
dbo_debug
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment