Commit e598432c authored by jml's avatar jml
Browse files

upgrade to friendlyts

parent 223fbd6f
Package: frostlyr
Type: Package
Version: 0.0.1
Version: 0.0.4
Authors@R: c(person("Jean-Marie", "Lepioufle", , "jml@nilu.no", role=c("aut","cre")),
person("NILU",role="cph"))
Title: frostlyr
......@@ -12,12 +12,13 @@ Depends:
R (>= 3.2.0)
Imports:
frostr,
timelyr,
jsonlite,
friendlyts,
timemanip
Remotes: git::git@git.nilu.no:rextapi/frostr.git,
git::git@git.nilu.no:rfriendlyr/timelyr.git,
git::git@git.nilu.no:rfriendlyts/friendlyts.git,
git::git@git.nilu.no:rspacetimemanip/timemanip.git
License: GPL-3
Encoding: UTF-8
LazyData: false
RoxygenNote: 5.0.1
RoxygenNote: 6.0.1
......@@ -11,16 +11,18 @@
#' }
frostlyr_df_data <- function(x,res){
tmp <- df_data(x=x,ugly_df=res,target="value")
if (x$dateStructObj$COL_DATE) {
# ..
} else if (!x$dateStructObj$COL_DATE){
tmp <- timelyr::checkDate(df = tmp, timeObj=x$timeObj, missingValues = NA,date_col="date",date_type="posixlt")
tmp <- friendlyts::ts_spread(df=res, col_date=c("date"),
col_key=c("CO_NAME","ID"),col_target="value",
precision=x$timeObj$precision(),tzone=x$timeObj$tzone(),
date_type="%Y-%m-%dT%H:%M:%OSZ")
} else stop("COL_DATE in the right format")
df <- friendlyts::check_date(tbl_fts=tmp, fromDate=x$timeObj$fromDateTime(),toDate=x$timeObj$toDateTime(),timeResolution=x$timeObj$timeResolution(), v=x$timeObj$v(), precision=x$timeObj$precision(), tzone=x$timeObj$tzone(),missingValues=NA,date_type="posixlt")
return(tmp)
if (x$dateStructObj$COL_DATE) {
stop("to be done")
}
return(df)
}
#' frostlyr_df_qa
......@@ -36,64 +38,18 @@ frostlyr_df_data <- function(x,res){
#' }
frostlyr_df_qa <- function(x,res){
tmp <- df_data(x=x,ugly_df=res,target="qualityCode")
names(tmp) <- c(names(tmp)[1],paste0("qa_",names(tmp)[-1]))
if (x$dateStructObj$COL_DATE) {
# ..
} else if (!x$dateStructObj$COL_DATE){
tmp <- timelyr::checkDate(df = tmp, timeObj=x$timeObj, missingValues = NA,date_col="date",date_type="posixlt")
} else stop("COL_DATE in the right format")
return(tmp)
}
tmp <- friendlyts::ts_spread(df=res, col_date=c("date"),
col_key=c("CO_NAME","ID"),col_target="qualityCode",
precision=x$timeObj$precision(),tzone=x$timeObj$tzone(),
date_type="%Y-%m-%dT%H:%M:%OSZ")
df <- friendlyts::check_date(tbl_fts=tmp, fromDate=x$timeObj$fromDateTime(),toDate=x$timeObj$toDateTime(),timeResolution=x$timeObj$timeResolution(), v=x$timeObj$v(), precision=x$timeObj$precision(), tzone=x$timeObj$tzone(),missingValues=NA,date_type="posixlt")
df_data <- function(x,ugly_df,target){
output <- data.frame(date = x$timeObj$seqPeriod())
for (i_e in 1:length(x$elementObj$element_id)) {
if (length(x$stationObj$station_id)>0) {
indice <- NULL
i_s <- 0
while ( (!length(indice)) && (i_s< length(x$stationObj$station_id))) {
i_s <- i_s+1
indice <- which( (ugly_df["ID"] == x$stationObj$station_id[i_s]) & (ugly_df["CO_NAME"] == x$elementObj$element_id[i_e]))
}
stations_id <- x$stationObj$station_id[i_s]
tmp <- timelyr::checkDate(df=ugly_df[indice,],timeObj = x$timeObj, missingValues=NA,date_col="date",date_type="char_iso8601")[,target]
df <- tmp
if (length(x$stationObj$station_id)>1) {
while (i_s< length(x$stationObj$station_id)) {
indice <- NULL
while ( (!length(indice)) && (i_s< length(x$stationObj$station_id))) {
i_s <- i_s+1
indice <- which( (ugly_df["ID"] == x$stationObj$station_id[i_s]) & (ugly_df["CO_NAME"] == x$elementObj$element_id[i_e]))
}
stations_id <- c(stations_id,x$stationObj$station_id[i_s])
tmp <- timelyr::checkDate(df=ugly_df[indice,],timeObj = x$timeObj, missingValues=NA,date_col="date",date_type="char_iso8601")[,target]
df <- cbind(df,tmp)
}
}
output$element <- data.frame(df)
colnames(output$element) <- (stations_id)
}
colnames(output) <- c("date",x$elementObj$element_id[1:i_e])
icol <- friendlyts::get_date_col(precision=x$timeObj$precision())
names(df) <- c(names(df)[icol],paste0("qa_",names(tmp)[-c(icol)]))
if (x$dateStructObj$COL_DATE) {
stop("to be done")
}
# flatten the multi-data.frame
return(timelyr::flatten(output))
return(df)
}
......@@ -62,5 +62,6 @@ frostlyr_get_meta <- function(x,username=NULL,password=NULL) {
#' frostlyr_get_qa()
#' }
frostlyr_get_qa <- function(x,username=NULL,password=NULL) {
stop("qa gathering not implemented")
res <- frostlyr_get_data(x=x,username=username,password=password)
return(res)
}
......@@ -22,4 +22,3 @@ frostly_friendly()
}
}
\keyword{frostly}
......@@ -22,4 +22,3 @@ frostlyr_df_data()
}
}
\keyword{frostlyr}
......@@ -22,4 +22,3 @@ frostlyr_df_qa()
}
}
\keyword{frostlyr}
......@@ -24,4 +24,3 @@ frostlyr_get_data()
}
}
\keyword{frostlyr}
......@@ -24,4 +24,3 @@ frostlyr_get_meta()
}
}
\keyword{frostlyr}
......@@ -24,4 +24,3 @@ frostlyr_get_qa()
}
}
\keyword{frostlyr}
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