From cda49e23bba389a356d0da65a6b3aed87dab250a Mon Sep 17 00:00:00 2001 From: Nicholas Long Date: Wed, 23 Apr 2025 11:11:45 -0600 Subject: [PATCH 01/22] update nmecr version, add simple dataframe test --- .github/workflows/test.yml | 24 ++ .gitignore | 10 +- CHANGELOG.md | 4 + DESCRIPTION | 2 +- LICENSE.txt | 2 +- R/bsync_utils.R | 2 +- README.md | 36 ++- bsyncr.Rproj | 2 +- cspell.json | 11 + tests/data/ex_bsync.xml | 591 +++++++++++++++++++++++++++++++++++++ tests/test_bsyncr.R | 54 ++++ vignettes/.gitignore | 3 - 12 files changed, 726 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 CHANGELOG.md create mode 100644 cspell.json create mode 100644 tests/data/ex_bsync.xml create mode 100644 tests/test_bsyncr.R delete mode 100644 vignettes/.gitignore diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..37da93b --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,24 @@ +name: R-CMD-check + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up R + uses: r-lib/actions/setup-r@v2 + with: + r-version: '4.5.0' + + # - name: Install dependencies + # run: | + # install.packages('devtools') + # devtools::install_deps(dependencies = TRUE) + + - name: Run script + run: Rscript tests/test_bsyncr.R \ No newline at end of file diff --git a/.gitignore b/.gitignore index a647cd8..5a3476d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,5 @@ -.Rproj.user -.Rhistory -.RData -.Ruserdata .DS_Store -inst/doc -*.html + +vignettes/*.html +vignettes/*.R +vignettes/output diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..61066cb --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ +# Version 0.1 + +* initial release. This is currently only released to GitHub. + \ No newline at end of file diff --git a/DESCRIPTION b/DESCRIPTION index ec93572..83eb6ac 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: bsyncr Type: Package Title: What the Package Does (Title Case) Version: 0.1.0 -Author: Cory Mosiman +Author: Cory Mosiman, Nicholas Long Maintainer: Not Maintained Description: More about what it does (maybe more than one line) Use four spaces when indenting paragraphs within the Description. diff --git a/LICENSE.txt b/LICENSE.txt index f975438..233f1d6 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2020-2021, Alliance for Sustainable Energy, LLC. All rights reserved. +Copyright (c) 2020-2025, Alliance for Sustainable Energy, LLC. All rights reserved. BSD 3-Clause License diff --git a/R/bsync_utils.R b/R/bsync_utils.R index a8a38ef..950f584 100644 --- a/R/bsync_utils.R +++ b/R/bsync_utils.R @@ -257,7 +257,7 @@ bs_parse_nmecr_df <- function(tree, insert_weather_data=FALSE) { start_date = format(ts_start, format="%m/%d/%y %H:%M"), end_date = format(ts_end, format="%m/%d/%y %H:%M"), convert_to_data_interval = data_int, - timestamps="start")) + temp_balancepoint = 65)) } #' Add inputs, parameters, and performance statistics to a auc:DerivedModel diff --git a/README.md b/README.md index 09f9eac..3738f44 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,29 @@ # bsyncr -A package for generating BuildingSync documents in R. It is intended to be used in parallel with the [nmecr](https://github.com/kW-Labs/nmecr) package, enabling serialization of NMEC analysis into -BuildingSync documents. + +A package for generating BuildingSync documents in R. It is intended to be used in parallel with the [nmecr](https://github.com/kW-Labs/nmecr) package, enabling serialization of NMEC analysis into BuildingSync documents. + +## Using as a package + +Go to [NOAA's website](https://www.ncdc.noaa.gov/cdo-web/token) to request an API key. This is needed to look up weather data. Set an environment variable names `NOAA_TOKEN` with your API key. + +```bash +export NOAA_TOKEN=YOUR_KEY_HERE +``` + +Within R, run the following to test if the package loads. There are many dependent packages that might need to be installed, check the logs as needed. + +```r +remotes::install_github('BuildingSync/bsyncr', upgrade='never') + +# using a specific release +remotes::install_github('BuildingSync/bsyncr@v0.1.0', upgrade='never') + +# verify that the package loads +library(bsyncr) + +# see the vignette PDF file or the test file for an +# example on using. +``` # TODO - Stub out `auc:DerivedModels` for both the baseline and reporting scenarios @@ -8,3 +31,12 @@ BuildingSync documents. - Serialize the SLR model - Serialize the 5p CPM - Add timeseries serialization into utility functions + +# Releasing new version + +* Update version in bsync.RProj and DESCRIPTION to the next correct semantic version +* Create CHANGELOG in GitHub +* Paste in updates and merge release prep PR to develop +* Test +* Merge to main +* Tag on GitHub (TODO: release with GitHub action) \ No newline at end of file diff --git a/bsyncr.Rproj b/bsyncr.Rproj index 497f8bf..fb44373 100644 --- a/bsyncr.Rproj +++ b/bsyncr.Rproj @@ -1,4 +1,4 @@ -Version: 1.0 +Version: 0.1 RestoreWorkspace: Default SaveWorkspace: Default diff --git a/cspell.json b/cspell.json new file mode 100644 index 0000000..e5f2c71 --- /dev/null +++ b/cspell.json @@ -0,0 +1,11 @@ +{ + "version": "0.2", + "ignorePaths": [], + "dictionaryDefinitions": [], + "dictionaries": [], + "words": [ + "balancepoint" + ], + "ignoreWords": [], + "import": [] +} diff --git a/tests/data/ex_bsync.xml b/tests/data/ex_bsync.xml new file mode 100644 index 0000000..93bd7cb --- /dev/null +++ b/tests/data/ex_bsync.xml @@ -0,0 +1,591 @@ + + + + + + + + Example Building + + + Custom + seed_analysis_property_view_id + 1617 + + + + Arvada + Colorado + 80005 + + + -105.1340 + 39.8446 + Office + + + Gross + 45000 + + + + + + + + + + + + + + + + + + + + Electricity + kBtu + All end uses + + + Natural gas + kBtu + All end uses + + + + + Total + 2018-01-19T08:00:00+00:00 + 2018-02-16T08:00:00+00:00 + Month + 129580.0 + + + + Total + 2018-02-16T08:00:00+00:00 + 2018-03-20T07:00:00+00:00 + Month + 138582.4 + + + + Total + 2018-03-20T07:00:00+00:00 + 2018-04-18T07:00:00+00:00 + Month + 139673.6 + + + + Total + 2018-04-18T07:00:00+00:00 + 2018-05-18T07:00:00+00:00 + Month + 149221.6 + + + + Total + 2018-05-18T07:00:00+00:00 + 2018-06-18T07:00:00+00:00 + Month + 159860.80000000002 + + + + Total + 2018-06-18T07:00:00+00:00 + 2018-07-18T07:00:00+00:00 + Month + 186322.4 + + + + Total + 2018-07-18T07:00:00+00:00 + 2018-08-17T07:00:00+00:00 + Month + 196961.6 + + + + Total + 2018-08-17T07:00:00+00:00 + 2018-09-18T07:00:00+00:00 + Month + 190141.6 + + + + Total + 2018-09-18T07:00:00+00:00 + 2018-10-18T07:00:00+00:00 + Month + 161224.80000000002 + + + + Total + 2018-10-18T07:00:00+00:00 + 2018-11-16T08:00:00+00:00 + Month + 142128.80000000002 + + + + Total + 2018-11-16T08:00:00+00:00 + 2018-12-17T08:00:00+00:00 + Month + 144038.4 + + + + Total + 2018-12-17T08:00:00+00:00 + 2019-01-15T08:00:00+00:00 + Month + 135036.0 + + + + Total + 2019-01-15T08:00:00+00:00 + 2019-02-13T08:00:00+00:00 + Month + 129307.20000000001 + + + + Total + 2019-02-13T08:00:00+00:00 + 2019-03-15T07:00:00+00:00 + Month + 137764.0 + + + + Total + 2019-03-15T07:00:00+00:00 + 2019-04-16T07:00:00+00:00 + Month + 136400.0 + + + + Total + 2019-04-16T07:00:00+00:00 + 2019-05-16T07:00:00+00:00 + Month + 131489.6 + + + + Total + 2019-05-16T07:00:00+00:00 + 2019-06-17T07:00:00+00:00 + Month + 140219.2 + + + + Total + 2019-06-17T07:00:00+00:00 + 2019-07-17T07:00:00+00:00 + Month + 147312.0 + + + + Total + 2019-07-17T07:00:00+00:00 + 2019-08-16T07:00:00+00:00 + Month + 169954.4 + + + + Total + 2019-08-16T07:00:00+00:00 + 2019-09-17T07:00:00+00:00 + Month + 168863.2 + + + + Total + 2019-09-17T07:00:00+00:00 + 2019-10-17T07:00:00+00:00 + Month + 144311.2 + + + + Total + 2019-10-17T07:00:00+00:00 + 2019-11-18T08:00:00+00:00 + Month + 147857.6 + + + + Total + 2019-11-18T08:00:00+00:00 + 2019-12-17T08:00:00+00:00 + Month + 128761.6 + + + + Total + 2019-12-17T08:00:00+00:00 + 2020-01-15T08:00:00+00:00 + Month + 121396.0 + + + + Total + 2020-01-15T08:00:00+00:00 + 2020-02-14T08:00:00+00:00 + Month + 131216.80000000002 + + + + Total + 2020-02-14T08:00:00+00:00 + 2020-03-17T07:00:00+00:00 + Month + 140219.2 + + + + Total + 2020-03-17T07:00:00+00:00 + 2020-04-17T07:00:00+00:00 + Month + 122760.0 + + + + Total + 2020-04-17T07:00:00+00:00 + 2020-05-15T07:00:00+00:00 + Month + 113212.0 + + + + Total + 2020-05-15T07:00:00+00:00 + 2020-06-16T07:00:00+00:00 + Month + 141856.0 + + + + Total + 2020-06-16T07:00:00+00:00 + 2020-07-16T07:00:00+00:00 + Month + 143492.80000000002 + + + + Total + 2020-07-16T07:00:00+00:00 + 2020-08-17T07:00:00+00:00 + Month + 156041.6 + + + + Total + 2018-01-01T08:00:00+00:00 + 2018-01-31T08:00:00+00:00 + Month + 79200.0 + + + + Total + 2018-02-01T08:00:00+00:00 + 2018-02-28T08:00:00+00:00 + Month + 55200.0 + + + + Total + 2018-03-01T08:00:00+00:00 + 2018-03-31T07:00:00+00:00 + Month + 69400.0 + + + + Total + 2018-04-01T07:00:00+00:00 + 2018-04-30T07:00:00+00:00 + Month + 48000.0 + + + + Total + 2018-05-01T07:00:00+00:00 + 2018-05-31T07:00:00+00:00 + Month + 41200.0 + + + + Total + 2018-06-01T07:00:00+00:00 + 2018-06-30T07:00:00+00:00 + Month + 38000.0 + + + + Total + 2018-07-01T07:00:00+00:00 + 2018-07-31T07:00:00+00:00 + Month + 26000.0 + + + + Total + 2018-08-01T07:00:00+00:00 + 2018-08-31T07:00:00+00:00 + Month + 22000.0 + + + + Total + 2018-09-01T07:00:00+00:00 + 2018-09-30T07:00:00+00:00 + Month + 34600.0 + + + + Total + 2018-10-01T07:00:00+00:00 + 2018-10-31T07:00:00+00:00 + Month + 38200.0 + + + + Total + 2018-11-01T07:00:00+00:00 + 2018-11-30T08:00:00+00:00 + Month + 79200.0 + + + + Total + 2018-12-01T08:00:00+00:00 + 2018-12-31T08:00:00+00:00 + Month + 143200.0 + + + + Total + 2019-01-01T08:00:00+00:00 + 2019-01-31T08:00:00+00:00 + Month + 159000.0 + + + + Total + 2019-02-01T08:00:00+00:00 + 2019-02-28T08:00:00+00:00 + Month + 125400.0 + + + + Total + 2019-03-01T08:00:00+00:00 + 2019-03-31T07:00:00+00:00 + Month + 103600.0 + + + + Total + 2019-04-01T07:00:00+00:00 + 2019-04-30T07:00:00+00:00 + Month + 63200.0 + + + + Total + 2019-05-01T07:00:00+00:00 + 2019-05-31T07:00:00+00:00 + Month + 24400.0 + + + + Total + 2019-06-01T07:00:00+00:00 + 2019-06-30T07:00:00+00:00 + Month + 52200.0 + + + + Total + 2019-07-01T07:00:00+00:00 + 2019-07-31T07:00:00+00:00 + Month + 36000.0 + + + + Total + 2019-08-01T07:00:00+00:00 + 2019-08-31T07:00:00+00:00 + Month + 25400.0 + + + + Total + 2019-09-01T07:00:00+00:00 + 2019-09-30T07:00:00+00:00 + Month + 24200.0 + + + + Total + 2019-10-01T07:00:00+00:00 + 2019-10-31T07:00:00+00:00 + Month + 61400.0 + + + + Total + 2019-11-01T07:00:00+00:00 + 2019-11-30T08:00:00+00:00 + Month + 91600.0 + + + + Total + 2019-12-01T08:00:00+00:00 + 2019-12-31T08:00:00+00:00 + Month + 96800.0 + + + + Total + 2020-01-01T08:00:00+00:00 + 2020-01-31T08:00:00+00:00 + Month + 102800.0 + + + + Total + 2020-02-01T08:00:00+00:00 + 2020-02-29T08:00:00+00:00 + Month + 103000.0 + + + + Total + 2020-03-01T08:00:00+00:00 + 2020-03-31T07:00:00+00:00 + Month + 76800.0 + + + + Total + 2020-04-01T07:00:00+00:00 + 2020-04-30T07:00:00+00:00 + Month + 74600.0 + + + + Total + 2020-05-01T07:00:00+00:00 + 2020-05-31T07:00:00+00:00 + Month + 56000.0 + + + + Total + 2020-06-01T07:00:00+00:00 + 2020-06-30T07:00:00+00:00 + Month + 41800.0 + + + + Total + 2020-07-01T07:00:00+00:00 + 2020-07-31T07:00:00+00:00 + Month + 200.0 + + + + Total + 2020-09-01T07:00:00+00:00 + 2020-09-30T07:00:00+00:00 + Month + 800.0 + + + + Total + 2020-11-01T07:00:00+00:00 + 2020-11-30T08:00:00+00:00 + Month + 27000.0 + + + + Total + 2020-12-01T08:00:00+00:00 + 2020-12-31T08:00:00+00:00 + Month + 96800.0 + + + + + + + + + + + + + + + diff --git a/tests/test_bsyncr.R b/tests/test_bsyncr.R new file mode 100644 index 0000000..736903f --- /dev/null +++ b/tests/test_bsyncr.R @@ -0,0 +1,54 @@ +# TODO: Add license info + +# I am not sure the best way to test in R, but this is a start. +# The script will run the analysis and the result should be non zero. + +# Ensure that R is installed. A recent version should suffice +# `brew install R` + +# Install packages needed (assuming that this is the first time configuring) +install.packages(c('remotes', 'crayon', 'dplyr', 'crayon', 'tidyr'), repos='http://cran.us.r-project.org') +# print out the current working directory +print("Current working directory:") +print(getwd()) + +remotes::install_github('ropensci/rnoaa@v1.3.4', upgrade='never') +remotes::install_github('kW-Labs/nmecr@v1.0.17', upgrade='never') +# populate stations +library(rnoaa) +rnoaa::ghcnd_stations() + +# print out my current working directory +remotes::install_local(".", force = TRUE, upgrade = "never") +library(bsyncr) + +# Load the packages +library(xml2) +library(dplyr) +library(crayon) + +# Read in the NOAA token env variable and set the option for nmecr to use +NOAA_TOKEN <- Sys.getenv('NOAA_TOKEN') +if (NOAA_TOKEN == "") { + stop("Missing NOAA token env var: NOAA_TOKEN") +} +options(noaakey=NOAA_TOKEN) + +test_create_dataframe <- function(bsync_filepath, model_type) { + baseline_scenario_id <- "Scenario-bsyncr" + bsync_doc <- xml2::read_xml(bsync_filepath) %>% + bsyncr::bs_stub_scenarios(linked_building_id = "My-Fav-Building", baseline_id = baseline_scenario_id) + + baseline_xpath <- sprintf("//auc:Scenario[@ID = '%s']", baseline_scenario_id) + sc_baseline <- xml2::xml_find_first(bsync_doc, baseline_xpath) + not_used <- sc_baseline %>% bsyncr::bs_stub_derived_model(dm_id = "DerivedModel-bsyncr", + dm_period = "Baseline") + + b_df <- bsyncr::bs_parse_nmecr_df(bsync_doc, insert_weather_data=TRUE) +} + +# Test that the dataframe is created +result <- test_create_dataframe("./tests/data/ex_bsync.xml", "SLR") +print(result) + + diff --git a/vignettes/.gitignore b/vignettes/.gitignore deleted file mode 100644 index 633cfe6..0000000 --- a/vignettes/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.html -*.R -output From 342a4c796b44d204e0f337610966c5627ca0d1a8 Mon Sep 17 00:00:00 2001 From: Nicholas Long Date: Wed, 23 Apr 2025 11:17:34 -0600 Subject: [PATCH 02/22] fix bsync file to pass validation --- tests/data/ex_bsync.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/data/ex_bsync.xml b/tests/data/ex_bsync.xml index 93bd7cb..598cb40 100644 --- a/tests/data/ex_bsync.xml +++ b/tests/data/ex_bsync.xml @@ -15,10 +15,10 @@ Arvada - Colorado + CO 80005 - + RMPA -105.1340 39.8446 Office From 0f0e2475d49d7d822d6adb50785cde42e0384be1 Mon Sep 17 00:00:00 2001 From: Nicholas Long Date: Wed, 23 Apr 2025 11:28:40 -0600 Subject: [PATCH 03/22] fix test name --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 37da93b..b915baf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: R-CMD-check +name: R-tests on: [push, pull_request] From 020cf7a0426be349980b60f1449ceeaa6cacd57a Mon Sep 17 00:00:00 2001 From: Nicholas Long Date: Wed, 23 Apr 2025 11:30:00 -0600 Subject: [PATCH 04/22] use default github token --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b915baf..60822e1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,8 @@ on: [push, pull_request] jobs: test: runs-on: ubuntu-latest - + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - name: Checkout code uses: actions/checkout@v2 From ff57a947fe0ce272b15ee076cd48c39f3f307ce0 Mon Sep 17 00:00:00 2001 From: Nicholas Long Date: Wed, 23 Apr 2025 11:39:20 -0600 Subject: [PATCH 05/22] install package crul --- tests/test_bsyncr.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_bsyncr.R b/tests/test_bsyncr.R index 736903f..2d14fea 100644 --- a/tests/test_bsyncr.R +++ b/tests/test_bsyncr.R @@ -7,7 +7,7 @@ # `brew install R` # Install packages needed (assuming that this is the first time configuring) -install.packages(c('remotes', 'crayon', 'dplyr', 'crayon', 'tidyr'), repos='http://cran.us.r-project.org') +install.packages(c('remotes', 'crayon', 'dplyr', 'crayon', 'tidyr', 'crul'), repos='http://cran.us.r-project.org') # print out the current working directory print("Current working directory:") print(getwd()) @@ -51,4 +51,3 @@ test_create_dataframe <- function(bsync_filepath, model_type) { result <- test_create_dataframe("./tests/data/ex_bsync.xml", "SLR") print(result) - From 2d0b81900223964c60542c56a2bbabe5d4671d9b Mon Sep 17 00:00:00 2001 From: Nicholas Long Date: Wed, 23 Apr 2025 11:44:03 -0600 Subject: [PATCH 06/22] run precommit to cleanup files --- .github/workflows/test.yml | 24 ++++++++++++------------ .gitignore | 3 +++ CHANGELOG.md | 5 ++--- DESCRIPTION | 2 +- R/bsync_utils.R | 2 +- README.md | 17 +++++++++-------- cspell.json | 18 +++++++++--------- man/bs_gen_root_doc.Rd | 2 +- tests/test_bsyncr.R | 1 - vignettes/introduction.Rmd | 14 +++++++------- 10 files changed, 45 insertions(+), 43 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 60822e1..5ab51f9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,18 +8,18 @@ jobs: env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - name: Checkout code - uses: actions/checkout@v2 + - name: Checkout code + uses: actions/checkout@v2 - - name: Set up R - uses: r-lib/actions/setup-r@v2 - with: - r-version: '4.5.0' + - name: Set up R + uses: r-lib/actions/setup-r@v2 + with: + r-version: "4.5.0" - # - name: Install dependencies - # run: | - # install.packages('devtools') - # devtools::install_deps(dependencies = TRUE) + # - name: Install dependencies + # run: | + # install.packages('devtools') + # devtools::install_deps(dependencies = TRUE) - - name: Run script - run: Rscript tests/test_bsyncr.R \ No newline at end of file + - name: Run script + run: Rscript tests/test_bsyncr.R diff --git a/.gitignore b/.gitignore index 5a3476d..1b0f9bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ .DS_Store +.python-version + +node_modules vignettes/*.html vignettes/*.R diff --git a/CHANGELOG.md b/CHANGELOG.md index 61066cb..f64c7fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,3 @@ # Version 0.1 - -* initial release. This is currently only released to GitHub. - \ No newline at end of file + +- initial release. This is currently only released to GitHub. diff --git a/DESCRIPTION b/DESCRIPTION index 83eb6ac..7c61583 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -14,7 +14,7 @@ Imports: nmecr (>= 1.0.4), anytime RoxygenNote: 7.1.0 -Suggests: +Suggests: knitr, rmarkdown VignetteBuilder: knitr diff --git a/R/bsync_utils.R b/R/bsync_utils.R index 950f584..5a8c16b 100644 --- a/R/bsync_utils.R +++ b/R/bsync_utils.R @@ -257,7 +257,7 @@ bs_parse_nmecr_df <- function(tree, insert_weather_data=FALSE) { start_date = format(ts_start, format="%m/%d/%y %H:%M"), end_date = format(ts_end, format="%m/%d/%y %H:%M"), convert_to_data_interval = data_int, - temp_balancepoint = 65)) + temp_balancepoint = 65)) } #' Add inputs, parameters, and performance statistics to a auc:DerivedModel diff --git a/README.md b/README.md index 3738f44..ee795c5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # bsyncr -A package for generating BuildingSync documents in R. It is intended to be used in parallel with the [nmecr](https://github.com/kW-Labs/nmecr) package, enabling serialization of NMEC analysis into BuildingSync documents. +A package for generating BuildingSync documents in R. It is intended to be used in parallel with the [nmecr](https://github.com/kW-Labs/nmecr) package, enabling serialization of NMEC analysis into BuildingSync documents. ## Using as a package @@ -21,11 +21,12 @@ remotes::install_github('BuildingSync/bsyncr@v0.1.0', upgrade='never') # verify that the package loads library(bsyncr) -# see the vignette PDF file or the test file for an +# see the vignette PDF file or the test file for an # example on using. ``` # TODO + - Stub out `auc:DerivedModels` for both the baseline and reporting scenarios - Run NMEC analysis, as shown in nmecr vignette - Serialize the SLR model @@ -34,9 +35,9 @@ library(bsyncr) # Releasing new version -* Update version in bsync.RProj and DESCRIPTION to the next correct semantic version -* Create CHANGELOG in GitHub -* Paste in updates and merge release prep PR to develop -* Test -* Merge to main -* Tag on GitHub (TODO: release with GitHub action) \ No newline at end of file +- Update version in bsync.RProj and DESCRIPTION to the next correct semantic version +- Create CHANGELOG in GitHub +- Paste in updates and merge release prep PR to develop +- Test +- Merge to main +- Tag on GitHub (TODO: release with GitHub action) diff --git a/cspell.json b/cspell.json index e5f2c71..9b43a12 100644 --- a/cspell.json +++ b/cspell.json @@ -1,11 +1,11 @@ { - "version": "0.2", - "ignorePaths": [], - "dictionaryDefinitions": [], - "dictionaries": [], - "words": [ - "balancepoint" - ], - "ignoreWords": [], - "import": [] + "version": "0.2", + "ignorePaths": [], + "dictionaryDefinitions": [], + "dictionaries": [], + "words": [ + "balancepoint" + ], + "ignoreWords": [], + "import": [] } diff --git a/man/bs_gen_root_doc.Rd b/man/bs_gen_root_doc.Rd index 7163a0a..60ce3e4 100644 --- a/man/bs_gen_root_doc.Rd +++ b/man/bs_gen_root_doc.Rd @@ -5,7 +5,7 @@ \title{Stub out the root node for an auc:BuildingSync document} \usage{ bs_gen_root_doc( - + raw_schema_location = "https://raw.githubusercontent.com/BuildingSync/schema/c620c7e58688698901edcb8560cd3e1b4b34d971/BuildingSync.xsd" ) } diff --git a/tests/test_bsyncr.R b/tests/test_bsyncr.R index 2d14fea..c15bbde 100644 --- a/tests/test_bsyncr.R +++ b/tests/test_bsyncr.R @@ -50,4 +50,3 @@ test_create_dataframe <- function(bsync_filepath, model_type) { # Test that the dataframe is created result <- test_create_dataframe("./tests/data/ex_bsync.xml", "SLR") print(result) - diff --git a/vignettes/introduction.Rmd b/vignettes/introduction.Rmd index d183af2..a56d1a8 100644 --- a/vignettes/introduction.Rmd +++ b/vignettes/introduction.Rmd @@ -62,7 +62,7 @@ For both the Baseline and Reporting Scenarios: ```{r, results = 'hide'} baseline_xpath <- "//auc:Scenario[auc:ScenarioType/auc:CurrentBuilding/auc:CalculationMethod/auc:Measured]" reporting_xpath <- "//auc:Scenario[auc:ScenarioType/auc:PackageOfMeasures/auc:CalculationMethod/auc:Measured]" - + sc_baseline <- xml2::xml_find_first(bsync_doc, baseline_xpath) not_used <- sc_baseline %>% bsyncr::bs_stub_derived_model(dm_id = "DerivedModel-Baseline", dm_period = "Baseline", @@ -83,13 +83,13 @@ start_dt <- "03/01/2012 00:00" end_dt <- "02/28/2013 23:59" data_int <- "Daily" -b_df <- nmecr::create_dataframe(eload_data = nmecr::eload, - temp_data = nmecr::temp, - start_date = start_dt, - end_date = end_dt, +b_df <- nmecr::create_dataframe(eload_data = nmecr::eload, + temp_data = nmecr::temp, + start_date = start_dt, + end_date = end_dt, convert_to_data_interval = data_int) -SLR_model <- nmecr::model_with_SLR(b_df, +SLR_model <- nmecr::model_with_SLR(b_df, nmecr::assign_model_inputs(regression_type = "SLR")) ``` @@ -97,7 +97,7 @@ SLR_model <- nmecr::model_with_SLR(b_df, ```{r} dm_base_xpath <- "//auc:DerivedModel[auc:DerivedModelPeriod = 'Baseline']/auc:DerivedModelInputs" -dm_baseline <- xml2::xml_find_first(bsync_doc, +dm_baseline <- xml2::xml_find_first(bsync_doc, dm_base_xpath) not_used <- bs_gen_dm_nmecr(nmecr_baseline_model = SLR_model, From 03b590994326eb425077ee833a1a2008d7258fc5 Mon Sep 17 00:00:00 2001 From: Nicholas Long Date: Wed, 23 Apr 2025 13:51:26 -0600 Subject: [PATCH 07/22] install other ubuntu packages --- .github/workflows/test.yml | 21 ++++++++++++++++- .pre-commit-config.yaml | 46 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5ab51f9..0956529 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,26 @@ jobs: with: r-version: "4.5.0" - # - name: Install dependencies + - name: Install system dependencies for R packages + run: | + sudo apt-get update + sudo apt-get install -y \ + git \ + libcurl4-openssl-dev \ + libfontconfig1-dev \ + libfreetype6-dev \ + libfribidi-dev \ + libgit2-dev \ + libharfbuzz-dev \ + libjpeg-dev \ + libpng-dev \ + libssl-dev \ + libtiff5-dev \ + libv8-dev \ + libxml2-dev \ + wget + + # - name: Install R dependencies # run: | # install.packages('devtools') # devtools::install_deps(dependencies = TRUE) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..900403d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,46 @@ +exclude: | + (?x)( + ^data/ + ) + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: check-ast + - id: check-added-large-files + args: ["--maxkb=2000"] + - id: end-of-file-fixer + - id: trailing-whitespace + - id: check-toml + - id: check-yaml + - id: check-json + - id: name-tests-test + args: ["--pytest-test-first"] + - id: fix-byte-order-marker + - id: check-case-conflict + - id: check-docstring-first + - id: check-executables-have-shebangs + - id: check-merge-conflict + - id: check-xml + - id: check-yaml + - id: debug-statements + - id: end-of-file-fixer + - id: mixed-line-ending + - id: pretty-format-json + args: ["--autofix", "--no-sort-keys"] + files: \.(json|template)$ + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v4.0.0-alpha.8 + hooks: + - id: prettier + types_or: [yaml, markdown] + # https://docs.astral.sh/ruff/integrations/#pre-commit + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.11.5 + hooks: + - id: ruff + args: [--fix, --exit-non-zero-on-fix, --output-format=full] + types_or: [python, pyi, jupyter] + - id: ruff-format + types_or: [python, pyi, jupyter] From b070d72f67354f02031e0e8c8a9302707aaeb421 Mon Sep 17 00:00:00 2001 From: Nicholas Long Date: Wed, 23 Apr 2025 16:21:24 -0600 Subject: [PATCH 08/22] add noaa token --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0956529..d1bbbf4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,6 +7,7 @@ jobs: runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + NOAA_TOKEN: ${{ secrets.NOAA_TOKEN }} steps: - name: Checkout code uses: actions/checkout@v2 From ec34c943e2aaaea64c3797a3df6de29e407058ab Mon Sep 17 00:00:00 2001 From: Nicholas Long Date: Wed, 23 Apr 2025 16:30:17 -0600 Subject: [PATCH 09/22] more formatting --- .pre-commit-config.yaml | 3 +-- CHANGELOG.md | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 900403d..c04fcd6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -35,9 +35,8 @@ repos: hooks: - id: prettier types_or: [yaml, markdown] - # https://docs.astral.sh/ruff/integrations/#pre-commit - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.11.5 + rev: v0.11.6 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix, --output-format=full] diff --git a/CHANGELOG.md b/CHANGELOG.md index f64c7fe..1246b28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ # Version 0.1 - initial release. This is currently only released to GitHub. +- Upgrade to latest version of NMECR (Version 1.0.17) +- Add integration and unit test From 5ab9b6d34b55dd57770740324f2906e521cad3d6 Mon Sep 17 00:00:00 2001 From: Nicholas Long Date: Wed, 23 Apr 2025 16:38:01 -0600 Subject: [PATCH 10/22] move src code --- CHANGELOG.md | 1 + DESCRIPTION | 10 +++++----- cspell.json | 13 ++++++++++++- {R => src}/bsync_utils.R | 4 ++-- 4 files changed, 20 insertions(+), 8 deletions(-) rename {R => src}/bsync_utils.R (99%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1246b28..2e9a7c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,3 +3,4 @@ - initial release. This is currently only released to GitHub. - Upgrade to latest version of NMECR (Version 1.0.17) - Add integration and unit test +- Move source code out of R directory and into src directory diff --git a/DESCRIPTION b/DESCRIPTION index 7c61583..8d47105 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,17 +1,17 @@ Package: bsyncr Type: Package -Title: What the Package Does (Title Case) +Title: Read BSync files for R Version: 0.1.0 Author: Cory Mosiman, Nicholas Long -Maintainer: Not Maintained -Description: More about what it does (maybe more than one line) - Use four spaces when indenting paragraphs within the Description. +Maintainer: Nicholas Long +Description: Generic functions for reading BSync files into R. The package + provides a set of functions to read BSync files and convert them into R data structures. License: See LICENSE.txt Encoding: UTF-8 LazyData: true Imports: xml2 (>= 1.3.2), - nmecr (>= 1.0.4), + nmecr (>= 1.0.17), anytime RoxygenNote: 7.1.0 Suggests: diff --git a/cspell.json b/cspell.json index 9b43a12..87970f7 100644 --- a/cspell.json +++ b/cspell.json @@ -4,7 +4,18 @@ "dictionaryDefinitions": [], "dictionaries": [], "words": [ - "balancepoint" + "Arvada", + "balancepoint", + "crul", + "dataframe", + "datatypeid", + "dplyr", + "Drybulb", + "elec", + "nmecr", + "NOAA", + "noaakey", + "tidyr" ], "ignoreWords": [], "import": [] diff --git a/R/bsync_utils.R b/src/bsync_utils.R similarity index 99% rename from R/bsync_utils.R rename to src/bsync_utils.R index 5a8c16b..866911a 100644 --- a/R/bsync_utils.R +++ b/src/bsync_utils.R @@ -225,7 +225,7 @@ bs_parse_nmecr_df <- function(tree, insert_weather_data=FALSE) { row_units <- closest_row$units if (row_units == "celsius") { row_temp <- (closest_row$value * 9 / 5) + 32 - } else if (row_units == "farenheit") { + } else if (row_units == "fahrenheit") { row_temp <- closest_row$value } else { stop(sprintf("Invalid unit type: %s", row_units)) @@ -343,7 +343,7 @@ bs_gen_dm_nmecr <- function(nmecr_baseline_model, x, bsync_beta1 <- NULL bsync_beta2 <- NULL bsync_beta3 <- NULL - # TODO: find a better way of cathching cases where we faild to fit the model + # TODO: find a better way of catching cases where we failed to fit the model tryCatch({ if (bsync_model_type == "2 parameter simple linear regression") { bsync_intercept <- coeffs[["(Intercept)"]] From 5bf63fb43c8b119ee84140a2539a2878a66a1b42 Mon Sep 17 00:00:00 2001 From: Nicholas Long Date: Wed, 23 Apr 2025 16:49:07 -0600 Subject: [PATCH 11/22] run only on push --- .github/workflows/test.yml | 2 +- README.md | 20 ++++++++++---------- cspell.json | 4 ++++ tests/test_bsyncr.R | 2 +- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d1bbbf4..349c207 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,6 @@ name: R-tests -on: [push, pull_request] +on: push jobs: test: diff --git a/README.md b/README.md index ee795c5..0fb310a 100644 --- a/README.md +++ b/README.md @@ -25,19 +25,19 @@ library(bsyncr) # example on using. ``` -# TODO - -- Stub out `auc:DerivedModels` for both the baseline and reporting scenarios -- Run NMEC analysis, as shown in nmecr vignette - - Serialize the SLR model - - Serialize the 5p CPM -- Add timeseries serialization into utility functions - -# Releasing new version +## Releasing new version - Update version in bsync.RProj and DESCRIPTION to the next correct semantic version - Create CHANGELOG in GitHub - Paste in updates and merge release prep PR to develop - Test - Merge to main -- Tag on GitHub (TODO: release with GitHub action) +- Tag on GitHub + +## TODO + +- Stub out `auc:DerivedModels` for both the baseline and reporting scenarios +- Run NMEC analysis, as shown in nmecr vignette + - Serialize the SLR model + - Serialize the 5p change point model +- Add timeseries serialization into utility functions diff --git a/cspell.json b/cspell.json index 87970f7..05ab3d9 100644 --- a/cspell.json +++ b/cspell.json @@ -6,15 +6,19 @@ "words": [ "Arvada", "balancepoint", + "bsync", + "bsyncr", "crul", "dataframe", "datatypeid", "dplyr", "Drybulb", "elec", + "NMEC", "nmecr", "NOAA", "noaakey", + "rnoaa", "tidyr" ], "ignoreWords": [], diff --git a/tests/test_bsyncr.R b/tests/test_bsyncr.R index c15bbde..5c40c19 100644 --- a/tests/test_bsyncr.R +++ b/tests/test_bsyncr.R @@ -4,7 +4,7 @@ # The script will run the analysis and the result should be non zero. # Ensure that R is installed. A recent version should suffice -# `brew install R` +# macos:`brew install R` # Install packages needed (assuming that this is the first time configuring) install.packages(c('remotes', 'crayon', 'dplyr', 'crayon', 'tidyr', 'crul'), repos='http://cran.us.r-project.org') From 4de150be6802fd28d6daf80b6515179b41813474 Mon Sep 17 00:00:00 2001 From: Nicholas Long Date: Wed, 23 Apr 2025 17:04:56 -0600 Subject: [PATCH 12/22] ugh, has to be R directory --- {src => R}/bsync_utils.R | 0 tests/test_bsyncr.R | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename {src => R}/bsync_utils.R (100%) diff --git a/src/bsync_utils.R b/R/bsync_utils.R similarity index 100% rename from src/bsync_utils.R rename to R/bsync_utils.R diff --git a/tests/test_bsyncr.R b/tests/test_bsyncr.R index 5c40c19..eaa87ab 100644 --- a/tests/test_bsyncr.R +++ b/tests/test_bsyncr.R @@ -34,7 +34,7 @@ if (NOAA_TOKEN == "") { } options(noaakey=NOAA_TOKEN) -test_create_dataframe <- function(bsync_filepath, model_type) { +test_create_dataframe <- function(bsync_filepath) { baseline_scenario_id <- "Scenario-bsyncr" bsync_doc <- xml2::read_xml(bsync_filepath) %>% bsyncr::bs_stub_scenarios(linked_building_id = "My-Fav-Building", baseline_id = baseline_scenario_id) @@ -48,5 +48,5 @@ test_create_dataframe <- function(bsync_filepath, model_type) { } # Test that the dataframe is created -result <- test_create_dataframe("./tests/data/ex_bsync.xml", "SLR") +result <- test_create_dataframe("./tests/data/ex_bsync.xml") print(result) From 152af4a37490b466d26be3221c4cf8009f7f9c76 Mon Sep 17 00:00:00 2001 From: Nicholas Long <1907354+nllong@users.noreply.github.com> Date: Wed, 23 Apr 2025 17:17:02 -0600 Subject: [PATCH 13/22] Update README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0fb310a..cf70c5a 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A package for generating BuildingSync documents in R. It is intended to be used ## Using as a package -Go to [NOAA's website](https://www.ncdc.noaa.gov/cdo-web/token) to request an API key. This is needed to look up weather data. Set an environment variable names `NOAA_TOKEN` with your API key. +Go to [NOAA's website](https://www.ncdc.noaa.gov/cdo-web/token) to request an API key. This is needed to look up weather data. Set an environment variable named `NOAA_TOKEN` with your API key. ```bash export NOAA_TOKEN=YOUR_KEY_HERE From 0b66eacb8d6576382e9393afcdee52abd799bfb3 Mon Sep 17 00:00:00 2001 From: Nicholas Long Date: Wed, 23 Apr 2025 17:27:44 -0600 Subject: [PATCH 14/22] use R testthat framework --- .github/workflows/test.yml | 4 ++- cspell.json | 1 + setup_environment.R | 31 +++++++++++++++++++++++ tests/test-bsyncr.R | 42 ++++++++++++++++++++++++++++++ tests/test_bsyncr.R | 52 -------------------------------------- 5 files changed, 77 insertions(+), 53 deletions(-) create mode 100644 setup_environment.R create mode 100644 tests/test-bsyncr.R delete mode 100644 tests/test_bsyncr.R diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 349c207..e26be2f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,4 +42,6 @@ jobs: # devtools::install_deps(dependencies = TRUE) - name: Run script - run: Rscript tests/test_bsyncr.R + run: | + Rscript setup_environment.R + Rscript -e "testthat::test_dir('tests')" diff --git a/cspell.json b/cspell.json index 05ab3d9..c6e331f 100644 --- a/cspell.json +++ b/cspell.json @@ -19,6 +19,7 @@ "NOAA", "noaakey", "rnoaa", + "testthat", "tidyr" ], "ignoreWords": [], diff --git a/setup_environment.R b/setup_environment.R new file mode 100644 index 0000000..bee02f2 --- /dev/null +++ b/setup_environment.R @@ -0,0 +1,31 @@ +# Print the current working directory +cat("Current working directory:\n") +cat(getwd(), "\n\n") + +# Install required packages if not already installed +required_packages <- c( + "remotes", "crayon", "dplyr", "tidyr", "crul", "xml2", "testthat", "rnoaa" +) + +cat("Checking and installing required packages...\n") +for (pkg in required_packages) { + if (!requireNamespace(pkg, quietly = TRUE)) { + install.packages(pkg, repos = "http://cran.us.r-project.org") + } +} + +# Install specific versions of GitHub packages +cat("Installing GitHub packages...\n") +remotes::install_github("ropensci/rnoaa@v1.3.4", upgrade = "never") +remotes::install_github("kW-Labs/nmecr@v1.0.17", upgrade = "never") + +# Populate NOAA stations (required for rnoaa) +cat("Populating NOAA stations...\n") +library(rnoaa) +rnoaa::ghcnd_stations() + +# Install the local package +cat("Installing the local bsyncr package...\n") +remotes::install_local(".", force = TRUE, upgrade = "never") + +cat("Setup complete. You can now run your tests.\n") \ No newline at end of file diff --git a/tests/test-bsyncr.R b/tests/test-bsyncr.R new file mode 100644 index 0000000..fe9090e --- /dev/null +++ b/tests/test-bsyncr.R @@ -0,0 +1,42 @@ +# Load required libraries +library(testthat) +library(xml2) +library(dplyr) +library(crayon) +library(bsyncr) + +# Ensure NOAA token is set +NOAA_TOKEN <- Sys.getenv('NOAA_TOKEN') +if (NOAA_TOKEN == "") { + stop("Missing NOAA token env var: NOAA_TOKEN") +} +options(noaakey = NOAA_TOKEN) + +# Define a helper function for testing +test_create_dataframe <- function(bsync_filepath) { + baseline_scenario_id <- "Scenario-bsyncr" + bsync_doc <- xml2::read_xml(bsync_filepath) %>% + bsyncr::bs_stub_scenarios(linked_building_id = "My-Fav-Building", baseline_id = baseline_scenario_id) + + baseline_xpath <- sprintf("//auc:Scenario[@ID = '%s']", baseline_scenario_id) + sc_baseline <- xml2::xml_find_first(bsync_doc, baseline_xpath) + not_used <- sc_baseline %>% bsyncr::bs_stub_derived_model(dm_id = "DerivedModel-bsyncr", + dm_period = "Baseline") + + b_df <- bsyncr::bs_parse_nmecr_df(bsync_doc, insert_weather_data = TRUE) + return(b_df) +} + +# Test cases +test_that("Dataframe is created successfully", { + # Path to the test file + bsync_filepath <- "./data/ex_bsync.xml" + + # Run the function and check the result + result <- test_create_dataframe(bsync_filepath) + print(result) + + # Ensure the result is not NULL and has rows + expect_true(!is.null(result), "Resulting dataframe should not be NULL") + expect_gt(nrow(result), 0, "Resulting dataframe should have rows") +}) \ No newline at end of file diff --git a/tests/test_bsyncr.R b/tests/test_bsyncr.R deleted file mode 100644 index eaa87ab..0000000 --- a/tests/test_bsyncr.R +++ /dev/null @@ -1,52 +0,0 @@ -# TODO: Add license info - -# I am not sure the best way to test in R, but this is a start. -# The script will run the analysis and the result should be non zero. - -# Ensure that R is installed. A recent version should suffice -# macos:`brew install R` - -# Install packages needed (assuming that this is the first time configuring) -install.packages(c('remotes', 'crayon', 'dplyr', 'crayon', 'tidyr', 'crul'), repos='http://cran.us.r-project.org') -# print out the current working directory -print("Current working directory:") -print(getwd()) - -remotes::install_github('ropensci/rnoaa@v1.3.4', upgrade='never') -remotes::install_github('kW-Labs/nmecr@v1.0.17', upgrade='never') -# populate stations -library(rnoaa) -rnoaa::ghcnd_stations() - -# print out my current working directory -remotes::install_local(".", force = TRUE, upgrade = "never") -library(bsyncr) - -# Load the packages -library(xml2) -library(dplyr) -library(crayon) - -# Read in the NOAA token env variable and set the option for nmecr to use -NOAA_TOKEN <- Sys.getenv('NOAA_TOKEN') -if (NOAA_TOKEN == "") { - stop("Missing NOAA token env var: NOAA_TOKEN") -} -options(noaakey=NOAA_TOKEN) - -test_create_dataframe <- function(bsync_filepath) { - baseline_scenario_id <- "Scenario-bsyncr" - bsync_doc <- xml2::read_xml(bsync_filepath) %>% - bsyncr::bs_stub_scenarios(linked_building_id = "My-Fav-Building", baseline_id = baseline_scenario_id) - - baseline_xpath <- sprintf("//auc:Scenario[@ID = '%s']", baseline_scenario_id) - sc_baseline <- xml2::xml_find_first(bsync_doc, baseline_xpath) - not_used <- sc_baseline %>% bsyncr::bs_stub_derived_model(dm_id = "DerivedModel-bsyncr", - dm_period = "Baseline") - - b_df <- bsyncr::bs_parse_nmecr_df(bsync_doc, insert_weather_data=TRUE) -} - -# Test that the dataframe is created -result <- test_create_dataframe("./tests/data/ex_bsync.xml") -print(result) From 1fe18a42fb690854e77f03d3eb446cb8904ab9f2 Mon Sep 17 00:00:00 2001 From: Nicholas Long Date: Wed, 23 Apr 2025 17:30:00 -0600 Subject: [PATCH 15/22] run precommit as github action --- .github/workflows/pre-commit.yml | 26 ++++++++++++++++++++++++++ .github/workflows/test.yml | 8 ++------ setup_environment.R | 2 +- tests/test-bsyncr.R | 6 +++--- 4 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/pre-commit.yml diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..5841916 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,26 @@ +name: Pre-Commit + +on: + push: + +jobs: + pre-commit: + name: Run Pre-Commit Checks + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.9 + + - name: Install Pre-Commit + run: | + pip install pre-commit + + - name: Run Pre-Commit + run: | + pre-commit run --all-files \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e26be2f..bbc2d19 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,7 @@ name: R-tests -on: push +on: + push: jobs: test: @@ -36,11 +37,6 @@ jobs: libxml2-dev \ wget - # - name: Install R dependencies - # run: | - # install.packages('devtools') - # devtools::install_deps(dependencies = TRUE) - - name: Run script run: | Rscript setup_environment.R diff --git a/setup_environment.R b/setup_environment.R index bee02f2..38150cd 100644 --- a/setup_environment.R +++ b/setup_environment.R @@ -28,4 +28,4 @@ rnoaa::ghcnd_stations() cat("Installing the local bsyncr package...\n") remotes::install_local(".", force = TRUE, upgrade = "never") -cat("Setup complete. You can now run your tests.\n") \ No newline at end of file +cat("Setup complete. You can now run your tests.\n") diff --git a/tests/test-bsyncr.R b/tests/test-bsyncr.R index fe9090e..c3ef9ec 100644 --- a/tests/test-bsyncr.R +++ b/tests/test-bsyncr.R @@ -31,12 +31,12 @@ test_create_dataframe <- function(bsync_filepath) { test_that("Dataframe is created successfully", { # Path to the test file bsync_filepath <- "./data/ex_bsync.xml" - + # Run the function and check the result result <- test_create_dataframe(bsync_filepath) print(result) - + # Ensure the result is not NULL and has rows expect_true(!is.null(result), "Resulting dataframe should not be NULL") expect_gt(nrow(result), 0, "Resulting dataframe should have rows") -}) \ No newline at end of file +}) From 4cc1ce76dd9ec2fae4e0f543abb1a89f86fcbf9e Mon Sep 17 00:00:00 2001 From: Nicholas Long Date: Wed, 23 Apr 2025 17:31:52 -0600 Subject: [PATCH 16/22] formatting --- .github/workflows/pre-commit.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 5841916..8e6c08b 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -2,13 +2,13 @@ name: Pre-Commit on: push: - + jobs: pre-commit: name: Run Pre-Commit Checks runs-on: ubuntu-latest - steps: + steps: - name: Checkout Code uses: actions/checkout@v3 @@ -23,4 +23,4 @@ jobs: - name: Run Pre-Commit run: | - pre-commit run --all-files \ No newline at end of file + pre-commit run --all-files From bea5076ced56e4d89d8270920cba81043fc52ab4 Mon Sep 17 00:00:00 2001 From: Nicholas Long Date: Wed, 23 Apr 2025 22:13:20 -0600 Subject: [PATCH 17/22] fix redundant pre-commit --- .pre-commit-config.yaml | 2 -- setup_environment.R | 3 ++- tests/test-bsyncr.R | 4 +++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c04fcd6..85e491a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,9 +23,7 @@ repos: - id: check-executables-have-shebangs - id: check-merge-conflict - id: check-xml - - id: check-yaml - id: debug-statements - - id: end-of-file-fixer - id: mixed-line-ending - id: pretty-format-json args: ["--autofix", "--no-sort-keys"] diff --git a/setup_environment.R b/setup_environment.R index 38150cd..13c97d3 100644 --- a/setup_environment.R +++ b/setup_environment.R @@ -4,7 +4,8 @@ cat(getwd(), "\n\n") # Install required packages if not already installed required_packages <- c( - "remotes", "crayon", "dplyr", "tidyr", "crul", "xml2", "testthat", "rnoaa" + "remotes", "crayon", "dplyr", "tidyr", "crul", "xml2", "testthat", "anytime", "lubridate", "segmented", "xts", "zoo" + "ggplot2", "scales", "XML", "rappdirs", "gridExtra", "isdparser", "geonames", "hoardr", "data.table" ) cat("Checking and installing required packages...\n") diff --git a/tests/test-bsyncr.R b/tests/test-bsyncr.R index c3ef9ec..edffcd4 100644 --- a/tests/test-bsyncr.R +++ b/tests/test-bsyncr.R @@ -1,3 +1,5 @@ +# TODO: add license. + # Load required libraries library(testthat) library(xml2) @@ -12,7 +14,7 @@ if (NOAA_TOKEN == "") { } options(noaakey = NOAA_TOKEN) -# Define a helper function for testing +# Define a helper function for testing -- this should probably be a src file. test_create_dataframe <- function(bsync_filepath) { baseline_scenario_id <- "Scenario-bsyncr" bsync_doc <- xml2::read_xml(bsync_filepath) %>% From a3f78caeb7164c5a9f17355136963deb8a485ecd Mon Sep 17 00:00:00 2001 From: Nicholas Long Date: Wed, 23 Apr 2025 22:14:19 -0600 Subject: [PATCH 18/22] formatting --- tests/test-bsyncr.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-bsyncr.R b/tests/test-bsyncr.R index edffcd4..1d5000c 100644 --- a/tests/test-bsyncr.R +++ b/tests/test-bsyncr.R @@ -1,4 +1,4 @@ -# TODO: add license. +# TODO: add license. # Load required libraries library(testthat) From 1bbb491958a95624c3a0ae96672d90cea3a40efc Mon Sep 17 00:00:00 2001 From: Nicholas Long Date: Wed, 23 Apr 2025 22:20:17 -0600 Subject: [PATCH 19/22] fix package list --- cspell.json | 6 ++++++ setup_environment.R | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cspell.json b/cspell.json index c6e331f..8e0bf27 100644 --- a/cspell.json +++ b/cspell.json @@ -14,10 +14,16 @@ "dplyr", "Drybulb", "elec", + "geonames", + "ggplot", + "hoardr", + "isdparser", + "lubridate", "NMEC", "nmecr", "NOAA", "noaakey", + "rappdirs", "rnoaa", "testthat", "tidyr" diff --git a/setup_environment.R b/setup_environment.R index 13c97d3..1fd1ab9 100644 --- a/setup_environment.R +++ b/setup_environment.R @@ -4,7 +4,7 @@ cat(getwd(), "\n\n") # Install required packages if not already installed required_packages <- c( - "remotes", "crayon", "dplyr", "tidyr", "crul", "xml2", "testthat", "anytime", "lubridate", "segmented", "xts", "zoo" + "remotes", "crayon", "dplyr", "tidyr", "crul", "xml2", "testthat", "anytime", "lubridate", "segmented", "xts", "zoo", "ggplot2", "scales", "XML", "rappdirs", "gridExtra", "isdparser", "geonames", "hoardr", "data.table" ) From 91fed31959c40cea9921586e0b360c3154a1e0b2 Mon Sep 17 00:00:00 2001 From: Nicholas Long Date: Thu, 24 Apr 2025 07:17:58 -0600 Subject: [PATCH 20/22] use 2.6.0 format bsync --- tests/data/ex_bsync.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/data/ex_bsync.xml b/tests/data/ex_bsync.xml index 598cb40..45002a2 100644 --- a/tests/data/ex_bsync.xml +++ b/tests/data/ex_bsync.xml @@ -1,4 +1,4 @@ - + From 80646e0be595f45fe2d4a0727eb0877ece67ef91 Mon Sep 17 00:00:00 2001 From: Nicholas Long Date: Thu, 24 Apr 2025 07:22:48 -0600 Subject: [PATCH 21/22] update license --- R/bsync_utils.R | 5 +++++ setup_environment.R | 5 +++++ tests/test-bsyncr.R | 5 ++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/R/bsync_utils.R b/R/bsync_utils.R index 866911a..0f57c45 100644 --- a/R/bsync_utils.R +++ b/R/bsync_utils.R @@ -1,3 +1,8 @@ +""" +BuildingSync®, Copyright (c) Alliance for Sustainable Energy, LLC, and other contributors. +See also https://github.com/BuildingSync/bsyncr/blob/main/LICENSE.txt +""" + library('rnoaa'); library('lubridate'); diff --git a/setup_environment.R b/setup_environment.R index 1fd1ab9..8d0f0b5 100644 --- a/setup_environment.R +++ b/setup_environment.R @@ -1,3 +1,8 @@ +""" +BuildingSync®, Copyright (c) Alliance for Sustainable Energy, LLC, and other contributors. +See also https://github.com/BuildingSync/bsyncr/blob/main/LICENSE.txt +""" + # Print the current working directory cat("Current working directory:\n") cat(getwd(), "\n\n") diff --git a/tests/test-bsyncr.R b/tests/test-bsyncr.R index 1d5000c..98b085b 100644 --- a/tests/test-bsyncr.R +++ b/tests/test-bsyncr.R @@ -1,4 +1,7 @@ -# TODO: add license. +""" +BuildingSync®, Copyright (c) Alliance for Sustainable Energy, LLC, and other contributors. +See also https://github.com/BuildingSync/bsyncr/blob/main/LICENSE.txt +""" # Load required libraries library(testthat) From 12933f62e304d531dd46dd29f00d4cd3da43b43c Mon Sep 17 00:00:00 2001 From: Nicholas Long Date: Thu, 24 Apr 2025 21:13:15 -0600 Subject: [PATCH 22/22] use pound for comments --- R/bsync_utils.R | 6 ++---- README.md | 2 ++ setup_environment.R | 9 +++------ tests/test-bsyncr.R | 7 +++---- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/R/bsync_utils.R b/R/bsync_utils.R index 0f57c45..644c1fa 100644 --- a/R/bsync_utils.R +++ b/R/bsync_utils.R @@ -1,7 +1,5 @@ -""" -BuildingSync®, Copyright (c) Alliance for Sustainable Energy, LLC, and other contributors. -See also https://github.com/BuildingSync/bsyncr/blob/main/LICENSE.txt -""" +# BuildingSync®, Copyright (c) Alliance for Sustainable Energy, LLC, and other contributors. +# See also https://github.com/BuildingSync/bsyncr-server/blob/main/LICENSE.txt library('rnoaa'); library('lubridate'); diff --git a/README.md b/README.md index cf70c5a..2fba349 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,8 @@ library(bsyncr) ## Releasing new version - Update version in bsync.RProj and DESCRIPTION to the next correct semantic version +- Make sure the DESCRIPTION has the correct version of the dependencies +- For testing purposes, make sure the versions of NMECR and RNOAA are correct in the `setup_environment.R` script - Create CHANGELOG in GitHub - Paste in updates and merge release prep PR to develop - Test diff --git a/setup_environment.R b/setup_environment.R index 8d0f0b5..3ec948c 100644 --- a/setup_environment.R +++ b/setup_environment.R @@ -1,7 +1,5 @@ -""" -BuildingSync®, Copyright (c) Alliance for Sustainable Energy, LLC, and other contributors. -See also https://github.com/BuildingSync/bsyncr/blob/main/LICENSE.txt -""" +# BuildingSync®, Copyright (c) Alliance for Sustainable Energy, LLC, and other contributors. +# See also https://github.com/BuildingSync/bsyncr-server/blob/main/LICENSE.txt # Print the current working directory cat("Current working directory:\n") @@ -9,8 +7,7 @@ cat(getwd(), "\n\n") # Install required packages if not already installed required_packages <- c( - "remotes", "crayon", "dplyr", "tidyr", "crul", "xml2", "testthat", "anytime", "lubridate", "segmented", "xts", "zoo", - "ggplot2", "scales", "XML", "rappdirs", "gridExtra", "isdparser", "geonames", "hoardr", "data.table" + "remotes", "crayon", "dplyr", "tidyr", "crul", "xml2", "testthat", "anytime", "lubridate", "segmented", "xts", "zoo", "ggplot2", "scales", "XML", "rappdirs", "gridExtra", "isdparser", "geonames", "hoardr", "data.table" ) cat("Checking and installing required packages...\n") diff --git a/tests/test-bsyncr.R b/tests/test-bsyncr.R index 98b085b..8decc42 100644 --- a/tests/test-bsyncr.R +++ b/tests/test-bsyncr.R @@ -1,7 +1,6 @@ -""" -BuildingSync®, Copyright (c) Alliance for Sustainable Energy, LLC, and other contributors. -See also https://github.com/BuildingSync/bsyncr/blob/main/LICENSE.txt -""" +# BuildingSync®, Copyright (c) Alliance for Sustainable Energy, LLC, and other contributors. +# See also https://github.com/BuildingSync/bsyncr-server/blob/main/LICENSE.txt + # Load required libraries library(testthat)