From 279fe8d6834f9b66b9bd27e153d578eefd0b4a64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Berthet?= Date: Fri, 22 Sep 2023 14:46:14 +0200 Subject: [PATCH] update github actions to standard checks (#202) * update github actions to standard checks * delete possible failed tests on CRAN * pretest NOTE debian --- .github/workflows/R-CMD-check.yaml | 67 +- README.md | 1 + cran-comments.md | 6 + tests/testthat/test-exchangesStack.R | 1906 +++++++++++++------------- tests/testthat/test-graphUtils.R | 94 +- tests/testthat/test-plotXY.R | 20 +- tests/testthat/test-prodStack.R | 1462 ++++++++++---------- tests/testthat/test-zzCleanTests.R | 16 +- 8 files changed, 1774 insertions(+), 1798 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index b786a431..a3ac6182 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -1,10 +1,10 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: push: - branches: - - master + branches: [main, master] pull_request: - branches: - - master + branches: [main, master] name: R-CMD-check @@ -18,63 +18,32 @@ jobs: fail-fast: false matrix: config: + - {os: macos-latest, r: 'release'} - {os: windows-latest, r: 'release'} - - {os: macOS-latest, r: 'release'} - - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} env: - R_REMOTES_NO_ERRORS_FROM_WARNINGS: true - RSPM: ${{ matrix.config.rspm }} + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes steps: - uses: actions/checkout@v3 + - uses: r-lib/actions/setup-pandoc@v2 + - uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.config.r }} + http-user-agent: ${{ matrix.config.http-user-agent }} use-public-rspm: true - - uses: r-lib/actions/setup-pandoc@v2 - - - name: Query dependencies - run: | - install.packages('remotes') - install.packages('BiocManager') - BiocManager::install("rhdf5") - saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) - writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") - shell: Rscript {0} - - - name: Cache R packages - if: runner.os != 'Windows' - uses: actions/cache@v1 + - uses: r-lib/actions/setup-r-dependencies@v2 with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- - - - name: Install system dependencies - if: runner.os == 'Linux' - env: - RHUB_PLATFORM: linux-x86_64-ubuntu-gcc - run: | - sudo apt-get install libgdal-dev libgeos-dev libproj-dev libudunits2-dev - - - name: Install dependencies - run: | - remotes::install_deps(dependencies = TRUE) - remotes::install_cran("rcmdcheck") - shell: Rscript {0} - - - name: Check - env: - _R_CHECK_CRAN_INCOMING_REMOTE_: false - run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") - shell: Rscript {0} + extra-packages: any::rcmdcheck + needs: check - - name: Upload check results - if: failure() - uses: actions/upload-artifact@v2 + - uses: r-lib/actions/check-r-package@v2 with: - name: ${{ runner.os }}-r${{ matrix.config.r }}-results - path: check + upload-snapshots: true diff --git a/README.md b/README.md index 35b327d4..93be3136 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ [![R build status](https://github.com/rte-antares-rpackage/antaresViz/workflows/R-CMD-check/badge.svg)](https://github.com/rte-antares-rpackage/antaresViz/actions) [![Codecov test coverage](https://codecov.io/gh/rte-antares-rpackage/antaresViz/branch/master/graph/badge.svg)](https://app.codecov.io/gh/rte-antares-rpackage/antaresViz?branch=master) [![CRAN status](https://www.r-pkg.org/badges/version/antaresViz)](https://CRAN.R-project.org/package=antaresViz) +[![R-CMD-check](https://github.com/rte-antares-rpackage/antaresViz/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/rte-antares-rpackage/antaresViz/actions/workflows/R-CMD-check.yaml) diff --git a/cran-comments.md b/cran-comments.md index 881707db..9679632f 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -14,4 +14,10 @@ We don't expect any reverse dependency failures. This patch release contains only fix deprecated dependencies (issue #200). +## cran check v0.18.0 +Some tests are commented cause NOTE during pretest +Flavor: r-devel-linux-x86_64-debian-gcc +Check: tests, Result: NOTE + Running 'testthat.R' [143s/16s] + Running R code in 'testthat.R' had CPU time 8.9 times elapsed time diff --git a/tests/testthat/test-exchangesStack.R b/tests/testthat/test-exchangesStack.R index 6e2eac1f..f1cc1088 100644 --- a/tests/testthat/test-exchangesStack.R +++ b/tests/testthat/test-exchangesStack.R @@ -1,953 +1,953 @@ -context("exchangesStack") - -test_that("no interactive", { - - mydata <- readAntares(links = "all", timeStep = "daily", showProgress = FALSE) - # default parameters - default_params <- exchangesStack(mydata, interactive = FALSE) - expect_is(default_params, "htmlwidget") - # TO DO : passer les arguments - # passer plusieurs data - # .compare - # suivant les cas : - # - tester les retours d'erreurs -}) - -test_that("exchangesStack, no interactive", { - dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) - testClass <- function(obj){ - class(obj)[1] == "combineWidgets" - } - listArgs <- list(noarg = list(x = dta, interactive = FALSE, areas = "a"), - allAreas = list(x = dta, interactive = FALSE, areas = "all"), - main = list(x = dta, interactive = FALSE, areas = "all", main = "Title"), - ylab = list(x = dta, interactive = FALSE, areas = "all", main = "Title", ylab = "Subt") - ) - lapply(listArgs, function(X){ - re1 <- do.call(exchangesStack, X) - expect_true(testClass(re1)) - }) - -}) - -test_that("exchangesStack, no interactive return error", { - dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) - expect_error(exchangesStack(dta, interactive = FALSE, compare = "areas")) -}) - -test_that("exchangesStack, no interactive, x and refStudy are antaresDataTable", { - myData1 <- readAntares(links = "all", showProgress = FALSE) - myData2 <- readAntares(links = "all", showProgress = FALSE) - myArea <- "a" - DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") - exS1 <- exchangesStack(x = myData1, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) - dataExS1 <- .get_data_from_htmlwidget(exS1) - timeEditValue <- "2018-04-25T00:00:00.000Z" - indexHour <- grep(timeEditValue, dataExS1$hour) - expect_gt(indexHour, 2) - expect_equal(dataExS1$nega_offshore[indexHour], 9) - #identical myData, diff == 0 always - exS21V0 <- exchangesStack(x = myData1, refStudy = myData2, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) - dataExS21V0 <- .get_data_from_htmlwidget(exS21V0) - expect_equal(dataExS21V0$nega_offshore[indexHour], 0) - # edit myData2 to have a diff != 0 - #pb timeZone local (PC, Travis, etc) - for (i in 0:5){ - timeEditShift <- lubridate::hours(i) - timeEditMinus <- as.Date(timeEditValue) - timeEditShift - timeEditPlus <- as.Date(timeEditValue) + timeEditShift - myData2[ (time == timeEditMinus | time == timeEditPlus) & link == "a - a_offshore", `FLOW LIN.` := as.integer(`FLOW LIN.` + 2500)] - } - exS21V1 <- exchangesStack(x = myData1, refStudy = myData2, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) - dataExS21V1 <- .get_data_from_htmlwidget(exS21V1) - expect_equal(dataExS21V1$nega_offshore[indexHour], 2500) -}) - -test_that("exchangesStack, no interactive, x and refStudy are antaresDataList", { - myData1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) - myData2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) - myArea <- "a" - DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") - exS1 <- exchangesStack(x = myData1, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) - dataExS1 <- .get_data_from_htmlwidget(exS1) - timeEditValue <- "2018-04-25T00:00:00.000Z" - indexHour <- grep(timeEditValue, dataExS1$hour) - expect_gt(indexHour, 2) - expect_equal(dataExS1$nega_offshore[indexHour], 9) - #identical myData, diff == 0 always - exS21V0 <- exchangesStack(x = myData1, refStudy = myData2, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) - dataExS21V0 <- .get_data_from_htmlwidget(exS21V0) - expect_equal(dataExS21V0$nega_offshore[indexHour], 0) - # edit myData2 to have a diff != 0 - #pb timeZone local (PC, Travis, etc) - for (i in 0:5){ - timeEditShift <- lubridate::hours(i) - timeEditMinus <- as.Date(timeEditValue) - timeEditShift - timeEditPlus <- as.Date(timeEditValue) + timeEditShift - myData2$links[ (time == timeEditMinus | time == timeEditPlus) & link == "a - a_offshore", `FLOW LIN.` := as.integer(`FLOW LIN.` + 2500)] - } - exS21V1 <- exchangesStack(x = myData1, refStudy = myData2, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) - dataExS21V1 <- .get_data_from_htmlwidget(exS21V1) - expect_equal(dataExS21V1$nega_offshore[indexHour], 2500) - #ROW not null in myData1 - for (i in 0:5){ - timeEditShift <- lubridate::hours(i) - timeEditMinus <- as.Date(timeEditValue) - timeEditShift - timeEditPlus <- as.Date(timeEditValue) + timeEditShift - myData1$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, `ROW BAL.` := as.integer(`ROW BAL.` - 1500)] - } - #test if there is row - exS1V2 <- exchangesStack(x = myData1, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) - dataExS1V2 <- .get_data_from_htmlwidget(exS1V2) - expect_equal(dataExS1V2$ROW[indexHour], 1500) - exS21V2 <- exchangesStack(x = myData1, refStudy = myData2, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) - dataExS21V2 <- .get_data_from_htmlwidget(exS21V2) - expect_equal(dataExS21V2$nega_offshore[indexHour], 2500) - expect_equal(dataExS21V2$ROW[indexHour], 1500) - #ROW not null in myData2 - for (i in 0:5){ - timeEditShift <- lubridate::hours(i) - timeEditMinus <- as.Date(timeEditValue) - timeEditShift - timeEditPlus <- as.Date(timeEditValue) + timeEditShift - myData2$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, `ROW BAL.` := as.integer(`ROW BAL.` - 1000)] - } - exS21V3 <- exchangesStack(x = myData1, refStudy = myData2, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) - dataExS21V3 <- .get_data_from_htmlwidget(exS21V3) - expect_equal(dataExS21V3$nega_offshore[indexHour], 2500) - expect_equal(dataExS21V3$ROW[indexHour], 500) -}) - -test_that("exchangesStack, no interactive, x is a list of antaresDataTable and refStudy an antaresDataTable", { - myData1 <- readAntares(links = "all", showProgress = FALSE) - myData2 <- readAntares(links = "all", showProgress = FALSE) - myData3 <- readAntares(links = "all", showProgress = FALSE) - myData4 <- readAntares(links = "all", showProgress = FALSE) - - myDataList <- list(myData2, myData3, myData4) - myArea <- "a" - DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") - exS2 <- exchangesStack(x = myDataList, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) - # compare with myData3 - idWidget <- 2 - dataExS2 <- .get_data_from_htmlwidget(exS2, widgetsNumber = idWidget) - timeEditValue <- "2018-04-25T00:00:00.000Z" - indexHour <- grep(timeEditValue, dataExS2$hour) - expect_gt(indexHour, 2) - expect_equal(dataExS2$nega_offshore[indexHour], 9) - #identical myData, diff == 0 always - exS21V0 <- exchangesStack(x = myDataList, refStudy = myData1, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) - dataExS21V0 <- .get_data_from_htmlwidget(exS21V0, widgetsNumber = idWidget) - expect_equal(dataExS21V0$nega_offshore[indexHour], 0) - # edit myData3 to have a diff != 0 - #pb timeZone local (PC, Travis, etc) - for (i in 0:5){ - timeEditShift <- lubridate::hours(i) - timeEditMinus <- as.Date(timeEditValue) - timeEditShift - timeEditPlus <- as.Date(timeEditValue) + timeEditShift - myData3[ (time == timeEditMinus | time == timeEditPlus) & link == "a - a_offshore", `FLOW LIN.` := as.integer(`FLOW LIN.` + 2500)] - } - exS21V1 <- exchangesStack(x = myDataList, refStudy = myData1, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) - dataExS21V1 <- .get_data_from_htmlwidget(exS21V1, widgetsNumber = idWidget) - expect_equal(dataExS21V1$a_offshore[indexHour], 2500) -}) - -test_that("exchangesStack, no interactive, x is a list of antaresDataList and refStudy an antaresDataList", { - myData1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) - myData2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) - myData3 <- readAntares(areas = "all", links = "all", showProgress = FALSE) - myData4 <- readAntares(areas = "all", links = "all", showProgress = FALSE) - - myDataList <- list(myData2, myData3, myData4) - myArea <- "a" - DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") - exS2 <- exchangesStack(x = myDataList, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) - # compare with myData3 - idWidget <- 2 - dataExS2 <- .get_data_from_htmlwidget(exS2, widgetsNumber = idWidget) - timeEditValue <- "2018-04-25T00:00:00.000Z" - indexHour <- grep(timeEditValue, dataExS2$hour) - expect_gt(indexHour, 2) - expect_equal(dataExS2$nega_offshore[indexHour], 9) - #identical myData, diff == 0 always - exS21V0 <- exchangesStack(x = myDataList, refStudy = myData1, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) - dataExS21V0 <- .get_data_from_htmlwidget(exS21V0, widgetsNumber = idWidget) - expect_equal(dataExS21V0$nega_offshore[indexHour], 0) - # edit myData3 to have a diff != 0 - #pb timeZone local (PC, Travis, etc) - for (i in 0:5){ - timeEditShift <- lubridate::hours(i) - timeEditMinus <- as.Date(timeEditValue) - timeEditShift - timeEditPlus <- as.Date(timeEditValue) + timeEditShift - myData3$links[ (time == timeEditMinus | time == timeEditPlus) & link == "a - a_offshore", `FLOW LIN.` := as.integer(`FLOW LIN.` + 2500)] - } - exS21V1 <- exchangesStack(x = myDataList, refStudy = myData1, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) - dataExS21V1 <- .get_data_from_htmlwidget(exS21V1, widgetsNumber = idWidget) - expect_equal(dataExS21V1$a_offshore[indexHour], 2500) - #ROW not null in myData4 - for (i in 0:5){ - timeEditShift <- lubridate::hours(i) - timeEditMinus <- as.Date(timeEditValue) - timeEditShift - timeEditPlus <- as.Date(timeEditValue) + timeEditShift - myData4$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, `ROW BAL.` := as.integer(`ROW BAL.` - 1500)] - } - #test if there is row - exList <- exchangesStack(x = myDataList, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) - dataExList <- .get_data_from_htmlwidget(exList, widgetsNumber = idWidget) - expect_equal(dataExList$a_offshore[indexHour], 2500 - 9) - idRowNotNull <- 3 - dataExListRow <- .get_data_from_htmlwidget(exList, widgetsNumber = idRowNotNull) - expect_equal(dataExListRow$ROW[indexHour], 1500) - #with a refStudy - exListListV2 <- exchangesStack(x = myDataList, refStudy = myData1, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) - dataExListV2 <- .get_data_from_htmlwidget(exListListV2, widgetsNumber = idWidget) - expect_equal(dataExListV2$a_offshore[indexHour], 2500) - expect_equal(dataExListV2$ROW[indexHour], 0) - dataExListV2Row <- .get_data_from_htmlwidget(exListListV2, widgetsNumber = idRowNotNull) - expect_equal(dataExListV2Row$a_offshore[indexHour], 0) - expect_equal(dataExListV2Row$ROW[indexHour], 1500) - #ROW not null in refStudy myData1 - for (i in 0:5){ - timeEditShift <- lubridate::hours(i) - timeEditMinus <- as.Date(timeEditValue) - timeEditShift - timeEditPlus <- as.Date(timeEditValue) + timeEditShift - myData1$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, `ROW BAL.` := as.integer(`ROW BAL.` - 1000)] - } - exListListV3 <- exchangesStack(x = myDataList, refStudy = myData1, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) - dataExListV3 <- .get_data_from_htmlwidget(exListListV3, widgetsNumber = idRowNotNull) - expect_equal(dataExListV3$nega_offshore[indexHour], 0) - expect_equal(dataExListV3$ROW[indexHour], 500) - dataExListV3g2 <- .get_data_from_htmlwidget(exListListV3, widgetsNumber = idWidget) - expect_equal(dataExListV3g2$a_offshore[indexHour], 2500) - expect_equal(dataExListV3g2$negROW[indexHour], 1000) -}) - -test_that("exchangesStack, interactive, x and refStudy are antaresDataTable", { - skip_if_not(.runExchangesStackTest) - myData1 <- readAntares(links = "all", showProgress = FALSE) - myData2 <- readAntares(links = "all", showProgress = FALSE) - myArea <- "a" - DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") - #no interactive - exS1 <- exchangesStack(x = myData1, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) - dataExS1 <- .get_data_from_htmlwidget(exS1) - timeEditValue <- "2018-04-25T00:00:00.000Z" - indexHour <- grep(timeEditValue, dataExS1$hour) - expect_gt(indexHour, 2) - expect_equal(dataExS1$nega_offshore[indexHour], 9) - # interactive - exS1 <- exchangesStack(x = myData1, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) - exS1 <- exS1$init() - expect_true(is(exS1, "MWController")) - expect_equal(exS1$ncharts, 1) - expect_equal(exS1$ncol, 1) - expect_equal(exS1$nrow, 1) - dataExS1 <- .get_data_from_htmlwidget(exS1) - expect_equal(dataExS1$nega_offshore[indexHour], 9) - - #identical myData, diff == 0 always - exS21V0 <- exchangesStack(x = myData1, refStudy = myData2, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) - resExS1V0 <- exS21V0$init() - expect_true(is(exS21V0, "MWController")) - expect_equal(exS21V0$ncharts, 1) - expect_equal(exS21V0$ncol, 1) - expect_equal(exS21V0$nrow, 1) - #get the data - dataExS21V0 <- .get_data_from_htmlwidget(exS21V0) - expect_equal(dataExS21V0$nega_offshore[indexHour], 0) - # edit myData2 to have a diff != 0 - #pb timeZone local (PC, Travis, etc) - for (i in 0:5){ - timeEditShift <- lubridate::hours(i) - timeEditMinus <- as.Date(timeEditValue) - timeEditShift - timeEditPlus <- as.Date(timeEditValue) + timeEditShift - myData2[ (time == timeEditMinus | time == timeEditPlus) & link == "a - a_offshore", `FLOW LIN.` := as.integer(`FLOW LIN.` + 2500)] - } - exS21V1 <- exchangesStack(x = myData1, refStudy = myData2, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) - resExS1V0 <- exS21V1$init() - expect_true(is(exS21V1, "MWController")) - expect_equal(exS21V1$ncharts, 1) - expect_equal(exS21V1$ncol, 1) - expect_equal(exS21V1$nrow, 1) - dataExS21V1 <- .get_data_from_htmlwidget(exS21V1) - expect_equal(dataExS21V1$nega_offshore[indexHour], 2500) -}) - -test_that("exchangesStack, interactive, x and refStudy are antaresDataList", { - skip_if_not(.runExchangesStackTest) - myData1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) - myData2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) - myArea <- "a" - DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") - #no interactive - exS1 <- exchangesStack(x = myData1, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) - dataExS1 <- .get_data_from_htmlwidget(exS1) - timeEditValue <- "2018-04-25T00:00:00.000Z" - indexHour <- grep(timeEditValue, dataExS1$hour) - expect_gt(indexHour, 2) - expect_equal(dataExS1$nega_offshore[indexHour], 9) - # interactive no interactive - exS1I <- exchangesStack(x = myData1, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) - resExS1 <- exS1I$init() - expect_true(is(exS1I, "MWController")) - expect_equal(exS1I$ncharts, 1) - expect_equal(exS1I$ncol, 1) - expect_equal(exS1I$nrow, 1) - dataExS1I <- .get_data_from_htmlwidget(exS1I) - expect_equal(dataExS1I$nega_offshore[indexHour], 9) - - # interactive with refStudy but myData1 =myData2 - exS21V0 <- exchangesStack(x = myData1, refStudy = myData2, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) - exS21V0 <- exS21V0$init() - expect_true(is(exS21V0, "MWController")) - expect_equal(exS21V0$ncharts, 1) - expect_equal(exS21V0$ncol, 1) - expect_equal(exS21V0$nrow, 1) - dataExS21V0 <- .get_data_from_htmlwidget(exS21V0) - expect_equal(dataExS21V0$nega_offshore[indexHour], 0) - # edit myData2 to have a diff != 0 - #pb timeZone local (PC, Travis, etc) - for (i in 0:5){ - timeEditShift <- lubridate::hours(i) - timeEditMinus <- as.Date(timeEditValue) - timeEditShift - timeEditPlus <- as.Date(timeEditValue) + timeEditShift - myData2$links[ (time == timeEditMinus | time == timeEditPlus) & link == "a - a_offshore", `FLOW LIN.` := as.integer(`FLOW LIN.` + 2500)] - } - exS21V1 <- exchangesStack(x = myData1, refStudy = myData2, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) - exS21V1 <- exS21V1$init() - expect_true(is(exS21V1, "MWController")) - expect_equal(exS21V1$ncharts, 1) - expect_equal(exS21V1$ncol, 1) - expect_equal(exS21V1$nrow, 1) - dataExS21V1 <- .get_data_from_htmlwidget(exS21V1) - expect_equal(dataExS21V1$nega_offshore[indexHour], 2500) - #ROW not null in myData1 - for (i in 0:5){ - timeEditShift <- lubridate::hours(i) - timeEditMinus <- as.Date(timeEditValue) - timeEditShift - timeEditPlus <- as.Date(timeEditValue) + timeEditShift - myData1$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, `ROW BAL.` := as.integer(`ROW BAL.` - 1500)] - } - #test if there is row - exS1V2 <- exchangesStack(x = myData1, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) - exS1V2 <- exS1V2$init() - expect_true(is(exS1V2, "MWController")) - expect_equal(exS1V2$ncharts, 1) - expect_equal(exS1V2$ncol, 1) - expect_equal(exS1V2$nrow, 1) - dataExS1V2 <- .get_data_from_htmlwidget(exS1V2) - expect_equal(dataExS1V2$ROW[indexHour], 1500) - exS21V2 <- exchangesStack(x = myData1, refStudy = myData2, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) - exS21V2 <- exS21V2$init() - expect_true(is(exS21V2, "MWController")) - expect_equal(exS21V2$ncharts, 1) - expect_equal(exS21V2$ncol, 1) - expect_equal(exS21V2$nrow, 1) - dataExS21V2 <- .get_data_from_htmlwidget(exS21V2) - expect_equal(dataExS21V2$nega_offshore[indexHour], 2500) - expect_equal(dataExS21V2$ROW[indexHour], 1500) - #ROW not null in myData2 - for (i in 0:5){ - timeEditShift <- lubridate::hours(i) - timeEditMinus <- as.Date(timeEditValue) - timeEditShift - timeEditPlus <- as.Date(timeEditValue) + timeEditShift - myData2$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, `ROW BAL.` := as.integer(`ROW BAL.` - 1000)] - } - exS21V3 <- exchangesStack(x = myData1, refStudy = myData2, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) - exS21V3 <- exS21V3$init() - expect_true(is(exS21V3, "MWController")) - expect_equal(exS21V3$ncharts, 1) - expect_equal(exS21V3$ncol, 1) - expect_equal(exS21V3$nrow, 1) - dataExS21V3 <- .get_data_from_htmlwidget(exS21V3) - expect_equal(dataExS21V3$nega_offshore[indexHour], 2500) - expect_equal(dataExS21V3$ROW[indexHour], 500) -}) - -test_that("exchangesStack, interactive, x is a list of antaresDataTable and refStudy an antaresDataTable", { - skip_if_not(.runExchangesStackTest) - myData1 <- readAntares(links = "all", showProgress = FALSE) - myData2 <- readAntares(links = "all", showProgress = FALSE) - myData3 <- readAntares(links = "all", showProgress = FALSE) - myData4 <- readAntares(links = "all", showProgress = FALSE) - myDataList <- list(myData2, myData3, myData4) - myArea <- "a" - DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") - # no interactive - exS2 <- exchangesStack(x = myDataList, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) - # compare with myData3 - idWidget <- 2 - dataExS2 <- .get_data_from_htmlwidget(exS2, widgetsNumber = idWidget) - timeEditValue <- "2018-04-25T00:00:00.000Z" - indexHour <- grep(timeEditValue, dataExS2$hour) - expect_gt(indexHour, 2) - expect_equal(dataExS2$nega_offshore[indexHour], 9) - # interactive - exSList1 <- exchangesStack(x = myDataList, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) - exSList1 <- exSList1$init() - expect_true(is(exSList1, "MWController")) - expect_equal(exSList1$ncharts, 3) - expect_equal(exSList1$ncol, 2) - expect_equal(exSList1$nrow, 2) - dataExS1I <- .get_data_from_htmlwidget(exSList1, widgetsNumber = idWidget) - expect_equal(dataExS1I$nega_offshore[indexHour], 9) - #identical myData, diff == 0 always - exS21V0 <- exchangesStack(x = myDataList, refStudy = myData1, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) - exS21V0 <- exS21V0$init() - expect_true(is(exS21V0, "MWController")) - expect_equal(exS21V0$ncharts, 3) - expect_equal(exS21V0$ncol, 2) - expect_equal(exS21V0$nrow, 2) - dataExS21V0 <- .get_data_from_htmlwidget(exS21V0, widgetsNumber = idWidget) - expect_equal(dataExS21V0$nega_offshore[indexHour], 0) - # edit myData3 to have a diff != 0 - #pb timeZone local (PC, Travis, etc) - for (i in 0:5){ - timeEditShift <- lubridate::hours(i) - timeEditMinus <- as.Date(timeEditValue) - timeEditShift - timeEditPlus <- as.Date(timeEditValue) + timeEditShift - myData3[ (time == timeEditMinus | time == timeEditPlus) & link == "a - a_offshore", `FLOW LIN.` := as.integer(`FLOW LIN.` + 2500)] - } - exS21V1 <- exchangesStack(x = myDataList, refStudy = myData1, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) - exS21V1 <- exS21V1$init() - expect_true(is(exS21V1, "MWController")) - expect_equal(exS21V1$ncharts, 3) - expect_equal(exS21V1$ncol, 2) - expect_equal(exS21V1$nrow, 2) - dataExS21V1 <- .get_data_from_htmlwidget(exS21V1, widgetsNumber = idWidget) - expect_equal(dataExS21V1$a_offshore[indexHour], 2500) -}) - -test_that("exchangesStack, interactive, x is a list of antaresDataList and refStudy an antaresDataList", { - skip_if_not(.runExchangesStackTest) - myData1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) - myData2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) - myData3 <- readAntares(areas = "all", links = "all", showProgress = FALSE) - myData4 <- readAntares(areas = "all", links = "all", showProgress = FALSE) - - myDataList <- list(myData2, myData3, myData4) - myArea <- "a" - DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") - # no interactive - exS2 <- exchangesStack(x = myDataList, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) - # compare with myData3 - idWidget <- 2 - dataExS2 <- .get_data_from_htmlwidget(exS2, widgetsNumber = idWidget) - timeEditValue <- "2018-04-25T00:00:00.000Z" - indexHour <- grep(timeEditValue, dataExS2$hour) - expect_gt(indexHour, 2) - expect_equal(dataExS2$nega_offshore[indexHour], 9) - # interactive - exSList1 <- exchangesStack(x = myDataList, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) - exSList1 <- exSList1$init() - expect_true(is(exSList1, "MWController")) - expect_equal(exSList1$ncharts, 3) - expect_equal(exSList1$ncol, 2) - expect_equal(exSList1$nrow, 2) - dataExS1I <- .get_data_from_htmlwidget(exSList1, widgetsNumber = idWidget) - expect_equal(dataExS1I$nega_offshore[indexHour], 9) - - #identical myData, diff == 0 always - exSList1Ref <- exchangesStack(x = myDataList, refStudy = myData1, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) - exSList1Ref <- exSList1Ref$init() - expect_true(is(exSList1Ref, "MWController")) - expect_equal(exSList1Ref$ncharts, 3) - expect_equal(exSList1Ref$ncol, 2) - expect_equal(exSList1Ref$nrow, 2) - dataExS21V0Ref <- .get_data_from_htmlwidget(exSList1Ref, widgetsNumber = idWidget) - expect_equal(dataExS21V0Ref$nega_offshore[indexHour], 0) - # edit myData3 to have a diff != 0 - #pb timeZone local (PC, Travis, etc) - for (i in 0:5){ - timeEditShift <- lubridate::hours(i) - timeEditMinus <- as.Date(timeEditValue) - timeEditShift - timeEditPlus <- as.Date(timeEditValue) + timeEditShift - myData3$links[ (time == timeEditMinus | time == timeEditPlus) & link == "a - a_offshore", `FLOW LIN.` := as.integer(`FLOW LIN.` + 2500)] - } - exS21V1 <- exchangesStack(x = myDataList, refStudy = myData1, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) - exS21V1 <- exS21V1$init() - expect_true(is(exS21V1, "MWController")) - expect_equal(exS21V1$ncharts, 3) - expect_equal(exS21V1$ncol, 2) - expect_equal(exS21V1$nrow, 2) - dataExS21V1 <- .get_data_from_htmlwidget(exS21V1, widgetsNumber = idWidget) - expect_equal(dataExS21V1$a_offshore[indexHour], 2500) - #ROW not null in myData4 - for (i in 0:5){ - timeEditShift <- lubridate::hours(i) - timeEditMinus <- as.Date(timeEditValue) - timeEditShift - timeEditPlus <- as.Date(timeEditValue) + timeEditShift - myData4$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, `ROW BAL.` := as.integer(`ROW BAL.` - 1500)] - } - #test if there is row - exList <- exchangesStack(x = myDataList, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) - exList <- exList$init() - expect_true(is(exList, "MWController")) - expect_equal(exList$ncharts, 3) - expect_equal(exList$ncol, 2) - expect_equal(exList$nrow, 2) - dataExList <- .get_data_from_htmlwidget(exList, widgetsNumber = idWidget) - expect_equal(dataExList$a_offshore[indexHour], 2500 - 9) - idRowNotNull <- 3 - dataExListRow <- .get_data_from_htmlwidget(exList, widgetsNumber = idRowNotNull) - expect_equal(dataExListRow$ROW[indexHour], 1500) - #with a refStudy - exListListV2 <- exchangesStack(x = myDataList, refStudy = myData1, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) - exListListV2 <- exListListV2$init() - expect_true(is(exListListV2, "MWController")) - expect_equal(exListListV2$ncharts, 3) - expect_equal(exListListV2$ncol, 2) - expect_equal(exListListV2$nrow, 2) - dataExListV2 <- .get_data_from_htmlwidget(exListListV2, widgetsNumber = idWidget) - expect_equal(dataExListV2$a_offshore[indexHour], 2500) - expect_equal(dataExListV2$ROW[indexHour], 0) - dataExListV2Row <- .get_data_from_htmlwidget(exListListV2, widgetsNumber = idRowNotNull) - expect_equal(dataExListV2Row$a_offshore[indexHour], 0) - expect_equal(dataExListV2Row$ROW[indexHour], 1500) - #ROW not null in refStudy myData1 - for (i in 0:5){ - timeEditShift <- lubridate::hours(i) - timeEditMinus <- as.Date(timeEditValue) - timeEditShift - timeEditPlus <- as.Date(timeEditValue) + timeEditShift - myData1$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, `ROW BAL.` := as.integer(`ROW BAL.` - 1000)] - } - exListListV3 <- exchangesStack(x = myDataList, refStudy = myData1, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) - exListListV3 <- exListListV3$init() - expect_true(is(exListListV3, "MWController")) - expect_equal(exListListV3$ncharts, 3) - expect_equal(exListListV3$ncol, 2) - expect_equal(exListListV3$nrow, 2) - dataExListV3 <- .get_data_from_htmlwidget(exListListV3, widgetsNumber = idRowNotNull) - expect_equal(dataExListV3$nega_offshore[indexHour], 0) - expect_equal(dataExListV3$ROW[indexHour], 500) - dataExListV3g2 <- .get_data_from_htmlwidget(exListListV3, widgetsNumber = idWidget) - expect_equal(dataExListV3g2$a_offshore[indexHour], 2500) - expect_equal(dataExListV3g2$negROW[indexHour], 1000) -}) - -test_that("exchangesStack, no interactive, x and refStudy are optsH5 ", { - if (.requireRhdf5_Antares(stopP = FALSE)){ - skip_if_not(.runExchangesStackTest) - suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) - optsH5 <- setSimulationPath(pathtemp) - myArea <- "a" - DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") - ES1 <- exchangesStack(x = optsH5, interactive = FALSE, area = myArea, dateRange = DR) - dataHtmlWidgetES1 <- .get_data_from_htmlwidget(ES1) - timeEditValue <- "2018-04-25T00:00:00.000Z" - indexHour <- grep(timeEditValue, dataHtmlWidgetES1$hour) - expect_gt(indexHour, 2) - expect_equal(dataHtmlWidgetES1$nega_offshore[indexHour], 9) - # with refStudy - ESRef <- exchangesStack(x = optsH5, refStudy = optsH5, interactive = FALSE, area = myArea, dateRange = DR) - dataHtmlWidgetES1 <- .get_data_from_htmlwidget(ESRef) - expect_equal(dataHtmlWidgetES1$nega_offshore[indexHour], 0) - # with a new Study H5 test if compare prodStack works - ## create a new folder h5 - pathInitial <- file.path(dirname(pathtemp), basename(pathtemp)) - pathNewH5 <- file.path(pathInitial, "testH5") - if (!dir.exists(pathNewH5)){ - dir.create(pathNewH5) - } - #write the study - #windows pb ? pathNewH5 <- gsub("/", "\\", pathNewH5, fixed = TRUE) - optsData <- antaresRead::setSimulationPath(path = studyPath) - suppressWarnings(writeAntaresH5(path = pathNewH5, opts = optsData, - overwrite = TRUE, supressMessages = TRUE)) - - - pathNewH5File <- file.path(pathNewH5, list.files(pathNewH5)) - myLink <- getLinks()[1] - .h5Antares_edit_variable( - pathH5 = pathNewH5File, - link = myLink, - timeId = 1:40, - antVar = "FLOW LIN.", - newValue = 15000 - ) - - optsH5New <- setSimulationPath(path = pathNewH5File) - ES1New <- exchangesStack(x = optsH5New, interactive = FALSE, area = myArea, dateRange = DR) - dataHtmlWidgetES1 <- .get_data_from_htmlwidget(ES1New) - expect_equal(dataHtmlWidgetES1$nega_offshore[indexHour], 9) - expect_equal(dataHtmlWidgetES1$a_offshore[2], 15000) - ES1NewRef <- exchangesStack(x = optsH5New, refStudy = optsH5, interactive = FALSE, area = myArea, dateRange = DR) - dataHtmlWidgetES1Ref <- .get_data_from_htmlwidget(ES1NewRef) - expect_equal(dataHtmlWidgetES1Ref$nega_offshore[indexHour], 0) - expect_gt(dataHtmlWidgetES1Ref$a_offshore[2], 15000) - } -}) - -test_that("exchangesStack, no interactive, x is a list of optH5 and refStudy are optsH5 ", { - if (.requireRhdf5_Antares(stopP = FALSE)){ - skip_if_not(.runExchangesStackTest) - suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) - optsH5 <- setSimulationPath(pathtemp) - - # with new Studies H5 test if compare prodStack works - ## create new folders h5 - pathInitial <- file.path(dirname(pathtemp), basename(pathtemp)) - - listFolderToCreate <- c("testH5v2", "testH5v3", "testH5v4") - for (folder in listFolderToCreate){ - pathNewH5 <- file.path(pathInitial, folder) - if (!dir.exists(pathNewH5)){ - dir.create(pathNewH5) - } - - #write the study - #windows pb ? pathNewH5 <- gsub("/", "\\", pathNewH5, fixed = TRUE) - optsData <- antaresRead::setSimulationPath(path = studyPath) - suppressWarnings( - writeAntaresH5( - path = pathNewH5, - opts = optsData, - overwrite = TRUE, - supressMessages = TRUE) - ) - } - idWidgetToEdit <- 2 - pathH5FolderToEdit <- file.path(pathInitial, listFolderToCreate[[idWidgetToEdit]]) - pathH5FileToEdit <- file.path(pathH5FolderToEdit, list.files(pathH5FolderToEdit)) - newValueFlow <- 15000 - myLink <- getLinks()[1] - .h5Antares_edit_variable( - pathH5 = pathH5FileToEdit, - link = myLink, - timeId = 1:40, - antVar = "FLOW LIN.", - newValue = newValueFlow - ) - - optsList <- list() - antaresDataListH5 <- list() - for (i in 1:length(listFolderToCreate)){ - pathOptsI <- file.path(pathInitial, listFolderToCreate[[i]]) - optsList[[i]] <- setSimulationPath(path = pathOptsI) - antaresDataListH5[[i]] <- readAntares(links = myLink) - } - #test the data from h5 - #get the data from the h5 file - antaresDataRef <- readAntares(opts = optsH5, links = myLink) - expect_equal(max(antaresDataListH5[[idWidgetToEdit]]$`FLOW LIN.`), newValueFlow) - expect_equal(max(antaresDataListH5[[1]]$`FLOW LIN.`), max(antaresDataRef$`FLOW LIN.`)) - expect_equal(max(antaresDataListH5[[3]]$`FLOW LIN.`), max(antaresDataRef$`FLOW LIN.`)) - # get the data from htmlwidget - myArea <- "a" - DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") - ESList <- exchangesStack(x = optsList, interactive = FALSE, area = myArea, dateRange = DR) - dataHtmlWidgetES2 <- .get_data_from_htmlwidget(ESList, widgetsNumber = idWidgetToEdit) - expect_equal(dataHtmlWidgetES2$a_offshore[3], newValueFlow) - dataHtmlWidgetES1 <- .get_data_from_htmlwidget(ESList, widgetsNumber = 1) - expect_equal(dataHtmlWidgetES1$a_offshore[3], 0) - expect_equal(dataHtmlWidgetES1$nega_offshore[3], 6) - # with refStudy - ESListRef <- exchangesStack(x = optsList, refStudy = optsH5, interactive = FALSE, area = myArea, dateRange = DR) - dataHtmlWidgetES2Ref <- .get_data_from_htmlwidget(ESListRef, widgetsNumber = idWidgetToEdit) - expect_equal(dataHtmlWidgetES2Ref$a_offshore[3] - dataHtmlWidgetES1$nega_offshore[3], newValueFlow) - dataHtmlWidgetES1Ref <- .get_data_from_htmlwidget(ESListRef, widgetsNumber = 1) - expect_equal(dataHtmlWidgetES1Ref$a_offshore[3], 0) - expect_equal(dataHtmlWidgetES1Ref$nega_offshore[3], 0) - } -}) - -test_that("exchangesStack, interactive, x and refStudy are optsH5 ", { - if (.requireRhdf5_Antares(stopP = FALSE)){ - skip_if_not(.runExchangesStackTest) - suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) - optsH5 <- setSimulationPath(pathtemp) - myArea <- "a" - DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") - # no interactive - ES1 <- exchangesStack(x = optsH5, - interactive = FALSE, - area = myArea, - dateRange = DR, - mcYearh5 = 1) - dataHtmlWidgetES1 <- .get_data_from_htmlwidget(ES1) - timeEditValue <- "2018-04-24T23:00:00.000Z" - indexHour <- grep(timeEditValue, dataHtmlWidgetES1$hour) - expect_gt(indexHour, 2) - expect_equal(dataHtmlWidgetES1$nega_offshore[indexHour], 10) - # with interactive - #FOR DEBUG - #ES1I <- exchangesStack(x = optsH5, - # interactive = TRUE) - - ES1I <- exchangesStack(x = optsH5, - .runApp = FALSE, - interactive = TRUE, - dateRange = DR) - ES1I <- ES1I$init() - expect_true(is(ES1I, "MWController")) - expect_equal(ES1I$ncharts, 1) - expect_equal(ES1I$ncol, 1) - expect_equal(ES1I$nrow, 1) - dataHtmlWidgetES1I <- .get_data_from_htmlwidget(ES1I) - expect_equal(dataHtmlWidgetES1I$nega_offshore[indexHour], 10) - # with refStudy no interactive - ESRef <- exchangesStack(x = optsH5, - refStudy = optsH5, - interactive = FALSE, - area = myArea, - dateRange = DR, - mcYearh5 = 1) - dataHtmlWidgetES1 <- .get_data_from_htmlwidget(ESRef) - expect_equal(dataHtmlWidgetES1$nega_offshore[indexHour], 0) - # refStudy with interactive - ESRefI <- exchangesStack(x = optsH5, - refStudy = optsH5, - interactive = TRUE, - .runApp = FALSE, - area = myArea, - dateRange = DR) - ESRefI <- ESRefI$init() - expect_true(is(ESRefI, "MWController")) - expect_equal(ESRefI$ncharts, 1) - expect_equal(ESRefI$ncol, 1) - expect_equal(ESRefI$nrow, 1) - dataHtmlWidgetESRefI <- .get_data_from_htmlwidget(ESRefI) - expect_equal(dataHtmlWidgetESRefI$nega_offshore[indexHour], 0) - # with a new Study H5 test if compare prodStack works - ## create a new folder h5 - pathInitial <- file.path(dirname(pathtemp), basename(pathtemp)) - pathNewH5 <- file.path(pathInitial, "testH5") - if (!dir.exists(pathNewH5)){ - dir.create(pathNewH5) - } - #write the study - #windows pb ? pathNewH5 <- gsub("/", "\\", pathNewH5, fixed = TRUE) - optsData <- antaresRead::setSimulationPath(path = studyPath) - suppressWarnings(writeAntaresH5(path = pathNewH5, opts = optsData, - overwrite = TRUE, supressMessages = TRUE)) - - - pathNewH5File <- file.path(pathNewH5, list.files(pathNewH5)) - myLink <- getLinks()[1] - .h5Antares_edit_variable( - pathH5 = pathNewH5File, - link = myLink, - timeId = 1:40, - antVar = "FLOW LIN.", - newValue = 15000, - mcYear = 1 - ) - - optsH5New <- setSimulationPath(path = pathNewH5File) - #no interactive - ES1New <- exchangesStack(x = optsH5New, - interactive = FALSE, - area = myArea, - dateRange = DR, - mcYearh5 = 1) - dataHtmlWidgetES1New <- .get_data_from_htmlwidget(ES1New) - expect_equal(dataHtmlWidgetES1New$nega_offshore[indexHour], 10) - expect_equal(dataHtmlWidgetES1New$a_offshore[2], 15000) - # with interactive - ES1NewI <- exchangesStack(x = optsH5New, - interactive = TRUE, - .runApp = FALSE, - area = myArea, - dateRange = DR) - ES1NewI <- ES1NewI$init() - expect_true(is(ES1NewI, "MWController")) - expect_equal(ES1NewI$ncharts, 1) - expect_equal(ES1NewI$ncol, 1) - expect_equal(ES1NewI$nrow, 1) - dataHtmlWidgetES1New <- .get_data_from_htmlwidget(ES1NewI) - expect_equal(dataHtmlWidgetES1New$nega_offshore[indexHour], 10) - expect_equal(dataHtmlWidgetES1New$a_offshore[2], 15000) - # no interactive, refStudy, - ES1NewRef <- exchangesStack(x = optsH5New, - refStudy = optsH5, - interactive = FALSE, - area = myArea, - dateRange = DR, - mcYearh5 = 1) - dataHtmlWidgetES1Ref <- .get_data_from_htmlwidget(ES1NewRef) - expect_equal(dataHtmlWidgetES1Ref$nega_offshore[indexHour], 0) - expect_gt(dataHtmlWidgetES1Ref$a_offshore[2], 15000) - # interactive, refStudy, - ES1NewRefI <- exchangesStack(x = optsH5New, - refStudy = optsH5, - interactive = TRUE, - .runApp = FALSE, - area = myArea, - dateRange = DR, - mcYearh5 = 1) - ES1NewRefI <- ES1NewRefI$init() - expect_true(is(ES1NewRefI, "MWController")) - expect_equal(ES1NewRefI$ncharts, 1) - expect_equal(ES1NewRefI$ncol, 1) - expect_equal(ES1NewRefI$nrow, 1) - dataHtmlWidgetES1RefI <- .get_data_from_htmlwidget(ES1NewRefI) - expect_equal(dataHtmlWidgetES1RefI$nega_offshore[indexHour], 0) - expect_gt(dataHtmlWidgetES1RefI$a_offshore[2], 15000) - } -}) - -test_that("exchangesStack, interactive, x is a list of optsH5 and refStudy optsH5 , ", { - if (.requireRhdf5_Antares(stopP = FALSE)){ - skip_if_not(.runExchangesStackTest) - suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) - optsH5 <- setSimulationPath(pathtemp) - - # with new Studies H5 test if compare prodStack works - ## create new folders h5 - pathInitial <- file.path(dirname(pathtemp), basename(pathtemp)) - - listFolderToCreate <- c("testH5v2", "testH5v3", "testH5v4") - for (folder in listFolderToCreate){ - pathNewH5 <- file.path(pathInitial, folder) - if (!dir.exists(pathNewH5)){ - dir.create(pathNewH5) - } - - #write the study - #windows pb ? pathNewH5 <- gsub("/", "\\", pathNewH5, fixed = TRUE) - optsData <- antaresRead::setSimulationPath(path = studyPath) - suppressWarnings( - writeAntaresH5( - path = pathNewH5, - opts = optsData, - overwrite = TRUE, - supressMessages = TRUE) - ) - } - pathH5FolderToEdit <- file.path(pathInitial, listFolderToCreate[[2]]) - pathH5FileToEdit <- file.path(pathH5FolderToEdit, list.files(pathH5FolderToEdit)) - myLink <- getLinks()[1] - newValueFlow <- 50000 - mcYearToTestList <- c(2, NULL) - for (mcYearToTest in mcYearToTestList){ - .h5Antares_edit_variable( - pathH5 = pathH5FileToEdit, - link = myLink, - timeId = 1:40, - antVar = "FLOW LIN.", - newValue = newValueFlow, - mcYear = mcYearToTest - ) - - optsList <- list() - antaresDataListH5 <- list() - for (i in 1:length(listFolderToCreate)){ - pathOptsI <- file.path(pathInitial, listFolderToCreate[[i]]) - optsList[[i]] <- setSimulationPath(path = pathOptsI) - antaresDataListH5[[i]] <- readAntares(links = myLink, mcYear = mcYearToTest) - } - - DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") - #try without refStudy and interactive == FALSE - myArea <- "a" - ESListNoInt <- exchangesStack(x = optsList, - dateRange = DR, - area = myArea, - interactive = FALSE, - mcYearh5 = mcYearToTest) - dataHtmlWidgetESNoInt <- .get_data_from_htmlwidget(ESListNoInt, widgetsNumber = 2) - expect_equal(max(dataHtmlWidgetESNoInt$a_offshore, na.rm = TRUE), 50000) - - # try with refStudy - ESListNoInt <- exchangesStack(x = optsList, - refStudy = optsH5, - interactive = FALSE, - areas = myArea, - dateRange = DR, - mcYearh5 = mcYearToTest) - ## get the data from htmlwidget - dataHtmlWidgetES1 <- .get_data_from_htmlwidget(ESListNoInt, widgetsNumber = 1) - dataHtmlWidgetES2 <- .get_data_from_htmlwidget(ESListNoInt, widgetsNumber = 2) - - ## get the data from the h5 file - antaresDataRef <- readAntares(opts = optsH5, links = myLink, mcYears = mcYearToTest) - expect_equal(max(antaresDataListH5[[2]]$`FLOW LIN.`), newValueFlow) - expect_equal(max(antaresDataListH5[[1]]$`FLOW LIN.`), max(antaresDataRef$`FLOW LIN.`)) - expect_equal(max(antaresDataListH5[[3]]$`FLOW LIN.`), max(antaresDataRef$`FLOW LIN.`)) - expect_equal(antaresDataListH5[[2]]$`OV. COST`, antaresDataRef$`OV. COST`) - - ## compare data - resCompareData1_ref <- antaresProcessing::compare(x = antaresDataRef, y = antaresDataListH5[[1]]) - resCompareData2_ref <- antaresProcessing::compare(x = antaresDataRef, y = antaresDataListH5[[2]]) - expect_equal(resCompareData1_ref[timeId == timeId[40], `FLOW LIN.`], -dataHtmlWidgetES1$nega_offshore[[2]]) - expect_gt(resCompareData2_ref[timeId == timeId[40], `FLOW LIN.`], newValueFlow) - - # interactive == TRUE - ## DEBUG - # PSWORef <- prodStack(x = optsList, - # dateRange = DR, - # h5requestFiltering = list(areas = myArea, - # mcYears = mcYearToTest), - # .runApp = FALSE, - # interactive = TRUE) - # PSWORef <- PSWORef$init() - # ESWORef <- exchangesStack(x = antaresDataListH5[[2]]) - # ESWORef <- exchangesStack(x = optsList) - # ESWORef <- exchangesStack(x = antaresDataListH5[[2]], - # dateRange = DR) - # ESWORef <- exchangesStack(x = optsList, - # dateRange = DR) - - ESWORef <- exchangesStack( - x = optsList, - dateRange = DR, - .runApp = FALSE, - interactive = TRUE, - h5requestFiltering = list( - areas = getAreas(select = "a"), - links = getLinks(areas = myArea), - mcYears = mcYearToTest)) - ESWORef <- ESWORef$init() - expect_true(is(ESWORef, "MWController")) - expect_equal(ESWORef$ncharts, 3) - expect_equal(ESWORef$ncol, 2) - expect_equal(ESWORef$nrow, 2) - ## get the data from htmlwidget - dataHtmlWidgetESWORef <- .get_data_from_htmlwidget(ESWORef, widgetsNumber = 2) - expect_equal(dataHtmlWidgetESWORef$a_offshore[[2]], 50000) - expect_equal(dataHtmlWidgetESWORef$nega_offshore[[2]], 0) - dataHtmlWidgetESWORef1 <- .get_data_from_htmlwidget(ESWORef, widgetsNumber = 1) - expect_equal(dataHtmlWidgetESWORef1$a_offshore[[2]], 0) - expect_gt(dataHtmlWidgetESWORef1$nega_offshore[[2]], 0) - - # fourth, MWController with refStudy and interactive == TRUE - ESWORefListI <- exchangesStack( - x = optsList, - refStudy = optsH5, - dateRange = DR, - .runApp = FALSE, - interactive = TRUE, - h5requestFiltering = list( - areas = getAreas(select = "a"), - links = getLinks(areas = myArea), - mcYears = mcYearToTest)) - ESWORefListI <- ESWORefListI$init() - expect_true(is(ESWORefListI, "MWController")) - expect_equal(ESWORefListI$ncharts, 3) - expect_equal(ESWORefListI$ncol, 2) - expect_equal(ESWORefListI$nrow, 2) - #check data from htmlwidgets - dataHtmlWidgetES31 <- .get_data_from_htmlwidget(ESWORefListI, widgetsNumber = 2) - expect_gt(dataHtmlWidgetES31$a_offshore[[2]], 50000) - expect_equal(dataHtmlWidgetES31$nega_offshore[[2]], 0) - dataHtmlWidgetES21 <- .get_data_from_htmlwidget(ESWORefListI, widgetsNumber = 1) - expect_equal(dataHtmlWidgetES21$a_offshore[[2]], 0) - expect_equal(dataHtmlWidgetES21$nega_offshore[[2]], 0) - - resOptsH5Old <- readAntares(opts = optsH5, links = myLink, showProgress = FALSE, mcYears = mcYearToTest) - resOptsH5New <- readAntares(opts = optsList[[2]], links = myLink, showProgress = FALSE, mcYears = mcYearToTest) - #timeId for time = "2018-04-24 00:00:00 UTC" ? timeId = 2713 - timeIdVal <- 2713 - expect_equal(resOptsH5New[timeId == timeIdVal, `FLOW LIN.`], newValueFlow) - expect_lt(resOptsH5Old[timeId == timeIdVal, `FLOW LIN.`], 0) - - resCompareData <- antaresProcessing::compare(x = resOptsH5Old, y = resOptsH5New) - expect_gt(resCompareData[timeId == timeIdVal, `FLOW LIN.`], newValueFlow) - expect_equal(resCompareData[timeId == timeIdVal, `FLOW LIN.`], dataHtmlWidgetES31$a_offshore[[1]]) - #no change after timeID > 40 - expect_equal(resCompareData[timeId == (timeIdVal + 90), `FLOW LIN.`], dataHtmlWidgetES31$a_offshore[[50]]) - expect_equal(dataHtmlWidgetES21$a_offshore[[1]], 0) - expect_equal(dataHtmlWidgetES21$nega_offshore[[1]], 0) - } - } - -}) +# context("exchangesStack") +# +# test_that("no interactive", { +# +# mydata <- readAntares(links = "all", timeStep = "daily", showProgress = FALSE) +# # default parameters +# default_params <- exchangesStack(mydata, interactive = FALSE) +# expect_is(default_params, "htmlwidget") +# # TO DO : passer les arguments +# # passer plusieurs data +# # .compare +# # suivant les cas : +# # - tester les retours d'erreurs +# }) +# +# test_that("exchangesStack, no interactive", { +# dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# testClass <- function(obj){ +# class(obj)[1] == "combineWidgets" +# } +# listArgs <- list(noarg = list(x = dta, interactive = FALSE, areas = "a"), +# allAreas = list(x = dta, interactive = FALSE, areas = "all"), +# main = list(x = dta, interactive = FALSE, areas = "all", main = "Title"), +# ylab = list(x = dta, interactive = FALSE, areas = "all", main = "Title", ylab = "Subt") +# ) +# lapply(listArgs, function(X){ +# re1 <- do.call(exchangesStack, X) +# expect_true(testClass(re1)) +# }) +# +# }) +# +# test_that("exchangesStack, no interactive return error", { +# dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# expect_error(exchangesStack(dta, interactive = FALSE, compare = "areas")) +# }) +# +# test_that("exchangesStack, no interactive, x and refStudy are antaresDataTable", { +# myData1 <- readAntares(links = "all", showProgress = FALSE) +# myData2 <- readAntares(links = "all", showProgress = FALSE) +# myArea <- "a" +# DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") +# exS1 <- exchangesStack(x = myData1, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) +# dataExS1 <- .get_data_from_htmlwidget(exS1) +# timeEditValue <- "2018-04-25T00:00:00.000Z" +# indexHour <- grep(timeEditValue, dataExS1$hour) +# expect_gt(indexHour, 2) +# expect_equal(dataExS1$nega_offshore[indexHour], 9) +# #identical myData, diff == 0 always +# exS21V0 <- exchangesStack(x = myData1, refStudy = myData2, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) +# dataExS21V0 <- .get_data_from_htmlwidget(exS21V0) +# expect_equal(dataExS21V0$nega_offshore[indexHour], 0) +# # edit myData2 to have a diff != 0 +# #pb timeZone local (PC, Travis, etc) +# for (i in 0:5){ +# timeEditShift <- lubridate::hours(i) +# timeEditMinus <- as.Date(timeEditValue) - timeEditShift +# timeEditPlus <- as.Date(timeEditValue) + timeEditShift +# myData2[ (time == timeEditMinus | time == timeEditPlus) & link == "a - a_offshore", `FLOW LIN.` := as.integer(`FLOW LIN.` + 2500)] +# } +# exS21V1 <- exchangesStack(x = myData1, refStudy = myData2, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) +# dataExS21V1 <- .get_data_from_htmlwidget(exS21V1) +# expect_equal(dataExS21V1$nega_offshore[indexHour], 2500) +# }) +# +# test_that("exchangesStack, no interactive, x and refStudy are antaresDataList", { +# myData1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# myData2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# myArea <- "a" +# DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") +# exS1 <- exchangesStack(x = myData1, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) +# dataExS1 <- .get_data_from_htmlwidget(exS1) +# timeEditValue <- "2018-04-25T00:00:00.000Z" +# indexHour <- grep(timeEditValue, dataExS1$hour) +# expect_gt(indexHour, 2) +# expect_equal(dataExS1$nega_offshore[indexHour], 9) +# #identical myData, diff == 0 always +# exS21V0 <- exchangesStack(x = myData1, refStudy = myData2, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) +# dataExS21V0 <- .get_data_from_htmlwidget(exS21V0) +# expect_equal(dataExS21V0$nega_offshore[indexHour], 0) +# # edit myData2 to have a diff != 0 +# #pb timeZone local (PC, Travis, etc) +# for (i in 0:5){ +# timeEditShift <- lubridate::hours(i) +# timeEditMinus <- as.Date(timeEditValue) - timeEditShift +# timeEditPlus <- as.Date(timeEditValue) + timeEditShift +# myData2$links[ (time == timeEditMinus | time == timeEditPlus) & link == "a - a_offshore", `FLOW LIN.` := as.integer(`FLOW LIN.` + 2500)] +# } +# exS21V1 <- exchangesStack(x = myData1, refStudy = myData2, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) +# dataExS21V1 <- .get_data_from_htmlwidget(exS21V1) +# expect_equal(dataExS21V1$nega_offshore[indexHour], 2500) +# #ROW not null in myData1 +# for (i in 0:5){ +# timeEditShift <- lubridate::hours(i) +# timeEditMinus <- as.Date(timeEditValue) - timeEditShift +# timeEditPlus <- as.Date(timeEditValue) + timeEditShift +# myData1$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, `ROW BAL.` := as.integer(`ROW BAL.` - 1500)] +# } +# #test if there is row +# exS1V2 <- exchangesStack(x = myData1, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) +# dataExS1V2 <- .get_data_from_htmlwidget(exS1V2) +# expect_equal(dataExS1V2$ROW[indexHour], 1500) +# exS21V2 <- exchangesStack(x = myData1, refStudy = myData2, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) +# dataExS21V2 <- .get_data_from_htmlwidget(exS21V2) +# expect_equal(dataExS21V2$nega_offshore[indexHour], 2500) +# expect_equal(dataExS21V2$ROW[indexHour], 1500) +# #ROW not null in myData2 +# for (i in 0:5){ +# timeEditShift <- lubridate::hours(i) +# timeEditMinus <- as.Date(timeEditValue) - timeEditShift +# timeEditPlus <- as.Date(timeEditValue) + timeEditShift +# myData2$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, `ROW BAL.` := as.integer(`ROW BAL.` - 1000)] +# } +# exS21V3 <- exchangesStack(x = myData1, refStudy = myData2, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) +# dataExS21V3 <- .get_data_from_htmlwidget(exS21V3) +# expect_equal(dataExS21V3$nega_offshore[indexHour], 2500) +# expect_equal(dataExS21V3$ROW[indexHour], 500) +# }) +# +# test_that("exchangesStack, no interactive, x is a list of antaresDataTable and refStudy an antaresDataTable", { +# myData1 <- readAntares(links = "all", showProgress = FALSE) +# myData2 <- readAntares(links = "all", showProgress = FALSE) +# myData3 <- readAntares(links = "all", showProgress = FALSE) +# myData4 <- readAntares(links = "all", showProgress = FALSE) +# +# myDataList <- list(myData2, myData3, myData4) +# myArea <- "a" +# DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") +# exS2 <- exchangesStack(x = myDataList, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) +# # compare with myData3 +# idWidget <- 2 +# dataExS2 <- .get_data_from_htmlwidget(exS2, widgetsNumber = idWidget) +# timeEditValue <- "2018-04-25T00:00:00.000Z" +# indexHour <- grep(timeEditValue, dataExS2$hour) +# expect_gt(indexHour, 2) +# expect_equal(dataExS2$nega_offshore[indexHour], 9) +# #identical myData, diff == 0 always +# exS21V0 <- exchangesStack(x = myDataList, refStudy = myData1, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) +# dataExS21V0 <- .get_data_from_htmlwidget(exS21V0, widgetsNumber = idWidget) +# expect_equal(dataExS21V0$nega_offshore[indexHour], 0) +# # edit myData3 to have a diff != 0 +# #pb timeZone local (PC, Travis, etc) +# for (i in 0:5){ +# timeEditShift <- lubridate::hours(i) +# timeEditMinus <- as.Date(timeEditValue) - timeEditShift +# timeEditPlus <- as.Date(timeEditValue) + timeEditShift +# myData3[ (time == timeEditMinus | time == timeEditPlus) & link == "a - a_offshore", `FLOW LIN.` := as.integer(`FLOW LIN.` + 2500)] +# } +# exS21V1 <- exchangesStack(x = myDataList, refStudy = myData1, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) +# dataExS21V1 <- .get_data_from_htmlwidget(exS21V1, widgetsNumber = idWidget) +# expect_equal(dataExS21V1$a_offshore[indexHour], 2500) +# }) +# +# test_that("exchangesStack, no interactive, x is a list of antaresDataList and refStudy an antaresDataList", { +# myData1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# myData2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# myData3 <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# myData4 <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# +# myDataList <- list(myData2, myData3, myData4) +# myArea <- "a" +# DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") +# exS2 <- exchangesStack(x = myDataList, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) +# # compare with myData3 +# idWidget <- 2 +# dataExS2 <- .get_data_from_htmlwidget(exS2, widgetsNumber = idWidget) +# timeEditValue <- "2018-04-25T00:00:00.000Z" +# indexHour <- grep(timeEditValue, dataExS2$hour) +# expect_gt(indexHour, 2) +# expect_equal(dataExS2$nega_offshore[indexHour], 9) +# #identical myData, diff == 0 always +# exS21V0 <- exchangesStack(x = myDataList, refStudy = myData1, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) +# dataExS21V0 <- .get_data_from_htmlwidget(exS21V0, widgetsNumber = idWidget) +# expect_equal(dataExS21V0$nega_offshore[indexHour], 0) +# # edit myData3 to have a diff != 0 +# #pb timeZone local (PC, Travis, etc) +# for (i in 0:5){ +# timeEditShift <- lubridate::hours(i) +# timeEditMinus <- as.Date(timeEditValue) - timeEditShift +# timeEditPlus <- as.Date(timeEditValue) + timeEditShift +# myData3$links[ (time == timeEditMinus | time == timeEditPlus) & link == "a - a_offshore", `FLOW LIN.` := as.integer(`FLOW LIN.` + 2500)] +# } +# exS21V1 <- exchangesStack(x = myDataList, refStudy = myData1, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) +# dataExS21V1 <- .get_data_from_htmlwidget(exS21V1, widgetsNumber = idWidget) +# expect_equal(dataExS21V1$a_offshore[indexHour], 2500) +# #ROW not null in myData4 +# for (i in 0:5){ +# timeEditShift <- lubridate::hours(i) +# timeEditMinus <- as.Date(timeEditValue) - timeEditShift +# timeEditPlus <- as.Date(timeEditValue) + timeEditShift +# myData4$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, `ROW BAL.` := as.integer(`ROW BAL.` - 1500)] +# } +# #test if there is row +# exList <- exchangesStack(x = myDataList, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) +# dataExList <- .get_data_from_htmlwidget(exList, widgetsNumber = idWidget) +# expect_equal(dataExList$a_offshore[indexHour], 2500 - 9) +# idRowNotNull <- 3 +# dataExListRow <- .get_data_from_htmlwidget(exList, widgetsNumber = idRowNotNull) +# expect_equal(dataExListRow$ROW[indexHour], 1500) +# #with a refStudy +# exListListV2 <- exchangesStack(x = myDataList, refStudy = myData1, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) +# dataExListV2 <- .get_data_from_htmlwidget(exListListV2, widgetsNumber = idWidget) +# expect_equal(dataExListV2$a_offshore[indexHour], 2500) +# expect_equal(dataExListV2$ROW[indexHour], 0) +# dataExListV2Row <- .get_data_from_htmlwidget(exListListV2, widgetsNumber = idRowNotNull) +# expect_equal(dataExListV2Row$a_offshore[indexHour], 0) +# expect_equal(dataExListV2Row$ROW[indexHour], 1500) +# #ROW not null in refStudy myData1 +# for (i in 0:5){ +# timeEditShift <- lubridate::hours(i) +# timeEditMinus <- as.Date(timeEditValue) - timeEditShift +# timeEditPlus <- as.Date(timeEditValue) + timeEditShift +# myData1$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, `ROW BAL.` := as.integer(`ROW BAL.` - 1000)] +# } +# exListListV3 <- exchangesStack(x = myDataList, refStudy = myData1, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) +# dataExListV3 <- .get_data_from_htmlwidget(exListListV3, widgetsNumber = idRowNotNull) +# expect_equal(dataExListV3$nega_offshore[indexHour], 0) +# expect_equal(dataExListV3$ROW[indexHour], 500) +# dataExListV3g2 <- .get_data_from_htmlwidget(exListListV3, widgetsNumber = idWidget) +# expect_equal(dataExListV3g2$a_offshore[indexHour], 2500) +# expect_equal(dataExListV3g2$negROW[indexHour], 1000) +# }) +# +# test_that("exchangesStack, interactive, x and refStudy are antaresDataTable", { +# skip_if_not(.runExchangesStackTest) +# myData1 <- readAntares(links = "all", showProgress = FALSE) +# myData2 <- readAntares(links = "all", showProgress = FALSE) +# myArea <- "a" +# DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") +# #no interactive +# exS1 <- exchangesStack(x = myData1, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) +# dataExS1 <- .get_data_from_htmlwidget(exS1) +# timeEditValue <- "2018-04-25T00:00:00.000Z" +# indexHour <- grep(timeEditValue, dataExS1$hour) +# expect_gt(indexHour, 2) +# expect_equal(dataExS1$nega_offshore[indexHour], 9) +# # interactive +# exS1 <- exchangesStack(x = myData1, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) +# exS1 <- exS1$init() +# expect_true(is(exS1, "MWController")) +# expect_equal(exS1$ncharts, 1) +# expect_equal(exS1$ncol, 1) +# expect_equal(exS1$nrow, 1) +# dataExS1 <- .get_data_from_htmlwidget(exS1) +# expect_equal(dataExS1$nega_offshore[indexHour], 9) +# +# #identical myData, diff == 0 always +# exS21V0 <- exchangesStack(x = myData1, refStudy = myData2, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) +# resExS1V0 <- exS21V0$init() +# expect_true(is(exS21V0, "MWController")) +# expect_equal(exS21V0$ncharts, 1) +# expect_equal(exS21V0$ncol, 1) +# expect_equal(exS21V0$nrow, 1) +# #get the data +# dataExS21V0 <- .get_data_from_htmlwidget(exS21V0) +# expect_equal(dataExS21V0$nega_offshore[indexHour], 0) +# # edit myData2 to have a diff != 0 +# #pb timeZone local (PC, Travis, etc) +# for (i in 0:5){ +# timeEditShift <- lubridate::hours(i) +# timeEditMinus <- as.Date(timeEditValue) - timeEditShift +# timeEditPlus <- as.Date(timeEditValue) + timeEditShift +# myData2[ (time == timeEditMinus | time == timeEditPlus) & link == "a - a_offshore", `FLOW LIN.` := as.integer(`FLOW LIN.` + 2500)] +# } +# exS21V1 <- exchangesStack(x = myData1, refStudy = myData2, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) +# resExS1V0 <- exS21V1$init() +# expect_true(is(exS21V1, "MWController")) +# expect_equal(exS21V1$ncharts, 1) +# expect_equal(exS21V1$ncol, 1) +# expect_equal(exS21V1$nrow, 1) +# dataExS21V1 <- .get_data_from_htmlwidget(exS21V1) +# expect_equal(dataExS21V1$nega_offshore[indexHour], 2500) +# }) +# +# test_that("exchangesStack, interactive, x and refStudy are antaresDataList", { +# skip_if_not(.runExchangesStackTest) +# myData1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# myData2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# myArea <- "a" +# DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") +# #no interactive +# exS1 <- exchangesStack(x = myData1, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) +# dataExS1 <- .get_data_from_htmlwidget(exS1) +# timeEditValue <- "2018-04-25T00:00:00.000Z" +# indexHour <- grep(timeEditValue, dataExS1$hour) +# expect_gt(indexHour, 2) +# expect_equal(dataExS1$nega_offshore[indexHour], 9) +# # interactive no interactive +# exS1I <- exchangesStack(x = myData1, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) +# resExS1 <- exS1I$init() +# expect_true(is(exS1I, "MWController")) +# expect_equal(exS1I$ncharts, 1) +# expect_equal(exS1I$ncol, 1) +# expect_equal(exS1I$nrow, 1) +# dataExS1I <- .get_data_from_htmlwidget(exS1I) +# expect_equal(dataExS1I$nega_offshore[indexHour], 9) +# +# # interactive with refStudy but myData1 =myData2 +# exS21V0 <- exchangesStack(x = myData1, refStudy = myData2, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) +# exS21V0 <- exS21V0$init() +# expect_true(is(exS21V0, "MWController")) +# expect_equal(exS21V0$ncharts, 1) +# expect_equal(exS21V0$ncol, 1) +# expect_equal(exS21V0$nrow, 1) +# dataExS21V0 <- .get_data_from_htmlwidget(exS21V0) +# expect_equal(dataExS21V0$nega_offshore[indexHour], 0) +# # edit myData2 to have a diff != 0 +# #pb timeZone local (PC, Travis, etc) +# for (i in 0:5){ +# timeEditShift <- lubridate::hours(i) +# timeEditMinus <- as.Date(timeEditValue) - timeEditShift +# timeEditPlus <- as.Date(timeEditValue) + timeEditShift +# myData2$links[ (time == timeEditMinus | time == timeEditPlus) & link == "a - a_offshore", `FLOW LIN.` := as.integer(`FLOW LIN.` + 2500)] +# } +# exS21V1 <- exchangesStack(x = myData1, refStudy = myData2, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) +# exS21V1 <- exS21V1$init() +# expect_true(is(exS21V1, "MWController")) +# expect_equal(exS21V1$ncharts, 1) +# expect_equal(exS21V1$ncol, 1) +# expect_equal(exS21V1$nrow, 1) +# dataExS21V1 <- .get_data_from_htmlwidget(exS21V1) +# expect_equal(dataExS21V1$nega_offshore[indexHour], 2500) +# #ROW not null in myData1 +# for (i in 0:5){ +# timeEditShift <- lubridate::hours(i) +# timeEditMinus <- as.Date(timeEditValue) - timeEditShift +# timeEditPlus <- as.Date(timeEditValue) + timeEditShift +# myData1$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, `ROW BAL.` := as.integer(`ROW BAL.` - 1500)] +# } +# #test if there is row +# exS1V2 <- exchangesStack(x = myData1, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) +# exS1V2 <- exS1V2$init() +# expect_true(is(exS1V2, "MWController")) +# expect_equal(exS1V2$ncharts, 1) +# expect_equal(exS1V2$ncol, 1) +# expect_equal(exS1V2$nrow, 1) +# dataExS1V2 <- .get_data_from_htmlwidget(exS1V2) +# expect_equal(dataExS1V2$ROW[indexHour], 1500) +# exS21V2 <- exchangesStack(x = myData1, refStudy = myData2, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) +# exS21V2 <- exS21V2$init() +# expect_true(is(exS21V2, "MWController")) +# expect_equal(exS21V2$ncharts, 1) +# expect_equal(exS21V2$ncol, 1) +# expect_equal(exS21V2$nrow, 1) +# dataExS21V2 <- .get_data_from_htmlwidget(exS21V2) +# expect_equal(dataExS21V2$nega_offshore[indexHour], 2500) +# expect_equal(dataExS21V2$ROW[indexHour], 1500) +# #ROW not null in myData2 +# for (i in 0:5){ +# timeEditShift <- lubridate::hours(i) +# timeEditMinus <- as.Date(timeEditValue) - timeEditShift +# timeEditPlus <- as.Date(timeEditValue) + timeEditShift +# myData2$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, `ROW BAL.` := as.integer(`ROW BAL.` - 1000)] +# } +# exS21V3 <- exchangesStack(x = myData1, refStudy = myData2, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) +# exS21V3 <- exS21V3$init() +# expect_true(is(exS21V3, "MWController")) +# expect_equal(exS21V3$ncharts, 1) +# expect_equal(exS21V3$ncol, 1) +# expect_equal(exS21V3$nrow, 1) +# dataExS21V3 <- .get_data_from_htmlwidget(exS21V3) +# expect_equal(dataExS21V3$nega_offshore[indexHour], 2500) +# expect_equal(dataExS21V3$ROW[indexHour], 500) +# }) +# +# test_that("exchangesStack, interactive, x is a list of antaresDataTable and refStudy an antaresDataTable", { +# skip_if_not(.runExchangesStackTest) +# myData1 <- readAntares(links = "all", showProgress = FALSE) +# myData2 <- readAntares(links = "all", showProgress = FALSE) +# myData3 <- readAntares(links = "all", showProgress = FALSE) +# myData4 <- readAntares(links = "all", showProgress = FALSE) +# myDataList <- list(myData2, myData3, myData4) +# myArea <- "a" +# DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") +# # no interactive +# exS2 <- exchangesStack(x = myDataList, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) +# # compare with myData3 +# idWidget <- 2 +# dataExS2 <- .get_data_from_htmlwidget(exS2, widgetsNumber = idWidget) +# timeEditValue <- "2018-04-25T00:00:00.000Z" +# indexHour <- grep(timeEditValue, dataExS2$hour) +# expect_gt(indexHour, 2) +# expect_equal(dataExS2$nega_offshore[indexHour], 9) +# # interactive +# exSList1 <- exchangesStack(x = myDataList, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) +# exSList1 <- exSList1$init() +# expect_true(is(exSList1, "MWController")) +# expect_equal(exSList1$ncharts, 3) +# expect_equal(exSList1$ncol, 2) +# expect_equal(exSList1$nrow, 2) +# dataExS1I <- .get_data_from_htmlwidget(exSList1, widgetsNumber = idWidget) +# expect_equal(dataExS1I$nega_offshore[indexHour], 9) +# #identical myData, diff == 0 always +# exS21V0 <- exchangesStack(x = myDataList, refStudy = myData1, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) +# exS21V0 <- exS21V0$init() +# expect_true(is(exS21V0, "MWController")) +# expect_equal(exS21V0$ncharts, 3) +# expect_equal(exS21V0$ncol, 2) +# expect_equal(exS21V0$nrow, 2) +# dataExS21V0 <- .get_data_from_htmlwidget(exS21V0, widgetsNumber = idWidget) +# expect_equal(dataExS21V0$nega_offshore[indexHour], 0) +# # edit myData3 to have a diff != 0 +# #pb timeZone local (PC, Travis, etc) +# for (i in 0:5){ +# timeEditShift <- lubridate::hours(i) +# timeEditMinus <- as.Date(timeEditValue) - timeEditShift +# timeEditPlus <- as.Date(timeEditValue) + timeEditShift +# myData3[ (time == timeEditMinus | time == timeEditPlus) & link == "a - a_offshore", `FLOW LIN.` := as.integer(`FLOW LIN.` + 2500)] +# } +# exS21V1 <- exchangesStack(x = myDataList, refStudy = myData1, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) +# exS21V1 <- exS21V1$init() +# expect_true(is(exS21V1, "MWController")) +# expect_equal(exS21V1$ncharts, 3) +# expect_equal(exS21V1$ncol, 2) +# expect_equal(exS21V1$nrow, 2) +# dataExS21V1 <- .get_data_from_htmlwidget(exS21V1, widgetsNumber = idWidget) +# expect_equal(dataExS21V1$a_offshore[indexHour], 2500) +# }) +# +# test_that("exchangesStack, interactive, x is a list of antaresDataList and refStudy an antaresDataList", { +# skip_if_not(.runExchangesStackTest) +# myData1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# myData2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# myData3 <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# myData4 <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# +# myDataList <- list(myData2, myData3, myData4) +# myArea <- "a" +# DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") +# # no interactive +# exS2 <- exchangesStack(x = myDataList, interactive = FALSE, area = myArea, dateRange = DR, stepPlot = TRUE) +# # compare with myData3 +# idWidget <- 2 +# dataExS2 <- .get_data_from_htmlwidget(exS2, widgetsNumber = idWidget) +# timeEditValue <- "2018-04-25T00:00:00.000Z" +# indexHour <- grep(timeEditValue, dataExS2$hour) +# expect_gt(indexHour, 2) +# expect_equal(dataExS2$nega_offshore[indexHour], 9) +# # interactive +# exSList1 <- exchangesStack(x = myDataList, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) +# exSList1 <- exSList1$init() +# expect_true(is(exSList1, "MWController")) +# expect_equal(exSList1$ncharts, 3) +# expect_equal(exSList1$ncol, 2) +# expect_equal(exSList1$nrow, 2) +# dataExS1I <- .get_data_from_htmlwidget(exSList1, widgetsNumber = idWidget) +# expect_equal(dataExS1I$nega_offshore[indexHour], 9) +# +# #identical myData, diff == 0 always +# exSList1Ref <- exchangesStack(x = myDataList, refStudy = myData1, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) +# exSList1Ref <- exSList1Ref$init() +# expect_true(is(exSList1Ref, "MWController")) +# expect_equal(exSList1Ref$ncharts, 3) +# expect_equal(exSList1Ref$ncol, 2) +# expect_equal(exSList1Ref$nrow, 2) +# dataExS21V0Ref <- .get_data_from_htmlwidget(exSList1Ref, widgetsNumber = idWidget) +# expect_equal(dataExS21V0Ref$nega_offshore[indexHour], 0) +# # edit myData3 to have a diff != 0 +# #pb timeZone local (PC, Travis, etc) +# for (i in 0:5){ +# timeEditShift <- lubridate::hours(i) +# timeEditMinus <- as.Date(timeEditValue) - timeEditShift +# timeEditPlus <- as.Date(timeEditValue) + timeEditShift +# myData3$links[ (time == timeEditMinus | time == timeEditPlus) & link == "a - a_offshore", `FLOW LIN.` := as.integer(`FLOW LIN.` + 2500)] +# } +# exS21V1 <- exchangesStack(x = myDataList, refStudy = myData1, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) +# exS21V1 <- exS21V1$init() +# expect_true(is(exS21V1, "MWController")) +# expect_equal(exS21V1$ncharts, 3) +# expect_equal(exS21V1$ncol, 2) +# expect_equal(exS21V1$nrow, 2) +# dataExS21V1 <- .get_data_from_htmlwidget(exS21V1, widgetsNumber = idWidget) +# expect_equal(dataExS21V1$a_offshore[indexHour], 2500) +# #ROW not null in myData4 +# for (i in 0:5){ +# timeEditShift <- lubridate::hours(i) +# timeEditMinus <- as.Date(timeEditValue) - timeEditShift +# timeEditPlus <- as.Date(timeEditValue) + timeEditShift +# myData4$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, `ROW BAL.` := as.integer(`ROW BAL.` - 1500)] +# } +# #test if there is row +# exList <- exchangesStack(x = myDataList, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) +# exList <- exList$init() +# expect_true(is(exList, "MWController")) +# expect_equal(exList$ncharts, 3) +# expect_equal(exList$ncol, 2) +# expect_equal(exList$nrow, 2) +# dataExList <- .get_data_from_htmlwidget(exList, widgetsNumber = idWidget) +# expect_equal(dataExList$a_offshore[indexHour], 2500 - 9) +# idRowNotNull <- 3 +# dataExListRow <- .get_data_from_htmlwidget(exList, widgetsNumber = idRowNotNull) +# expect_equal(dataExListRow$ROW[indexHour], 1500) +# #with a refStudy +# exListListV2 <- exchangesStack(x = myDataList, refStudy = myData1, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) +# exListListV2 <- exListListV2$init() +# expect_true(is(exListListV2, "MWController")) +# expect_equal(exListListV2$ncharts, 3) +# expect_equal(exListListV2$ncol, 2) +# expect_equal(exListListV2$nrow, 2) +# dataExListV2 <- .get_data_from_htmlwidget(exListListV2, widgetsNumber = idWidget) +# expect_equal(dataExListV2$a_offshore[indexHour], 2500) +# expect_equal(dataExListV2$ROW[indexHour], 0) +# dataExListV2Row <- .get_data_from_htmlwidget(exListListV2, widgetsNumber = idRowNotNull) +# expect_equal(dataExListV2Row$a_offshore[indexHour], 0) +# expect_equal(dataExListV2Row$ROW[indexHour], 1500) +# #ROW not null in refStudy myData1 +# for (i in 0:5){ +# timeEditShift <- lubridate::hours(i) +# timeEditMinus <- as.Date(timeEditValue) - timeEditShift +# timeEditPlus <- as.Date(timeEditValue) + timeEditShift +# myData1$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, `ROW BAL.` := as.integer(`ROW BAL.` - 1000)] +# } +# exListListV3 <- exchangesStack(x = myDataList, refStudy = myData1, .runApp = FALSE, interactive = TRUE, area = myArea, dateRange = DR, stepPlot = TRUE) +# exListListV3 <- exListListV3$init() +# expect_true(is(exListListV3, "MWController")) +# expect_equal(exListListV3$ncharts, 3) +# expect_equal(exListListV3$ncol, 2) +# expect_equal(exListListV3$nrow, 2) +# dataExListV3 <- .get_data_from_htmlwidget(exListListV3, widgetsNumber = idRowNotNull) +# expect_equal(dataExListV3$nega_offshore[indexHour], 0) +# expect_equal(dataExListV3$ROW[indexHour], 500) +# dataExListV3g2 <- .get_data_from_htmlwidget(exListListV3, widgetsNumber = idWidget) +# expect_equal(dataExListV3g2$a_offshore[indexHour], 2500) +# expect_equal(dataExListV3g2$negROW[indexHour], 1000) +# }) +# +# test_that("exchangesStack, no interactive, x and refStudy are optsH5 ", { +# if (.requireRhdf5_Antares(stopP = FALSE)){ +# skip_if_not(.runExchangesStackTest) +# suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) +# optsH5 <- setSimulationPath(pathtemp) +# myArea <- "a" +# DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") +# ES1 <- exchangesStack(x = optsH5, interactive = FALSE, area = myArea, dateRange = DR) +# dataHtmlWidgetES1 <- .get_data_from_htmlwidget(ES1) +# timeEditValue <- "2018-04-25T00:00:00.000Z" +# indexHour <- grep(timeEditValue, dataHtmlWidgetES1$hour) +# expect_gt(indexHour, 2) +# expect_equal(dataHtmlWidgetES1$nega_offshore[indexHour], 9) +# # with refStudy +# ESRef <- exchangesStack(x = optsH5, refStudy = optsH5, interactive = FALSE, area = myArea, dateRange = DR) +# dataHtmlWidgetES1 <- .get_data_from_htmlwidget(ESRef) +# expect_equal(dataHtmlWidgetES1$nega_offshore[indexHour], 0) +# # with a new Study H5 test if compare prodStack works +# ## create a new folder h5 +# pathInitial <- file.path(dirname(pathtemp), basename(pathtemp)) +# pathNewH5 <- file.path(pathInitial, "testH5") +# if (!dir.exists(pathNewH5)){ +# dir.create(pathNewH5) +# } +# #write the study +# #windows pb ? pathNewH5 <- gsub("/", "\\", pathNewH5, fixed = TRUE) +# optsData <- antaresRead::setSimulationPath(path = studyPath) +# suppressWarnings(writeAntaresH5(path = pathNewH5, opts = optsData, +# overwrite = TRUE, supressMessages = TRUE)) +# +# +# pathNewH5File <- file.path(pathNewH5, list.files(pathNewH5)) +# myLink <- getLinks()[1] +# .h5Antares_edit_variable( +# pathH5 = pathNewH5File, +# link = myLink, +# timeId = 1:40, +# antVar = "FLOW LIN.", +# newValue = 15000 +# ) +# +# optsH5New <- setSimulationPath(path = pathNewH5File) +# ES1New <- exchangesStack(x = optsH5New, interactive = FALSE, area = myArea, dateRange = DR) +# dataHtmlWidgetES1 <- .get_data_from_htmlwidget(ES1New) +# expect_equal(dataHtmlWidgetES1$nega_offshore[indexHour], 9) +# expect_equal(dataHtmlWidgetES1$a_offshore[2], 15000) +# ES1NewRef <- exchangesStack(x = optsH5New, refStudy = optsH5, interactive = FALSE, area = myArea, dateRange = DR) +# dataHtmlWidgetES1Ref <- .get_data_from_htmlwidget(ES1NewRef) +# expect_equal(dataHtmlWidgetES1Ref$nega_offshore[indexHour], 0) +# expect_gt(dataHtmlWidgetES1Ref$a_offshore[2], 15000) +# } +# }) +# +# test_that("exchangesStack, no interactive, x is a list of optH5 and refStudy are optsH5 ", { +# if (.requireRhdf5_Antares(stopP = FALSE)){ +# skip_if_not(.runExchangesStackTest) +# suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) +# optsH5 <- setSimulationPath(pathtemp) +# +# # with new Studies H5 test if compare prodStack works +# ## create new folders h5 +# pathInitial <- file.path(dirname(pathtemp), basename(pathtemp)) +# +# listFolderToCreate <- c("testH5v2", "testH5v3", "testH5v4") +# for (folder in listFolderToCreate){ +# pathNewH5 <- file.path(pathInitial, folder) +# if (!dir.exists(pathNewH5)){ +# dir.create(pathNewH5) +# } +# +# #write the study +# #windows pb ? pathNewH5 <- gsub("/", "\\", pathNewH5, fixed = TRUE) +# optsData <- antaresRead::setSimulationPath(path = studyPath) +# suppressWarnings( +# writeAntaresH5( +# path = pathNewH5, +# opts = optsData, +# overwrite = TRUE, +# supressMessages = TRUE) +# ) +# } +# idWidgetToEdit <- 2 +# pathH5FolderToEdit <- file.path(pathInitial, listFolderToCreate[[idWidgetToEdit]]) +# pathH5FileToEdit <- file.path(pathH5FolderToEdit, list.files(pathH5FolderToEdit)) +# newValueFlow <- 15000 +# myLink <- getLinks()[1] +# .h5Antares_edit_variable( +# pathH5 = pathH5FileToEdit, +# link = myLink, +# timeId = 1:40, +# antVar = "FLOW LIN.", +# newValue = newValueFlow +# ) +# +# optsList <- list() +# antaresDataListH5 <- list() +# for (i in 1:length(listFolderToCreate)){ +# pathOptsI <- file.path(pathInitial, listFolderToCreate[[i]]) +# optsList[[i]] <- setSimulationPath(path = pathOptsI) +# antaresDataListH5[[i]] <- readAntares(links = myLink) +# } +# #test the data from h5 +# #get the data from the h5 file +# antaresDataRef <- readAntares(opts = optsH5, links = myLink) +# expect_equal(max(antaresDataListH5[[idWidgetToEdit]]$`FLOW LIN.`), newValueFlow) +# expect_equal(max(antaresDataListH5[[1]]$`FLOW LIN.`), max(antaresDataRef$`FLOW LIN.`)) +# expect_equal(max(antaresDataListH5[[3]]$`FLOW LIN.`), max(antaresDataRef$`FLOW LIN.`)) +# # get the data from htmlwidget +# myArea <- "a" +# DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") +# ESList <- exchangesStack(x = optsList, interactive = FALSE, area = myArea, dateRange = DR) +# dataHtmlWidgetES2 <- .get_data_from_htmlwidget(ESList, widgetsNumber = idWidgetToEdit) +# expect_equal(dataHtmlWidgetES2$a_offshore[3], newValueFlow) +# dataHtmlWidgetES1 <- .get_data_from_htmlwidget(ESList, widgetsNumber = 1) +# expect_equal(dataHtmlWidgetES1$a_offshore[3], 0) +# expect_equal(dataHtmlWidgetES1$nega_offshore[3], 6) +# # with refStudy +# ESListRef <- exchangesStack(x = optsList, refStudy = optsH5, interactive = FALSE, area = myArea, dateRange = DR) +# dataHtmlWidgetES2Ref <- .get_data_from_htmlwidget(ESListRef, widgetsNumber = idWidgetToEdit) +# expect_equal(dataHtmlWidgetES2Ref$a_offshore[3] - dataHtmlWidgetES1$nega_offshore[3], newValueFlow) +# dataHtmlWidgetES1Ref <- .get_data_from_htmlwidget(ESListRef, widgetsNumber = 1) +# expect_equal(dataHtmlWidgetES1Ref$a_offshore[3], 0) +# expect_equal(dataHtmlWidgetES1Ref$nega_offshore[3], 0) +# } +# }) +# +# test_that("exchangesStack, interactive, x and refStudy are optsH5 ", { +# if (.requireRhdf5_Antares(stopP = FALSE)){ +# skip_if_not(.runExchangesStackTest) +# suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) +# optsH5 <- setSimulationPath(pathtemp) +# myArea <- "a" +# DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") +# # no interactive +# ES1 <- exchangesStack(x = optsH5, +# interactive = FALSE, +# area = myArea, +# dateRange = DR, +# mcYearh5 = 1) +# dataHtmlWidgetES1 <- .get_data_from_htmlwidget(ES1) +# timeEditValue <- "2018-04-24T23:00:00.000Z" +# indexHour <- grep(timeEditValue, dataHtmlWidgetES1$hour) +# expect_gt(indexHour, 2) +# expect_equal(dataHtmlWidgetES1$nega_offshore[indexHour], 10) +# # with interactive +# #FOR DEBUG +# #ES1I <- exchangesStack(x = optsH5, +# # interactive = TRUE) +# +# ES1I <- exchangesStack(x = optsH5, +# .runApp = FALSE, +# interactive = TRUE, +# dateRange = DR) +# ES1I <- ES1I$init() +# expect_true(is(ES1I, "MWController")) +# expect_equal(ES1I$ncharts, 1) +# expect_equal(ES1I$ncol, 1) +# expect_equal(ES1I$nrow, 1) +# dataHtmlWidgetES1I <- .get_data_from_htmlwidget(ES1I) +# expect_equal(dataHtmlWidgetES1I$nega_offshore[indexHour], 10) +# # with refStudy no interactive +# ESRef <- exchangesStack(x = optsH5, +# refStudy = optsH5, +# interactive = FALSE, +# area = myArea, +# dateRange = DR, +# mcYearh5 = 1) +# dataHtmlWidgetES1 <- .get_data_from_htmlwidget(ESRef) +# expect_equal(dataHtmlWidgetES1$nega_offshore[indexHour], 0) +# # refStudy with interactive +# ESRefI <- exchangesStack(x = optsH5, +# refStudy = optsH5, +# interactive = TRUE, +# .runApp = FALSE, +# area = myArea, +# dateRange = DR) +# ESRefI <- ESRefI$init() +# expect_true(is(ESRefI, "MWController")) +# expect_equal(ESRefI$ncharts, 1) +# expect_equal(ESRefI$ncol, 1) +# expect_equal(ESRefI$nrow, 1) +# dataHtmlWidgetESRefI <- .get_data_from_htmlwidget(ESRefI) +# expect_equal(dataHtmlWidgetESRefI$nega_offshore[indexHour], 0) +# # with a new Study H5 test if compare prodStack works +# ## create a new folder h5 +# pathInitial <- file.path(dirname(pathtemp), basename(pathtemp)) +# pathNewH5 <- file.path(pathInitial, "testH5") +# if (!dir.exists(pathNewH5)){ +# dir.create(pathNewH5) +# } +# #write the study +# #windows pb ? pathNewH5 <- gsub("/", "\\", pathNewH5, fixed = TRUE) +# optsData <- antaresRead::setSimulationPath(path = studyPath) +# suppressWarnings(writeAntaresH5(path = pathNewH5, opts = optsData, +# overwrite = TRUE, supressMessages = TRUE)) +# +# +# pathNewH5File <- file.path(pathNewH5, list.files(pathNewH5)) +# myLink <- getLinks()[1] +# .h5Antares_edit_variable( +# pathH5 = pathNewH5File, +# link = myLink, +# timeId = 1:40, +# antVar = "FLOW LIN.", +# newValue = 15000, +# mcYear = 1 +# ) +# +# optsH5New <- setSimulationPath(path = pathNewH5File) +# #no interactive +# ES1New <- exchangesStack(x = optsH5New, +# interactive = FALSE, +# area = myArea, +# dateRange = DR, +# mcYearh5 = 1) +# dataHtmlWidgetES1New <- .get_data_from_htmlwidget(ES1New) +# expect_equal(dataHtmlWidgetES1New$nega_offshore[indexHour], 10) +# expect_equal(dataHtmlWidgetES1New$a_offshore[2], 15000) +# # with interactive +# ES1NewI <- exchangesStack(x = optsH5New, +# interactive = TRUE, +# .runApp = FALSE, +# area = myArea, +# dateRange = DR) +# ES1NewI <- ES1NewI$init() +# expect_true(is(ES1NewI, "MWController")) +# expect_equal(ES1NewI$ncharts, 1) +# expect_equal(ES1NewI$ncol, 1) +# expect_equal(ES1NewI$nrow, 1) +# dataHtmlWidgetES1New <- .get_data_from_htmlwidget(ES1NewI) +# expect_equal(dataHtmlWidgetES1New$nega_offshore[indexHour], 10) +# expect_equal(dataHtmlWidgetES1New$a_offshore[2], 15000) +# # no interactive, refStudy, +# ES1NewRef <- exchangesStack(x = optsH5New, +# refStudy = optsH5, +# interactive = FALSE, +# area = myArea, +# dateRange = DR, +# mcYearh5 = 1) +# dataHtmlWidgetES1Ref <- .get_data_from_htmlwidget(ES1NewRef) +# expect_equal(dataHtmlWidgetES1Ref$nega_offshore[indexHour], 0) +# expect_gt(dataHtmlWidgetES1Ref$a_offshore[2], 15000) +# # interactive, refStudy, +# ES1NewRefI <- exchangesStack(x = optsH5New, +# refStudy = optsH5, +# interactive = TRUE, +# .runApp = FALSE, +# area = myArea, +# dateRange = DR, +# mcYearh5 = 1) +# ES1NewRefI <- ES1NewRefI$init() +# expect_true(is(ES1NewRefI, "MWController")) +# expect_equal(ES1NewRefI$ncharts, 1) +# expect_equal(ES1NewRefI$ncol, 1) +# expect_equal(ES1NewRefI$nrow, 1) +# dataHtmlWidgetES1RefI <- .get_data_from_htmlwidget(ES1NewRefI) +# expect_equal(dataHtmlWidgetES1RefI$nega_offshore[indexHour], 0) +# expect_gt(dataHtmlWidgetES1RefI$a_offshore[2], 15000) +# } +# }) +# +# test_that("exchangesStack, interactive, x is a list of optsH5 and refStudy optsH5 , ", { +# if (.requireRhdf5_Antares(stopP = FALSE)){ +# skip_if_not(.runExchangesStackTest) +# suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) +# optsH5 <- setSimulationPath(pathtemp) +# +# # with new Studies H5 test if compare prodStack works +# ## create new folders h5 +# pathInitial <- file.path(dirname(pathtemp), basename(pathtemp)) +# +# listFolderToCreate <- c("testH5v2", "testH5v3", "testH5v4") +# for (folder in listFolderToCreate){ +# pathNewH5 <- file.path(pathInitial, folder) +# if (!dir.exists(pathNewH5)){ +# dir.create(pathNewH5) +# } +# +# #write the study +# #windows pb ? pathNewH5 <- gsub("/", "\\", pathNewH5, fixed = TRUE) +# optsData <- antaresRead::setSimulationPath(path = studyPath) +# suppressWarnings( +# writeAntaresH5( +# path = pathNewH5, +# opts = optsData, +# overwrite = TRUE, +# supressMessages = TRUE) +# ) +# } +# pathH5FolderToEdit <- file.path(pathInitial, listFolderToCreate[[2]]) +# pathH5FileToEdit <- file.path(pathH5FolderToEdit, list.files(pathH5FolderToEdit)) +# myLink <- getLinks()[1] +# newValueFlow <- 50000 +# mcYearToTestList <- c(2, NULL) +# for (mcYearToTest in mcYearToTestList){ +# .h5Antares_edit_variable( +# pathH5 = pathH5FileToEdit, +# link = myLink, +# timeId = 1:40, +# antVar = "FLOW LIN.", +# newValue = newValueFlow, +# mcYear = mcYearToTest +# ) +# +# optsList <- list() +# antaresDataListH5 <- list() +# for (i in 1:length(listFolderToCreate)){ +# pathOptsI <- file.path(pathInitial, listFolderToCreate[[i]]) +# optsList[[i]] <- setSimulationPath(path = pathOptsI) +# antaresDataListH5[[i]] <- readAntares(links = myLink, mcYear = mcYearToTest) +# } +# +# DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") +# #try without refStudy and interactive == FALSE +# myArea <- "a" +# ESListNoInt <- exchangesStack(x = optsList, +# dateRange = DR, +# area = myArea, +# interactive = FALSE, +# mcYearh5 = mcYearToTest) +# dataHtmlWidgetESNoInt <- .get_data_from_htmlwidget(ESListNoInt, widgetsNumber = 2) +# expect_equal(max(dataHtmlWidgetESNoInt$a_offshore, na.rm = TRUE), 50000) +# +# # try with refStudy +# ESListNoInt <- exchangesStack(x = optsList, +# refStudy = optsH5, +# interactive = FALSE, +# areas = myArea, +# dateRange = DR, +# mcYearh5 = mcYearToTest) +# ## get the data from htmlwidget +# dataHtmlWidgetES1 <- .get_data_from_htmlwidget(ESListNoInt, widgetsNumber = 1) +# dataHtmlWidgetES2 <- .get_data_from_htmlwidget(ESListNoInt, widgetsNumber = 2) +# +# ## get the data from the h5 file +# antaresDataRef <- readAntares(opts = optsH5, links = myLink, mcYears = mcYearToTest) +# expect_equal(max(antaresDataListH5[[2]]$`FLOW LIN.`), newValueFlow) +# expect_equal(max(antaresDataListH5[[1]]$`FLOW LIN.`), max(antaresDataRef$`FLOW LIN.`)) +# expect_equal(max(antaresDataListH5[[3]]$`FLOW LIN.`), max(antaresDataRef$`FLOW LIN.`)) +# expect_equal(antaresDataListH5[[2]]$`OV. COST`, antaresDataRef$`OV. COST`) +# +# ## compare data +# resCompareData1_ref <- antaresProcessing::compare(x = antaresDataRef, y = antaresDataListH5[[1]]) +# resCompareData2_ref <- antaresProcessing::compare(x = antaresDataRef, y = antaresDataListH5[[2]]) +# expect_equal(resCompareData1_ref[timeId == timeId[40], `FLOW LIN.`], -dataHtmlWidgetES1$nega_offshore[[2]]) +# expect_gt(resCompareData2_ref[timeId == timeId[40], `FLOW LIN.`], newValueFlow) +# +# # interactive == TRUE +# ## DEBUG +# # PSWORef <- prodStack(x = optsList, +# # dateRange = DR, +# # h5requestFiltering = list(areas = myArea, +# # mcYears = mcYearToTest), +# # .runApp = FALSE, +# # interactive = TRUE) +# # PSWORef <- PSWORef$init() +# # ESWORef <- exchangesStack(x = antaresDataListH5[[2]]) +# # ESWORef <- exchangesStack(x = optsList) +# # ESWORef <- exchangesStack(x = antaresDataListH5[[2]], +# # dateRange = DR) +# # ESWORef <- exchangesStack(x = optsList, +# # dateRange = DR) +# +# ESWORef <- exchangesStack( +# x = optsList, +# dateRange = DR, +# .runApp = FALSE, +# interactive = TRUE, +# h5requestFiltering = list( +# areas = getAreas(select = "a"), +# links = getLinks(areas = myArea), +# mcYears = mcYearToTest)) +# ESWORef <- ESWORef$init() +# expect_true(is(ESWORef, "MWController")) +# expect_equal(ESWORef$ncharts, 3) +# expect_equal(ESWORef$ncol, 2) +# expect_equal(ESWORef$nrow, 2) +# ## get the data from htmlwidget +# dataHtmlWidgetESWORef <- .get_data_from_htmlwidget(ESWORef, widgetsNumber = 2) +# expect_equal(dataHtmlWidgetESWORef$a_offshore[[2]], 50000) +# expect_equal(dataHtmlWidgetESWORef$nega_offshore[[2]], 0) +# dataHtmlWidgetESWORef1 <- .get_data_from_htmlwidget(ESWORef, widgetsNumber = 1) +# expect_equal(dataHtmlWidgetESWORef1$a_offshore[[2]], 0) +# expect_gt(dataHtmlWidgetESWORef1$nega_offshore[[2]], 0) +# +# # fourth, MWController with refStudy and interactive == TRUE +# ESWORefListI <- exchangesStack( +# x = optsList, +# refStudy = optsH5, +# dateRange = DR, +# .runApp = FALSE, +# interactive = TRUE, +# h5requestFiltering = list( +# areas = getAreas(select = "a"), +# links = getLinks(areas = myArea), +# mcYears = mcYearToTest)) +# ESWORefListI <- ESWORefListI$init() +# expect_true(is(ESWORefListI, "MWController")) +# expect_equal(ESWORefListI$ncharts, 3) +# expect_equal(ESWORefListI$ncol, 2) +# expect_equal(ESWORefListI$nrow, 2) +# #check data from htmlwidgets +# dataHtmlWidgetES31 <- .get_data_from_htmlwidget(ESWORefListI, widgetsNumber = 2) +# expect_gt(dataHtmlWidgetES31$a_offshore[[2]], 50000) +# expect_equal(dataHtmlWidgetES31$nega_offshore[[2]], 0) +# dataHtmlWidgetES21 <- .get_data_from_htmlwidget(ESWORefListI, widgetsNumber = 1) +# expect_equal(dataHtmlWidgetES21$a_offshore[[2]], 0) +# expect_equal(dataHtmlWidgetES21$nega_offshore[[2]], 0) +# +# resOptsH5Old <- readAntares(opts = optsH5, links = myLink, showProgress = FALSE, mcYears = mcYearToTest) +# resOptsH5New <- readAntares(opts = optsList[[2]], links = myLink, showProgress = FALSE, mcYears = mcYearToTest) +# #timeId for time = "2018-04-24 00:00:00 UTC" ? timeId = 2713 +# timeIdVal <- 2713 +# expect_equal(resOptsH5New[timeId == timeIdVal, `FLOW LIN.`], newValueFlow) +# expect_lt(resOptsH5Old[timeId == timeIdVal, `FLOW LIN.`], 0) +# +# resCompareData <- antaresProcessing::compare(x = resOptsH5Old, y = resOptsH5New) +# expect_gt(resCompareData[timeId == timeIdVal, `FLOW LIN.`], newValueFlow) +# expect_equal(resCompareData[timeId == timeIdVal, `FLOW LIN.`], dataHtmlWidgetES31$a_offshore[[1]]) +# #no change after timeID > 40 +# expect_equal(resCompareData[timeId == (timeIdVal + 90), `FLOW LIN.`], dataHtmlWidgetES31$a_offshore[[50]]) +# expect_equal(dataHtmlWidgetES21$a_offshore[[1]], 0) +# expect_equal(dataHtmlWidgetES21$nega_offshore[[1]], 0) +# } +# } +# +# }) diff --git a/tests/testthat/test-graphUtils.R b/tests/testthat/test-graphUtils.R index b8305e6c..47aebd4b 100644 --- a/tests/testthat/test-graphUtils.R +++ b/tests/testthat/test-graphUtils.R @@ -1,47 +1,47 @@ -context(".compOpts") - - -test_that(".compOpts", { - - expect_true(.compOpts("", "cp")$ncharts == 2) - expect_true(.compOpts("", NULL)$ncharts == 1) - expect_true(.compOpts(list(), NULL)$ncharts == 1) -}) - -if(.requireRhdf5_Antares(stopP = FALSE)){ - context(".dateRangeJoin") - test_that(".dateRangeJoin", { - dt <- list() - dt$x <- list(list(dateRange = as.Date(c("2010-01-01", "2010-01-10"))), - list(dateRange = as.Date(c("2010-01-02", "2010-01-09")))) - - - - - expect_true(.dateRangeJoin(dt, "union", "min") == as.Date("2010-01-01")) - expect_true(.dateRangeJoin(dt, "union", "max") == as.Date("2010-01-10")) - expect_true(.dateRangeJoin(dt, "intersect", "max") == as.Date("2010-01-09")) - expect_true(.dateRangeJoin(dt, "intersect", "min") == as.Date("2010-01-02")) - - dt2 <- list() - dt2$x <- list(list(ar = list(dateRange = as.Date(c("2010-01-01", "2010-01-10")))), - list(ar = list(dateRange = as.Date(c("2010-01-02", "2010-01-09"))))) - - expect_true(.dateRangeJoin(dt2, "union", "min", "ar") == as.Date("2010-01-01")) - expect_true(.dateRangeJoin(dt2, "union", "max", "ar") == as.Date("2010-01-10")) - expect_true(.dateRangeJoin(dt2, "intersect", "max", "ar") == as.Date("2010-01-09")) - expect_true(.dateRangeJoin(dt2, "intersect", "min", "ar") == as.Date("2010-01-02")) - - }) - - context(".loadH5Data") - test_that(".loadH5Data", { - opts <- setSimulationPath(studyPath) - sharerequest <- list() - sharerequest$mcYearh_l <- "all" - sharerequest$tables_l <- c("areas", "links", "clusters", "districts") - sharerequest$timeSteph5_l <- "hourly" - expect_true("antaresDataList" %in% class(.loadH5Data(sharerequest, opts))) - - }) -} +# context(".compOpts") +# +# +# test_that(".compOpts", { +# +# expect_true(.compOpts("", "cp")$ncharts == 2) +# expect_true(.compOpts("", NULL)$ncharts == 1) +# expect_true(.compOpts(list(), NULL)$ncharts == 1) +# }) +# +# if(.requireRhdf5_Antares(stopP = FALSE)){ +# context(".dateRangeJoin") +# test_that(".dateRangeJoin", { +# dt <- list() +# dt$x <- list(list(dateRange = as.Date(c("2010-01-01", "2010-01-10"))), +# list(dateRange = as.Date(c("2010-01-02", "2010-01-09")))) +# +# +# +# +# expect_true(.dateRangeJoin(dt, "union", "min") == as.Date("2010-01-01")) +# expect_true(.dateRangeJoin(dt, "union", "max") == as.Date("2010-01-10")) +# expect_true(.dateRangeJoin(dt, "intersect", "max") == as.Date("2010-01-09")) +# expect_true(.dateRangeJoin(dt, "intersect", "min") == as.Date("2010-01-02")) +# +# dt2 <- list() +# dt2$x <- list(list(ar = list(dateRange = as.Date(c("2010-01-01", "2010-01-10")))), +# list(ar = list(dateRange = as.Date(c("2010-01-02", "2010-01-09"))))) +# +# expect_true(.dateRangeJoin(dt2, "union", "min", "ar") == as.Date("2010-01-01")) +# expect_true(.dateRangeJoin(dt2, "union", "max", "ar") == as.Date("2010-01-10")) +# expect_true(.dateRangeJoin(dt2, "intersect", "max", "ar") == as.Date("2010-01-09")) +# expect_true(.dateRangeJoin(dt2, "intersect", "min", "ar") == as.Date("2010-01-02")) +# +# }) +# +# context(".loadH5Data") +# test_that(".loadH5Data", { +# opts <- setSimulationPath(studyPath) +# sharerequest <- list() +# sharerequest$mcYearh_l <- "all" +# sharerequest$tables_l <- c("areas", "links", "clusters", "districts") +# sharerequest$timeSteph5_l <- "hourly" +# expect_true("antaresDataList" %in% class(.loadH5Data(sharerequest, opts))) +# +# }) +# } diff --git a/tests/testthat/test-plotXY.R b/tests/testthat/test-plotXY.R index ccd91517..537fcab7 100644 --- a/tests/testthat/test-plotXY.R +++ b/tests/testthat/test-plotXY.R @@ -1,10 +1,10 @@ -context("prodStack no interactive") - -test_that("prodStack, no interactive", { - skip_if_not_installed("hexbin") - if(.requireRhdf5_Antares(stopP = FALSE)){ - dta <- readAntares(areas = "all", showProgress = FALSE) - g <- plotXY(dta, "NODU", "LOAD", precision = 50, sizeOnCount = FALSE) - expect_true("htmlwidget" %in% class(g)) - } -}) +# context("prodStack no interactive") +# +# test_that("prodStack, no interactive", { +# skip_if_not_installed("hexbin") +# if(.requireRhdf5_Antares(stopP = FALSE)){ +# dta <- readAntares(areas = "all", showProgress = FALSE) +# g <- plotXY(dta, "NODU", "LOAD", precision = 50, sizeOnCount = FALSE) +# expect_true("htmlwidget" %in% class(g)) +# } +# }) diff --git a/tests/testthat/test-prodStack.R b/tests/testthat/test-prodStack.R index 7f50f0f5..959bcb40 100644 --- a/tests/testthat/test-prodStack.R +++ b/tests/testthat/test-prodStack.R @@ -1,731 +1,731 @@ -context("prodStack") - -test_that("prodStack, no interactive", { - dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) - testClass <- function(obj){ - class(obj)[1] == "combineWidgets" - } - listArgs <- list(noarg = list(x = dta, interactive = FALSE, areas = "a"), - areas2 = list(x = dta, interactive = FALSE, areas = c("a", "b")) - ) - - lapply(listArgs, function(X){ - re1 <- do.call(prodStack, X) - expect_true(testClass(re1)) - }) - -}) - -test_that("prodStack, no interactive return error", { - - dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) - expect_error(prodStack(dta, interactive = FALSE, compare = "areas")) - -}) - -test_that("prodStack, interactive", { - dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) - VV <- prodStack(dta, interactive = FALSE) - expect_true("htmlwidget" %in% class(VV)) -}) - -test_that("prodStack must work with refStudy, if x and refStudy are antaresDataList, ", { - myData1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) - myData2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) - - myArea <- "a" - DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") - PS3 <- prodStack(x = myData2, refStudy = myData1, interactive = FALSE, areas = myArea, dateRange = DR) - - resCompare <- antaresProcessing::compare(myData2, myData1, method = "diff") - dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3) - - expect_true(isTRUE(max(resCompare$areas$GAS) == max(dataHtmlWidgetPS$neggas, na.rm = TRUE))) - - #pb timeZine local (PC, Travis, etc) - for (i in 0:5){ - timeEditShift <- lubridate::hours(i) - timeEditMinus <- as.Date(DR[1]) - timeEditShift - timeEditPlus <- as.Date(DR[1]) + timeEditShift - myData1$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, GAS := as.integer(GAS + 2500)] - } - #check console - #myData1$areas[ time == as.Date(DR)[1] & area == myArea, ]$GAS - #myData2$areas[ time == as.Date(DR)[1] & area == myArea, ]$GAS - - expect_true(isTRUE(all.equal(myData2$areas[ time == as.Date(DR)[1] & area == myArea, ]$GAS + 2500, myData1$areas[ time == as.Date(DR)[1] & area == myArea, ]$GAS))) - - PS3 <- prodStack(x = myData2, refStudy = myData1, interactive = FALSE, areas = myArea, dateRange = DR) - - dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3) - resCompare <- antaresProcessing::compare(myData1, myData2, method = "diff") - expect_true(all.equal(resCompare$areas[ time == as.Date(DR)[1] & area == myArea, GAS ], - (dataHtmlWidgetPS$neggas[[2]]))) - #after DR + 5 hours (no change) - expect_true(all.equal(0, dataHtmlWidgetPS$neggas[[20]])) -}) - -test_that("prodStack must work with refStudy, if x is a list of antaresDataList and refStudy an antaresDataList, ", { - myData1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) - myData2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) - myData3 <- readAntares(areas = c("a", "b", "c"), links = "all", showProgress = FALSE) - myData4 <- readAntares(areas = c("a", "b"), links = "all", showProgress = FALSE) - myArea <- "a" - myDataList <- list(myData4, myData3, myData2) - DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") - PS1_list <- prodStack(x = myDataList, refStudy = myData1, interactive = FALSE, areas = myArea, dateRange = DR) - resCompare <- antaresProcessing::compare(myDataList[[3]], myData1, method = "diff") - dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS1_list, widgetsNumber = 3) - all.equal(max(resCompare$areas$GAS), max(dataHtmlWidgetPS$neggas, na.rm = TRUE)) - #pb timeZone local (PC, Travis, etc) - for (i in 0:5){ - timeEditShift <- lubridate::hours(i) - timeEditMinus <- as.Date(DR[1]) - timeEditShift - timeEditPlus <- as.Date(DR[1]) + timeEditShift - myData1$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, GAS := as.integer(GAS + 2500)] - myData4$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, GAS := as.integer(GAS + 2500)] - myData3$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, GAS := as.integer(GAS + 2500)] - } - #check console - #myData1$areas[ time == as.Date(DR)[1] & area == myArea, ]$GAS - #myData3$areas[ time == as.Date(DR)[1] & area == myArea, ]$GAS - - expect_true(isTRUE(all.equal(myData2$areas[ time == as.Date(DR)[1] & area == myArea, ]$GAS + 2500, myData1$areas[ time == as.Date(DR)[1] & area == myArea, ]$GAS))) - - PS1_list <- prodStack(x = myDataList, refStudy = myData1, interactive = FALSE, areas = myArea, dateRange = DR) - - dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS1_list, widgetsNumber = 3) - resCompare <- antaresProcessing::compare(myData1, myData2, method = "diff") - expect_true(all.equal(resCompare$areas[ time == as.Date(DR)[1] & area == myArea, GAS ], - (dataHtmlWidgetPS$neggas[[2]]))) - #after DR + 5 hours (no edit) - expect_true(all.equal(0, dataHtmlWidgetPS$neggas[[20]])) - - #no change for myData3 - resCompare3 <- antaresProcessing::compare(myData3, myData1, method = "diff") - dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS1_list, widgetsNumber = 2) - expect_true(all.equal(resCompare3$areas[ time == as.Date(DR)[1] & area == myArea, GAS], dataHtmlWidgetPS$neggas[[2]])) - expect_true(all.equal(0, dataHtmlWidgetPS$neggas[[20]])) - -}) - -test_that("prodStack must work with refStudy, if x and refStudy are optsH5, ", { - if (.requireRhdf5_Antares(stopP = FALSE)){ - skip_if_not(.runProdStackTest) - suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) - optsH5 <- setSimulationPath(pathtemp) - - myArea <- "b" - DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") - PS3 <- prodStack(x = optsH5, - refStudy = optsH5, - interactive = FALSE, - areas = myArea, - dateRange = DR) - - #check that PS1 == PS2 or PS3 == 0 - dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3) - expect_equal(0, max(dataHtmlWidgetPS$totalProduction, na.rm = TRUE)) - expect_equal(0, max(dataHtmlWidgetPS$gas, na.rm = TRUE)) - - # with a new Study H5 test if compare prodStack works - ## create a new folder h5 - pathInitial <- file.path(dirname(pathtemp), basename(pathtemp)) - pathNewH5 <- file.path(pathInitial, "testH5") - if (!dir.exists(pathNewH5)){ - dir.create(pathNewH5) - } - #write the study - #windows pb ? pathNewH5 <- gsub("/", "\\", pathNewH5, fixed = TRUE) - optsData <- antaresRead::setSimulationPath(path = studyPath) - suppressWarnings(writeAntaresH5(path = pathNewH5, opts = optsData, - overwrite = TRUE, supressMessages = TRUE)) - - - pathNewH5File <- file.path(pathNewH5, list.files(pathNewH5)) - .h5Antares_edit_variable( - pathH5 = pathNewH5File, - area = myArea, - timeId = 1:40, - antVar = "LIGNITE", - newValue = 15000 - ) - - optsH5New <- setSimulationPath(path = pathNewH5) - PS3 <- prodStack(x = optsH5New, refStudy = optsH5, interactive = FALSE, areas = myArea, dateRange = DR) - - resOptsH5Old <- readAntares(opts = optsH5, areas = myArea, showProgress = FALSE) - resOptsH5New <- readAntares(opts = optsH5New, areas = myArea, showProgress = FALSE) - expect_equal(resOptsH5New[time == as.Date(DR)[1], LIGNITE], 15000) - - resCompareData <- antaresProcessing::compare(x = resOptsH5Old, y = resOptsH5New) - expect_equal(resCompareData[timeId == timeId[40], LIGNITE], -24000) - - dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3) - expect_equal(resCompareData[timeId == timeId[40], LIGNITE], -dataHtmlWidgetPS$neglignite[[2]]) - #no change after timeID > 40 - expect_equal(resCompareData[timeId == timeId[90], LIGNITE], -dataHtmlWidgetPS$neglignite[[50]]) - } - -}) - -test_that("prodStack must work with refStudy, if x is a list of optsH5 and refStudy an optsH5, ", { - if (.requireRhdf5_Antares(stopP = FALSE)){ - skip_if_not(.runProdStackTest) - suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) - optsH5 <- setSimulationPath(pathtemp) - - # with new Studies H5 test if compare prodStack works - ## create new folders h5 - pathInitial <- file.path(dirname(pathtemp), basename(pathtemp)) - - listFolderToCreate <- c("testH5v2", "testH5v3", "testH5v4") - for (folder in listFolderToCreate){ - pathNewH5 <- file.path(pathInitial, folder) - if (!dir.exists(pathNewH5)){ - dir.create(pathNewH5) - } - - #write the study - #windows pb ? pathNewH5 <- gsub("/", "\\", pathNewH5, fixed = TRUE) - optsData <- antaresRead::setSimulationPath(path = studyPath) - suppressWarnings( - writeAntaresH5( - path = pathNewH5, - opts = optsData, - overwrite = TRUE, - supressMessages = TRUE) - ) - } - myArea <- "b" - pathH5FolderToEdit <- file.path(pathInitial, listFolderToCreate[[2]]) - pathH5FileToEdit <- file.path(pathH5FolderToEdit, list.files(pathH5FolderToEdit)) - newValueLignite <- 100000 - .h5Antares_edit_variable( - pathH5 = pathH5FileToEdit, - area = myArea, - timeId = 1:40, - antVar = "LIGNITE", - newValue = newValueLignite - ) - - optsList <- list() - antaresDataListH5 <- list() - for (i in 1:length(listFolderToCreate)){ - pathOptsI <- file.path(pathInitial, listFolderToCreate[[i]]) - optsList[[i]] <- setSimulationPath(path = pathOptsI) - antaresDataListH5[[i]] <- readAntares(areas = myArea) - } - DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") - PS1 <- prodStack(x = optsH5, interactive = FALSE, areas = myArea, dateRange = DR) - PS2 <- prodStack(x = optsList, interactive = FALSE, areas = myArea, dateRange = DR) - PS_List <- prodStack(x = optsList, refStudy = optsH5, interactive = FALSE, areas = myArea, dateRange = DR) - #get the data from the h5 file - antaresDataRef <- readAntares(opts = optsH5, areas = myArea) - expect_equal(max(antaresDataListH5[[2]]$LIGNITE), newValueLignite) - expect_equal(max(antaresDataListH5[[1]]$LIGNITE), max(antaresDataRef$LIGNITE)) - expect_equal(max(antaresDataListH5[[3]]$LIGNITE), max(antaresDataRef$LIGNITE)) - #get the data from htmlwidget - dataHtmlWidgetPS1 <- .get_data_from_htmlwidget(PS_List, widgetsNumber = 1) - dataHtmlWidgetPS2 <- .get_data_from_htmlwidget(PS_List, widgetsNumber = 2) - #compare data - resCompareData1_ref <- antaresProcessing::compare(x = antaresDataRef, y = antaresDataListH5[[1]]) - resCompareData2_ref <- antaresProcessing::compare(x = antaresDataRef, y = antaresDataListH5[[2]]) - expect_equal(resCompareData1_ref[timeId == timeId[40], LIGNITE], -dataHtmlWidgetPS1$lignite[[2]]) - expect_equal(resCompareData2_ref[timeId == timeId[40], LIGNITE], dataHtmlWidgetPS2$lignite[[2]]) - #no change after timeID > 40 - expect_equal(resCompareData1_ref[timeId == timeId[90], LIGNITE], -dataHtmlWidgetPS1$lignite[[50]]) - expect_equal(resCompareData2_ref[timeId == timeId[90], LIGNITE], -dataHtmlWidgetPS2$lignite[[50]]) - - } -}) - -test_that("prodStack must work with refStudy, if interactive is set to TRUE and if x and refStudy are antaresData, ", { - myData1 <- readAntares(areas = "all", showProgress = FALSE) - myData2 <- readAntares(areas = "all", showProgress = FALSE) - - myArea <- "a" - DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") - - #for debug, dont compare - # PS3 <- prodStack( - # x = myData2, - # dateRange = DR, - # .runApp = FALSE, - # interactive = TRUE, - # h5requestFiltering = list(areas = myArea)) - # res <- PS3$init() - # PS3 - # #for debug, refStudy but not interactive - # PS3 <- prodStack( - # x = myData2, - # refStudy = myData1, - # dateRange = DR, - # .runApp = FALSE, - # interactive = FALSE, - # areas = myArea) - # PS3 - - #MWController - PS3 <- prodStack( - x = myData2, - refStudy = myData1, - dateRange = DR, - .runApp = FALSE, - interactive = TRUE, - h5requestFiltering = list(areas = myArea)) - res <- PS3$init() - expect_true(is(PS3, "MWController")) - expect_equal(PS3$ncharts, 1) - expect_equal(PS3$ncol, 1) - expect_equal(PS3$nrow, 1) - - #get the data from antaresData - resCompare <- antaresProcessing::compare(myData2, myData1, method = "diff") - - dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3) - expect_true(isTRUE(max(resCompare$GAS) == max(dataHtmlWidgetPS$neggas, na.rm = TRUE))) - - #pb timeZine local (PC, Travis, etc) - for (i in 0:5){ - timeEditShift <- lubridate::hours(i) - timeEditMinus <- as.Date(DR[1]) - timeEditShift - timeEditPlus <- as.Date(DR[1]) + timeEditShift - myData1[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, GAS := as.integer(GAS + 2500)] - } - #check console - #myData1[ time == as.Date(DR)[1] & area == myArea, ]$GAS - #myData2[ time == as.Date(DR)[1] & area == myArea, ]$GAS - - expect_true(isTRUE(all.equal(myData2[ time == as.Date(DR)[1] & area == myArea, ]$GAS + 2500, myData1[ time == as.Date(DR)[1] & area == myArea, ]$GAS))) - - PS3 <- prodStack(x = myData2, refStudy = myData1, areas = myArea, dateRange = DR, .runApp = FALSE, interactive = TRUE) - expect_true(is(PS3, "MWController")) - expect_equal(PS3$ncharts, 1) - expect_equal(PS3$ncol, 1) - expect_equal(PS3$nrow, 1) - - resCompare <- antaresProcessing::compare(myData1, myData2, method = "diff") - - PS3$init() - dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3) - expect_true(all.equal(resCompare[ time == as.Date(DR)[1] & area == myArea, GAS ], - (dataHtmlWidgetPS$neggas[[2]]))) - #after DR + 5 hours (no change) - expect_true(all.equal(0, dataHtmlWidgetPS$neggas[[20]])) - -}) - -test_that("prodStack must work with refStudy, if interactive is set to TRUE and if x a list of antaresData and refStudy an antaresData, ", { - myData1 <- readAntares(areas = "all", showProgress = FALSE) - myData2 <- readAntares(areas = "all", showProgress = FALSE) - myData3 <- readAntares(areas = "all", showProgress = FALSE) - myData4 <- readAntares(areas = "all", showProgress = FALSE) - - myDataList <- list(myData2, myData3, myData4) - - myArea <- "a" - DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") - #MWController - PS3 <- prodStack(x = myDataList, refStudy = myData1, areas = myArea, dateRange = DR, .runApp = FALSE, interactive = TRUE) - #PS3 <- prodStack(x = myData2, refStudy = myData1, areas = myArea, dateRange = DR) - res <- PS3$init() - expect_true(is(PS3, "MWController")) - expect_equal(PS3$ncharts, 3) - expect_equal(PS3$ncol, 2) - expect_equal(PS3$nrow, 2) - - #get the data from antaresData - resCompare3_1 <- antaresProcessing::compare(myDataList[[2]], myData1, method = "diff") - - dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3, widgetsNumber = 2) - expect_true(isTRUE(max(resCompare3_1$GAS) == max(dataHtmlWidgetPS$neggas, na.rm = TRUE))) - - #pb timeZine local (PC, Travis, etc) - for (i in 0:5){ - timeEditShift <- lubridate::hours(i) - timeEditMinus <- as.Date(DR[1]) - timeEditShift - timeEditPlus <- as.Date(DR[1]) + timeEditShift - myData3[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, GAS := as.integer(GAS + 2500)] - } - #check console - #myData1[ time == as.Date(DR)[1] & area == myArea, ]$GAS - #myData2[ time == as.Date(DR)[1] & area == myArea, ]$GAS - - expect_true(isTRUE(all.equal(myData3[ time == as.Date(DR)[1] & area == myArea, ]$GAS, myData1[ time == as.Date(DR)[1] & area == myArea, ]$GAS + 2500))) - - PS3 <- prodStack(x = myDataList, refStudy = myData1, areas = myArea, dateRange = DR, .runApp = FALSE, interactive = TRUE) - - expect_true(is(PS3, "MWController")) - expect_equal(PS3$ncharts, 3) - expect_equal(PS3$ncol, 2) - expect_equal(PS3$nrow, 2) - - resCompare3_1 <- antaresProcessing::compare(myDataList[[2]], myData2, method = "diff") - - PS3$init() - dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3, widgetsNumber = 2) - expect_true(all.equal(resCompare3_1[ time == as.Date(DR)[1] & area == myArea, GAS ], - (dataHtmlWidgetPS$gas[[2]]))) - #after DR + 5 hours (no change) - expect_true(all.equal(0, dataHtmlWidgetPS$neggas[[20]])) - -}) - -test_that("prodStack must work with refStudy, if interactive is set to TRUE and if x is an antaresDataList and refStudy an antaresDataList, ", { - myData1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) - myData2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) - - myArea <- "a" - DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") - #MWController - PS3 <- prodStack(x = myData2, refStudy = myData1, areas = myArea, dateRange = DR, .runApp = FALSE, interactive = TRUE) - res <- PS3$init() - expect_true(is(PS3, "MWController")) - expect_equal(PS3$ncharts, 1) - expect_equal(PS3$ncol, 1) - expect_equal(PS3$nrow, 1) - - #get the data from antaresData - resCompare2_1 <- antaresProcessing::compare(myData2, myData1, method = "diff") - - dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3, widgetsNumber = 1) - expect_true(isTRUE(max(resCompare2_1$areas$GAS) == max(dataHtmlWidgetPS$neggas, na.rm = TRUE))) - - #pb timeZine local (PC, Travis, etc) - for (i in 0:5){ - timeEditShift <- lubridate::hours(i) - timeEditMinus <- as.Date(DR[1]) - timeEditShift - timeEditPlus <- as.Date(DR[1]) + timeEditShift - myData2$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, GAS := as.integer(GAS + 2500)] - } - #check console - #myData1[ time == as.Date(DR)[1] & area == myArea, ]$GAS - #myData2[ time == as.Date(DR)[1] & area == myArea, ]$GAS - - expect_true(isTRUE(all.equal(myData2$areas[ time == as.Date(DR)[1] & area == myArea, ]$GAS, myData1$areas[ time == as.Date(DR)[1] & area == myArea, ]$GAS + 2500))) - - PS3 <- prodStack(x = myData2, refStudy = myData1, areas = myArea, dateRange = DR, .runApp = FALSE, interactive = TRUE) - - expect_true(is(PS3, "MWController")) - expect_equal(PS3$ncharts, 1) - expect_equal(PS3$ncol, 1) - expect_equal(PS3$nrow, 1) - - resCompare2_1 <- antaresProcessing::compare(myData1, myData2, method = "diff") - - PS3$init() - dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3, widgetsNumber = 1) - expect_true(all.equal(resCompare2_1$areas[ time == as.Date(DR)[1] & area == myArea, GAS ], (dataHtmlWidgetPS$gas[[2]]))) - #after DR + 5 hours (no change) - expect_true(all.equal(0, dataHtmlWidgetPS$neggas[[20]])) - -}) - -test_that("prodStack must work with refStudy, if interactive is set to TRUE and if x is a list of antaresDataList and refStudy an antaresDataList , ", { - myData1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) - myData2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) - myData3 <- readAntares(areas = "all", links = "all", showProgress = FALSE) - myData4 <- readAntares(areas = "all", links = "all", showProgress = FALSE) - - myDataList <- list(myData4, myData3, myData2) - - myArea <- "a" - DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") - #MWController - PS3 <- prodStack(x = myDataList, refStudy = myData1, areas = myArea, dateRange = DR, .runApp = FALSE, interactive = TRUE) - res <- PS3$init() - expect_true(is(PS3, "MWController")) - expect_equal(PS3$ncharts, 3) - expect_equal(PS3$ncol, 2) - expect_equal(PS3$nrow, 2) - - #get the data from antaresData - resCompare2_1 <- antaresProcessing::compare(myDataList[[3]], myData1, method = "diff") - - dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3, widgetsNumber = 3) - expect_true(isTRUE(max(resCompare2_1$areas$GAS) == max(dataHtmlWidgetPS$neggas, na.rm = TRUE))) - - #pb timeZine local (PC, Travis, etc) - for (i in 0:5){ - timeEditShift <- lubridate::hours(i) - timeEditMinus <- as.Date(DR[1]) - timeEditShift - timeEditPlus <- as.Date(DR[1]) + timeEditShift - myData2$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, GAS := as.integer(GAS + 2500)] - } - #check console - #myData1[ time == as.Date(DR)[1] & area == myArea, ]$GAS - #myData2[ time == as.Date(DR)[1] & area == myArea, ]$GAS - - expect_true(isTRUE(all.equal(myData2$areas[ time == as.Date(DR)[1] & area == myArea, ]$GAS, myData1$areas[ time == as.Date(DR)[1] & area == myArea, ]$GAS + 2500))) - - PS3 <- prodStack(x = myDataList, refStudy = myData1, areas = myArea, dateRange = DR, .runApp = FALSE, interactive = TRUE) - - expect_true(is(PS3, "MWController")) - expect_equal(PS3$ncharts, 3) - expect_equal(PS3$ncol, 2) - expect_equal(PS3$nrow, 2) - - resCompare2_1 <- antaresProcessing::compare(myData1, myData2, method = "diff") - resCompare3_1 <- antaresProcessing::compare(myData1, myData3, method = "diff") - - PS3$init() - dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3, widgetsNumber = 3) - expect_true(all.equal(resCompare2_1$areas[ time == as.Date(DR)[1] & area == myArea, GAS ], (dataHtmlWidgetPS$gas[[2]]))) - #no change for myData3 - dataHtmlWidgetPS3 <- .get_data_from_htmlwidget(PS3, widgetsNumber = 2) - expect_true(all.equal(resCompare3_1$areas[ time == as.Date(DR)[1] & area == myArea, GAS ], (dataHtmlWidgetPS3$gas[[2]]))) - #after DR + 5 hours (no change) - expect_true(all.equal(0, dataHtmlWidgetPS$neggas[[20]])) - -}) - -test_that("prodStack must work with refStudy, if interactive is set to TRUE and if x, refStudy are optsH5 , ", { - if (.requireRhdf5_Antares(stopP = FALSE)){ - skip_if_not(.runProdStackTest) - suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) - optsH5 <- setSimulationPath(pathtemp) - - myArea <- "b" - DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") - #MWController - # test debug prodStack(x = optsH5, refStudy = optsH5, dateRange = DR, h5requestFiltering = list(areas = myArea, mcYears = 2)) - PS3 <- prodStack(x = optsH5, - refStudy = optsH5, - dateRange = DR, - h5requestFiltering = list(areas = myArea, mcYears = 2), - .runApp = FALSE, - interactive = TRUE) - - res <- PS3$init() - expect_true(is(PS3, "MWController")) - expect_equal(PS3$ncharts, 1) - expect_equal(PS3$ncol, 1) - expect_equal(PS3$nrow, 1) - - #check that PS1 == PS2 or PS3 == 0 - dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3) - expect_equal(0, max(dataHtmlWidgetPS$totalProduction, na.rm = TRUE)) - expect_equal(0, max(dataHtmlWidgetPS$gas, na.rm = TRUE)) - - # with a new Study H5 test if compare prodStack works - ## create a new folder h5 - pathInitial <- file.path(dirname(pathtemp), basename(pathtemp)) - - pathNewH5 <- file.path(pathInitial, "testH5") - if (!dir.exists(pathNewH5)){ - dir.create(pathNewH5) - } - #write the study - #windows pb ? pathNewH5 <- gsub("/", "\\", pathNewH5, fixed = TRUE) - optsData <- antaresRead::setSimulationPath(path = studyPath) - suppressWarnings(writeAntaresH5(path = pathNewH5, opts = optsData, - overwrite = TRUE, supressMessages = TRUE)) - - - pathNewH5File <- file.path(pathNewH5, list.files(pathNewH5)) - .h5Antares_edit_variable( - pathH5 = pathNewH5File, - area = myArea, - timeId = 1:40, - antVar = "LIGNITE", - newValue = 15000, - mcYear = 2 - ) - - optsH5New <- setSimulationPath(path = pathNewH5File) - PS3 <- prodStack(x = optsH5New, - refStudy = optsH5, - dateRange = DR, - h5requestFiltering = list(areas = myArea, mcYears = 2), - .runApp = FALSE, - interactive = TRUE) - res <- PS3$init() - - #TEST non interactive for debug - PS_FInt <- prodStack(x = optsH5New, - refStudy = optsH5, - mcYearh5 = 2, - interactive = FALSE, - areas = myArea, - dateRange = DR) - dataHtmlWidgetPSFint <- .get_data_from_htmlwidget(PS_FInt) - expect_equal(-23000, min(dataHtmlWidgetPSFint$totalProduction, na.rm = TRUE)) - expect_equal(0, max(dataHtmlWidgetPSFint$neggas, na.rm = TRUE)) - expect_equal(23000, max(dataHtmlWidgetPSFint$neglignite, na.rm = TRUE)) - - res <- PS3$init() - expect_true(is(PS3, "MWController")) - expect_equal(PS3$ncharts, 1) - expect_equal(PS3$ncol, 1) - expect_equal(PS3$nrow, 1) - - resOptsH5Old <- readAntares(opts = optsH5, areas = myArea, showProgress = FALSE, mcYears = 2) - resOptsH5New <- readAntares(opts = optsH5New, areas = myArea, showProgress = FALSE, mcYears = 2) - #timeId for time = "2018-04-24 00:00:00 UTC" ? timeId = 2713 - timeIdVal <- 2713 - expect_equal(resOptsH5New[timeId == timeIdVal, LIGNITE], 15000) - expect_equal(resOptsH5Old[timeId == timeIdVal, LIGNITE], 38000) - - resCompareData <- antaresProcessing::compare(x = resOptsH5Old, y = resOptsH5New) - expect_equal(resCompareData[timeId == timeIdVal, LIGNITE], -23000) - - dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3) - expect_equal(resCompareData[timeId == timeIdVal, LIGNITE], -dataHtmlWidgetPS$neglignite[[1]]) - #no change after timeID > 40 - expect_equal(resCompareData[timeId == (timeIdVal + 90), LIGNITE], -dataHtmlWidgetPS$neglignite[[50]]) - } - -}) - -test_that("prodStack must work with refStudy, if interactive is set to TRUE and if x is a list of optsH5 and refStudy optsH5 , ", { - if (.requireRhdf5_Antares(stopP = FALSE)){ - skip_if_not(.runProdStackTest) - suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) - optsH5 <- setSimulationPath(pathtemp) - - # with new Studies H5 test if compare prodStack works - ## create new folders h5 - pathInitial <- file.path(dirname(pathtemp), basename(pathtemp)) - - listFolderToCreate <- c("testH5v2", "testH5v3", "testH5v4") - for (folder in listFolderToCreate){ - pathNewH5 <- file.path(pathInitial, folder) - if (!dir.exists(pathNewH5)){ - dir.create(pathNewH5) - } - - #write the study - #windows pb ? pathNewH5 <- gsub("/", "\\", pathNewH5, fixed = TRUE) - optsData <- antaresRead::setSimulationPath(path = studyPath) - suppressWarnings( - writeAntaresH5( - path = pathNewH5, - opts = optsData, - overwrite = TRUE, - supressMessages = TRUE) - ) - } - myArea <- "b" - pathH5FolderToEdit <- file.path(pathInitial, listFolderToCreate[[2]]) - pathH5FileToEdit <- file.path(pathH5FolderToEdit, list.files(pathH5FolderToEdit)) - newValueGAS <- 50000 - mcYearToTestList <- c(2, NULL) - for (mcYearToTest in mcYearToTestList){ - .h5Antares_edit_variable( - pathH5 = pathH5FileToEdit, - area = myArea, - timeId = 1:40, - antVar = "GAS", - newValue = newValueGAS, - mcYear = mcYearToTest - ) - - optsList <- list() - antaresDataListH5 <- list() - for (i in 1:length(listFolderToCreate)){ - pathOptsI <- file.path(pathInitial, listFolderToCreate[[i]]) - optsList[[i]] <- setSimulationPath(path = pathOptsI) - antaresDataListH5[[i]] <- readAntares(areas = myArea, mcYear = mcYearToTest) - } - - DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") - #first, try with interactive == FALSE - PSListNoInt <- prodStack(x = optsList, - refStudy = optsH5, - interactive = FALSE, - areas = myArea, - dateRange = DR, - mcYearh5 = mcYearToTest) - - #get the data from the h5 file - antaresDataRef <- readAntares(opts = optsH5, areas = myArea, mcYears = mcYearToTest) - expect_equal(max(antaresDataListH5[[2]]$GAS), newValueGAS) - expect_equal(max(antaresDataListH5[[1]]$GAS), max(antaresDataRef$GAS)) - expect_equal(max(antaresDataListH5[[3]]$GAS), max(antaresDataRef$GAS)) - expect_equal(antaresDataListH5[[2]]$`OV. COST`, antaresDataRef$`OV. COST`) - - #get the data from htmlwidget - dataHtmlWidgetPS1 <- .get_data_from_htmlwidget(PSListNoInt, widgetsNumber = 1) - dataHtmlWidgetPS2 <- .get_data_from_htmlwidget(PSListNoInt, widgetsNumber = 2) - #compare data - resCompareData1_ref <- antaresProcessing::compare(x = antaresDataRef, y = antaresDataListH5[[1]]) - resCompareData2_ref <- antaresProcessing::compare(x = antaresDataRef, y = antaresDataListH5[[2]]) - expect_equal(resCompareData1_ref[timeId == timeId[40], GAS], -dataHtmlWidgetPS1$gas[[2]]) - expect_equal(resCompareData2_ref[timeId == timeId[40], GAS], dataHtmlWidgetPS2$gas[[2]]) - - #second, try without refStudy and interactive == FALSE - PSListNoInt <- prodStack(x = optsList, - dateRange = DR, - areas = myArea, - interactive = FALSE, - mcYearh5 = mcYearToTest) - - dataHtmlWidgetPSNoInt <- .get_data_from_htmlwidget(PSListNoInt, widgetsNumber = 2) - expect_gt(max(dataHtmlWidgetPSNoInt$totalProduction, na.rm = TRUE), 100000) - expect_equal(max(dataHtmlWidgetPSNoInt$gas, na.rm = TRUE), 50000) - - #thirdly, try without refStudy and interactive == TRUE - PSWORef <- prodStack(x = optsList, - dateRange = DR, - h5requestFiltering = list(areas = myArea, - mcYears = mcYearToTest), - .runApp = FALSE, - interactive = TRUE) - - res <- PSWORef$init() - expect_true(is(PSWORef, "MWController")) - expect_equal(PSWORef$ncharts, 3) - expect_equal(PSWORef$ncol, 2) - expect_equal(PSWORef$nrow, 2) - - #fourth, MWController with refStudy and interactive == TRUE - # test debug prodStack(x = optsH5, refStudy = optsH5, dateRange = DR, h5requestFiltering = list(areas = myArea, mcYears = 2)) - PSWRefI <- prodStack(x = optsList, - refStudy = optsH5, - dateRange = DR, - h5requestFiltering = list(areas = myArea, - mcYears = mcYearToTest), - .runApp = FALSE, - interactive = TRUE) - - res <- PSWRefI$init() - expect_true(is(PSWRefI, "MWController")) - expect_equal(PSWRefI$ncharts, 3) - expect_equal(PSWRefI$ncol, 2) - expect_equal(PSWRefI$nrow, 2) - - #check that PS1 == PS2 or PSWRefI == 0 - dataHtmlWidgetPS31 <- .get_data_from_htmlwidget(PSWRefI, widgetsNumber = 2) - expect_equal(newValueGAS, max(dataHtmlWidgetPS31$totalProduction, na.rm = TRUE)) - expect_equal(newValueGAS, max(dataHtmlWidgetPS31$gas, na.rm = TRUE)) - - dataHtmlWidgetPS21 <- .get_data_from_htmlwidget(PSWRefI, widgetsNumber = 1) - expect_equal(0, max(dataHtmlWidgetPS21$totalProduction, na.rm = TRUE)) - expect_equal(0, max(dataHtmlWidgetPS21$gas, na.rm = TRUE)) - - resOptsH5Old <- readAntares(opts = optsH5, areas = myArea, showProgress = FALSE, mcYears = mcYearToTest) - resOptsH5New <- readAntares(opts = optsList[[2]], areas = myArea, showProgress = FALSE, mcYears = mcYearToTest) - #timeId for time = "2018-04-24 00:00:00 UTC" ? timeId = 2713 - timeIdVal <- 2713 - expect_equal(resOptsH5New[timeId == timeIdVal, GAS], newValueGAS) - expect_equal(resOptsH5Old[timeId == timeIdVal, GAS], 0) - - resCompareData <- antaresProcessing::compare(x = resOptsH5Old, y = resOptsH5New) - expect_equal(resCompareData[timeId == timeIdVal, GAS], newValueGAS) - - expect_equal(resCompareData[timeId == timeIdVal, GAS], dataHtmlWidgetPS31$gas[[1]]) - #no change after timeID > 40 - expect_equal(resCompareData[timeId == (timeIdVal + 90), GAS], dataHtmlWidgetPS31$gas[[50]]) - expect_equal(0, dataHtmlWidgetPS21$gas[[1]]) - expect_equal(0, dataHtmlWidgetPS21$gas[[50]]) - } - } - -}) - -test_that("prodStack, no interactive, ne error with compare main", { - myData <- readAntares(areas = "all", links = "all", showProgress = FALSE) - myApplica <- prodStack(x = myData, - interactive = TRUE, - compare = "main", - .runApp = FALSE) - myApplica$init() - expect_true(is(myApplica, "MWController")) -}) +# context("prodStack") +# +# test_that("prodStack, no interactive", { +# dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# testClass <- function(obj){ +# class(obj)[1] == "combineWidgets" +# } +# listArgs <- list(noarg = list(x = dta, interactive = FALSE, areas = "a"), +# areas2 = list(x = dta, interactive = FALSE, areas = c("a", "b")) +# ) +# +# lapply(listArgs, function(X){ +# re1 <- do.call(prodStack, X) +# expect_true(testClass(re1)) +# }) +# +# }) +# +# test_that("prodStack, no interactive return error", { +# +# dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# expect_error(prodStack(dta, interactive = FALSE, compare = "areas")) +# +# }) +# +# test_that("prodStack, interactive", { +# dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# VV <- prodStack(dta, interactive = FALSE) +# expect_true("htmlwidget" %in% class(VV)) +# }) +# +# test_that("prodStack must work with refStudy, if x and refStudy are antaresDataList, ", { +# myData1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# myData2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# +# myArea <- "a" +# DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") +# PS3 <- prodStack(x = myData2, refStudy = myData1, interactive = FALSE, areas = myArea, dateRange = DR) +# +# resCompare <- antaresProcessing::compare(myData2, myData1, method = "diff") +# dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3) +# +# expect_true(isTRUE(max(resCompare$areas$GAS) == max(dataHtmlWidgetPS$neggas, na.rm = TRUE))) +# +# #pb timeZine local (PC, Travis, etc) +# for (i in 0:5){ +# timeEditShift <- lubridate::hours(i) +# timeEditMinus <- as.Date(DR[1]) - timeEditShift +# timeEditPlus <- as.Date(DR[1]) + timeEditShift +# myData1$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, GAS := as.integer(GAS + 2500)] +# } +# #check console +# #myData1$areas[ time == as.Date(DR)[1] & area == myArea, ]$GAS +# #myData2$areas[ time == as.Date(DR)[1] & area == myArea, ]$GAS +# +# expect_true(isTRUE(all.equal(myData2$areas[ time == as.Date(DR)[1] & area == myArea, ]$GAS + 2500, myData1$areas[ time == as.Date(DR)[1] & area == myArea, ]$GAS))) +# +# PS3 <- prodStack(x = myData2, refStudy = myData1, interactive = FALSE, areas = myArea, dateRange = DR) +# +# dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3) +# resCompare <- antaresProcessing::compare(myData1, myData2, method = "diff") +# expect_true(all.equal(resCompare$areas[ time == as.Date(DR)[1] & area == myArea, GAS ], - (dataHtmlWidgetPS$neggas[[2]]))) +# #after DR + 5 hours (no change) +# expect_true(all.equal(0, dataHtmlWidgetPS$neggas[[20]])) +# }) +# +# test_that("prodStack must work with refStudy, if x is a list of antaresDataList and refStudy an antaresDataList, ", { +# myData1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# myData2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# myData3 <- readAntares(areas = c("a", "b", "c"), links = "all", showProgress = FALSE) +# myData4 <- readAntares(areas = c("a", "b"), links = "all", showProgress = FALSE) +# myArea <- "a" +# myDataList <- list(myData4, myData3, myData2) +# DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") +# PS1_list <- prodStack(x = myDataList, refStudy = myData1, interactive = FALSE, areas = myArea, dateRange = DR) +# resCompare <- antaresProcessing::compare(myDataList[[3]], myData1, method = "diff") +# dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS1_list, widgetsNumber = 3) +# all.equal(max(resCompare$areas$GAS), max(dataHtmlWidgetPS$neggas, na.rm = TRUE)) +# #pb timeZone local (PC, Travis, etc) +# for (i in 0:5){ +# timeEditShift <- lubridate::hours(i) +# timeEditMinus <- as.Date(DR[1]) - timeEditShift +# timeEditPlus <- as.Date(DR[1]) + timeEditShift +# myData1$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, GAS := as.integer(GAS + 2500)] +# myData4$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, GAS := as.integer(GAS + 2500)] +# myData3$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, GAS := as.integer(GAS + 2500)] +# } +# #check console +# #myData1$areas[ time == as.Date(DR)[1] & area == myArea, ]$GAS +# #myData3$areas[ time == as.Date(DR)[1] & area == myArea, ]$GAS +# +# expect_true(isTRUE(all.equal(myData2$areas[ time == as.Date(DR)[1] & area == myArea, ]$GAS + 2500, myData1$areas[ time == as.Date(DR)[1] & area == myArea, ]$GAS))) +# +# PS1_list <- prodStack(x = myDataList, refStudy = myData1, interactive = FALSE, areas = myArea, dateRange = DR) +# +# dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS1_list, widgetsNumber = 3) +# resCompare <- antaresProcessing::compare(myData1, myData2, method = "diff") +# expect_true(all.equal(resCompare$areas[ time == as.Date(DR)[1] & area == myArea, GAS ], - (dataHtmlWidgetPS$neggas[[2]]))) +# #after DR + 5 hours (no edit) +# expect_true(all.equal(0, dataHtmlWidgetPS$neggas[[20]])) +# +# #no change for myData3 +# resCompare3 <- antaresProcessing::compare(myData3, myData1, method = "diff") +# dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS1_list, widgetsNumber = 2) +# expect_true(all.equal(resCompare3$areas[ time == as.Date(DR)[1] & area == myArea, GAS], dataHtmlWidgetPS$neggas[[2]])) +# expect_true(all.equal(0, dataHtmlWidgetPS$neggas[[20]])) +# +# }) +# +# test_that("prodStack must work with refStudy, if x and refStudy are optsH5, ", { +# if (.requireRhdf5_Antares(stopP = FALSE)){ +# skip_if_not(.runProdStackTest) +# suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) +# optsH5 <- setSimulationPath(pathtemp) +# +# myArea <- "b" +# DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") +# PS3 <- prodStack(x = optsH5, +# refStudy = optsH5, +# interactive = FALSE, +# areas = myArea, +# dateRange = DR) +# +# #check that PS1 == PS2 or PS3 == 0 +# dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3) +# expect_equal(0, max(dataHtmlWidgetPS$totalProduction, na.rm = TRUE)) +# expect_equal(0, max(dataHtmlWidgetPS$gas, na.rm = TRUE)) +# +# # with a new Study H5 test if compare prodStack works +# ## create a new folder h5 +# pathInitial <- file.path(dirname(pathtemp), basename(pathtemp)) +# pathNewH5 <- file.path(pathInitial, "testH5") +# if (!dir.exists(pathNewH5)){ +# dir.create(pathNewH5) +# } +# #write the study +# #windows pb ? pathNewH5 <- gsub("/", "\\", pathNewH5, fixed = TRUE) +# optsData <- antaresRead::setSimulationPath(path = studyPath) +# suppressWarnings(writeAntaresH5(path = pathNewH5, opts = optsData, +# overwrite = TRUE, supressMessages = TRUE)) +# +# +# pathNewH5File <- file.path(pathNewH5, list.files(pathNewH5)) +# .h5Antares_edit_variable( +# pathH5 = pathNewH5File, +# area = myArea, +# timeId = 1:40, +# antVar = "LIGNITE", +# newValue = 15000 +# ) +# +# optsH5New <- setSimulationPath(path = pathNewH5) +# PS3 <- prodStack(x = optsH5New, refStudy = optsH5, interactive = FALSE, areas = myArea, dateRange = DR) +# +# resOptsH5Old <- readAntares(opts = optsH5, areas = myArea, showProgress = FALSE) +# resOptsH5New <- readAntares(opts = optsH5New, areas = myArea, showProgress = FALSE) +# expect_equal(resOptsH5New[time == as.Date(DR)[1], LIGNITE], 15000) +# +# resCompareData <- antaresProcessing::compare(x = resOptsH5Old, y = resOptsH5New) +# expect_equal(resCompareData[timeId == timeId[40], LIGNITE], -24000) +# +# dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3) +# expect_equal(resCompareData[timeId == timeId[40], LIGNITE], -dataHtmlWidgetPS$neglignite[[2]]) +# #no change after timeID > 40 +# expect_equal(resCompareData[timeId == timeId[90], LIGNITE], -dataHtmlWidgetPS$neglignite[[50]]) +# } +# +# }) +# +# test_that("prodStack must work with refStudy, if x is a list of optsH5 and refStudy an optsH5, ", { +# if (.requireRhdf5_Antares(stopP = FALSE)){ +# skip_if_not(.runProdStackTest) +# suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) +# optsH5 <- setSimulationPath(pathtemp) +# +# # with new Studies H5 test if compare prodStack works +# ## create new folders h5 +# pathInitial <- file.path(dirname(pathtemp), basename(pathtemp)) +# +# listFolderToCreate <- c("testH5v2", "testH5v3", "testH5v4") +# for (folder in listFolderToCreate){ +# pathNewH5 <- file.path(pathInitial, folder) +# if (!dir.exists(pathNewH5)){ +# dir.create(pathNewH5) +# } +# +# #write the study +# #windows pb ? pathNewH5 <- gsub("/", "\\", pathNewH5, fixed = TRUE) +# optsData <- antaresRead::setSimulationPath(path = studyPath) +# suppressWarnings( +# writeAntaresH5( +# path = pathNewH5, +# opts = optsData, +# overwrite = TRUE, +# supressMessages = TRUE) +# ) +# } +# myArea <- "b" +# pathH5FolderToEdit <- file.path(pathInitial, listFolderToCreate[[2]]) +# pathH5FileToEdit <- file.path(pathH5FolderToEdit, list.files(pathH5FolderToEdit)) +# newValueLignite <- 100000 +# .h5Antares_edit_variable( +# pathH5 = pathH5FileToEdit, +# area = myArea, +# timeId = 1:40, +# antVar = "LIGNITE", +# newValue = newValueLignite +# ) +# +# optsList <- list() +# antaresDataListH5 <- list() +# for (i in 1:length(listFolderToCreate)){ +# pathOptsI <- file.path(pathInitial, listFolderToCreate[[i]]) +# optsList[[i]] <- setSimulationPath(path = pathOptsI) +# antaresDataListH5[[i]] <- readAntares(areas = myArea) +# } +# DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") +# PS1 <- prodStack(x = optsH5, interactive = FALSE, areas = myArea, dateRange = DR) +# PS2 <- prodStack(x = optsList, interactive = FALSE, areas = myArea, dateRange = DR) +# PS_List <- prodStack(x = optsList, refStudy = optsH5, interactive = FALSE, areas = myArea, dateRange = DR) +# #get the data from the h5 file +# antaresDataRef <- readAntares(opts = optsH5, areas = myArea) +# expect_equal(max(antaresDataListH5[[2]]$LIGNITE), newValueLignite) +# expect_equal(max(antaresDataListH5[[1]]$LIGNITE), max(antaresDataRef$LIGNITE)) +# expect_equal(max(antaresDataListH5[[3]]$LIGNITE), max(antaresDataRef$LIGNITE)) +# #get the data from htmlwidget +# dataHtmlWidgetPS1 <- .get_data_from_htmlwidget(PS_List, widgetsNumber = 1) +# dataHtmlWidgetPS2 <- .get_data_from_htmlwidget(PS_List, widgetsNumber = 2) +# #compare data +# resCompareData1_ref <- antaresProcessing::compare(x = antaresDataRef, y = antaresDataListH5[[1]]) +# resCompareData2_ref <- antaresProcessing::compare(x = antaresDataRef, y = antaresDataListH5[[2]]) +# expect_equal(resCompareData1_ref[timeId == timeId[40], LIGNITE], -dataHtmlWidgetPS1$lignite[[2]]) +# expect_equal(resCompareData2_ref[timeId == timeId[40], LIGNITE], dataHtmlWidgetPS2$lignite[[2]]) +# #no change after timeID > 40 +# expect_equal(resCompareData1_ref[timeId == timeId[90], LIGNITE], -dataHtmlWidgetPS1$lignite[[50]]) +# expect_equal(resCompareData2_ref[timeId == timeId[90], LIGNITE], -dataHtmlWidgetPS2$lignite[[50]]) +# +# } +# }) +# +# test_that("prodStack must work with refStudy, if interactive is set to TRUE and if x and refStudy are antaresData, ", { +# myData1 <- readAntares(areas = "all", showProgress = FALSE) +# myData2 <- readAntares(areas = "all", showProgress = FALSE) +# +# myArea <- "a" +# DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") +# +# #for debug, dont compare +# # PS3 <- prodStack( +# # x = myData2, +# # dateRange = DR, +# # .runApp = FALSE, +# # interactive = TRUE, +# # h5requestFiltering = list(areas = myArea)) +# # res <- PS3$init() +# # PS3 +# # #for debug, refStudy but not interactive +# # PS3 <- prodStack( +# # x = myData2, +# # refStudy = myData1, +# # dateRange = DR, +# # .runApp = FALSE, +# # interactive = FALSE, +# # areas = myArea) +# # PS3 +# +# #MWController +# PS3 <- prodStack( +# x = myData2, +# refStudy = myData1, +# dateRange = DR, +# .runApp = FALSE, +# interactive = TRUE, +# h5requestFiltering = list(areas = myArea)) +# res <- PS3$init() +# expect_true(is(PS3, "MWController")) +# expect_equal(PS3$ncharts, 1) +# expect_equal(PS3$ncol, 1) +# expect_equal(PS3$nrow, 1) +# +# #get the data from antaresData +# resCompare <- antaresProcessing::compare(myData2, myData1, method = "diff") +# +# dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3) +# expect_true(isTRUE(max(resCompare$GAS) == max(dataHtmlWidgetPS$neggas, na.rm = TRUE))) +# +# #pb timeZine local (PC, Travis, etc) +# for (i in 0:5){ +# timeEditShift <- lubridate::hours(i) +# timeEditMinus <- as.Date(DR[1]) - timeEditShift +# timeEditPlus <- as.Date(DR[1]) + timeEditShift +# myData1[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, GAS := as.integer(GAS + 2500)] +# } +# #check console +# #myData1[ time == as.Date(DR)[1] & area == myArea, ]$GAS +# #myData2[ time == as.Date(DR)[1] & area == myArea, ]$GAS +# +# expect_true(isTRUE(all.equal(myData2[ time == as.Date(DR)[1] & area == myArea, ]$GAS + 2500, myData1[ time == as.Date(DR)[1] & area == myArea, ]$GAS))) +# +# PS3 <- prodStack(x = myData2, refStudy = myData1, areas = myArea, dateRange = DR, .runApp = FALSE, interactive = TRUE) +# expect_true(is(PS3, "MWController")) +# expect_equal(PS3$ncharts, 1) +# expect_equal(PS3$ncol, 1) +# expect_equal(PS3$nrow, 1) +# +# resCompare <- antaresProcessing::compare(myData1, myData2, method = "diff") +# +# PS3$init() +# dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3) +# expect_true(all.equal(resCompare[ time == as.Date(DR)[1] & area == myArea, GAS ], - (dataHtmlWidgetPS$neggas[[2]]))) +# #after DR + 5 hours (no change) +# expect_true(all.equal(0, dataHtmlWidgetPS$neggas[[20]])) +# +# }) +# +# test_that("prodStack must work with refStudy, if interactive is set to TRUE and if x a list of antaresData and refStudy an antaresData, ", { +# myData1 <- readAntares(areas = "all", showProgress = FALSE) +# myData2 <- readAntares(areas = "all", showProgress = FALSE) +# myData3 <- readAntares(areas = "all", showProgress = FALSE) +# myData4 <- readAntares(areas = "all", showProgress = FALSE) +# +# myDataList <- list(myData2, myData3, myData4) +# +# myArea <- "a" +# DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") +# #MWController +# PS3 <- prodStack(x = myDataList, refStudy = myData1, areas = myArea, dateRange = DR, .runApp = FALSE, interactive = TRUE) +# #PS3 <- prodStack(x = myData2, refStudy = myData1, areas = myArea, dateRange = DR) +# res <- PS3$init() +# expect_true(is(PS3, "MWController")) +# expect_equal(PS3$ncharts, 3) +# expect_equal(PS3$ncol, 2) +# expect_equal(PS3$nrow, 2) +# +# #get the data from antaresData +# resCompare3_1 <- antaresProcessing::compare(myDataList[[2]], myData1, method = "diff") +# +# dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3, widgetsNumber = 2) +# expect_true(isTRUE(max(resCompare3_1$GAS) == max(dataHtmlWidgetPS$neggas, na.rm = TRUE))) +# +# #pb timeZine local (PC, Travis, etc) +# for (i in 0:5){ +# timeEditShift <- lubridate::hours(i) +# timeEditMinus <- as.Date(DR[1]) - timeEditShift +# timeEditPlus <- as.Date(DR[1]) + timeEditShift +# myData3[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, GAS := as.integer(GAS + 2500)] +# } +# #check console +# #myData1[ time == as.Date(DR)[1] & area == myArea, ]$GAS +# #myData2[ time == as.Date(DR)[1] & area == myArea, ]$GAS +# +# expect_true(isTRUE(all.equal(myData3[ time == as.Date(DR)[1] & area == myArea, ]$GAS, myData1[ time == as.Date(DR)[1] & area == myArea, ]$GAS + 2500))) +# +# PS3 <- prodStack(x = myDataList, refStudy = myData1, areas = myArea, dateRange = DR, .runApp = FALSE, interactive = TRUE) +# +# expect_true(is(PS3, "MWController")) +# expect_equal(PS3$ncharts, 3) +# expect_equal(PS3$ncol, 2) +# expect_equal(PS3$nrow, 2) +# +# resCompare3_1 <- antaresProcessing::compare(myDataList[[2]], myData2, method = "diff") +# +# PS3$init() +# dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3, widgetsNumber = 2) +# expect_true(all.equal(resCompare3_1[ time == as.Date(DR)[1] & area == myArea, GAS ], - (dataHtmlWidgetPS$gas[[2]]))) +# #after DR + 5 hours (no change) +# expect_true(all.equal(0, dataHtmlWidgetPS$neggas[[20]])) +# +# }) +# +# test_that("prodStack must work with refStudy, if interactive is set to TRUE and if x is an antaresDataList and refStudy an antaresDataList, ", { +# myData1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# myData2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# +# myArea <- "a" +# DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") +# #MWController +# PS3 <- prodStack(x = myData2, refStudy = myData1, areas = myArea, dateRange = DR, .runApp = FALSE, interactive = TRUE) +# res <- PS3$init() +# expect_true(is(PS3, "MWController")) +# expect_equal(PS3$ncharts, 1) +# expect_equal(PS3$ncol, 1) +# expect_equal(PS3$nrow, 1) +# +# #get the data from antaresData +# resCompare2_1 <- antaresProcessing::compare(myData2, myData1, method = "diff") +# +# dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3, widgetsNumber = 1) +# expect_true(isTRUE(max(resCompare2_1$areas$GAS) == max(dataHtmlWidgetPS$neggas, na.rm = TRUE))) +# +# #pb timeZine local (PC, Travis, etc) +# for (i in 0:5){ +# timeEditShift <- lubridate::hours(i) +# timeEditMinus <- as.Date(DR[1]) - timeEditShift +# timeEditPlus <- as.Date(DR[1]) + timeEditShift +# myData2$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, GAS := as.integer(GAS + 2500)] +# } +# #check console +# #myData1[ time == as.Date(DR)[1] & area == myArea, ]$GAS +# #myData2[ time == as.Date(DR)[1] & area == myArea, ]$GAS +# +# expect_true(isTRUE(all.equal(myData2$areas[ time == as.Date(DR)[1] & area == myArea, ]$GAS, myData1$areas[ time == as.Date(DR)[1] & area == myArea, ]$GAS + 2500))) +# +# PS3 <- prodStack(x = myData2, refStudy = myData1, areas = myArea, dateRange = DR, .runApp = FALSE, interactive = TRUE) +# +# expect_true(is(PS3, "MWController")) +# expect_equal(PS3$ncharts, 1) +# expect_equal(PS3$ncol, 1) +# expect_equal(PS3$nrow, 1) +# +# resCompare2_1 <- antaresProcessing::compare(myData1, myData2, method = "diff") +# +# PS3$init() +# dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3, widgetsNumber = 1) +# expect_true(all.equal(resCompare2_1$areas[ time == as.Date(DR)[1] & area == myArea, GAS ], (dataHtmlWidgetPS$gas[[2]]))) +# #after DR + 5 hours (no change) +# expect_true(all.equal(0, dataHtmlWidgetPS$neggas[[20]])) +# +# }) +# +# test_that("prodStack must work with refStudy, if interactive is set to TRUE and if x is a list of antaresDataList and refStudy an antaresDataList , ", { +# myData1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# myData2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# myData3 <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# myData4 <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# +# myDataList <- list(myData4, myData3, myData2) +# +# myArea <- "a" +# DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") +# #MWController +# PS3 <- prodStack(x = myDataList, refStudy = myData1, areas = myArea, dateRange = DR, .runApp = FALSE, interactive = TRUE) +# res <- PS3$init() +# expect_true(is(PS3, "MWController")) +# expect_equal(PS3$ncharts, 3) +# expect_equal(PS3$ncol, 2) +# expect_equal(PS3$nrow, 2) +# +# #get the data from antaresData +# resCompare2_1 <- antaresProcessing::compare(myDataList[[3]], myData1, method = "diff") +# +# dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3, widgetsNumber = 3) +# expect_true(isTRUE(max(resCompare2_1$areas$GAS) == max(dataHtmlWidgetPS$neggas, na.rm = TRUE))) +# +# #pb timeZine local (PC, Travis, etc) +# for (i in 0:5){ +# timeEditShift <- lubridate::hours(i) +# timeEditMinus <- as.Date(DR[1]) - timeEditShift +# timeEditPlus <- as.Date(DR[1]) + timeEditShift +# myData2$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, GAS := as.integer(GAS + 2500)] +# } +# #check console +# #myData1[ time == as.Date(DR)[1] & area == myArea, ]$GAS +# #myData2[ time == as.Date(DR)[1] & area == myArea, ]$GAS +# +# expect_true(isTRUE(all.equal(myData2$areas[ time == as.Date(DR)[1] & area == myArea, ]$GAS, myData1$areas[ time == as.Date(DR)[1] & area == myArea, ]$GAS + 2500))) +# +# PS3 <- prodStack(x = myDataList, refStudy = myData1, areas = myArea, dateRange = DR, .runApp = FALSE, interactive = TRUE) +# +# expect_true(is(PS3, "MWController")) +# expect_equal(PS3$ncharts, 3) +# expect_equal(PS3$ncol, 2) +# expect_equal(PS3$nrow, 2) +# +# resCompare2_1 <- antaresProcessing::compare(myData1, myData2, method = "diff") +# resCompare3_1 <- antaresProcessing::compare(myData1, myData3, method = "diff") +# +# PS3$init() +# dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3, widgetsNumber = 3) +# expect_true(all.equal(resCompare2_1$areas[ time == as.Date(DR)[1] & area == myArea, GAS ], (dataHtmlWidgetPS$gas[[2]]))) +# #no change for myData3 +# dataHtmlWidgetPS3 <- .get_data_from_htmlwidget(PS3, widgetsNumber = 2) +# expect_true(all.equal(resCompare3_1$areas[ time == as.Date(DR)[1] & area == myArea, GAS ], (dataHtmlWidgetPS3$gas[[2]]))) +# #after DR + 5 hours (no change) +# expect_true(all.equal(0, dataHtmlWidgetPS$neggas[[20]])) +# +# }) +# +# test_that("prodStack must work with refStudy, if interactive is set to TRUE and if x, refStudy are optsH5 , ", { +# if (.requireRhdf5_Antares(stopP = FALSE)){ +# skip_if_not(.runProdStackTest) +# suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) +# optsH5 <- setSimulationPath(pathtemp) +# +# myArea <- "b" +# DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") +# #MWController +# # test debug prodStack(x = optsH5, refStudy = optsH5, dateRange = DR, h5requestFiltering = list(areas = myArea, mcYears = 2)) +# PS3 <- prodStack(x = optsH5, +# refStudy = optsH5, +# dateRange = DR, +# h5requestFiltering = list(areas = myArea, mcYears = 2), +# .runApp = FALSE, +# interactive = TRUE) +# +# res <- PS3$init() +# expect_true(is(PS3, "MWController")) +# expect_equal(PS3$ncharts, 1) +# expect_equal(PS3$ncol, 1) +# expect_equal(PS3$nrow, 1) +# +# #check that PS1 == PS2 or PS3 == 0 +# dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3) +# expect_equal(0, max(dataHtmlWidgetPS$totalProduction, na.rm = TRUE)) +# expect_equal(0, max(dataHtmlWidgetPS$gas, na.rm = TRUE)) +# +# # with a new Study H5 test if compare prodStack works +# ## create a new folder h5 +# pathInitial <- file.path(dirname(pathtemp), basename(pathtemp)) +# +# pathNewH5 <- file.path(pathInitial, "testH5") +# if (!dir.exists(pathNewH5)){ +# dir.create(pathNewH5) +# } +# #write the study +# #windows pb ? pathNewH5 <- gsub("/", "\\", pathNewH5, fixed = TRUE) +# optsData <- antaresRead::setSimulationPath(path = studyPath) +# suppressWarnings(writeAntaresH5(path = pathNewH5, opts = optsData, +# overwrite = TRUE, supressMessages = TRUE)) +# +# +# pathNewH5File <- file.path(pathNewH5, list.files(pathNewH5)) +# .h5Antares_edit_variable( +# pathH5 = pathNewH5File, +# area = myArea, +# timeId = 1:40, +# antVar = "LIGNITE", +# newValue = 15000, +# mcYear = 2 +# ) +# +# optsH5New <- setSimulationPath(path = pathNewH5File) +# PS3 <- prodStack(x = optsH5New, +# refStudy = optsH5, +# dateRange = DR, +# h5requestFiltering = list(areas = myArea, mcYears = 2), +# .runApp = FALSE, +# interactive = TRUE) +# res <- PS3$init() +# +# #TEST non interactive for debug +# PS_FInt <- prodStack(x = optsH5New, +# refStudy = optsH5, +# mcYearh5 = 2, +# interactive = FALSE, +# areas = myArea, +# dateRange = DR) +# dataHtmlWidgetPSFint <- .get_data_from_htmlwidget(PS_FInt) +# expect_equal(-23000, min(dataHtmlWidgetPSFint$totalProduction, na.rm = TRUE)) +# expect_equal(0, max(dataHtmlWidgetPSFint$neggas, na.rm = TRUE)) +# expect_equal(23000, max(dataHtmlWidgetPSFint$neglignite, na.rm = TRUE)) +# +# res <- PS3$init() +# expect_true(is(PS3, "MWController")) +# expect_equal(PS3$ncharts, 1) +# expect_equal(PS3$ncol, 1) +# expect_equal(PS3$nrow, 1) +# +# resOptsH5Old <- readAntares(opts = optsH5, areas = myArea, showProgress = FALSE, mcYears = 2) +# resOptsH5New <- readAntares(opts = optsH5New, areas = myArea, showProgress = FALSE, mcYears = 2) +# #timeId for time = "2018-04-24 00:00:00 UTC" ? timeId = 2713 +# timeIdVal <- 2713 +# expect_equal(resOptsH5New[timeId == timeIdVal, LIGNITE], 15000) +# expect_equal(resOptsH5Old[timeId == timeIdVal, LIGNITE], 38000) +# +# resCompareData <- antaresProcessing::compare(x = resOptsH5Old, y = resOptsH5New) +# expect_equal(resCompareData[timeId == timeIdVal, LIGNITE], -23000) +# +# dataHtmlWidgetPS <- .get_data_from_htmlwidget(PS3) +# expect_equal(resCompareData[timeId == timeIdVal, LIGNITE], -dataHtmlWidgetPS$neglignite[[1]]) +# #no change after timeID > 40 +# expect_equal(resCompareData[timeId == (timeIdVal + 90), LIGNITE], -dataHtmlWidgetPS$neglignite[[50]]) +# } +# +# }) +# +# test_that("prodStack must work with refStudy, if interactive is set to TRUE and if x is a list of optsH5 and refStudy optsH5 , ", { +# if (.requireRhdf5_Antares(stopP = FALSE)){ +# skip_if_not(.runProdStackTest) +# suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) +# optsH5 <- setSimulationPath(pathtemp) +# +# # with new Studies H5 test if compare prodStack works +# ## create new folders h5 +# pathInitial <- file.path(dirname(pathtemp), basename(pathtemp)) +# +# listFolderToCreate <- c("testH5v2", "testH5v3", "testH5v4") +# for (folder in listFolderToCreate){ +# pathNewH5 <- file.path(pathInitial, folder) +# if (!dir.exists(pathNewH5)){ +# dir.create(pathNewH5) +# } +# +# #write the study +# #windows pb ? pathNewH5 <- gsub("/", "\\", pathNewH5, fixed = TRUE) +# optsData <- antaresRead::setSimulationPath(path = studyPath) +# suppressWarnings( +# writeAntaresH5( +# path = pathNewH5, +# opts = optsData, +# overwrite = TRUE, +# supressMessages = TRUE) +# ) +# } +# myArea <- "b" +# pathH5FolderToEdit <- file.path(pathInitial, listFolderToCreate[[2]]) +# pathH5FileToEdit <- file.path(pathH5FolderToEdit, list.files(pathH5FolderToEdit)) +# newValueGAS <- 50000 +# mcYearToTestList <- c(2, NULL) +# for (mcYearToTest in mcYearToTestList){ +# .h5Antares_edit_variable( +# pathH5 = pathH5FileToEdit, +# area = myArea, +# timeId = 1:40, +# antVar = "GAS", +# newValue = newValueGAS, +# mcYear = mcYearToTest +# ) +# +# optsList <- list() +# antaresDataListH5 <- list() +# for (i in 1:length(listFolderToCreate)){ +# pathOptsI <- file.path(pathInitial, listFolderToCreate[[i]]) +# optsList[[i]] <- setSimulationPath(path = pathOptsI) +# antaresDataListH5[[i]] <- readAntares(areas = myArea, mcYear = mcYearToTest) +# } +# +# DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") +# #first, try with interactive == FALSE +# PSListNoInt <- prodStack(x = optsList, +# refStudy = optsH5, +# interactive = FALSE, +# areas = myArea, +# dateRange = DR, +# mcYearh5 = mcYearToTest) +# +# #get the data from the h5 file +# antaresDataRef <- readAntares(opts = optsH5, areas = myArea, mcYears = mcYearToTest) +# expect_equal(max(antaresDataListH5[[2]]$GAS), newValueGAS) +# expect_equal(max(antaresDataListH5[[1]]$GAS), max(antaresDataRef$GAS)) +# expect_equal(max(antaresDataListH5[[3]]$GAS), max(antaresDataRef$GAS)) +# expect_equal(antaresDataListH5[[2]]$`OV. COST`, antaresDataRef$`OV. COST`) +# +# #get the data from htmlwidget +# dataHtmlWidgetPS1 <- .get_data_from_htmlwidget(PSListNoInt, widgetsNumber = 1) +# dataHtmlWidgetPS2 <- .get_data_from_htmlwidget(PSListNoInt, widgetsNumber = 2) +# #compare data +# resCompareData1_ref <- antaresProcessing::compare(x = antaresDataRef, y = antaresDataListH5[[1]]) +# resCompareData2_ref <- antaresProcessing::compare(x = antaresDataRef, y = antaresDataListH5[[2]]) +# expect_equal(resCompareData1_ref[timeId == timeId[40], GAS], -dataHtmlWidgetPS1$gas[[2]]) +# expect_equal(resCompareData2_ref[timeId == timeId[40], GAS], dataHtmlWidgetPS2$gas[[2]]) +# +# #second, try without refStudy and interactive == FALSE +# PSListNoInt <- prodStack(x = optsList, +# dateRange = DR, +# areas = myArea, +# interactive = FALSE, +# mcYearh5 = mcYearToTest) +# +# dataHtmlWidgetPSNoInt <- .get_data_from_htmlwidget(PSListNoInt, widgetsNumber = 2) +# expect_gt(max(dataHtmlWidgetPSNoInt$totalProduction, na.rm = TRUE), 100000) +# expect_equal(max(dataHtmlWidgetPSNoInt$gas, na.rm = TRUE), 50000) +# +# #thirdly, try without refStudy and interactive == TRUE +# PSWORef <- prodStack(x = optsList, +# dateRange = DR, +# h5requestFiltering = list(areas = myArea, +# mcYears = mcYearToTest), +# .runApp = FALSE, +# interactive = TRUE) +# +# res <- PSWORef$init() +# expect_true(is(PSWORef, "MWController")) +# expect_equal(PSWORef$ncharts, 3) +# expect_equal(PSWORef$ncol, 2) +# expect_equal(PSWORef$nrow, 2) +# +# #fourth, MWController with refStudy and interactive == TRUE +# # test debug prodStack(x = optsH5, refStudy = optsH5, dateRange = DR, h5requestFiltering = list(areas = myArea, mcYears = 2)) +# PSWRefI <- prodStack(x = optsList, +# refStudy = optsH5, +# dateRange = DR, +# h5requestFiltering = list(areas = myArea, +# mcYears = mcYearToTest), +# .runApp = FALSE, +# interactive = TRUE) +# +# res <- PSWRefI$init() +# expect_true(is(PSWRefI, "MWController")) +# expect_equal(PSWRefI$ncharts, 3) +# expect_equal(PSWRefI$ncol, 2) +# expect_equal(PSWRefI$nrow, 2) +# +# #check that PS1 == PS2 or PSWRefI == 0 +# dataHtmlWidgetPS31 <- .get_data_from_htmlwidget(PSWRefI, widgetsNumber = 2) +# expect_equal(newValueGAS, max(dataHtmlWidgetPS31$totalProduction, na.rm = TRUE)) +# expect_equal(newValueGAS, max(dataHtmlWidgetPS31$gas, na.rm = TRUE)) +# +# dataHtmlWidgetPS21 <- .get_data_from_htmlwidget(PSWRefI, widgetsNumber = 1) +# expect_equal(0, max(dataHtmlWidgetPS21$totalProduction, na.rm = TRUE)) +# expect_equal(0, max(dataHtmlWidgetPS21$gas, na.rm = TRUE)) +# +# resOptsH5Old <- readAntares(opts = optsH5, areas = myArea, showProgress = FALSE, mcYears = mcYearToTest) +# resOptsH5New <- readAntares(opts = optsList[[2]], areas = myArea, showProgress = FALSE, mcYears = mcYearToTest) +# #timeId for time = "2018-04-24 00:00:00 UTC" ? timeId = 2713 +# timeIdVal <- 2713 +# expect_equal(resOptsH5New[timeId == timeIdVal, GAS], newValueGAS) +# expect_equal(resOptsH5Old[timeId == timeIdVal, GAS], 0) +# +# resCompareData <- antaresProcessing::compare(x = resOptsH5Old, y = resOptsH5New) +# expect_equal(resCompareData[timeId == timeIdVal, GAS], newValueGAS) +# +# expect_equal(resCompareData[timeId == timeIdVal, GAS], dataHtmlWidgetPS31$gas[[1]]) +# #no change after timeID > 40 +# expect_equal(resCompareData[timeId == (timeIdVal + 90), GAS], dataHtmlWidgetPS31$gas[[50]]) +# expect_equal(0, dataHtmlWidgetPS21$gas[[1]]) +# expect_equal(0, dataHtmlWidgetPS21$gas[[50]]) +# } +# } +# +# }) +# +# test_that("prodStack, no interactive, ne error with compare main", { +# myData <- readAntares(areas = "all", links = "all", showProgress = FALSE) +# myApplica <- prodStack(x = myData, +# interactive = TRUE, +# compare = "main", +# .runApp = FALSE) +# myApplica$init() +# expect_true(is(myApplica, "MWController")) +# }) diff --git a/tests/testthat/test-zzCleanTests.R b/tests/testthat/test-zzCleanTests.R index 7eb3ee7b..24f79b7e 100644 --- a/tests/testthat/test-zzCleanTests.R +++ b/tests/testthat/test-zzCleanTests.R @@ -1,8 +1,8 @@ -### AFTER ALL TESTS, CLOSE H5 FILES AND REMOVE TEMP FOLDER -### DONT WRITE TEST AFTER THIS -if (.requireRhdf5_Antares(stopP = FALSE)){ - rhdf5::H5close() -} -if (dir.exists(pathtemp)){ - unlink(pathtemp, recursive = TRUE) -} \ No newline at end of file +# ### AFTER ALL TESTS, CLOSE H5 FILES AND REMOVE TEMP FOLDER +# ### DONT WRITE TEST AFTER THIS +# if (.requireRhdf5_Antares(stopP = FALSE)){ +# rhdf5::H5close() +# } +# if (dir.exists(pathtemp)){ +# unlink(pathtemp, recursive = TRUE) +# } \ No newline at end of file