R/get_interval_demand.R

Defines functions get_interval_demand

Documented in get_interval_demand

#' Get Interval Demand Data from Encompass
#'
#' @param dbase_connection A database connection
#' @param scenario_id The id of the encompass scenario
#'
#' @return data.frame
#' @export
#'
#' @examples
#' \dontrun{
#' Set up a database connection
#' con <- DBI::dbConnect(odbc::odbc(), "MPWENCSQL01", database = "IRP - Brocks Test")
#' 
#' Run the query 
#' get_interval_demand(con, "SCMWM00003")
#' 
#' Close the database connection
#' DBI::dbDisconnect(con)
#' 
#' }
get_interval_demand <- function(dbase_connection, scenario_id){
  return_data <- DBI::dbGetQuery(
    conn = dbase_connection, 
    glue::glue(
      "select * from dbo.oHourlyResults_{scenario_id}
      where ItemID = 'Demand'
      and ScenarioID = '{scenario_id}'"),
    scenario_id = scenario_id
  )
  return_data$Date <- as.Date(return_data$Date)
  .data <- return_data
  .data
}
bsuhy/EncompassR documentation built on Feb. 22, 2022, 12:58 a.m.