Commit a15b4b7a authored by Jean-Marie Lepioufle's avatar Jean-Marie Lepioufle
Browse files

enable extraction of multiple station and multiple elements

parent 3848a8e1
......@@ -20,7 +20,7 @@ get_short_data <- function(frostObj,stations,referencetime,elements,...) {
nrows <- tmp$totalItemCount
res <- short_data_init()
for ( i in 1:nrows) {
df <- short_data_df(tmp=tmp,indice=i)
df <- build_data_df(tmp=tmp,indice=i)
res <- rbind(res,df)
}
res[,"ID"] <-gsub(":.*","",res[,"ID"])
......@@ -32,6 +32,20 @@ get_short_data <- function(frostObj,stations,referencetime,elements,...) {
}
build_data_df <- function(tmp,indice){
if (length(tmp$data[[indice]]$observations)>1){
res <- short_data_init()
for (i in 1:length(tmp$data[[indice]]$observations)){
df <- short_data_df(tmp=tmp,indice=indice,iobs=i)
res <- rbind(res,df)
}
} else {
res <- short_data_df(tmp=tmp,indice=indice,iobs=1)
}
return(res)
}
short_data_init <- function(){
df <- data.frame(date = character(0),
ID = character(0),
......@@ -51,21 +65,23 @@ short_data_init <- function(){
return(df)
}
short_data_df <- function(tmp,indice){
short_data_df <- function(tmp,indice,iobs){
df <- data.frame(date = ifelse(is.null(tmp$data[[indice]]$referenceTime),NA,tmp$data[[indice]]$referenceTime),
ID = ifelse(is.null(tmp$data[[indice]]$sourceId),NA,tmp$data[[indice]]$sourceId),
CO_NAME = ifelse(is.null(tmp$data[[indice]]$observations[[1]]$elementId),NA,tmp$data[[indice]]$observations[[1]]$elementId),
value = ifelse(is.null(tmp$data[[indice]]$observations[[1]]$value),NA,tmp$data[[indice]]$observations[[1]]$value),
unit = ifelse(is.null(tmp$data[[indice]]$observations[[1]]$unit),NA,tmp$data[[indice]]$observations[[1]]$unit),
levelType = ifelse(is.null(tmp$data[[indice]]$observations[[1]]$level$levelType),NA,tmp$data[[indice]]$observations[[1]]$level$levelType),
levelUnit = ifelse(is.null(tmp$data[[indice]]$observations[[1]]$level$unit),NA,tmp$data[[indice]]$observations[[1]]$level$unit),
levelValue = ifelse(is.null(tmp$data[[indice]]$observations[[1]]$level$value),NA,tmp$data[[indice]]$observations[[1]]$level$value),
timeOffset = ifelse(is.null(tmp$data[[indice]]$observations[[1]]$timeOffset),NA,tmp$data[[indice]]$observations[[1]]$timeOffset),
timeResolution = ifelse(is.null(tmp$data[[indice]]$observations[[1]]$timeResolution),NA,tmp$data[[indice]]$observations[[1]]$timeResolution),
timeSeriesId = ifelse(is.null(tmp$data[[indice]]$observations[[1]]$timeSeriesId),NA,tmp$data[[indice]]$observations[[1]]$timeSeriesId),
performanceCategory = ifelse(is.null(tmp$data[[indice]]$observations[[1]]$performanceCategory),NA,tmp$data[[indice]]$observations[[1]]$performanceCategory),
exposureCategory = ifelse(is.null(tmp$data[[indice]]$observations[[1]]$exposureCategory),NA,tmp$data[[indice]]$observations[[1]]$exposureCategory),
qualityCode = ifelse(is.null(tmp$data[[indice]]$observations[[1]]$qualityCode),NA,tmp$data[[indice]]$observations[[1]]$qualityCode)
CO_NAME = ifelse(is.null(tmp$data[[indice]]$observations[[iobs]]$elementId),NA,tmp$data[[indice]]$observations[[iobs]]$elementId),
value = ifelse(is.null(tmp$data[[indice]]$observations[[iobs]]$value),NA,tmp$data[[indice]]$observations[[iobs]]$value),
unit = ifelse(is.null(tmp$data[[indice]]$observations[[iobs]]$unit),NA,tmp$data[[indice]]$observations[[iobs]]$unit),
levelType = ifelse(is.null(tmp$data[[indice]]$observations[[iobs]]$level$levelType),NA,tmp$data[[indice]]$observations[[iobs]]$level$levelType),
levelUnit = ifelse(is.null(tmp$data[[indice]]$observations[[iobs]]$level$unit),NA,tmp$data[[indice]]$observations[[iobs]]$level$unit),
levelValue = ifelse(is.null(tmp$data[[indice]]$observations[[iobs]]$level$value),NA,tmp$data[[indice]]$observations[[iobs]]$level$value),
timeOffset = ifelse(is.null(tmp$data[[indice]]$observations[[iobs]]$timeOffset),NA,tmp$data[[indice]]$observations[[iobs]]$timeOffset),
timeResolution = ifelse(is.null(tmp$data[[indice]]$observations[[iobs]]$timeResolution),NA,tmp$data[[indice]]$observations[[iobs]]$timeResolution),
timeSeriesId = ifelse(is.null(tmp$data[[indice]]$observations[[iobs]]$timeSeriesId),NA,tmp$data[[indice]]$observations[[iobs]]$timeSeriesId),
performanceCategory = ifelse(is.null(tmp$data[[indice]]$observations[[iobs]]$performanceCategory),NA,tmp$data[[indice]]$observations[[iobs]]$performanceCategory),
exposureCategory = ifelse(is.null(tmp$data[[indice]]$observations[[iobs]]$exposureCategory),NA,tmp$data[[indice]]$observations[[iobs]]$exposureCategory),
qualityCode = ifelse(is.null(tmp$data[[indice]]$observations[[iobs]]$qualityCode),NA,tmp$data[[indice]]$observations[[iobs]]$qualityCode)
)
return(df)
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment