Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 18 additions & 7 deletions R/ATTAINSCrosswalks.R
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,12 @@ TADA_GetATTAINSAUMLCrosswalk <- function(org_id = NULL,
#'
#' @param batch_upload Boolean argument. When batch_upload = TRUE, the column
#' names in the returned df will match the column names required for ATTAINS
#' batch upload. When batch_upload = FALSE, the column names will match those in
#' the TADA workflow. Default is batch_upload = FALSE.
#' batch upload and all WQP Monitoring Locations that have not been matched to
#' an existing Assessment Unit from the user-specified organization are removed
#' from the dataframe. When batch_upload = FALSE, the column names will match
#' those in the TADA workflow and Monitoring Locations not assigned to existing
#' Assessment Units from the user-specified organization will be retained.
#' Default is batch_upload = FALSE.
#'
#' @return When batch_upload = FALSE, A dataframe with six columns:
#' OrganizationIdentifier, ATTAINS.OrganizationIdentifier,
Expand Down Expand Up @@ -252,13 +256,13 @@ TADA_GetATTAINSAUMLCrosswalk <- function(org_id = NULL,
#' "ExampleSite1", "ExampleSite2", "ExampleSite3",
#' "ExampleSite4", "ExampleSite5"
#' )
#'
#'
#' # example water types
#' ATTAINS.WaterType <- c(
#' "BEACH", "BAY", "CREEK",
#' "ESTUARY", "CREEK"
#' )
#'
#'
#' # example urls
#' ATTAINS.MonitoringDataLinkText <- c(
#' "https://www.waterqualitydata.us/provider/STORET/AKDECWQ/",
Expand Down Expand Up @@ -358,8 +362,12 @@ TADA_UpdateATTAINSAUMLCrosswalk <- function(org_id = NULL,
ATTAINS.MonitoringLocationIdentifier = MS_LOCATION_ID,
OrganizationIdentifier = MS_ORG_ID,
ATTAINS.MonitoringDataLinkText = MS_DATA_LINK) %>%
dplyr::rowwise() %>%
dplyr::mutate(ATTAINS.OrganizationIdentifier = org_id,
ATTAINS.WaterType = NA)
ATTAINS.WaterType =
ifelse(
"ATTAINS.WaterType" %in% names(.), ATTAINS.WaterType,
NA_character_ ))
}
}

Expand Down Expand Up @@ -694,6 +702,7 @@ TADA_UpdateATTAINSAUMLCrosswalk <- function(org_id = NULL,
# If batch upload is desired, format the output in the required format.
if (batch_upload == TRUE) {
update.crosswalk <- update.crosswalk %>%
dplyr::filter(!is.na(ATTAINS.AssessmentUnitIdentifier)) %>%
dplyr::select(-c(ATTAINS.WaterType, ATTAINS.OrganizationIdentifier)) %>%
dplyr::rename(ASSESSMENT_UNIT_ID = ATTAINS.AssessmentUnitIdentifier,
MS_ORG_ID = ATTAINS.MonitoringLocationIdentifier,
Expand Down Expand Up @@ -2515,8 +2524,8 @@ TADA_CreateUseAURef <- function(.data, org_id = NULL, AUMLRef = NULL, # Required

#' Helper Function to Apply Uses to Unassigned Assessment Units by Water Type
#'
#' This is a helper function to TADA_CreateUseAURef and is meant to help users
#' with reviewing all water type and use name combination from their org.
#' This is a helper function to TADA_CreateUseAURef and is meant to assist users
#' with reviewing all water type and use name combinations from their organization.
#' This function will help to assign ATTAINS use names to any new or modified
#' assessment unit provided from a user's AUMLRef if there are any.
#'
Expand Down Expand Up @@ -2550,7 +2559,9 @@ TADA_CreateUseAURef <- function(.data, org_id = NULL, AUMLRef = NULL, # Required
#' @export
#'
#' @examples
#' \dontrun{
#' TADA_CreateWaterUseRef(TADA_AK_EXAMPLE, org_id = "AKDECWQ")
#' }
#'
TADA_CreateWaterUseRef <- function(.data, org_id = NULL, waterUseRef = NULL) {
# If org_id argument is not provided, this will attempt to pull in org_id from TADA_GetATTAINS.
Expand Down
125 changes: 63 additions & 62 deletions R/DataDiscoveryRetrieval.R
Original file line number Diff line number Diff line change
Expand Up @@ -1051,10 +1051,8 @@ TADA_TribalOptions <- function(tribal_area_type, return_sf = FALSE) {
#'
#' Note: It may be useful to save the Query URL from the WQP as well as a
#' comment within your code. This URL let's you return to the WQP query page
#' with all your selected data filters. For example, this is the query used
#' in the examples for this function:
#' https://www.waterqualitydata.us/#statecode=US%3A09&sampleMedia=water&sampleMedia=Water&startDateLo=01-01-2021&startDateHi=02-01-2021&mimeType=csv&providers=NWIS&providers=STORET
#'
#' with all your selected data filters. See example below.
#'
#' **Extra tip:** Note that the web service call built using the Water
#' Quality Portal uses the inputs startDateLo and startDateHi rather than
#' startDate and endDate, and dates are in the format MM-DD-YYYY rather
Expand All @@ -1071,47 +1069,31 @@ TADA_TribalOptions <- function(tribal_area_type, return_sf = FALSE) {
#' @return WQP Data Profile
#'
#' @export
#'
#'
#' @examples
#' \dontrun{
#' # construct the WQP web service URL for each profile
#' # Define base URL and common components
#' baseurl <- "https://www.waterqualitydata.us"
#' profile_station <- "/data/Station"
#' profile_result <- "/data/Result"
#' profile_result_2 <- "&dataProfile=biological"
#' profile_project <- "/data/Project"
#' filters <- "/search?statecode=US%3A09&sampleMedia=water&sampleMedia=Water"
#' dates <- "&startDateLo=01-01-2021&startDateHi=02-01-2021"
#' type <- "&mimeType=csv&zip=yes"
#' providers <- "&providers=NWIS&providers=STEWARDS&providers=STORET"
#'
#' physchemresults1 <- TADA_ReadWQPWebServices(paste0(
#' baseurl,
#' profile_station,
#' filters,
#' dates,
#' type,
#' providers
#' ))
#'
#' sites1 <- TADA_ReadWQPWebServices(paste0(
#' baseurl,
#' profile_result,
#' filters,
#' dates,
#' type,
#' profile_result_2,
#' providers
#' ))
#'
#' projects1 <- TADA_ReadWQPWebServices(paste0(
#' baseurl,
#' profile_project,
#' filters,
#' dates,
#' type,
#' providers
#' ))
#' # Construct URLs for different profiles
#' station_url <- paste0(
#' baseurl, "/data/Station", filters, dates, type, providers
#' )
#' result_url <- paste0(
#' baseurl, "/data/Result", filters, dates, type, "&dataProfile=biological", providers
#' )
#' project_url <- paste0(
#' baseurl, "/data/Project", filters, dates, type, providers
#' )
#'
#' # Retrieve data from Water Quality Portal web services
#' physchemresults1 <- TADA_ReadWQPWebServices(station_url)
#' sites1 <- TADA_ReadWQPWebServices(result_url)
#' projects1 <- TADA_ReadWQPWebServices(project_url)
#' }
#'
TADA_ReadWQPWebServices <- function(webservice) {
Expand Down Expand Up @@ -1298,28 +1280,23 @@ TADA_BigDataHelper <- function(record_summary, WQPquery, maxrecs = 250000, maxsi
#'
#' @examples
#' \dontrun{
#' # construct the WQP web service URL for each profile
#' # Define base URL and common components
#' baseurl <- "https://www.waterqualitydata.us"
#' profile_station <- "/data/Station"
#' profile_result <- "/data/Result"
#' profile_result_2 <- "&dataProfile=resultPhysChem"
#' profile_project <- "/data/Project"
#' filters <- "/search?statecode=US%3A09&characteristicType=Nutrient"
#' dates <- "&startDateLo=04-01-2023&startDateHi=11-01-2023"
#' type <- "&mimeType=csv&zip=yes"
#' providers <- "&providers=NWIS&providers=STEWARDS&providers=STORET"
#'
#' stationProfile <- TADA_ReadWQPWebServices(
#' paste0(baseurl, profile_station, filters, dates, type, providers)
#' )
#' # Construct URLs for different profiles
#' station_url <- paste0(baseurl, "/data/Station", filters, dates, type, providers)
#' result_url <- paste0(baseurl, "/data/Result", filters,
#' dates, type, "&dataProfile=resultPhysChem", providers)
#' project_url <- paste0(baseurl, "/data/Project", filters, dates, type, providers)
#'
#' physchemProfile <- TADA_ReadWQPWebServices(
#' paste0(baseurl, profile_result, filters, dates, type, profile_result_2, providers)
#' )
#'
#' projectProfile <- TADA_ReadWQPWebServices(
#' paste0(baseurl, profile_project, filters, dates, type, providers)
#' )
#' # Retrieve data from Water Quality Portal web services
#' stationProfile <- TADA_ReadWQPWebServices(station_url)
#' physchemProfile <- TADA_ReadWQPWebServices(result_url)
#' projectProfile <- TADA_ReadWQPWebServices(project_url)
#'
#' # Join all three profiles using TADA_JoinWQPProfiles
#' TADAProfile <- TADA_JoinWQPProfiles(
Expand Down Expand Up @@ -1476,25 +1453,49 @@ make_groups <- function(x, maxrecs) {
#'
#' @examples
#' \dontrun{
#' # Find web service URLs for each Profile using WQP User Interface (https://www.waterqualitydata.us/)
#' # Example WQP URL: https://www.waterqualitydata.us/#statecode=US%3A09&characteristicType=Nutrient&startDateLo=04-01-2023&startDateHi=11-01-2023&mimeType=csv&providers=NWIS&providers=STEWARDS&providers=STORET
#' # Find web service URLs for each Profile using WQP User Interface
#' # (https://www.waterqualitydata.us/)
#' # Example WQP URL:
#' # https://www.waterqualitydata.us/#statecode=US%3A09&characteristicType=Nutrient&
#' # startDateLo=04-01-2023&startDateHi=11-01-2023&mimeType=csv&providers=NWIS&
#' # providers=STEWARDS&providers=STORET
#'
#' # Define base URL and common components
#' baseurl <- "https://www.waterqualitydata.us"
#' filters <- "/search?statecode=US%3A09&characteristicType=Nutrient"
#' dates <- "&startDateLo=04-01-2023&startDateHi=11-01-2023"
#' type <- "&mimeType=csv&zip=yes"
#' providers <- "&providers=NWIS&providers=STEWARDS&providers=STORET"
#'
#' # Construct URLs for different profiles
#' station_url <- paste0(
#' baseurl, "/data/Station", filters, dates, type, providers
#' )
#' result_url <- paste0(
#' baseurl, "/data/Result", filters, dates, type,
#' "&dataProfile=resultPhysChem", providers
#' )
#' project_url <- paste0(
#' baseurl, "/data/Project", filters, dates, type, providers
#' )
#'
#' # Use TADA_ReadWQPWebServices to load the Station, Project, and Phys-Chem Result profiles
#' stationProfile <- TADA_ReadWQPWebServices("https://www.waterqualitydata.us/data/Station/search?statecode=US%3A09&characteristicType=Nutrient&startDateLo=04-01-2023&startDateHi=11-01-2023&mimeType=csv&zip=yes&providers=NWIS&providers=STEWARDS&providers=STORET")
#' physchemProfile <- TADA_ReadWQPWebServices("https://www.waterqualitydata.us/data/Result/search?statecode=US%3A09&characteristicType=Nutrient&startDateLo=04-01-2023&startDateHi=11-01-2023&mimeType=csv&zip=yes&dataProfile=resultPhysChem&providers=NWIS&providers=STEWARDS&providers=STORET")
#' projectProfile <- TADA_ReadWQPWebServices("https://www.waterqualitydata.us/data/Project/search?statecode=US%3A09&characteristicType=Nutrient&startDateLo=04-01-2023&startDateHi=11-01-2023&mimeType=csv&zip=yes&providers=NWIS&providers=STEWARDS&providers=STORET")
#' # Use TADA_ReadWQPWebServices to load Station, Project,
#' # and Phys-Chem Result profiles
#' stationProfile <- TADA_ReadWQPWebServices(station_url)
#' physchemProfile <- TADA_ReadWQPWebServices(result_url)
#' projectProfile <- TADA_ReadWQPWebServices(project_url)
#'
#' # Join all three profiles using TADA_JoinWQPProfiles
#' TADAProfile <- TADA_JoinWQPProfiles(
#' FullPhysChem = physchemProfile, Sites = stationProfile,
#' FullPhysChem = physchemProfile,
#' Sites = stationProfile,
#' Projects = projectProfile
#' )
#'
#' # Run TADA_CheckRequiredFields, returns error message,
#' # 'The dataframe does not contain the required fields: ActivityStartDateTime'
#' # Run TADA_CheckRequiredFields, returns error message
#' TADA_CheckRequiredFields(TADAProfile)
#'
#' # Add missing col
#' # Add missing column
#' TADAProfile1 <- TADA_CreateDateTime(
#' .data = TADAProfile,
#' date_col = "ActivityStartDate",
Expand Down
5 changes: 3 additions & 2 deletions R/GeospatialFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -3542,14 +3542,15 @@ TADA_CreateAUMLCrosswalk <- function(.data, au_ref = NULL,
sf::st_drop_geometry() %>%
dplyr::select(TADA.MonitoringLocationIdentifier,
ATTAINS.AssessmentUnitIdentifier,
OrganizationIdentifier) %>%
OrganizationIdentifier,
ATTAINS.WaterType) %>%
dplyr::distinct() %>%
dplyr::rename(MS_LOCATION_ID = TADA.MonitoringLocationIdentifier,
ASSESSMENT_UNIT_ID = ATTAINS.AssessmentUnitIdentifier,
MS_ORG_ID = OrganizationIdentifier) %>%
dplyr::mutate(MS_DATA_LINK = NA) %>%
dplyr::select(ASSESSMENT_UNIT_ID, MS_ORG_ID, MS_LOCATION_ID,
MS_DATA_LINK)
MS_DATA_LINK, ATTAINS.WaterType)

final_list <- c(final_list, list("ATTAINS_batchupload" = ATTAINS_batchupload))
}
Expand Down
81 changes: 61 additions & 20 deletions R/RequiredCols.R
Original file line number Diff line number Diff line change
Expand Up @@ -282,18 +282,36 @@ last.cols <- c(
#'
#' @examples
#' \dontrun{
#' # Find web service URLs for each Profile using WQP User Interface (https://www.waterqualitydata.us/)
#' # Example WQP URL: https://www.waterqualitydata.us/#statecode=US%3A09&characteristicType=Nutrient&startDateLo=04-01-2023&startDateHi=11-01-2023&mimeType=csv&providers=NWIS&providers=STEWARDS&providers=STORET
#'
#' # Use TADA_ReadWQPWebServices to load the Station, Project, and Phys-Chem Result profiles
#' stationProfile <- TADA_ReadWQPWebServices("https://www.waterqualitydata.us/data/Station/search?statecode=US%3A09&characteristicType=Nutrient&startDateLo=04-01-2023&startDateHi=11-01-2023&mimeType=csv&zip=yes&providers=NWIS&providers=STEWARDS&providers=STORET")
#' physchemProfile <- TADA_ReadWQPWebServices("https://www.waterqualitydata.us/data/Result/search?statecode=US%3A09&characteristicType=Nutrient&startDateLo=04-01-2023&startDateHi=11-01-2023&mimeType=csv&zip=yes&dataProfile=resultPhysChem&providers=NWIS&providers=STEWARDS&providers=STORET")
#' projectProfile <- TADA_ReadWQPWebServices("https://www.waterqualitydata.us/data/Project/search?statecode=US%3A09&characteristicType=Nutrient&startDateLo=04-01-2023&startDateHi=11-01-2023&mimeType=csv&zip=yes&providers=NWIS&providers=STEWARDS&providers=STORET")
#' # Find web service URLs for each Profile using WQP User Interface
#' # (https://www.waterqualitydata.us/)
#' # Example WQP URL:
#' # https://www.waterqualitydata.us/#statecode=US%3A09&characteristicType=Nutrient&
#' # startDateLo=04-01-2023&startDateHi=11-01-2023&mimeType=csv&providers=NWIS&
#' # providers=STEWARDS&providers=STORET
#'
#' # Define base URL and common components
#' baseurl <- "https://www.waterqualitydata.us"
#' filters <- "/search?statecode=US%3A09&characteristicType=Nutrient"
#' dates <- "&startDateLo=04-01-2023&startDateHi=11-01-2023"
#' type <- "&mimeType=csv&zip=yes"
#' providers <- "&providers=NWIS&providers=STEWARDS&providers=STORET"
#'
#' # Construct URLs for different profiles
#' station_url <- paste0(baseurl, "/data/Station", filters, dates, type, providers)
#' result_url <- paste0(baseurl, "/data/Result", filters, dates, type,
#' "&dataProfile=resultPhysChem", providers)
#' project_url <- paste0(baseurl, "/data/Project", filters, dates, type, providers)
#'
#' # Use TADA_ReadWQPWebServices to load Station, Project, and Phys-Chem Result profiles
#' stationProfile <- TADA_ReadWQPWebServices(station_url)
#' physchemProfile <- TADA_ReadWQPWebServices(result_url)
#' projectProfile <- TADA_ReadWQPWebServices(project_url)
#'
#' # Join all three profiles using TADA_JoinWQPProfiles
#' TADAProfile <- TADA_JoinWQPProfiles(
#' FullPhysChem = physchemProfile,
#' Sites = stationProfile, Projects = projectProfile
#' Sites = stationProfile,
#' Projects = projectProfile
#' )
#'
#' # Run TADA_OrderCols
Expand Down Expand Up @@ -362,25 +380,48 @@ TADA_GetTemplate <- function() {
#'
#' @examples
#' \dontrun{
#' # Find web service URLs for each Profile using WQP User Interface (https://www.waterqualitydata.us/)
#' # Example WQP URL: https://www.waterqualitydata.us/#statecode=US%3A09&characteristicType=Nutrient&startDateLo=04-01-2023&startDateHi=11-01-2023&mimeType=csv&providers=NWIS&providers=STEWARDS&providers=STORET
#' # Find web service URLs for each Profile using WQP User Interface
#' # (https://www.waterqualitydata.us/)
#' # Example WQP URL:
#' # https://www.waterqualitydata.us/#statecode=US%3A09&characteristicType=Nutrient&
#' # startDateLo=04-01-2023&startDateHi=11-01-2023&mimeType=csv&providers=NWIS&
#' # providers=STEWARDS&providers=STORET
#'
#' # Define base URL and common components
#' baseurl <- "https://www.waterqualitydata.us"
#' filters <- "/search?statecode=US%3A09&characteristicType=Nutrient"
#' dates <- "&startDateLo=04-01-2023&startDateHi=11-01-2023"
#' type <- "&mimeType=csv&zip=yes"
#' providers <- "&providers=NWIS&providers=STEWARDS&providers=STORET"
#'
#' # Construct URLs for different profiles
#' station_url <- paste0(
#' baseurl, "/data/Station", filters, dates, type, providers
#' )
#' result_url <- paste0(
#' baseurl, "/data/Result", filters, dates, type,
#' "&dataProfile=resultPhysChem", providers
#' )
#' project_url <- paste0(
#' baseurl, "/data/Project", filters, dates, type, providers
#' )
#'
#' # Use TADA_ReadWQPWebServices to load the Station, Project, and Phys-Chem Result profiles
#' stationProfile <- TADA_ReadWQPWebServices("https://www.waterqualitydata.us/data/Station/search?statecode=US%3A09&characteristicType=Nutrient&startDateLo=04-01-2023&startDateHi=11-01-2023&mimeType=csv&zip=yes&providers=NWIS&providers=STEWARDS&providers=STORET")
#' physchemProfile <- TADA_ReadWQPWebServices("https://www.waterqualitydata.us/data/Result/search?statecode=US%3A09&characteristicType=Nutrient&startDateLo=04-01-2023&startDateHi=11-01-2023&mimeType=csv&zip=yes&dataProfile=resultPhysChem&providers=NWIS&providers=STEWARDS&providers=STORET")
#' projectProfile <- TADA_ReadWQPWebServices("https://www.waterqualitydata.us/data/Project/search?statecode=US%3A09&characteristicType=Nutrient&startDateLo=04-01-2023&startDateHi=11-01-2023&mimeType=csv&zip=yes&providers=NWIS&providers=STEWARDS&providers=STORET")
#' # Use TADA_ReadWQPWebServices to load Station, Project, and Phys-Chem profiles
#' stationProfile <- TADA_ReadWQPWebServices(station_url)
#' physchemProfile <- TADA_ReadWQPWebServices(result_url)
#' projectProfile <- TADA_ReadWQPWebServices(project_url)
#'
#' # Join all three profiles using TADA_JoinWQPProfiles
#' # Join profiles using TADA_JoinWQPProfiles
#' TADAProfile <- TADA_JoinWQPProfiles(
#' FullPhysChem = physchemProfile, Sites = stationProfile,
#' FullPhysChem = physchemProfile,
#' Sites = stationProfile,
#' Projects = projectProfile
#' )
#'
#' # Run TADA_CheckRequiredFields, returns error message,
#' # 'The dataframe does not contain the required fields: ActivityStartDateTime'
#' # Run TADA_CheckRequiredFields, returns error message
#' TADA_CheckRequiredFields(TADAProfile)
#'
#' # Add missing col
#' # Add missing column
#' TADAProfile1 <- TADA_CreateDateTime(
#' .data = TADAProfile,
#' date_col = "ActivityStartDate",
Expand All @@ -397,7 +438,7 @@ TADA_GetTemplate <- function() {
#' "ActivityStartTime.TimeZoneCode_offset"
#' ))
#'
#' # re-run TADA_CheckRequiredFields, returns TRUE
#' # Re-run TADA_CheckRequiredFields, returns TRUE
#' TADA_CheckRequiredFields(TADAProfile1)
#' }
#'
Expand Down
Loading
Loading