From 010a9edcfe11a61dd0feaf97427abcb61e8d0b6f Mon Sep 17 00:00:00 2001 From: "C. Brogan" <79171911+COBrogan@users.noreply.github.com> Date: Wed, 4 Jun 2025 09:35:04 -0400 Subject: [PATCH 01/23] Update r.yml --- .github/workflows/r.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/r.yml b/.github/workflows/r.yml index 01450fe6..3c142d50 100644 --- a/.github/workflows/r.yml +++ b/.github/workflows/r.yml @@ -22,7 +22,7 @@ jobs: runs-on: macos-latest strategy: matrix: - r-version: ['3.6.3', '4.1.1'] + r-version: ['4.4.1'] steps: - uses: actions/checkout@v3 From 0fa3a9f6bcd8239d0158680c8cfe75ae036e6b81 Mon Sep 17 00:00:00 2001 From: Brogan Date: Wed, 4 Jun 2025 09:49:33 -0400 Subject: [PATCH 02/23] Tried to fix yml --- .Rbuildignore | 3 ++- .github/.gitignore | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 .github/.gitignore diff --git a/.Rbuildignore b/.Rbuildignore index 8080423d..3912071b 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,2 +1,3 @@ ^.*\.Rproj$ -^\.Rproj\.user$ \ No newline at end of file +^\.Rproj\.user$ +^\.github$ diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 00000000..2d19fc76 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html From b0ba873e93db3d02c91e16e9c1d1930c03845bd6 Mon Sep 17 00:00:00 2001 From: "C. Brogan" <79171911+COBrogan@users.noreply.github.com> Date: Wed, 4 Jun 2025 09:50:17 -0400 Subject: [PATCH 03/23] Update r.yml From b0c52ee02021df709cd0134ea40cd548de32e9de Mon Sep 17 00:00:00 2001 From: "C. Brogan" <79171911+COBrogan@users.noreply.github.com> Date: Wed, 4 Jun 2025 09:53:39 -0400 Subject: [PATCH 04/23] Update r.yml --- .github/workflows/r.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/r.yml b/.github/workflows/r.yml index 3c142d50..d58dbd3f 100644 --- a/.github/workflows/r.yml +++ b/.github/workflows/r.yml @@ -19,7 +19,7 @@ permissions: jobs: build: - runs-on: macos-latest + runs-on: windows-latest strategy: matrix: r-version: ['4.4.1'] From c2bac36ca92804477a2c1af92905ff51c963a4b0 Mon Sep 17 00:00:00 2001 From: "C. Brogan" <79171911+COBrogan@users.noreply.github.com> Date: Wed, 4 Jun 2025 10:04:01 -0400 Subject: [PATCH 05/23] Update r.yml --- .github/workflows/r.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/r.yml b/.github/workflows/r.yml index d58dbd3f..0fe5d2cf 100644 --- a/.github/workflows/r.yml +++ b/.github/workflows/r.yml @@ -27,7 +27,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up R ${{ matrix.r-version }} - uses: r-lib/actions/setup-r@f57f1301a053485946083d7a45022b278929a78a + uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.r-version }} - name: Install dependencies From 94255983973107c9654ffecb9f3a5409805c0cbf Mon Sep 17 00:00:00 2001 From: "C. Brogan" <79171911+COBrogan@users.noreply.github.com> Date: Wed, 4 Jun 2025 10:17:57 -0400 Subject: [PATCH 06/23] Update r.yml I'll be honest, not sure why this works or if this is preferable. It's certainly less legible but is suggested by R's `usethis::use_github_action()`. It doens't seem as rooted in https://github.com/r-lib/actions/tree/v2/setup-r but it does work for some reason that is beyond me. So I reverted to this as I wasn't sure if v2 is up to date. I think this change is trying to pull the latest release of the r-lib actions above rather than hard-coding to v2 as I had here before. --- .github/workflows/r.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/r.yml b/.github/workflows/r.yml index 0fe5d2cf..d58dbd3f 100644 --- a/.github/workflows/r.yml +++ b/.github/workflows/r.yml @@ -27,7 +27,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up R ${{ matrix.r-version }} - uses: r-lib/actions/setup-r@v2 + uses: r-lib/actions/setup-r@f57f1301a053485946083d7a45022b278929a78a with: r-version: ${{ matrix.r-version }} - name: Install dependencies From a70bb506b2f508f1861cb2749239e204590ea805 Mon Sep 17 00:00:00 2001 From: Brogan Date: Thu, 5 Jun 2025 11:28:33 -0400 Subject: [PATCH 07/23] Added plugins for hydroImps to modify outputs --- R/RomDataSource.R | 3 ++ R/dHVariablePluginDefault.R | 73 ++++++++++++++++++++++++++++++++++++- 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/R/RomDataSource.R b/R/RomDataSource.R index 64fb2788..61b778b1 100644 --- a/R/RomDataSource.R +++ b/R/RomDataSource.R @@ -587,6 +587,9 @@ RomDataSource <- R6Class( } } } + # have an post process export method + export[[thisobject$propname]] <- plugin$exportOpenMIpost(thisobject, + export[[thisobject$propname]]) return(export) } else { diff --git a/R/dHVariablePluginDefault.R b/R/dHVariablePluginDefault.R index 603d5fd6..1bf20bc6 100644 --- a/R/dHVariablePluginDefault.R +++ b/R/dHVariablePluginDefault.R @@ -24,7 +24,6 @@ dHVariablePluginDefault <- R6Class( #message("Created plugin") }, #' @param entity the local object to work on - #' @param load_remote automatically query REST data source for matches? #' @return an updated config if necessary or FALSE if it fails exportOpenMI = function(entity) { # creates an array that can later be serialized as json, xml, or whatever @@ -490,6 +489,78 @@ dHOMWaterSystemTieredFlowBy <- R6Class( ) ) + +#' VA Hydro model impoundment plugin +#' @title dHOMHydroImpoundment +#' @description Simple class to deal with hydro impoundment class model objects +#' @details Has standard methods for exporting impoundment properties and subproperties +#' @importFrom R6 R6Class +#' @param entity list or object with entity info +#' @return reference class of type openmi.om.base. +#' @seealso NA +#' @examples NA +#' @export dHOMHydroImpoundment +dHOMHydroImpoundment <- R6Class( + "dHOMHydroImpoundment", + inherit = dHOMDataMatrix, + public = list( + #' @field name what is it called + name = NA, + #' @field object_class model object type + object_class = 'hydroImpoundment', + #' @param entity the local object to work on + #' @return an updated config if necessary or FALSE if it fails + exportOpenMIBase = function(entity) { + #print(paste("Entity matrix:", entity$propname)) + export = super$exportOpenMIBase(entity) + + return(export) + } + ) +) + +#' hydroimp +#' @title dHOMHydroImpoundmentSmall +#' @description Simple class to hold tabular flow by values +#' @details Has standard methods for managing data and meta data +#' @importFrom R6 R6Class +#' @param entity list or object with entity info +#' @return reference class of type openmi.om.base. +#' @seealso NA +#' @examples NA +#' @export dHOMHydroImpoundmentSmall +dHOMHydroImpoundmentSmall <- R6Class( + "dHOMHydroImpoundmentSmall", + inherit = dHOMHydroImpoundment, + public = list( + #' @field name what is it called + name = NA, + #' @field object_class model object type + object_class = 'hydroImpSmall', + #' @param entity the local object to work on + #' @return an updated config if necessary or FALSE if it fails + exportOpenMIBase = function(entity) { + #print(paste("Entity matrix:", entity$propname)) + export = super$exportOpenMIBase(entity) + + return(export) + }, + #' @param entity the local object to work on + #' @param export current export object + #' @return Returns a modified list of property and children + exportOpenMIpost = function(entity, export=list()) { + #Copy the storage_stage_area matrix and properties over to a new list + #matrix that is expected in the php import to OM + export$matrix <- export$storage_stage_area + #Remove the original list + export$storage_stage_area <- NULL + return(export) + } + ) +) + + + # 'This is here because there is no way to instantiate a dynamic class using # 'a string for a class name, so we have to have logic to expose allowed classes #' Retrieve Plugin object for a variable entity From 159551fd1bc98cc46b76e7b88d0574adc78c6aad Mon Sep 17 00:00:00 2001 From: Brogan Date: Thu, 5 Jun 2025 11:33:54 -0400 Subject: [PATCH 08/23] Updated documentation and build --- NAMESPACE | 3 + data/test.csv | 2 - man/RomFeature.Rd | 2 +- man/dHOMHydroImpoundment.Rd | 88 ++++++++++++++++++++++ man/dHOMHydroImpoundmentSmall.Rd | 110 +++++++++++++++++++++++++++ man/dHOMWaterSystemTieredFlowBy.Rd | 115 +++++++++++++++++++++++++++++ man/dHVariablePluginDefault.Rd | 2 - 7 files changed, 317 insertions(+), 5 deletions(-) delete mode 100644 data/test.csv create mode 100644 man/dHOMHydroImpoundment.Rd create mode 100644 man/dHOMHydroImpoundmentSmall.Rd create mode 100644 man/dHOMWaterSystemTieredFlowBy.Rd diff --git a/NAMESPACE b/NAMESPACE index f9bd73ba..dee25efe 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -15,7 +15,10 @@ export(dHOMConstant) export(dHOMConsumptiveUseFractionsPWS) export(dHOMDataMatrix) export(dHOMEquation) +export(dHOMHydroImpoundment) +export(dHOMHydroImpoundmentSmall) export(dHOMObjectClass) +export(dHOMWaterSystemTieredFlowBy) export(dHOMbroadCastObject) export(dHOMtextField) export(dHVarAnnotation) diff --git a/data/test.csv b/data/test.csv deleted file mode 100644 index d7e79264..00000000 --- a/data/test.csv +++ /dev/null @@ -1,2 +0,0 @@ -hydroid,name -1,dummy \ No newline at end of file diff --git a/man/RomFeature.Rd b/man/RomFeature.Rd index f7bea27d..6741e15c 100644 --- a/man/RomFeature.Rd +++ b/man/RomFeature.Rd @@ -252,7 +252,7 @@ NULL \item{\code{inputs}}{criteria to search for (list key = value format)} -\item{\code{operator}}{what type of spatial function, default = st_contains. +\item{\code{operator}}{what type of spatial function,default = st_contains Other options are 'overlaps' or 'st_within'} \item{\code{return_geoms}}{FALSE will return a smaller dataframe} diff --git a/man/dHOMHydroImpoundment.Rd b/man/dHOMHydroImpoundment.Rd new file mode 100644 index 00000000..6e218861 --- /dev/null +++ b/man/dHOMHydroImpoundment.Rd @@ -0,0 +1,88 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/dHVariablePluginDefault.R +\name{dHOMHydroImpoundment} +\alias{dHOMHydroImpoundment} +\title{dHOMHydroImpoundment} +\value{ +reference class of type openmi.om.base. +} +\description{ +Simple class to deal with hydro impoundment class model objects +} +\details{ +VA Hydro model impoundment plugin + +Has standard methods for exporting impoundment properties and subproperties +} +\examples{ +NA +} +\seealso{ +NA +} +\section{Super classes}{ +\code{\link[hydrotools:dHVariablePluginDefault]{hydrotools::dHVariablePluginDefault}} -> \code{\link[hydrotools:dHOMDataMatrix]{hydrotools::dHOMDataMatrix}} -> \code{dHOMHydroImpoundment} +} +\section{Public fields}{ +\if{html}{\out{
}} +\describe{ +\item{\code{name}}{what is it called} + +\item{\code{object_class}}{model object type} +} +\if{html}{\out{
}} +} +\section{Methods}{ +\subsection{Public methods}{ +\itemize{ +\item \href{#method-dHOMHydroImpoundment-exportOpenMIBase}{\code{dHOMHydroImpoundment$exportOpenMIBase()}} +\item \href{#method-dHOMHydroImpoundment-clone}{\code{dHOMHydroImpoundment$clone()}} +} +} +\if{html}{\out{ +
Inherited methods + +
+}} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-dHOMHydroImpoundment-exportOpenMIBase}{}}} +\subsection{Method \code{exportOpenMIBase()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{dHOMHydroImpoundment$exportOpenMIBase(entity)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{entity}}{the local object to work on} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +an updated config if necessary or FALSE if it fails +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-dHOMHydroImpoundment-clone}{}}} +\subsection{Method \code{clone()}}{ +The objects of this class are cloneable with this method. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{dHOMHydroImpoundment$clone(deep = FALSE)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{deep}}{Whether to make a deep clone.} +} +\if{html}{\out{
}} +} +} +} diff --git a/man/dHOMHydroImpoundmentSmall.Rd b/man/dHOMHydroImpoundmentSmall.Rd new file mode 100644 index 00000000..2c55fa13 --- /dev/null +++ b/man/dHOMHydroImpoundmentSmall.Rd @@ -0,0 +1,110 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/dHVariablePluginDefault.R +\name{dHOMHydroImpoundmentSmall} +\alias{dHOMHydroImpoundmentSmall} +\title{dHOMHydroImpoundmentSmall} +\value{ +reference class of type openmi.om.base. +} +\description{ +Simple class to hold tabular flow by values +} +\details{ +hydroimp + +Has standard methods for managing data and meta data +} +\examples{ +NA +} +\seealso{ +NA +} +\section{Super classes}{ +\code{\link[hydrotools:dHVariablePluginDefault]{hydrotools::dHVariablePluginDefault}} -> \code{\link[hydrotools:dHOMDataMatrix]{hydrotools::dHOMDataMatrix}} -> \code{\link[hydrotools:dHOMHydroImpoundment]{hydrotools::dHOMHydroImpoundment}} -> \code{dHOMHydroImpoundmentSmall} +} +\section{Public fields}{ +\if{html}{\out{
}} +\describe{ +\item{\code{name}}{what is it called} + +\item{\code{object_class}}{model object type} +} +\if{html}{\out{
}} +} +\section{Methods}{ +\subsection{Public methods}{ +\itemize{ +\item \href{#method-dHOMHydroImpoundmentSmall-exportOpenMIBase}{\code{dHOMHydroImpoundmentSmall$exportOpenMIBase()}} +\item \href{#method-dHOMHydroImpoundmentSmall-exportOpenMIpost}{\code{dHOMHydroImpoundmentSmall$exportOpenMIpost()}} +\item \href{#method-dHOMHydroImpoundmentSmall-clone}{\code{dHOMHydroImpoundmentSmall$clone()}} +} +} +\if{html}{\out{ +
Inherited methods + +
+}} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-dHOMHydroImpoundmentSmall-exportOpenMIBase}{}}} +\subsection{Method \code{exportOpenMIBase()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{dHOMHydroImpoundmentSmall$exportOpenMIBase(entity)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{entity}}{the local object to work on} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +an updated config if necessary or FALSE if it fails +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-dHOMHydroImpoundmentSmall-exportOpenMIpost}{}}} +\subsection{Method \code{exportOpenMIpost()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{dHOMHydroImpoundmentSmall$exportOpenMIpost(entity, export = list())}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{entity}}{the local object to work on} + +\item{\code{export}}{current export object} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +Returns a modified list of property and children +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-dHOMHydroImpoundmentSmall-clone}{}}} +\subsection{Method \code{clone()}}{ +The objects of this class are cloneable with this method. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{dHOMHydroImpoundmentSmall$clone(deep = FALSE)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{deep}}{Whether to make a deep clone.} +} +\if{html}{\out{
}} +} +} +} diff --git a/man/dHOMWaterSystemTieredFlowBy.Rd b/man/dHOMWaterSystemTieredFlowBy.Rd new file mode 100644 index 00000000..7591e709 --- /dev/null +++ b/man/dHOMWaterSystemTieredFlowBy.Rd @@ -0,0 +1,115 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/dHVariablePluginDefault.R +\name{dHOMWaterSystemTieredFlowBy} +\alias{dHOMWaterSystemTieredFlowBy} +\title{dHOMWaterSystemTieredFlowBy} +\value{ +reference class of type openmi.om.base. +} +\description{ +Simple class to hold tabular flow by values +} +\details{ +Tiered flowby meta-model object + +Has standard methods for managing data and meta data +} +\examples{ +NA +} +\seealso{ +NA +} +\section{Super classes}{ +\code{\link[hydrotools:dHVariablePluginDefault]{hydrotools::dHVariablePluginDefault}} -> \code{\link[hydrotools:dHOMDataMatrix]{hydrotools::dHOMDataMatrix}} -> \code{dHOMWaterSystemTieredFlowBy} +} +\section{Public fields}{ +\if{html}{\out{
}} +\describe{ +\item{\code{name}}{what is it called} + +\item{\code{object_class}}{model object type} +} +\if{html}{\out{
}} +} +\section{Methods}{ +\subsection{Public methods}{ +\itemize{ +\item \href{#method-dHOMWaterSystemTieredFlowBy-exportOpenMIBase}{\code{dHOMWaterSystemTieredFlowBy$exportOpenMIBase()}} +\item \href{#method-dHOMWaterSystemTieredFlowBy-list2matrix}{\code{dHOMWaterSystemTieredFlowBy$list2matrix()}} +\item \href{#method-dHOMWaterSystemTieredFlowBy-translateOMtoDH}{\code{dHOMWaterSystemTieredFlowBy$translateOMtoDH()}} +\item \href{#method-dHOMWaterSystemTieredFlowBy-clone}{\code{dHOMWaterSystemTieredFlowBy$clone()}} +} +} +\if{html}{\out{ +
Inherited methods + +
+}} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-dHOMWaterSystemTieredFlowBy-exportOpenMIBase}{}}} +\subsection{Method \code{exportOpenMIBase()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{dHOMWaterSystemTieredFlowBy$exportOpenMIBase(entity)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{entity}}{the local object to work on} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +an updated config if necessary or FALSE if it fails +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-dHOMWaterSystemTieredFlowBy-list2matrix}{}}} +\subsection{Method \code{list2matrix()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{dHOMWaterSystemTieredFlowBy$list2matrix(l)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-dHOMWaterSystemTieredFlowBy-translateOMtoDH}{}}} +\subsection{Method \code{translateOMtoDH()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{dHOMWaterSystemTieredFlowBy$translateOMtoDH(entity, om_json)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{entity}}{list or object with entity info} +} +\if{html}{\out{
}} +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-dHOMWaterSystemTieredFlowBy-clone}{}}} +\subsection{Method \code{clone()}}{ +The objects of this class are cloneable with this method. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{dHOMWaterSystemTieredFlowBy$clone(deep = FALSE)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{deep}}{Whether to make a deep clone.} +} +\if{html}{\out{
}} +} +} +} diff --git a/man/dHVariablePluginDefault.Rd b/man/dHVariablePluginDefault.Rd index 5fb8b83b..76684450 100644 --- a/man/dHVariablePluginDefault.Rd +++ b/man/dHVariablePluginDefault.Rd @@ -73,8 +73,6 @@ object instance \if{html}{\out{
}} \describe{ \item{\code{entity}}{the local object to work on} - -\item{\code{load_remote}}{automatically query REST data source for matches?} } \if{html}{\out{
}} } From 2e01be1a7c9a33b5b4ffb6756fbb84aac036fe16 Mon Sep 17 00:00:00 2001 From: Brogan Date: Thu, 5 Jun 2025 11:43:32 -0400 Subject: [PATCH 09/23] Added exportPost method to base class to allow export modifications as needed --- R/dHVariablePluginDefault.R | 8 +++++++- man/dHOMAlphanumericConstant.Rd | 1 + man/dHOMConstant.Rd | 1 + man/dHOMConsumptiveUseFractionsPWS.Rd | 1 + man/dHOMDataMatrix.Rd | 1 + man/dHOMEquation.Rd | 1 + man/dHOMHydroImpoundment.Rd | 1 + man/dHOMObjectClass.Rd | 1 + man/dHOMPublicVars.Rd | 3 ++- man/dHOMWaterSystemTieredFlowBy.Rd | 1 + man/dHOMbroadCastObject.Rd | 1 + man/dHOMtextField.Rd | 1 + man/dHVarAnnotation.Rd | 1 + man/dHVarImage.Rd | 1 + man/dHVariablePluginDefault.Rd | 19 +++++++++++++++++++ 15 files changed, 40 insertions(+), 2 deletions(-) diff --git a/R/dHVariablePluginDefault.R b/R/dHVariablePluginDefault.R index 1bf20bc6..2767df87 100644 --- a/R/dHVariablePluginDefault.R +++ b/R/dHVariablePluginDefault.R @@ -72,6 +72,12 @@ dHVariablePluginDefault <- R6Class( ) return(export) }, + #' @param entity the local object to work on + #' @param export list of properties and subproperties to export + exportOpenMIpost = function(entity, export){ + #Allows modification of exported property lists prior to JSON conversion + return(export) + }, #' @param om_list the open MI export array/list to work on #' @return a Rom importable config or FALSE if it fails fromOpenMIBase = function(om_list) { @@ -548,7 +554,7 @@ dHOMHydroImpoundmentSmall <- R6Class( #' @param entity the local object to work on #' @param export current export object #' @return Returns a modified list of property and children - exportOpenMIpost = function(entity, export=list()) { + exportOpenMIpost = function(entity, export = list()) { #Copy the storage_stage_area matrix and properties over to a new list #matrix that is expected in the php import to OM export$matrix <- export$storage_stage_area diff --git a/man/dHOMAlphanumericConstant.Rd b/man/dHOMAlphanumericConstant.Rd index 8574ecf7..dd04b002 100644 --- a/man/dHOMAlphanumericConstant.Rd +++ b/man/dHOMAlphanumericConstant.Rd @@ -44,6 +44,7 @@ NA
Inherited methods diff --git a/man/dHOMConstant.Rd b/man/dHOMConstant.Rd index 090e6b77..7da3de40 100644 --- a/man/dHOMConstant.Rd +++ b/man/dHOMConstant.Rd @@ -44,6 +44,7 @@ NA
Inherited methods diff --git a/man/dHOMConsumptiveUseFractionsPWS.Rd b/man/dHOMConsumptiveUseFractionsPWS.Rd index 01c6f4ff..8b943650 100644 --- a/man/dHOMConsumptiveUseFractionsPWS.Rd +++ b/man/dHOMConsumptiveUseFractionsPWS.Rd @@ -43,6 +43,7 @@ NA
Inherited methods
  • hydrotools::dHVariablePluginDefault$exportOpenMI()
  • +
  • hydrotools::dHVariablePluginDefault$exportOpenMIpost()
  • hydrotools::dHVariablePluginDefault$fromOpenMIBase()
  • hydrotools::dHVariablePluginDefault$initialize()
  • hydrotools::dHOMDataMatrix$param_info()
  • diff --git a/man/dHOMDataMatrix.Rd b/man/dHOMDataMatrix.Rd index 5569b7aa..ea547c2b 100644 --- a/man/dHOMDataMatrix.Rd +++ b/man/dHOMDataMatrix.Rd @@ -46,6 +46,7 @@ NA
    Inherited methods diff --git a/man/dHOMEquation.Rd b/man/dHOMEquation.Rd index 52bea810..52651807 100644 --- a/man/dHOMEquation.Rd +++ b/man/dHOMEquation.Rd @@ -44,6 +44,7 @@ NA
    Inherited methods diff --git a/man/dHOMHydroImpoundment.Rd b/man/dHOMHydroImpoundment.Rd index 6e218861..0db5aec5 100644 --- a/man/dHOMHydroImpoundment.Rd +++ b/man/dHOMHydroImpoundment.Rd @@ -43,6 +43,7 @@ NA
    Inherited methods
    • hydrotools::dHVariablePluginDefault$exportOpenMI()
    • +
    • hydrotools::dHVariablePluginDefault$exportOpenMIpost()
    • hydrotools::dHVariablePluginDefault$fromOpenMIBase()
    • hydrotools::dHVariablePluginDefault$initialize()
    • hydrotools::dHOMDataMatrix$param_info()
    • diff --git a/man/dHOMObjectClass.Rd b/man/dHOMObjectClass.Rd index 22ca24c0..2d9344fa 100644 --- a/man/dHOMObjectClass.Rd +++ b/man/dHOMObjectClass.Rd @@ -34,6 +34,7 @@ NA
      Inherited methods
      • hydrotools::dHVariablePluginDefault$exportOpenMI()
      • +
      • hydrotools::dHVariablePluginDefault$exportOpenMIpost()
      • hydrotools::dHVariablePluginDefault$fromOpenMIBase()
      • hydrotools::dHVariablePluginDefault$param_info()
      • hydrotools::dHOMAlphanumericConstant$initialize()
      • diff --git a/man/dHOMPublicVars.Rd b/man/dHOMPublicVars.Rd index a6451e63..6e463cb9 100644 --- a/man/dHOMPublicVars.Rd +++ b/man/dHOMPublicVars.Rd @@ -28,9 +28,10 @@ NA } } \if{html}{\out{ -
        Inherited methods +
        Inherited methods
        • hydrotools::dHVariablePluginDefault$exportOpenMI()
        • +
        • hydrotools::dHVariablePluginDefault$exportOpenMIpost()
        • hydrotools::dHVariablePluginDefault$fromOpenMIBase()
        • hydrotools::dHVariablePluginDefault$param_info()
        • hydrotools::dHOMAlphanumericConstant$exportOpenMIBase()
        • diff --git a/man/dHOMWaterSystemTieredFlowBy.Rd b/man/dHOMWaterSystemTieredFlowBy.Rd index 7591e709..0ac4c4c4 100644 --- a/man/dHOMWaterSystemTieredFlowBy.Rd +++ b/man/dHOMWaterSystemTieredFlowBy.Rd @@ -45,6 +45,7 @@ NA
          Inherited methods
          • hydrotools::dHVariablePluginDefault$exportOpenMI()
          • +
          • hydrotools::dHVariablePluginDefault$exportOpenMIpost()
          • hydrotools::dHVariablePluginDefault$fromOpenMIBase()
          • hydrotools::dHVariablePluginDefault$initialize()
          • hydrotools::dHOMDataMatrix$param_info()
          • diff --git a/man/dHOMbroadCastObject.Rd b/man/dHOMbroadCastObject.Rd index 6374a4dd..4914feec 100644 --- a/man/dHOMbroadCastObject.Rd +++ b/man/dHOMbroadCastObject.Rd @@ -43,6 +43,7 @@ NA
            Inherited methods
            • hydrotools::dHVariablePluginDefault$exportOpenMI()
            • +
            • hydrotools::dHVariablePluginDefault$exportOpenMIpost()
            • hydrotools::dHVariablePluginDefault$fromOpenMIBase()
            • hydrotools::dHVariablePluginDefault$initialize()
            • hydrotools::dHVariablePluginDefault$param_info()
            • diff --git a/man/dHOMtextField.Rd b/man/dHOMtextField.Rd index 00491717..db08175d 100644 --- a/man/dHOMtextField.Rd +++ b/man/dHOMtextField.Rd @@ -43,6 +43,7 @@ NA
              Inherited methods
              • hydrotools::dHVariablePluginDefault$exportOpenMI()
              • +
              • hydrotools::dHVariablePluginDefault$exportOpenMIpost()
              • hydrotools::dHVariablePluginDefault$fromOpenMIBase()
              • hydrotools::dHVariablePluginDefault$initialize()
              • hydrotools::dHVariablePluginDefault$param_info()
              • diff --git a/man/dHVarAnnotation.Rd b/man/dHVarAnnotation.Rd index 34647403..a09aea02 100644 --- a/man/dHVarAnnotation.Rd +++ b/man/dHVarAnnotation.Rd @@ -43,6 +43,7 @@ NA
                Inherited methods
                • hydrotools::dHVariablePluginDefault$exportOpenMI()
                • +
                • hydrotools::dHVariablePluginDefault$exportOpenMIpost()
                • hydrotools::dHVariablePluginDefault$fromOpenMIBase()
                • hydrotools::dHVariablePluginDefault$initialize()
                • hydrotools::dHVariablePluginDefault$param_info()
                • diff --git a/man/dHVarImage.Rd b/man/dHVarImage.Rd index 717295c4..11e8f417 100644 --- a/man/dHVarImage.Rd +++ b/man/dHVarImage.Rd @@ -44,6 +44,7 @@ NA
                  Inherited methods diff --git a/man/dHVariablePluginDefault.Rd b/man/dHVariablePluginDefault.Rd index 76684450..3c6c94ff 100644 --- a/man/dHVariablePluginDefault.Rd +++ b/man/dHVariablePluginDefault.Rd @@ -37,6 +37,7 @@ NA \item \href{#method-dHVariablePluginDefault-new}{\code{dHVariablePluginDefault$new()}} \item \href{#method-dHVariablePluginDefault-exportOpenMI}{\code{dHVariablePluginDefault$exportOpenMI()}} \item \href{#method-dHVariablePluginDefault-exportOpenMIBase}{\code{dHVariablePluginDefault$exportOpenMIBase()}} +\item \href{#method-dHVariablePluginDefault-exportOpenMIpost}{\code{dHVariablePluginDefault$exportOpenMIpost()}} \item \href{#method-dHVariablePluginDefault-fromOpenMIBase}{\code{dHVariablePluginDefault$fromOpenMIBase()}} \item \href{#method-dHVariablePluginDefault-param_info}{\code{dHVariablePluginDefault$param_info()}} \item \href{#method-dHVariablePluginDefault-clone}{\code{dHVariablePluginDefault$clone()}} @@ -100,6 +101,24 @@ an updated config if necessary or FALSE if it fails } } \if{html}{\out{
                  }} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-dHVariablePluginDefault-exportOpenMIpost}{}}} +\subsection{Method \code{exportOpenMIpost()}}{ +\subsection{Usage}{ +\if{html}{\out{
                  }}\preformatted{dHVariablePluginDefault$exportOpenMIpost(entity, export)}\if{html}{\out{
                  }} +} + +\subsection{Arguments}{ +\if{html}{\out{
                  }} +\describe{ +\item{\code{entity}}{the local object to work on} + +\item{\code{export}}{list of properties and subproperties to export} +} +\if{html}{\out{
                  }} +} +} +\if{html}{\out{
                  }} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-dHVariablePluginDefault-fromOpenMIBase}{}}} \subsection{Method \code{fromOpenMIBase()}}{ From 4b080aee920b94248bd9db7c62fe3dff447ab61d Mon Sep 17 00:00:00 2001 From: Brogan Date: Thu, 5 Jun 2025 11:58:42 -0400 Subject: [PATCH 10/23] Updated get_plugin_class --- R/dHVariablePluginDefault.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/dHVariablePluginDefault.R b/R/dHVariablePluginDefault.R index 2767df87..f2fce783 100644 --- a/R/dHVariablePluginDefault.R +++ b/R/dHVariablePluginDefault.R @@ -583,6 +583,10 @@ get_plugin_class <- function(plugin_name, entity) { plugin = dHVariablePluginDefault$new(entity) } else if (plugin_name == "dHOMConstant") { plugin = dHOMConstant$new(entity) + } else if (plugin_name == "dHOMHydroImpoundmentSmall") { + plugin = dHOMHydroImpoundmentSmall$new(entity) + } else if (plugin_name == "dHOMHydroImpoundment") { + plugin = dHOMHydroImpoundment$new(entity) } else if (plugin_name == "dHOMEquation") { plugin = dHOMEquation$new(entity) } else if (plugin_name == "dHOMAlphanumericConstant") { From 6f41a6b7ce9b70920bdd4959a80d9f73da278ef9 Mon Sep 17 00:00:00 2001 From: "connor.brogan@deq.virginia.gov" Date: Thu, 5 Jun 2025 15:23:35 -0400 Subject: [PATCH 11/23] Use remote database when reading objects for nest JSON export/import --- R/RomDataSource.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/RomDataSource.R b/R/RomDataSource.R index 61b778b1..0a501273 100644 --- a/R/RomDataSource.R +++ b/R/RomDataSource.R @@ -566,7 +566,7 @@ RomDataSource <- R6Class( #' @return unserialized json as list, with object stored in ds$prop_json_cache get_nested_export = function(ds, featureid, props, depth=0) { propatts <- as.list(props[which(props$pid == featureid),]) - thisobject = RomProperty$new(ds, propatts, FALSE ) + thisobject = RomProperty$new(ds, propatts, TRUE ) export = list() if (!is.null(thisobject$vardef)) { plugin <- thisobject$vardef$get_plugin(thisobject) From f2e093a320af7e3673a5119e2759ee82f3313d27 Mon Sep 17 00:00:00 2001 From: "connor.brogan@deq.virginia.gov" Date: Thu, 5 Jun 2025 15:45:47 -0400 Subject: [PATCH 12/23] Hydroimpsmall creates storage_matrix now --- R/dHVariablePluginDefault.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/dHVariablePluginDefault.R b/R/dHVariablePluginDefault.R index f2fce783..25b3b261 100644 --- a/R/dHVariablePluginDefault.R +++ b/R/dHVariablePluginDefault.R @@ -557,7 +557,7 @@ dHOMHydroImpoundmentSmall <- R6Class( exportOpenMIpost = function(entity, export = list()) { #Copy the storage_stage_area matrix and properties over to a new list #matrix that is expected in the php import to OM - export$matrix <- export$storage_stage_area + export$storage_matrix <- export$storage_stage_area #Remove the original list export$storage_stage_area <- NULL return(export) From c84802472e9ea44104759553f74bb48110ec86ea Mon Sep 17 00:00:00 2001 From: Burgholzer Date: Fri, 6 Jun 2025 08:19:58 -0400 Subject: [PATCH 13/23] test with different nomenclature --- R/dHVariablePluginDefault.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/dHVariablePluginDefault.R b/R/dHVariablePluginDefault.R index 25b3b261..4e5582f6 100644 --- a/R/dHVariablePluginDefault.R +++ b/R/dHVariablePluginDefault.R @@ -557,9 +557,9 @@ dHOMHydroImpoundmentSmall <- R6Class( exportOpenMIpost = function(entity, export = list()) { #Copy the storage_stage_area matrix and properties over to a new list #matrix that is expected in the php import to OM - export$storage_matrix <- export$storage_stage_area + export[['storage_matrix']] <- export[['storage_stage_area']] #Remove the original list - export$storage_stage_area <- NULL + export[['storage_stage_area']] <- NULL return(export) } ) From 774d8a33f23eefb31299798ee51d11e14017cc3b Mon Sep 17 00:00:00 2001 From: Burgholzer Date: Fri, 6 Jun 2025 08:22:52 -0400 Subject: [PATCH 14/23] test with different nomenclature --- R/RomDataSource.R | 2 +- R/dHVariablePluginDefault.R | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/R/RomDataSource.R b/R/RomDataSource.R index 0a501273..61b778b1 100644 --- a/R/RomDataSource.R +++ b/R/RomDataSource.R @@ -566,7 +566,7 @@ RomDataSource <- R6Class( #' @return unserialized json as list, with object stored in ds$prop_json_cache get_nested_export = function(ds, featureid, props, depth=0) { propatts <- as.list(props[which(props$pid == featureid),]) - thisobject = RomProperty$new(ds, propatts, TRUE ) + thisobject = RomProperty$new(ds, propatts, FALSE ) export = list() if (!is.null(thisobject$vardef)) { plugin <- thisobject$vardef$get_plugin(thisobject) diff --git a/R/dHVariablePluginDefault.R b/R/dHVariablePluginDefault.R index 4e5582f6..5a7ef35d 100644 --- a/R/dHVariablePluginDefault.R +++ b/R/dHVariablePluginDefault.R @@ -557,6 +557,7 @@ dHOMHydroImpoundmentSmall <- R6Class( exportOpenMIpost = function(entity, export = list()) { #Copy the storage_stage_area matrix and properties over to a new list #matrix that is expected in the php import to OM + message("Copying impoundment storage_stage_area to matrix") export[['storage_matrix']] <- export[['storage_stage_area']] #Remove the original list export[['storage_stage_area']] <- NULL From 0d6bc6f317fe0e04a1cacb380d43e5549d66cb74 Mon Sep 17 00:00:00 2001 From: Burgholzer Date: Fri, 6 Jun 2025 08:27:35 -0400 Subject: [PATCH 15/23] try matrix again instead of storage_matrix --- R/dHVariablePluginDefault.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/dHVariablePluginDefault.R b/R/dHVariablePluginDefault.R index 5a7ef35d..a765c3e1 100644 --- a/R/dHVariablePluginDefault.R +++ b/R/dHVariablePluginDefault.R @@ -558,7 +558,7 @@ dHOMHydroImpoundmentSmall <- R6Class( #Copy the storage_stage_area matrix and properties over to a new list #matrix that is expected in the php import to OM message("Copying impoundment storage_stage_area to matrix") - export[['storage_matrix']] <- export[['storage_stage_area']] + export[['matrix']] <- export[['storage_stage_area']] #Remove the original list export[['storage_stage_area']] <- NULL return(export) From 04829e76d541537f33c08626999113605dc96e7d Mon Sep 17 00:00:00 2001 From: Burgholzer Date: Fri, 6 Jun 2025 08:42:58 -0400 Subject: [PATCH 16/23] try matrix again instead of storage_matrix --- R/dHVariablePluginDefault.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/dHVariablePluginDefault.R b/R/dHVariablePluginDefault.R index a765c3e1..ef34b310 100644 --- a/R/dHVariablePluginDefault.R +++ b/R/dHVariablePluginDefault.R @@ -558,7 +558,7 @@ dHOMHydroImpoundmentSmall <- R6Class( #Copy the storage_stage_area matrix and properties over to a new list #matrix that is expected in the php import to OM message("Copying impoundment storage_stage_area to matrix") - export[['matrix']] <- export[['storage_stage_area']] + export[['matrix']] <- export[['storage_stage_area']][['matrix']] #Remove the original list export[['storage_stage_area']] <- NULL return(export) From e3fb6e27f4468b1b6dffa52a7c4a259d08faacd1 Mon Sep 17 00:00:00 2001 From: "connor.brogan@deq.virginia.gov" Date: Fri, 6 Jun 2025 10:33:58 -0400 Subject: [PATCH 17/23] Updates to RomProperty to allow for more consistent use of RomProperty to hopefully avoid unfortunate white space as t() coerces the input data frame to a matrix. Now handled column by column, which seems to help --- R/RomProperty.R | 24 +++++++++++++++++++++--- man/RomProperty.Rd | 10 ++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/R/RomProperty.R b/R/RomProperty.R index e63ce9d4..21cda14a 100644 --- a/R/RomProperty.R +++ b/R/RomProperty.R @@ -428,12 +428,30 @@ RomProperty <- R6Class( } super$delete(delete_remote) }, - #' @param row_cols update the matrix - #' @return NULL + #'@description + #'Takes in a data frame where each column represents a row to store in the + #'data matrix of this object. This method tranposes that data frame while + #'trying to maintain data strcutures and types + #' @param row_cols A data frame of rows that will be transposed to meet final + #' model or property structure e.g. \code{data.frame(c(1,'foo'), c(2,'bar'), c(3,'bingo'))} + #' will be coerced to \code{data.frame(c(1,2,3), c('foo','bar','bingo'))} + #' @return Nothing, but will set the data_matrix field on RomProperty + #' instance set_matrix = function(row_cols) { # expects a set of rows like this: # data.frame(c(1,'foo'), c(2,'bar'), c(3,'bingo')) - row_cols <- data.frame(t(row_cols),row.names=NULL) + #Transpose each row and then combine into one data frame. Previously we + #had used t() on the entire data frame to do this all at once, but t() + #required conversion to matrix which can only hold one data type and was + #adding white space to vectors with both charaters and numerics as it + #tried to keep consistent numbers of character + row_cols <- mapply( + FUN = function(df,coli){t(df[,coli])}, + coli = 1:ncol(row_cols), + MoreArgs = list(df = row_cols), + SIMPLIFY = FALSE) + #Convert to data frame, but remove column names: + row_cols <- as.data.frame(do.call(rbind,row_cols)) names(row_cols) <- NULL self$data_matrix = row_cols }, diff --git a/man/RomProperty.Rd b/man/RomProperty.Rd index 6b6f4a2d..72cb4f4b 100644 --- a/man/RomProperty.Rd +++ b/man/RomProperty.Rd @@ -285,6 +285,9 @@ NULL \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-RomProperty-set_matrix}{}}} \subsection{Method \code{set_matrix()}}{ +Takes in a data frame where each column represents a row to store in the +data matrix of this object. This method tranposes that data frame while +trying to maintain data strcutures and types \subsection{Usage}{ \if{html}{\out{
                  }}\preformatted{RomProperty$set_matrix(row_cols)}\if{html}{\out{
                  }} } @@ -292,12 +295,15 @@ NULL \subsection{Arguments}{ \if{html}{\out{
                  }} \describe{ -\item{\code{row_cols}}{update the matrix} +\item{\code{row_cols}}{A data frame of rows that will be transposed to meet final +model or property structure e.g. \code{data.frame(c(1,'foo'), c(2,'bar'), c(3,'bingo'))} +will be coerced to \code{data.frame(c(1,2,3), c('foo','bar','bingo'))}} } \if{html}{\out{
                  }} } \subsection{Returns}{ -NULL +Nothing, but will set the data_matrix field on RomProperty + instance } } \if{html}{\out{
                  }} From 2d446a5b2b144fbb206013ca2c8ee9bc54bffe67 Mon Sep 17 00:00:00 2001 From: "connor.brogan@deq.virginia.gov" Date: Mon, 9 Jun 2025 10:35:42 -0400 Subject: [PATCH 18/23] Updated documentation and added examples to IHA back in --- NAMESPACE | 1 + R/TNC_IHA_Ports.R | 18 +++++ data/test.csv | 2 - man/RomFeature.Rd | 2 +- man/dHOMWaterSystemTieredFlowBy.Rd | 115 +++++++++++++++++++++++++++++ man/group1.Rd | 10 +++ man/group2.Rd | 10 +++ 7 files changed, 155 insertions(+), 3 deletions(-) delete mode 100644 data/test.csv create mode 100644 man/dHOMWaterSystemTieredFlowBy.Rd diff --git a/NAMESPACE b/NAMESPACE index f9bd73ba..9872af7a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -16,6 +16,7 @@ export(dHOMConsumptiveUseFractionsPWS) export(dHOMDataMatrix) export(dHOMEquation) export(dHOMObjectClass) +export(dHOMWaterSystemTieredFlowBy) export(dHOMbroadCastObject) export(dHOMtextField) export(dHVarAnnotation) diff --git a/R/TNC_IHA_Ports.R b/R/TNC_IHA_Ports.R index ead2d5cd..9c0ddc52 100644 --- a/R/TNC_IHA_Ports.R +++ b/R/TNC_IHA_Ports.R @@ -132,6 +132,15 @@ water.year <- function (x) { #'@author jason.e.law@@gmail.com (imported to Hydrotools by Connor Brogan,connor.brogan@@deq.virginia.gov) #'@references #'\url{http://www.nature.org/initiatives/freshwater/conservationtools/art17004.html} +#' @examples +#'# #Get data for NF Shenandoah Mount Jackson +#'# flows <- dataRetrieval::readNWISdv("01633000",parameterCd = "00060") +#'# flows <- dataRetrieval::renameNWISColumns(flows) +#'# #Convert flows to zoo +#'# flows_zoo <- zoo::as.zoo(x = flows$Flow) +#'# zoo::index(flows_zoo) <- flows$Date +#'# #Use group 1 to get the minimum monthly flows: +#'# hydrotools::group1(flows_zoo,"water",FUN = min) #'@importFrom zoo index coredata is.zoo #'@importFrom lubridate year month #'@importFrom rapportools median @@ -193,6 +202,15 @@ group1 <- function ( #'@return a data frame with the group 2 statistics for each year #'@author jason.e.law@@gmail.com (imported to Hydrotools by Connor Brogan,connor.brogan@@deq.virginia.gov) #'@references \url{http://www.conservationgateway.org/Files/Pages/indicators-hydrologic-altaspx47.aspx} +#'@examples +#'# #Get data for NF Shenandoah Mount Jackson +#'# flows <- dataRetrieval::readNWISdv("01633000",parameterCd = "00060") +#'# flows <- dataRetrieval::renameNWISColumns(flows) +#'# #Convert flows to zoo +#'# flows_zoo <- zoo::as.zoo(x = flows$Flow) +#'# zoo::index(flows_zoo) <- flows$Date +#'# #Use group 2 to get critical period flows and stats: +#'# hydrotools::group2(flows_zoo,"water",mimic.tnc = TRUE) #'@importFrom plyr ddply '.' #'@importFrom zoo coredata index #'@importFrom lubridate year diff --git a/data/test.csv b/data/test.csv deleted file mode 100644 index d7e79264..00000000 --- a/data/test.csv +++ /dev/null @@ -1,2 +0,0 @@ -hydroid,name -1,dummy \ No newline at end of file diff --git a/man/RomFeature.Rd b/man/RomFeature.Rd index f7bea27d..6741e15c 100644 --- a/man/RomFeature.Rd +++ b/man/RomFeature.Rd @@ -252,7 +252,7 @@ NULL \item{\code{inputs}}{criteria to search for (list key = value format)} -\item{\code{operator}}{what type of spatial function, default = st_contains. +\item{\code{operator}}{what type of spatial function,default = st_contains Other options are 'overlaps' or 'st_within'} \item{\code{return_geoms}}{FALSE will return a smaller dataframe} diff --git a/man/dHOMWaterSystemTieredFlowBy.Rd b/man/dHOMWaterSystemTieredFlowBy.Rd new file mode 100644 index 00000000..7591e709 --- /dev/null +++ b/man/dHOMWaterSystemTieredFlowBy.Rd @@ -0,0 +1,115 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/dHVariablePluginDefault.R +\name{dHOMWaterSystemTieredFlowBy} +\alias{dHOMWaterSystemTieredFlowBy} +\title{dHOMWaterSystemTieredFlowBy} +\value{ +reference class of type openmi.om.base. +} +\description{ +Simple class to hold tabular flow by values +} +\details{ +Tiered flowby meta-model object + +Has standard methods for managing data and meta data +} +\examples{ +NA +} +\seealso{ +NA +} +\section{Super classes}{ +\code{\link[hydrotools:dHVariablePluginDefault]{hydrotools::dHVariablePluginDefault}} -> \code{\link[hydrotools:dHOMDataMatrix]{hydrotools::dHOMDataMatrix}} -> \code{dHOMWaterSystemTieredFlowBy} +} +\section{Public fields}{ +\if{html}{\out{
                  }} +\describe{ +\item{\code{name}}{what is it called} + +\item{\code{object_class}}{model object type} +} +\if{html}{\out{
                  }} +} +\section{Methods}{ +\subsection{Public methods}{ +\itemize{ +\item \href{#method-dHOMWaterSystemTieredFlowBy-exportOpenMIBase}{\code{dHOMWaterSystemTieredFlowBy$exportOpenMIBase()}} +\item \href{#method-dHOMWaterSystemTieredFlowBy-list2matrix}{\code{dHOMWaterSystemTieredFlowBy$list2matrix()}} +\item \href{#method-dHOMWaterSystemTieredFlowBy-translateOMtoDH}{\code{dHOMWaterSystemTieredFlowBy$translateOMtoDH()}} +\item \href{#method-dHOMWaterSystemTieredFlowBy-clone}{\code{dHOMWaterSystemTieredFlowBy$clone()}} +} +} +\if{html}{\out{ +
                  Inherited methods + +
                  +}} +\if{html}{\out{
                  }} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-dHOMWaterSystemTieredFlowBy-exportOpenMIBase}{}}} +\subsection{Method \code{exportOpenMIBase()}}{ +\subsection{Usage}{ +\if{html}{\out{
                  }}\preformatted{dHOMWaterSystemTieredFlowBy$exportOpenMIBase(entity)}\if{html}{\out{
                  }} +} + +\subsection{Arguments}{ +\if{html}{\out{
                  }} +\describe{ +\item{\code{entity}}{the local object to work on} +} +\if{html}{\out{
                  }} +} +\subsection{Returns}{ +an updated config if necessary or FALSE if it fails +} +} +\if{html}{\out{
                  }} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-dHOMWaterSystemTieredFlowBy-list2matrix}{}}} +\subsection{Method \code{list2matrix()}}{ +\subsection{Usage}{ +\if{html}{\out{
                  }}\preformatted{dHOMWaterSystemTieredFlowBy$list2matrix(l)}\if{html}{\out{
                  }} +} + +} +\if{html}{\out{
                  }} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-dHOMWaterSystemTieredFlowBy-translateOMtoDH}{}}} +\subsection{Method \code{translateOMtoDH()}}{ +\subsection{Usage}{ +\if{html}{\out{
                  }}\preformatted{dHOMWaterSystemTieredFlowBy$translateOMtoDH(entity, om_json)}\if{html}{\out{
                  }} +} + +\subsection{Arguments}{ +\if{html}{\out{
                  }} +\describe{ +\item{\code{entity}}{list or object with entity info} +} +\if{html}{\out{
                  }} +} +} +\if{html}{\out{
                  }} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-dHOMWaterSystemTieredFlowBy-clone}{}}} +\subsection{Method \code{clone()}}{ +The objects of this class are cloneable with this method. +\subsection{Usage}{ +\if{html}{\out{
                  }}\preformatted{dHOMWaterSystemTieredFlowBy$clone(deep = FALSE)}\if{html}{\out{
                  }} +} + +\subsection{Arguments}{ +\if{html}{\out{
                  }} +\describe{ +\item{\code{deep}}{Whether to make a deep clone.} +} +\if{html}{\out{
                  }} +} +} +} diff --git a/man/group1.Rd b/man/group1.Rd index a7ed0125..13d116ea 100644 --- a/man/group1.Rd +++ b/man/group1.Rd @@ -29,6 +29,16 @@ month+water year or calendar month+calendar year depending on user input See IHA documentation: \url{http://www.nature.org/initiatives/freshwater/conservationtools/art17004.html} } +\examples{ +# #Get data for NF Shenandoah Mount Jackson +# flows <- dataRetrieval::readNWISdv("01633000",parameterCd = "00060") +# flows <- dataRetrieval::renameNWISColumns(flows) +# #Convert flows to zoo +# flows_zoo <- zoo::as.zoo(x = flows$Flow) +# zoo::index(flows_zoo) <- flows$Date +# #Use group 1 to get the minimum monthly flows: +# hydrotools::group1(flows_zoo,"water",FUN = min) +} \references{ \url{http://www.nature.org/initiatives/freshwater/conservationtools/art17004.html} } diff --git a/man/group2.Rd b/man/group2.Rd index ba98ede6..3dfdd5d5 100644 --- a/man/group2.Rd +++ b/man/group2.Rd @@ -33,6 +33,16 @@ and finds the 1, 3, 7, 30, and 90 day rolling averages of the zoo. Then, it finds the range, base index, and days of zero flow of each year, with base index defined as the minimum 7-day flow divided by the average flow } +\examples{ +# #Get data for NF Shenandoah Mount Jackson +# flows <- dataRetrieval::readNWISdv("01633000",parameterCd = "00060") +# flows <- dataRetrieval::renameNWISColumns(flows) +# #Convert flows to zoo +# flows_zoo <- zoo::as.zoo(x = flows$Flow) +# zoo::index(flows_zoo) <- flows$Date +# #Use group 2 to get critical period flows and stats: +# hydrotools::group2(flows_zoo,"water",mimic.tnc = TRUE) +} \references{ \url{http://www.conservationgateway.org/Files/Pages/indicators-hydrologic-altaspx47.aspx} } From f1073f537bb7ba4097c95d7a5ee4cecc6d7fba39 Mon Sep 17 00:00:00 2001 From: "connor.brogan@deq.virginia.gov" Date: Mon, 9 Jun 2025 10:53:26 -0400 Subject: [PATCH 19/23] Specified DBI::dbConnect() in RomDataSource() --- DESCRIPTION | 1 + R/RomDataSource.R | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index c933f3cc..87bdea90 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -25,5 +25,6 @@ Imports: lubridate, plyr, RPostgres, + DBI, R6, sqldf diff --git a/R/RomDataSource.R b/R/RomDataSource.R index 61b778b1..e26a71b1 100644 --- a/R/RomDataSource.R +++ b/R/RomDataSource.R @@ -101,7 +101,7 @@ RomDataSource <- R6Class( if (self$connection_type == 'rest') { private$token <- om_vahydro_token(self$site, self$rest_uname, rest_pw) } else { - self$connection <- dbConnect( + self$connection <- DBI::dbConnect( bigint = "integer", RPostgres::Postgres(), dbname = self$dbname, From 36a1c16ee4fcaf6a07f6777c72a4b018ab1e0819 Mon Sep 17 00:00:00 2001 From: rburghol Date: Mon, 16 Jun 2025 12:27:44 -0400 Subject: [PATCH 20/23] Update auth.private.example --- auth.private.example | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/auth.private.example b/auth.private.example index d586ffca..e687ae8f 100644 --- a/auth.private.example +++ b/auth.private.example @@ -1,7 +1,10 @@ #VAHydro-1.0 Authentication -username <- "TRICKY_USERNAME" +username <- "old_USERNAME" hash <- "TRICKY_PASSWORD" #VAHydro-2.0 Admin REST Authentication -rest_uname <- 'TRICKY_USERNAME' +rest_uname <- 'rest_USERNAME' rest_pw <- 'TRICKY_PASSWORD' + +odbc_uname <- 'odbc_USERNAME' +odbc_pw <- 'TRICKY_PASSWORD' From b92090dfe1300349ebb247970d89a1513ad30019 Mon Sep 17 00:00:00 2001 From: rburghol Date: Mon, 16 Jun 2025 12:32:32 -0400 Subject: [PATCH 21/23] Update config.local.private.example --- config.local.private.example | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/config.local.private.example b/config.local.private.example index b42daf68..6ac53039 100644 --- a/config.local.private.example +++ b/config.local.private.example @@ -1,2 +1,13 @@ -# WHERE ARE YOU LOCALLY STORING THE hydro-tools REPOSITORY -repo_location <- "C:\\Users\\nrf46657\\Desktop\\VAHydro Development\\GitHub\\" \ No newline at end of file +# set up a caching function for NWIS +Sys.setenv(USGS_cache_dir = "/media/model/usgs") +export_path <- '/Workspace/tmp/' + +hydro_tools <- 'https://raw.githubusercontent.com/HARPgroup/hydro-tools/master' +cbp6_location <- 'https://raw.githubusercontent.com/HARPgroup/cbp6/master' +hydro_tools_location <- hydro_tools +om_location <- "https://raw.githubusercontent.com/HARPgroup/om/master" +elfgen_location <- "https://raw.githubusercontent.com/HARPgroup/elfgen/master" +openmi_om_location <- "https://raw.githubusercontent.com/HARPgroup/openmi-om/master" +vahydro_location <- "https://github.com/HARPgroup/vahydro/blob/master" +github_location <- "C:/usr/local/home/git" +HARParchive_location <- paste0(github_location, "/HARParchive") From 1e96953f14bce5b2d22e04d819a25e5a99113879 Mon Sep 17 00:00:00 2001 From: Brogan Date: Wed, 18 Jun 2025 15:00:21 -0400 Subject: [PATCH 22/23] Added CODEOWNERS file for pull request review --- .github/CODEOWNERS | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..17e8d41b --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,4 @@ +## Giving pull request review access to these users +* @rburghol +* @BrendanBrogan +* @COBrogan \ No newline at end of file From e04c4c1db3525af1913a77c8dd138d0d51add911 Mon Sep 17 00:00:00 2001 From: "connor.brogan@deq.virginia.gov" Date: Wed, 18 Jun 2025 16:29:53 -0400 Subject: [PATCH 23/23] Added a cleanup argument to fn_get_runfile and to its wrapper om_get_rundata to have it delete log files. Updated documentation for both functions --- R/om_get_rundata.R | 35 +++++++++++++++++++++++++---------- R/utils.R | 13 ++++++++++++- man/fn_get_runfile.Rd | 8 +++++++- man/om_get_rundata.Rd | 36 ++++++++++++++++++++++++------------ 4 files changed, 68 insertions(+), 24 deletions(-) diff --git a/R/om_get_rundata.R b/R/om_get_rundata.R index 59fc1d3c..5bf3ad1e 100644 --- a/R/om_get_rundata.R +++ b/R/om_get_rundata.R @@ -1,19 +1,32 @@ -#' The base class for executable equation based meta-model components. +#' Get OM Model Data +#' @description Retrieve model results (run data) from the VA Hydro server for a +#' particular model and run ID (scenario ID). +#' @details A wrapper of \code{hydrotools::fn_get_runfile()}. This function +#' returns the results in a zoo (see zoo::zoo()) that has the timestamp as the +#' index. See \code{hydrotools::fn_get_runfile()} for more details. #' -#' @param elid integer OM model element id -#' @param runid integer run id -#' @param site URL of om server +#' @param elid integer OM element connection ID e.g. the original OM model ID +#' @param runid integer run id representing the scenario. Ask the modeling team +#' for scenario IDs if you are unsure otherwise see the WSPA Shiny Dashboard +#' for more information +#' @param site URL of OM server, typically established in WSPA config files #' @param cached boolean - if TRUE will use recently stored local copy #' @param hydrowarmup boolean - if TRUE will trim beginning of model time frame -#' @return reference class of type openmi.om.equation -#' @seealso NA +#' to account for potential model warm up as water routes downstream from the +#' headwaters and operational rules engage +#' @param cleanup Logical. Should the function delete the log file create for +#' the cached argument? If this is TRUE, the .log files will be deleted after +#' download from OM server +#' @return data.frame of model results #' @export om_get_rundata -#' @examples NA -om_get_rundata <- function(elid, runid, site='http://deq2.bse.vt.edu', cached=FALSE, hydrowarmup=TRUE) { - +#' @examples #om_get_rundata(72446, 600, site=omsite) +om_get_rundata <- function(elid, runid, site='http://deq2.bse.vt.edu', + cached=FALSE, hydrowarmup=TRUE, + cleanup = FALSE) { # replace this with a single function that grabs # a hydro model for summarization and slims it down - dat <- fn_get_runfile(elid, runid, 37, site, cached = FALSE) + dat <- fn_get_runfile(elid, runid, 37, site, cached = FALSE, cleanup = cleanup, + outaszoo = outaszoo) syear = as.integer(min(dat$year)) eyear = as.integer(max(dat$year)) if ((hydrowarmup == TRUE) & (syear < (eyear - 2))) { @@ -33,9 +46,11 @@ om_get_rundata <- function(elid, runid, site='http://deq2.bse.vt.edu', cached=FA #ensure there are associated timezones sdate <- as.POSIXct(sdate,tz = "EST") edate <- as.POSIXct(edate,tz = "EST") + #Get the window of interest from the timeseries dat <- window(dat, start = sdate, end = edate); #Change mode of zoo to numeric e.g. Convert all fields to numeric mode(dat) <- 'numeric' + return(dat) } \ No newline at end of file diff --git a/R/utils.R b/R/utils.R index c87d057e..bf27a657 100644 --- a/R/utils.R +++ b/R/utils.R @@ -123,6 +123,10 @@ fn_get_runfile_info <- function( #' @param cached boolean - use local copy or force refresh #' @param outaszoo boolean return as a zoo timeseries if TRUE, or as data frame #' @param use_tz character pass in a custom timezone for zoo +#' @param cleanup Logical - Should the log file be deleted (TRUE) or written to +#' working directory (FALSE)? Note that the cached argument requires these log +#' files so setting cleanup to FALSE will prevent caching regardless of cached +#' argument #' @return reference class of type openmi.om.equation #' @seealso NA #' @export fn_get_runfile @@ -130,7 +134,8 @@ fn_get_runfile_info <- function( fn_get_runfile <- function( elementid = -1, runid = -1, scenid = 37, site = "http://deq2.bse.vt.edu", cached = TRUE, - outaszoo=TRUE, use_tz=FALSE + outaszoo=TRUE, use_tz=FALSE, + cleanup = FALSE ) { if (elementid == -1 ) { return(FALSE); @@ -222,6 +227,12 @@ fn_get_runfile <- function( f3 <- zoo::zoo(datv, order.by = datv$timestamp) } unlink('tempfile') + #If the user has provided a logical value for cleanup, check to see if user + #has requested the logfile be deleted. If cleanup is TRUE, delete the log file + if(is.logical(cleanup) && cleanup){ + unlink(filename) + } + #Return either the data frame or the zoo if(outaszoo){ return(f3) }else{ diff --git a/man/fn_get_runfile.Rd b/man/fn_get_runfile.Rd index 05d1beff..84d15f03 100644 --- a/man/fn_get_runfile.Rd +++ b/man/fn_get_runfile.Rd @@ -11,7 +11,8 @@ fn_get_runfile( site = "http://deq2.bse.vt.edu", cached = TRUE, outaszoo = TRUE, - use_tz = FALSE + use_tz = FALSE, + cleanup = FALSE ) } \arguments{ @@ -28,6 +29,11 @@ fn_get_runfile( \item{outaszoo}{boolean return as a zoo timeseries if TRUE, or as data frame} \item{use_tz}{character pass in a custom timezone for zoo} + +\item{cleanup}{Logical - Should the log file be deleted (TRUE) or written to +working directory (FALSE)? Note that the cached argument requires these log +files so setting cleanup to FALSE will prevent caching regardless of cached +argument} } \value{ reference class of type openmi.om.equation diff --git a/man/om_get_rundata.Rd b/man/om_get_rundata.Rd index ba94d0b9..229c0d83 100644 --- a/man/om_get_rundata.Rd +++ b/man/om_get_rundata.Rd @@ -2,36 +2,48 @@ % Please edit documentation in R/om_get_rundata.R \name{om_get_rundata} \alias{om_get_rundata} -\title{The base class for executable equation based meta-model components.} +\title{Get OM Model Data} \usage{ om_get_rundata( elid, runid, site = "http://deq2.bse.vt.edu", cached = FALSE, - hydrowarmup = TRUE + hydrowarmup = TRUE, + cleanup = FALSE ) } \arguments{ -\item{elid}{integer OM model element id} +\item{elid}{integer OM element connection ID e.g. the original OM model ID} -\item{runid}{integer run id} +\item{runid}{integer run id representing the scenario. Ask the modeling team +for scenario IDs if you are unsure otherwise see the WSPA Shiny Dashboard +for more information} -\item{site}{URL of om server} +\item{site}{URL of OM server, typically established in WSPA config files} \item{cached}{boolean - if TRUE will use recently stored local copy} -\item{hydrowarmup}{boolean - if TRUE will trim beginning of model time frame} +\item{hydrowarmup}{boolean - if TRUE will trim beginning of model time frame +to account for potential model warm up as water routes downstream from the +headwaters and operational rules engage} + +\item{cleanup}{Logical. Should the function delete the log file create for +the cached argument? If this is TRUE, the .log files will be deleted after +download from OM server} } \value{ -reference class of type openmi.om.equation +data.frame of model results } \description{ -The base class for executable equation based meta-model components. +Retrieve model results (run data) from the VA Hydro server for a + particular model and run ID (scenario ID). } -\examples{ -NA +\details{ +A wrapper of \code{hydrotools::fn_get_runfile()}. This function + returns the results in a zoo (see zoo::zoo()) that has the timestamp as the + index. See \code{hydrotools::fn_get_runfile()} for more details. } -\seealso{ -NA +\examples{ +#om_get_rundata(72446, 600, site=omsite) }