less_than_greater_than <- function(x, direction_col, standard_col, value_col) {
direction_col <- rlang::enquo(direction_col)
standard_col <- rlang::enquo(standard_col)
value_col <- rlang::enquo(value_col)
direction.vec <- x %>%
pull(!!direction_col) %>%
unique()
if (any(!direction.vec %in% c("less", "greater"))) stop("direction_col can only contain character strings 'less' or 'greater'")
x %>%
dplyr::mutate(impaired = dplyr::if_else(!!direction_col %in% "less",
!!value_col < !!standard_col,
!!value_col > !!standard_col)) %>%
dplyr::pull(impaired)
}
daily_average_do <- function(x) {
final.df <- do.df %>%
filter(wqs.type %in% "average",
wqs.time %in% "daily") %>%
group_by(SEG_ID, date, clean_class, CHEMICAL_NAME, wqs.narrative,
wqs.type,
wqs.violation.direction, wqs.numeric, units) %>%
summarize(daily_average = mean(RESULT_NUMERIC, na.rm = TRUE)) %>%
ungroup() %>%
mutate(impaired = less_than_greater_than(x = .,
direction_col = wqs.violation.direction,
standard_col = wqs.numeric,
value_col = daily_average))
}
impairment_do <- function(x, value_col) {
do.df <- x %>%
filter(CHEMICAL_NAME %in% "Dissolved Oxygen")
min_thresh.df <- do.df %>%
filter(wqs.type %in% "threshold",
wqs.time %in% "single") %>%
select(SEG_ID, date, clean_class, CHEMICAL_NAME, wqs.narrative,
wqs.type,
wqs.violation.direction, wqs.numeric, units, RESULT_NUMERIC) %>%
mutate(impaired = less_than_greater_than(x = .,
direction_col = wqs.violation.direction,
standard_col = wqs.numeric,
value_col = RESULT_NUMERIC)) %>%
select(-RESULT_NUMERIC)
bound.df <- dplyr::bind_rows(daily_avg.df, min_thresh.df) %>%
group_by(SEG_ID, date, clean_class, CHEMICAL_NAME, wqs.narrative,
wqs.violation.direction, units) %>%
summarize(impaired = any(impaired == TRUE))
}
mean_agg <- function(x, wqs_type, wqs_time) {
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.