Skip to content

Commit

Permalink
v2.0.5.9084
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
leppott committed Feb 24, 2021
1 parent cc989e5 commit 4b7bd67
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 73 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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"),
Expand Down
4 changes: 0 additions & 4 deletions LOG.Items.20210223.110344.tab

This file was deleted.

11 changes: 10 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@ NEWS-ContDataQC

<!-- NEWS.md is generated from NEWS.Rmd. Please edit that file -->

#> 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
Expand Down
11 changes: 10 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@ NEWS-ContDataQC

<!-- NEWS.md is generated from NEWS.Rmd. Please edit that file -->

#> 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
Expand Down
7 changes: 7 additions & 0 deletions NEWS.rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
96 changes: 51 additions & 45 deletions R/formatHobo.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
#'
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion inst/shiny-examples/ContDataQC/HOBO/test.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
File is here to avoid an empty directory.
1 change: 0 additions & 1 deletion inst/shiny-examples/ContDataQC/data/test.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
blank file
22 changes: 13 additions & 9 deletions inst/shiny-examples/ContDataQC/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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))

Expand Down Expand Up @@ -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))

Expand Down
20 changes: 11 additions & 9 deletions inst/shiny-examples/ContDataQC/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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).")
Expand All @@ -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')
Expand Down
3 changes: 2 additions & 1 deletion man/formatHobo.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4b7bd67

Please sign in to comment.