Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8b0bde9
Updating code after EPA internal review part 2
m-pennino Sep 26, 2024
b4921e1
Updating code after EPA internal review part 4
m-pennino Sep 26, 2024
327bd91
Updating code after EPA internal review part 5
m-pennino Sep 26, 2024
d1fa128
Updating code after EPA internal review part 6
m-pennino Sep 26, 2024
7d6e470
Updating code after EPA internal review part 7
m-pennino Sep 26, 2024
621b604
Updating code after EPA internal review part 8
m-pennino Sep 26, 2024
775e938
Updating code after EPA internal review part 9
m-pennino Sep 26, 2024
90f9625
Updating code after EPA internal review part 10
m-pennino Sep 26, 2024
8ec0941
Updating code after EPA internal review part 11
m-pennino Sep 26, 2024
0ccd50e
Updating code after EPA internal review part 12
m-pennino Sep 26, 2024
3574ef0
Updating code after EPA internal review part 13
m-pennino Sep 26, 2024
fb44380
Updating code after EPA internal review part 14
m-pennino Sep 26, 2024
2dcb7c6
Updating code after EPA internal review part 15
m-pennino Sep 26, 2024
0ab8a9c
Updating code after EPA internal review part 16
m-pennino Sep 26, 2024
0c69e8c
Updating Overview tab link closing bracket
m-pennino Sep 26, 2024
7737523
Updating readme file - removed planned updates section
m-pennino Oct 4, 2024
702c575
Updated readme.md file - removed planned updates section
m-pennino Oct 4, 2024
adbfbd4
Adding link to shiny app
m-pennino Oct 4, 2024
56f7cad
Update to paper version link
m-pennino Oct 4, 2024
a97a1dd
Updating Badge links
m-pennino Oct 4, 2024
bcfd1b4
Updated description contents
m-pennino Oct 4, 2024
84bd349
Added info about newest updates
m-pennino Oct 4, 2024
8112346
Updating version number in descripton, news, and global.R file
m-pennino Oct 7, 2024
5b777d7
Added Vignette folder with vignette html files for direct access. Up…
m-pennino Dec 17, 2024
980c396
Updated readme file with new vignette link and file path
m-pennino Dec 17, 2024
7ad8d91
Updated vignette help file path
m-pennino Dec 17, 2024
d3646a2
added #### to comment where threshold section is located in the file
m-pennino Dec 17, 2024
ae04dad
Updated config files to better locate thresholds
m-pennino Dec 17, 2024
89f6886
Pull request merge
leppott Feb 11, 2025
44c0f16
Update DESCRIPTION
leppott Feb 19, 2025
6940435
Update NEWS.md
leppott Feb 19, 2025
a50d04d
Update NEWS.rmd
leppott Feb 19, 2025
6331c4f
Update NEWS.md
leppott Feb 19, 2025
69eb23a
Update tab_3_MainFunc.R
leppott Feb 19, 2025
1a3c5f6
Added url for both contact us links
m-pennino Apr 8, 2025
a89f7d8
Merge branch 'main' of https://github.com/USEPA/ContDataQC
m-pennino Apr 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 54 additions & 38 deletions inst/shiny-examples/ContDataQC/global.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,30 @@ library(shinyjs)
# #access Window's zipping abilities
# Sys.setenv(PATH = paste(Sys.getenv("PATH"), "C:\\Rtools\\bin", sep = ";"))

# Version Number
version <- "2.0.7.9032"

#Maximum individual file size that can be uploaded is 70 MB
options(shiny.maxRequestSize = 70 * 1024^2)

#Names the data template spreadsheet
dataTemplate <- read.csv(file = "continuous_data_template_2017_11_15.csv"
, header = TRUE)

#Extracts properties of the input spreadsheets
# Environment ----
# Load default config if not present
# 2020-10-02 (ContDataQC.R), added to global 2022-12-22
if (exists("ContData.env", mode = "environment") == FALSE) {
source(system.file(package = "ContDataQC", "extdata", "config.ORIG.R")
, local = TRUE)
}## exists ~ END

# Other ----
sizeThreshEdit <- 4

# Functions ----

##Extracts properties of the input spreadsheets
fileParse <- function(inputFile) {

#Extracts site ID, start and end dates, and record count.
Expand All @@ -38,27 +54,27 @@ fileParse <- function(inputFile) {

#Dates are formatted differently for data input to QCRaw and data input
#to Aggregate and Summarize (output from QCRaw)
if("Flag" %in% substr(colnames(inputFile),1,4)) {
startDate <-min(as.Date(inputFile$Date.Time, format = "%Y-%m-%d"))
if ("Flag" %in% substr(colnames(inputFile),1,4)) {
startDate <- min(as.Date(inputFile$Date.Time, format = "%Y-%m-%d"))
endDate <- max(as.Date(inputFile$Date.Time, format = "%Y-%m-%d"))
}

#Recognizes dates if they are in a Date field as opposed to a Date.Time field
else if("Date" %in% colnames(inputFile)){
startDate <-min(as.Date(inputFile$Date, format = "%m/%d/%Y"))
else if ("Date" %in% colnames(inputFile)) {
startDate <- min(as.Date(inputFile$Date, format = "%m/%d/%Y"))
endDate <- max(as.Date(inputFile$Date, format = "%m/%d/%Y"))
}

#Recognizes dates if they are in a "Date Time" field
# as opposed to a Date.Time field
else if("Date Time" %in% colnames(inputFile)){
startDate <-min(as.Date(inputFile$`Date Time`, format = "%m/%d/%Y"))
else if ("Date Time" %in% colnames(inputFile)) {
startDate <- min(as.Date(inputFile$`Date Time`, format = "%m/%d/%Y"))
endDate <- max(as.Date(inputFile$`Date Time`, format = "%m/%d/%Y"))
}

#Recognizes dates if they are in a Date.Time field
else {
startDate <-min(as.Date(inputFile$Date.Time, format = "%m/%d/%Y"))
startDate <- min(as.Date(inputFile$Date.Time, format = "%m/%d/%Y"))
endDate <- max(as.Date(inputFile$Date.Time, format = "%m/%d/%Y"))
}

Expand Down Expand Up @@ -143,7 +159,7 @@ timeFormatter <- function(time) {
#Converts a string of USGS site IDs (comma delimited)
#into an array of site IDs for gage data retrieval
USGSsiteParser <- function(siteIDs) {
USGSsiteVector <- unlist(strsplit(siteIDs, split=", "))
USGSsiteVector <- unlist(strsplit(siteIDs, split = ", "))
return(USGSsiteVector)
}

Expand Down Expand Up @@ -203,7 +219,7 @@ renameAggOutput <- function(directory, fileAttribsTable) {

#Populates vectors for the input and output files if the input files are
#output from the Aggregate process
if ("DATA_DATA" %in% substr(allFiles,1,9)){
if ("DATA_DATA" %in% substr(allFiles,1,9)) {
csvInputs <- list.files(directory, pattern = "^DATA_QC.*csv")
csvOutput <- list.files(directory, pattern = "DATA_DATA_QC.*csv")
htmlOutput <- list.files(directory, pattern = "DATA_DATA_QC.*html")
Expand All @@ -227,7 +243,7 @@ renameAggOutput <- function(directory, fileAttribsTable) {
data.type.inputs <- vector()

#Extracts the data type from all input files
for (i in seq_len(length(csvInputs))){
for (i in seq_len(length(csvInputs))) {
csvInputs.parts <- strsplit(csvInputs[i], myDelim)
data.type.inputs.number <- which(csvInputs.parts[[1]] ==
fileAttribsTable[1, 2]) + 1
Expand All @@ -243,9 +259,9 @@ renameAggOutput <- function(directory, fileAttribsTable) {

#Changes the output file names if the input files have different data types
#and have the same start and end dates
if(data.type.inputs[1] != data.type.inputs[2]
if (data.type.inputs[1] != data.type.inputs[2]
&& minStartDate == maxStartDate
&& minEndDate == maxEndDate){
&& minEndDate == maxEndDate) {

#Creates a data.frame for converting the input data types to the
# output data type
Expand All @@ -259,29 +275,29 @@ renameAggOutput <- function(directory, fileAttribsTable) {
, combined.data.type)

#Finds the rows in the conversion data.frame which have that date type
type1 <- which(data.type.conversion[,1]==data.type.inputs[1])
type2 <- which(data.type.conversion[,2]==data.type.inputs[2])
type1 <- which(data.type.conversion[,1] == data.type.inputs[1])
type2 <- which(data.type.conversion[,2] == data.type.inputs[2])

#Finds the one row on the conversion data.frame that corresponds to
# those data types
output.type <- as.character(data.type.conversion[intersect(type1, type2)
, 3])

#Changes the data type in the output csv to the correct datatype
csvOutput.data.type <- gsub(paste("_", data.type.inputs[1], "_", sep=""),
paste("_", output.type, "_", sep=""),
csvOutput.data.type <- gsub(paste("_", data.type.inputs[1], "_", sep = ""),
paste("_", output.type, "_", sep = ""),
csvOutput)

#Sometimes the Aggregate process uses the second data type in its output
# name.
#This captures that eventuality.
csvOutput.data.type <- gsub(paste("_", data.type.inputs[2], "_", sep=""),
paste("_", output.type, "_", sep=""),
csvOutput.data.type <- gsub(paste("_", data.type.inputs[2], "_", sep = ""),
paste("_", output.type, "_", sep = ""),
csvOutput.data.type)

#Removes the "_append_x" from the output csv name
csvOutput.data.type <- gsub(paste("_Append_", length(csvInputs), sep=""),
paste("", sep=""),
csvOutput.data.type <- gsub(paste("_Append_", length(csvInputs), sep = ""),
paste("", sep = ""),
csvOutput.data.type)

#Renames the csv
Expand All @@ -290,25 +306,25 @@ renameAggOutput <- function(directory, fileAttribsTable) {


#Changes the data type in the output html to the correct datatype
htmlOutput.data.type <- gsub(paste("_", data.type.inputs[1], "_", sep=""),
paste("_", output.type, "_", sep=""),
htmlOutput.data.type <- gsub(paste("_", data.type.inputs[1], "_", sep = ""),
paste("_", output.type, "_", sep = ""),
htmlOutput)

#Sometimes the Aggregate process uses the second data type in its output
# name.
#This captures that eventuality.
htmlOutput.data.type <- gsub(paste("_", data.type.inputs[2], "_", sep=""),
paste("_", output.type, "_", sep=""),
htmlOutput.data.type <- gsub(paste("_", data.type.inputs[2], "_", sep = ""),
paste("_", output.type, "_", sep = ""),
htmlOutput.data.type)

#Removes the "_append_x" from the output html name
htmlOutput.data.type <- gsub(paste("_Append_", length(csvInputs), sep=""),
paste("", sep=""),
htmlOutput.data.type <- gsub(paste("_Append_", length(csvInputs), sep = ""),
paste("", sep = ""),
htmlOutput.data.type)

#Removes the "_Report_Aggregate" from the output html name
htmlOutput.data.type <- gsub(paste("_Report_Aggregate", sep=""),
paste("", sep=""),
htmlOutput.data.type <- gsub(paste("_Report_Aggregate", sep = ""),
paste("", sep = ""),
htmlOutput.data.type)

#Renames the html output
Expand All @@ -334,27 +350,27 @@ renameAggOutput <- function(directory, fileAttribsTable) {
#Determines how many characters should be removed from end of csv output
# name (through the (inaccurate) second date in the name, which is not the
# latest date of measurement)
csvCharsToRemove <- 8+1+8+1+6+1+nchar(numFiles)+4
csvCharsToRemove <- 8 + 1 + 8 + 1 + 6 + 1 + nchar(numFiles) + 4
# date min (8) + sep (1) + date max (8) + sep (1) + append (6) +
# NumFiles + .ext (4)

#Removes the specified number of characters
csvNewName <- substr(csvOutput, 0, nchar(csvOutput)-csvCharsToRemove)
csvNewName <- substr(csvOutput, 0, nchar(csvOutput) - csvCharsToRemove)

#Adds the last recorded date to the truncated file name
csvNewName <- paste(csvNewName, minDate, "_", maxDate, ".csv", sep="")
csvNewName <- paste(csvNewName, minDate, "_", maxDate, ".csv", sep = "")

#Replaces the old file name with the new one
file.rename(file.path(".", "data", csvOutput)
, file.path(".", "data", csvNewName))

#Same as above but for the HTML reports
htmlCharsToRemove <- 8+1+8+1+6+1+nchar(numFiles)+1+6+1+8+6
htmlCharsToRemove <- 8 + 1 + 8 + 1 + 6 + 1 + nchar(numFiles) + 1 + 6 + 1 + 8 + 6
# date min (8) + sep (1) + date max (8) + sep (1) + append (6) + NumFiles +
# sep (1) + Report (6) + sep (1) + Aggregate (8) + .ext (6?)

htmlNewName <- substr(htmlOutput, 0, nchar(htmlOutput)-htmlCharsToRemove)
htmlNewName <- paste(htmlNewName, minDate, "_", maxDate, ".html", sep="")
htmlNewName <- substr(htmlOutput, 0, nchar(htmlOutput) - htmlCharsToRemove)
htmlNewName <- paste(htmlNewName, minDate, "_", maxDate, ".html", sep = "")
file.rename(file.path(".", "data", htmlOutput)
, file.path(".", "data", htmlNewName))

Expand Down Expand Up @@ -386,7 +402,7 @@ nameParse <- function(strFile, process) {
,tolower(substring(strFile.DataType
,2
,nchar(strFile.DataType)))
,sep="")
,sep = "")
strFile.Date.Start <- as.Date(strFile.parts[[1]][4],"%Y%m%d")
strFile.Date.End <- as.Date(strFile.parts[[1]][5],"%Y%m%d")
}
Expand All @@ -401,7 +417,7 @@ nameParse <- function(strFile, process) {
,tolower(substring(strFile.DataType
,2
,nchar(strFile.DataType)))
,sep="")
,sep = "")
strFile.Date.Start <- as.Date(strFile.parts[[1]][5],"%Y%m%d")
strFile.Date.End <- as.Date(strFile.parts[[1]][6],"%Y%m%d")
}
Expand All @@ -415,7 +431,7 @@ nameParse <- function(strFile, process) {
,tolower(substring(strFile.DataType
,2
,nchar(strFile.DataType)))
,sep="")
,sep = "")
strFile.Date.Start <- as.Date(strFile.parts[[1]][3],"%Y%m%d")
strFile.Date.End <- as.Date(strFile.parts[[1]][4],"%Y%m%d")
}
Expand Down
Binary file not shown.
Loading