From 4b7bd67fb8af8a1a14dc0344445f5324d58b550a Mon Sep 17 00:00:00 2001 From: Erik Leppo Date: Wed, 24 Feb 2021 13:05:26 -0500 Subject: [PATCH] v2.0.5.9084 * feature: Shiny formatHobo add inputselect for date format, Issue #117 * refactor: Shiny server.R remove full.names from zip routine preventing proper construction of download zip file, Issue #109 --- DESCRIPTION | 2 +- LOG.Items.20210223.110344.tab | 4 - NEWS | 11 ++- NEWS.md | 11 ++- NEWS.rmd | 7 ++ R/formatHobo.R | 96 +++++++++++--------- inst/shiny-examples/ContDataQC/HOBO/test.txt | 1 - inst/shiny-examples/ContDataQC/data/test.txt | 1 - inst/shiny-examples/ContDataQC/server.R | 22 +++-- inst/shiny-examples/ContDataQC/ui.R | 20 ++-- man/formatHobo.Rd | 3 +- 11 files changed, 105 insertions(+), 73 deletions(-) delete mode 100644 LOG.Items.20210223.110344.tab diff --git a/DESCRIPTION b/DESCRIPTION index 8de21c5..a1d1737 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ContDataQC Title: Quality Control (QC) of Continous Monitoring Data -Version: 2.0.5.9083 +Version: 2.0.5.9084 Authors@R: c( person("Erik W", "Leppo", email="Erik.Leppo@tetratech.com",role=c("aut","cre")), person("Ann","Roseberry Lincoln", role="ctb"), diff --git a/LOG.Items.20210223.110344.tab b/LOG.Items.20210223.110344.tab deleted file mode 100644 index 72a3f12..0000000 --- a/LOG.Items.20210223.110344.tab +++ /dev/null @@ -1,4 +0,0 @@ -"ItemID" "Status" "ItemName" -1 "COMPLETE" "Charlies_Air_20170726_20170926.csv" -2 "COMPLETE" "Charlies_AW_20170726_20170926.csv" -3 "COMPLETE" "Charlies_Water_20170726_20170926.csv" diff --git a/NEWS b/NEWS index eb2e1fd..07f7ce3 100644 --- a/NEWS +++ b/NEWS @@ -3,10 +3,19 @@ NEWS-ContDataQC - #> Last Update: 2021-02-23 15:39:16 + #> Last Update: 2021-02-24 12:58:37 # Version History +## v2.0.5.9084 + +2021-02-24 + +- feature: Shiny formatHobo add inputselect for date format, Issue + \#117 +- refactor: Shiny server.R remove full.names from zip routine + preventing proper construction of download zip file, Issue \#109 + ## v2.0.5.9083 2021-02-23 diff --git a/NEWS.md b/NEWS.md index eb2e1fd..07f7ce3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,10 +3,19 @@ NEWS-ContDataQC - #> Last Update: 2021-02-23 15:39:16 + #> Last Update: 2021-02-24 12:58:37 # Version History +## v2.0.5.9084 + +2021-02-24 + +- feature: Shiny formatHobo add inputselect for date format, Issue + \#117 +- refactor: Shiny server.R remove full.names from zip routine + preventing proper construction of download zip file, Issue \#109 + ## v2.0.5.9083 2021-02-23 diff --git a/NEWS.rmd b/NEWS.rmd index c92b1a4..35a912d 100644 --- a/NEWS.rmd +++ b/NEWS.rmd @@ -21,6 +21,13 @@ cat(paste0("Last Update: ",Sys.time())) # Version History +## v2.0.5.9084 +2021-02-24 + +* feature: Shiny formatHobo add inputselect for date format, Issue #117 +* refactor: Shiny server.R remove full.names from zip routine preventing +proper construction of download zip file, Issue #109 + ## v2.0.5.9083 2021-02-23 diff --git a/R/formatHobo.R b/R/formatHobo.R index 147c2e3..317dade 100644 --- a/R/formatHobo.R +++ b/R/formatHobo.R @@ -4,7 +4,8 @@ #' Works on single files. Imports, modifies, and saves the new file. #' #' @details -#' 1. Imports a HoboWare output (with minimal tweaks) from a folder +#' 1. Imports a HoboWare output from a folder. +#' Minimal tweaks from within HOBOware. #' #' 2. Reformats it using defaults from the ContDataQC config file #' @@ -341,59 +342,64 @@ formatHobo <- function(fun.myFile = "" # Modify Date ---- + # if no format then no transformation if(is.null(fun.HoboDateFormat) == TRUE){ msg <- "No Hoboware date format (MDY, DMY, YMD) specified." - stop(msg) - }##IF.isnull.hobodate.END + message(msg) + } else { - # new date - date_new <- df_hobo[, col_Date] + # new date + date_new <- df_hobo[, col_Date] - # Determine delimiter - if(grepl("-", date_new[1]) == TRUE){ - HW_delim <- "-" - } else if (grepl("/", date_new[1]) == TRUE){ - HW_delim <- "/" - } else { - msg <- "Data format not discernable." - stop(msg) - }## grepl("-", date_new[1]) ~ END + # Determine delimiter + if(grepl("-", date_new[1]) == TRUE){ + HW_delim <- "-" + } else if (grepl("/", date_new[1]) == TRUE){ + HW_delim <- "/" + } else { + msg <- "Data format not discernable." + stop(msg) + }## grepl("-", date_new[1]) ~ END - # Determine format, time - n_colon <- nchar(date_new[1]) - nchar(gsub(":", "", date_new[1])) - if(n_colon == 2) { - time_fmt <- " %H:%M:%S" - } else if(n_colon == 1) { - time_fmt <- " %H:%M" - } else { - time_fmt <- "" - }## if(n_colon) ~ END + # Determine format, time + n_colon <- nchar(date_new[1]) - nchar(gsub(":", "", date_new[1])) + if(n_colon == 2) { + time_fmt <- " %H:%M:%S" + } else if(n_colon == 1) { + time_fmt <- " %H:%M" + } else { + time_fmt <- "" + }## if(n_colon) ~ END - # Determine format, year - dateonly <- strsplit(date_new, " ")[[1]][1] - dateonly_split <- unlist(strsplit(dateonly, HW_delim)[[1]]) - year_fmt <- ifelse(max(nchar(dateonly_split)) == 4 - , "%Y", "%y") + # Determine format, year + dateonly <- strsplit(date_new, " ")[[1]][1] + dateonly_split <- unlist(strsplit(dateonly, HW_delim)[[1]]) + year_fmt <- ifelse(max(nchar(dateonly_split)) == 4 + , "%Y", "%y") + + # Determine format, date + if(toupper(fun.HoboDateFormat) == "MDY"){ + HW_format <- paste0("%m", HW_delim, "%d", HW_delim, year_fmt, time_fmt) + } else if (toupper(fun.HoboDateFormat) == "DMY") { + HW_format <- paste0("%d", HW_delim, "%m", HW_delim, year_fmt, time_fmt) + } else if (toupper(fun.HoboDateFormat) == "YMD") { + HW_format <- paste0(year_fmt, HW_delim, "%m", HW_delim, "%d", time_fmt) + } else { + msg <- paste0("Incorrect Hoboware date format (MDY, DMY, YMD) specified, " + , fun.HoboDateFormat) + stop(msg) + }## if(toupper(fun.HoboDateFormat) ~ END + + # Modify dates + date_new_mod <- format(strptime(date_new, format = HW_format) + , ContData.env$myFormat.DateTime) + # modify hobo data frame to updated date format + df_hobo[,col_Date] <- date_new_mod + + }##IF.isnull.hobodate.END - # Determine format, date - if(toupper(fun.HoboDateFormat) == "MDY"){ - HW_format <- paste0("%m", HW_delim, "%d", HW_delim, year_fmt, time_fmt) - } else if (toupper(fun.HoboDateFormat) == "DMY") { - HW_format <- paste0("%d", HW_delim, "%m", HW_delim, year_fmt, time_fmt) - } else if (toupper(fun.HoboDateFormat) == "YMD") { - HW_format <- paste0(year_fmt, HW_delim, "%m", HW_delim, "%d", time_fmt) - } else { - msg <- paste0("Incorrect Hoboware date format (MDY, DMY, YMD) specified, " - , fun.HoboDateFormat) - stop(msg) - }## if(toupper(fun.HoboDateFormat) ~ END - # Modify dates - date_new_mod <- format(strptime(date_new, format = HW_format) - , ContData.env$myFormat.DateTime) - # modify hobo data frame to updated date format - df_hobo[,col_Date] <- date_new_mod # Columns, Output diff --git a/inst/shiny-examples/ContDataQC/HOBO/test.txt b/inst/shiny-examples/ContDataQC/HOBO/test.txt index 0899f22..e69de29 100644 --- a/inst/shiny-examples/ContDataQC/HOBO/test.txt +++ b/inst/shiny-examples/ContDataQC/HOBO/test.txt @@ -1 +0,0 @@ -File is here to avoid an empty directory. \ No newline at end of file diff --git a/inst/shiny-examples/ContDataQC/data/test.txt b/inst/shiny-examples/ContDataQC/data/test.txt index 7a06693..e69de29 100644 --- a/inst/shiny-examples/ContDataQC/data/test.txt +++ b/inst/shiny-examples/ContDataQC/data/test.txt @@ -1 +0,0 @@ -blank file \ No newline at end of file diff --git a/inst/shiny-examples/ContDataQC/server.R b/inst/shiny-examples/ContDataQC/server.R index 55b420c..5e33fbb 100644 --- a/inst/shiny-examples/ContDataQC/server.R +++ b/inst/shiny-examples/ContDataQC/server.R @@ -369,6 +369,8 @@ shinyServer(function(input, output, session) { #Creates a data.frame for the R console output of the ContDataQC() script console$disp <- data.frame(consoleOutput = character()) + HOBO_DateFormat_User <- input$HOBO_DateFormat + withProgress(message = paste("Running, format Hobo"), value = 0, { #A short pause before the operation begins @@ -392,7 +394,7 @@ shinyServer(function(input, output, session) { ,ContDataQC::formatHobo(fun.myFile = fileNameVector , fun.myDir.import = file.path("HOBO") , fun.myDir.export = file.path("HOBO") - , fun.HoboDateFormat = NULL + , fun.HoboDateFormat = HOBO_DateFormat_User , fun.myConfig = config ) # formatHOBO ~ END )## consoleRow ~ END @@ -600,6 +602,7 @@ shinyServer(function(input, output, session) { output$downloadData_HOBO <- downloadHandler( + # _zip-HOBO ---- #Names the zip file filename <- function() { paste0("formatHOBO_", format(Sys.time(), "%Y%m%d_%H%M%S"), ".zip") @@ -651,17 +654,18 @@ shinyServer(function(input, output, session) { #Lists only the csv and html files on the server zip.csv <- dir(file.path("data") - , full.names = FALSE + #, full.names = FALSE , pattern = "QC.*csv") zip.docx <- dir(file.path("data") - , full.names = FALSE + #, full.names = FALSE , pattern = "QC.*docx") zip.html <- dir(file.path("data") - , full.names = FALSE + #, full.names = FALSE , pattern = "QC.*html") files2zip <- file.path("data" , c(zip.csv, zip.docx, zip.html) - , full.names = FALSE) + #, full.names = FALSE + ) #Zips the files zip(zipfile = fname, files = files2zip) @@ -686,13 +690,13 @@ shinyServer(function(input, output, session) { #Lists only the csv and docx files on the server zip.csv <- dir(file.path("data") - , full.names = FALSE + #, full.names = FALSE , pattern = "DATA.*csv") zip.docx <- dir(file.path("data") - , full.names = FALSE + #, full.names = FALSE , pattern = ".*docx") zip.html <- dir(file.path("data") - , full.names = FALSE + #, full.names = FALSE , pattern = ".*html") files2zip <- file.path("data", c(zip.csv, zip.docx, zip.html)) @@ -834,7 +838,7 @@ shinyServer(function(input, output, session) { #Lists only the csv and html files on the server zip.csv <- dir(file.path("data") - , full.names = TRUE + #, full.names = TRUE , pattern = ".*Gage.*csv") files2zip <- file.path("data", c(zip.csv)) diff --git a/inst/shiny-examples/ContDataQC/ui.R b/inst/shiny-examples/ContDataQC/ui.R index 557b4f1..5fdb362 100644 --- a/inst/shiny-examples/ContDataQC/ui.R +++ b/inst/shiny-examples/ContDataQC/ui.R @@ -6,7 +6,7 @@ shinyUI( # VERSION ---- - navbarPage("Continuous data QC, summary, and statistics - v2.0.5.9080", + navbarPage("Continuous data QC, summary, and statistics - v2.0.5.9084", theme= shinytheme("spacelab"), #also liked "cerulean" at https://rstudio.github.io/shinythemes/ # tabPan, Site Intro ---- tabPanel("Site introduction", @@ -385,7 +385,9 @@ shinyUI( , p("One file or multiple files can be uploaded for processing.") , tags$b("Details") , p("Imports a HoboWare output (with minimal tweaks), reformats it using defaults from the ContDataQC config file , and exports a CSV to another folder for use with ContDataQC.") - , p("HOBOware will only output ambiguous dates with 2 digits. There are two delimiters (/ and -) and three formats (MDY, DMY, and YMD) resulting in six possible formats. The default is set to NULL and will not modify the date format.") + , p("Older versions of HOBOware only output ambiguous dates with 2 digits. + Newer versions use 4 digits. There are two delimiters (/ and -) and three formats (MDY, DMY, and YMD) resulting in six possible formats.") + , p("The user can specify the date format below. 'DMY' is the default as this is what most people use and is the default on Windows computers. NULL will not modify the input dates.") , p("It is assumed the user has a single Date Time field rather than two fields (Date and Time).") , p("A zip file with all CSV files ready for use with the ContDataQC QC function will be generated and can be downloaded.") , p("'Run' and 'Download' buttons do not appear until the previous step is complete ('Upload' and 'Run', respectively).") @@ -397,13 +399,13 @@ shinyUI( , accept = ".csv" , width = "600px") # wider for long file names ) - - # ,selectInput("HOBO_DateFormat", - # label = "Choose date format from HOBOware file", - # choices = c(NULL - # , "DMY" - # ) - # ,selected = NULL) + ,selectInput("HOBO_DateFormat", + label = "Choose date format from HOBOware file", + choices = c("MDY" + , "YMD" + , "DMY" + , NULL) + ,selected = "MDY") #Only shows the "Run operation" button after data are uploaded ,tags$div(title="Click to run selected operation (HOBO reformat)", uiOutput('ui.runProcess_HOBO') diff --git a/man/formatHobo.Rd b/man/formatHobo.Rd index 8e35b63..4491757 100644 --- a/man/formatHobo.Rd +++ b/man/formatHobo.Rd @@ -38,7 +38,8 @@ Format HoboWare output for use with `ContDataQC` package. Works on single files. Imports, modifies, and saves the new file. } \details{ -1. Imports a HoboWare output (with minimal tweaks) from a folder +1. Imports a HoboWare output from a folder. +Minimal tweaks from within HOBOware. 2. Reformats it using defaults from the ContDataQC config file