Skip to content

Commit

Permalink
rename util_dps_entfacseg to util_dps_entinfo, no bayseg
Browse files Browse the repository at this point in the history
  • Loading branch information
fawda123 committed Jan 30, 2024
1 parent a315fdc commit a81fef6
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export(anlz_dps_entity)
export(util_dps_addcol)
export(util_dps_checkfls)
export(util_dps_checkuni)
export(util_dps_entfacseg)
export(util_dps_entinfo)
importFrom(dplyr,"%>%")
importFrom(dplyr,case_when)
importFrom(dplyr,contains)
Expand Down
6 changes: 3 additions & 3 deletions R/anlz_dps_entity.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ anlz_dps_entity <- function(pth, skip = 0, sep = '\t'){
pivot_longer(names_to = 'var', values_to = 'conc_mgl', matches('tn_mgl|tp_mgl|tss_mgl|bod_mgl'))

# get entity, facility, and bay segment
entfac <- util_dps_entfacseg(pth)
entfac <- util_dps_entinfo(pth)

# get loads
out <- dat %>%
Expand All @@ -67,8 +67,8 @@ anlz_dps_entity <- function(pth, skip = 0, sep = '\t'){
grepl('^R\\-', source) ~ flow_m3m * 0.6,
T ~ flow_m3m
),
entity = entfac[[1]],
facility = entfac[[2]],
entity = entfac$entity,
facility = entfac$facname,
var = factor(var, levels = c('tn_mgl', 'tp_mgl', 'tss_mgl', 'bod_mgl'),
labels = c('tn_load', 'tp_load', 'tss_load', 'bod_load')
),
Expand Down
30 changes: 11 additions & 19 deletions R/util_dps_entfacseg.R → R/util_dps_entinfo.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Get DPS entity, facility, and bay segment from file name
#' Get DPS entity information from file name
#'
#' Get DPS entity, facility, and bay segment from file name
#' Get DPS entity information from file name
#'
#' @param pth path to raw entity data
#' @param asdf logical, if \code{TRUE} return as \code{data.frame}
Expand All @@ -12,12 +12,12 @@
#'
#' @importFrom dplyr filter pull select
#'
#' @return A list with entity, facility, and bay segment
#' @return A list or \code{data.frame} (if \code{asdf = TRUE}) with entity, facility, permit, and facility id
#'
#' @examples
#' pth <- system.file('extdata/ps_dom_hillsco_falkenburg_2019.txt', package = 'tbeploads')
#' util_dps_entfacseg(pth)
util_dps_entfacseg <- function(pth, asdf = FALSE){
#' util_dps_entinfo(pth)
util_dps_entinfo <- function(pth, asdf = FALSE){

# get entity and facility from path
flentfac <- basename(pth) %>%
Expand All @@ -26,24 +26,16 @@ util_dps_entfacseg <- function(pth, asdf = FALSE){
.[[1]] %>%
.[c(3, 4)]

entfac <- facilities %>%
facinfo <- facilities %>%
filter(entityshr == flentfac[1] & facnameshr == flentfac[2]) %>%
select(-source) %>%
select(-bayseg, -source, -basin) %>%
unique()

ent <- entfac %>%
pull(entity)
out <- facinfo %>%
select(entity, facname, permit, facid)

fac <- entfac %>%
pull(facname)

seg <- entfac %>%
pull(bayseg)

out <- list(entity = ent, facname = fac, bayseg = seg)

if(asdf)
out <- as.data.frame(out)
if(!asdf)
out <- as.list(out)

return(out)

Expand Down
16 changes: 8 additions & 8 deletions man/util_dps_entfacseg.Rd → man/util_dps_entinfo.Rd

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

8 changes: 0 additions & 8 deletions tests/testthat/test-util_dps_entfacseg.R

This file was deleted.

16 changes: 16 additions & 0 deletions tests/testthat/test-util_dps_entinfo.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
test_that("Extract entity, facility, and segment", {
pth <- system.file('extdata/ps_dom_hillsco_falkenburg_2019.txt', package = 'tbeploads')
result <- util_dps_entinfo(pth)

expect_equal(result, list(entity = "Hillsborough Co.", facname = "Falkenburg AWTP",
permit = "FL0040614", facid = "59"))
})

test_that("Extract entity, facility, and segment, as data frame", {
pth <- system.file('extdata/ps_dom_hillsco_falkenburg_2019.txt', package = 'tbeploads')
result <- util_dps_entinfo(pth, asdf = TRUE)

expect_equal(result, structure(list(entity = "Hillsborough Co.", facname = "Falkenburg AWTP",
permit = "FL0040614", facid = "59"), row.names = c(NA, -1L
), class = c("tbl_df", "tbl", "data.frame")))
})

0 comments on commit a81fef6

Please sign in to comment.