Skip to content
Merged
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
44 changes: 44 additions & 0 deletions R/cia_utils.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,50 @@
# cia_utils.R
# Supporting functions for the CIA static and Shiny dashboards.

#' Model element finder
#' @description Finds the model, and its parent feature or prop given an OM elementid
#' @param elid Desired elementid
#' @param ds RomDataSource
#' @return data frame of info about the target elementid
#' @import sqldf
#' @export om_find_dh_elid
om_find_dh_elid <- function(elid, ds) {

model_search_elid <- fn$sqldf(
"select a.name, a.hydrocode,
CASE
WHEN a.hydroid IS NULL THEN 'model'
ELSE 'feature'
END as parent_type,
CASE
WHEN a.hydroid IS NULL THEN p.pid
ELSE a.hydroid
END as parent_id,
b.propname, b.pid, e.propvalue as elid
from dh_properties as e
left outer join dh_properties as b
on (
e.featureid = b.pid
)
left outer join dh_feature as a
on (
a.hydroid = b.featureid
)
left outer join dh_properties as p
on (
p.pid = b.featureid
and b.entity_type = 'dh_properties'
)
where e.propname = 'om_element_connection'
and e.propvalue = $elid
",
connection = ds$connection
)
if (nrow(model_search_elid) == 0) {
model_search_elid = FALSE
}
return(model_search_elid)
}

# CIA_data Function: Grabs data from vahydro and returns data frame
#data frame contains flow and percent change data for 2 runids of all upstream and downstream river segments
Expand Down
Loading