X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=pkg%2FR%2FgetData.R;h=a6401f9e5cf98b8974e47324f3e8659accdd7cb1;hb=102bcfda4afbb5cfee885cbee0f55545624168fd;hp=b944dfb58dea49eb0a9b6830f56100e86c4a170a;hpb=72b9c50162bcdcf6c99fbb8b2ec6ea9ba98379cb;p=talweg.git diff --git a/pkg/R/getData.R b/pkg/R/getData.R index b944dfb..a6401f9 100644 --- a/pkg/R/getData.R +++ b/pkg/R/getData.R @@ -1,19 +1,20 @@ -#' @title Acquire data in a clean format +#' getData #' -#' @description Take in input data frames and/or files containing raw data, and -#' timezones, and output a Data object, roughly corresponding to a list where each cell -#' contains all value for one day (see \code{?Data}). +#' Acquire data as a Data object; see ?Data. +#' +#' Since series are given in columns (database format), this function builds series one +#' by one and incrementally grows a Data object which is finally returned. #' #' @param ts_data Time-series, as a data frame (DB style: 2 columns, first is date/time, -#' second is value) or a CSV file -#' @param exo_data Exogenous variables, as a data frame or a CSV file; first comlumn is +#' second is value) or a CSV file. +#' @param exo_data Exogenous variables, as a data frame or a CSV file; first column is #' dates, next block are measurements for the day, and final block are exogenous -#' forecasts +#' forecasts (for the same day). #' @param input_tz Timezone in the input files ("GMT" or e.g. "Europe/Paris") #' @param date_format How date/time are stored (e.g. year/month/day hour:minutes; -#' see \code{strptime}) +#' see ?strptime) #' @param working_tz Timezone to work with ("GMT" or e.g. "Europe/Paris") -#' @param predict_at When does the prediction take place ? Integer, in hours. Default: 0 +#' @param predict_at When does the prediction take place? Integer, in hours. Default: 0 #' @param limit Number of days to extract (default: Inf, for "all") #' #' @return An object of class Data @@ -71,12 +72,10 @@ getData = function(ts_data, exo_data, input_tz="GMT", date_format="%d/%m/%Y %H:% { time = c() serie = c() - hat_serie = c() repeat { { time = c(time, ts_df[line,1]) - hat_serie = c(serie, ts_df[line,3]) serie = c(serie, ts_df[line,2]) line = line + 1 }; @@ -87,10 +86,13 @@ getData = function(ts_data, exo_data, input_tz="GMT", date_format="%d/%m/%Y %H:% } } - hat_exo = as.data.frame( exo_df[i,(1+nb_exos+1):(1+2*nb_exos)] ) exo = as.data.frame( exo_df[i,2:(1+nb_exos)] ) - data$appendHat(time, hat_serie, hat_exo) - data$append(serie, exo) #in realtime, this call comes hours later + exo_hat = + if (i < nrow(exo_df)) + as.data.frame( exo_df[i+1,(1+nb_exos+1):(1+2*nb_exos)] ) + else + NA #exogenous prediction for next day are useless on last day + data$append(time, serie, exo, exo_hat) if (i >= limit) break i = i + 1