luftlyr_df.R 2.27 KB
Newer Older
1
#' luftlyr_df_data
2

3
#' luftlyr_df_data
4
#' @param x request object
5
#' @param res resulted data.frame
6
7
8
9
#' @keywords luftlyr
#' @export
#' @examples
#' \dontrun{
10
#' luftlyr_df_data()
11
#' }
12
luftlyr_df_data <- function(x,res){
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
13

14

jml's avatar
jml committed
15
16
17
18
19
20
21
22
  col_names <- get_name_date_col(x$timeObj$precision())

  target <- setdiff(names(res), c(col_names,"ST_ID","ST_NAME","CO_NAME"))

  tmp <- friendlyts::ts_spread(df=res, col_date=col_names,
                               col_key=c("CO_NAME","ST_ID"),col_target=target,
                               precision=x$timeObj$precision(),tzone=x$timeObj$tzone(),
                               date_type="df_yymmdd_hhmmss")
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
23

jml's avatar
jml committed
24
25
26
27
28
29
  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")

  if (x$dateStructObj$COL_DATE) {
     stop("to be done")
  }
  return(df)
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
30
31
32

}

33
34
35
36
37
38
39
40
41
42
43
44
45
#' luftlyr_df_qa

#' luftlyr_df_qa
#' @param x request object
#' @param res resulted data.frame
#' @keywords luftlyr
#' @export
#' @examples
#' \dontrun{
#' luftlyr_df_qa()
#' }
luftlyr_df_qa <- function(x,res){

jml's avatar
jml committed
46
  col_names <- get_name_date_col(x$timeObj$precision())
47

jml's avatar
jml committed
48
  target <- setdiff(names(res), c(col_names,"ST_ID","ST_NAME","CO_NAME"))
49

jml's avatar
jml committed
50
51
52
53
  tmp <- friendlyts::ts_spread(df=res, col_date=col_names,
                               col_key=c("CO_NAME","ST_ID"),col_target=target,
                               precision=x$timeObj$precision(),tzone=x$timeObj$tzone(),
                               date_type="df_yymmdd_hhmmss")
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
54

jml's avatar
jml committed
55
56
  icol <- friendlyts::get_date_col(precision=x$timeObj$precision())
  names(df) <- c(names(df)[icol],paste0("qa_",names(tmp)[-c(icol)]))
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
57

jml's avatar
jml committed
58
59
  if (x$dateStructObj$COL_DATE) {
     stop("to be done")
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
60
  }
jml's avatar
jml committed
61
62
  return(df)
}
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
63

jml's avatar
jml committed
64
65
66
67
68
69
70
71
72
73
74
get_name_date_col <- function(precision){
  res <- switch(precision,
      "yearly"  = "YEAR_UTC",
      "monthly" = c("YEAR_UTC","MONTH_UTC"),
      "daily"   = c("YEAR_UTC","MONTH_UTC","DAY_UTC"),
      "hourly"  = c("YEAR_UTC","MONTH_UTC","DAY_UTC","HOUR_UTC"),
      "minute"  = c("YEAR_UTC","MONTH_UTC","DAY_UTC","HOUR_UTC","MINUTE_UTC"),
      "second"  = c("YEAR_UTC","MONTH_UTC","DAY_UTC","HOUR_UTC","MINUTE_UTC","SECOND_UTC"),
      stop("precision not recognized"))

  return(res)
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
75
}