diff --git a/tests/testthat.R b/tests/testthat.R index 206fe35..cbbc7b4 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -1,4 +1,8 @@ library(testthat) library(antaresViz) +# CRAN limite CPU usage + # issue : +data.table::setDTthreads(2) + test_check("antaresViz") diff --git a/tests/testthat/test-exchangesStack.R b/tests/testthat/test-exchangesStack.R index f1cc108..95c8ad8 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 47aebd4..b4cdc46 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-plotMap.R b/tests/testthat/test-plotMap.R index 55f088b..45254c9 100644 --- a/tests/testthat/test-plotMap.R +++ b/tests/testthat/test-plotMap.R @@ -1,138 +1,138 @@ -# context("plotMap") -# -# test_that("plotMap, no interactive", { -# -# dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) -# testClass <- function(obj){ -# class(obj)[1] == 'combineWidgets' -# } -# load(system.file("mapLayout/ml.rda", package = "antaresViz")) -# -# listArgs <- list(noarg = list(x = dta, interactive = FALSE, mapLayout = ml), -# colorLinks = list(x = dta, interactive = FALSE, mapLayout = ml, colLinkVar = "FLOW LIN."), -# colorAll = list(x = dta, interactive = FALSE, mapLayout = ml, colLinkVar = "FLOW LIN.", -# colAreaVar = "OP. COST") -# ) -# -# lapply(listArgs, function(X){ -# re1 <- do.call(plotMap, X) -# expect_true(testClass(re1)) -# }) -# -# }) -# -# test_that("plotMap, no interactive return error", { -# -# dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) -# load(system.file("mapLayout/ml.rda", package = "antaresViz")) -# -# expect_error(plotMap(x = dta, mapLayout = ml , interactive = FALSE, compare = "areas")) -# -# -# }) -# -# test_that("plotMap, interactive", { -# dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) -# load(system.file("mapLayout/ml.rda", package = "antaresViz")) -# VV <- plotMap(x = dta, mapLayout = ml, .runApp = FALSE, interactive = TRUE) -# VV$init() -# expect_true("MWController" %in% class(VV)) -# }) -# -# test_that("plotMap, no interactive, x and refStudy are antaresDataList", { -# dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) -# load(system.file("mapLayout/ml.rda", package = "antaresViz")) -# resPlotMap <- plotMap(x = dta, -# mapLayout = ml, -# interactive = FALSE, -# colAreaVar = "LOAD", -# sizeAreaVars = c("LOAD", "WIND", "SOLAR")) -# expect_true("htmlwidget" %in% class(resPlotMap)) -# valToValid <- .getDataFromPlotMap(area = "c", -# time = "sam. 05 mai 2018
17:00", -# variable = "LOAD", -# htmlPlotMap = resPlotMap) -# expect_gt(valToValid, 50000) -# # with refStudy -# resPlotMap <- plotMap(x = dta, -# refStudy = dta, -# mapLayout = ml, -# interactive = FALSE, -# colAreaVar = "LOAD", -# sizeAreaVars = c("LOAD", "WIND", "SOLAR")) -# expect_true("htmlwidget" %in% class(resPlotMap)) -# valToValid <- .getDataFromPlotMap(area = "c", -# time = "sam. 05 mai 2018
17:00", -# variable = "LOAD", -# htmlPlotMap = resPlotMap) -# expect_equal(valToValid, 0) -# # edit myData -# data2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) -# data2$areas[ , LOAD := as.double(LOAD)][area=="c", LOAD := as.double(LOAD +2500.0)] -# resPlotMap2 <- plotMap(x = data2, -# refStudy = dta, -# mapLayout = ml, -# interactive = FALSE, -# colAreaVar = "LOAD", -# sizeAreaVars = c("LOAD", "WIND", "SOLAR")) -# expect_true("htmlwidget" %in% class(resPlotMap2)) -# valToValid <- .getDataFromPlotMap(area = "c", -# time = "sam. 05 mai 2018
17:00", -# variable = "LOAD", -# htmlPlotMap = resPlotMap2) -# expect_equal(valToValid, 2500) -# }) -# -# test_that("plotMap, no interactive, x is a list of antaresDataList and refStudy an antaresDataList", { -# data1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) -# dataList <- list(data1, data1, data1) -# load(system.file("mapLayout/ml.rda", package = "antaresViz")) -# resPlotMap <- plotMap(x = dataList, -# mapLayout = ml, -# interactive = FALSE, -# colAreaVar = "LOAD", -# sizeAreaVars = c("LOAD", "WIND", "SOLAR")) -# expect_true("htmlwidget" %in% class(resPlotMap)) -# valToValid <- .getDataFromPlotMap(area = "c", -# time = "sam. 05 mai 2018
17:00", -# variable = "LOAD", -# htmlPlotMap = resPlotMap, -# idWidget = 2) -# expect_gt(valToValid, 50000) -# # with refStudy -# resPlotMap <- plotMap(x = dataList, -# refStudy = data1, -# mapLayout = ml, -# interactive = FALSE, -# colAreaVar = "LOAD", -# sizeAreaVars = c("LOAD", "WIND", "SOLAR")) -# expect_true("htmlwidget" %in% class(resPlotMap)) -# valToValid <- .getDataFromPlotMap(area = "c", -# time = "sam. 05 mai 2018
17:00", -# variable = "LOAD", -# htmlPlotMap = resPlotMap, -# idWidget = 2) -# expect_equal(valToValid, 0) -# # edit myData -# data2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) -# data1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) -# data2$areas[ , LOAD := as.double(LOAD)][area=="c", LOAD := as.double(LOAD +2500.0)] -# dataList2 <- list(data1, data2, data1) -# expect_equal(dataList2[[2]]$areas[area=="c", LOAD], dataList2[[1]]$areas[area=="c", LOAD] + 2500) -# resPlotMap2 <- plotMap(x = dataList2, -# refStudy = data1, -# mapLayout = ml, -# interactive = FALSE, -# colAreaVar = "LOAD", -# sizeAreaVars = c("LOAD", "WIND", "SOLAR")) -# expect_true("htmlwidget" %in% class(resPlotMap2)) -# valToValid <- .getDataFromPlotMap(area = "c", -# time = "sam. 05 mai 2018
17:00", -# variable = "LOAD", -# htmlPlotMap = resPlotMap2, -# idWidget = 2) -# expect_equal(valToValid, 2500) -# }) +context("plotMap") + +test_that("plotMap, no interactive", { + + dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) + testClass <- function(obj){ + class(obj)[1] == 'combineWidgets' + } + load(system.file("mapLayout/ml.rda", package = "antaresViz")) + + listArgs <- list(noarg = list(x = dta, interactive = FALSE, mapLayout = ml), + colorLinks = list(x = dta, interactive = FALSE, mapLayout = ml, colLinkVar = "FLOW LIN."), + colorAll = list(x = dta, interactive = FALSE, mapLayout = ml, colLinkVar = "FLOW LIN.", + colAreaVar = "OP. COST") + ) + + lapply(listArgs, function(X){ + re1 <- do.call(plotMap, X) + expect_true(testClass(re1)) + }) + +}) + +test_that("plotMap, no interactive return error", { + + dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) + load(system.file("mapLayout/ml.rda", package = "antaresViz")) + + expect_error(plotMap(x = dta, mapLayout = ml , interactive = FALSE, compare = "areas")) + + +}) + +test_that("plotMap, interactive", { + dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) + load(system.file("mapLayout/ml.rda", package = "antaresViz")) + VV <- plotMap(x = dta, mapLayout = ml, .runApp = FALSE, interactive = TRUE) + VV$init() + expect_true("MWController" %in% class(VV)) +}) + +test_that("plotMap, no interactive, x and refStudy are antaresDataList", { + dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) + load(system.file("mapLayout/ml.rda", package = "antaresViz")) + resPlotMap <- plotMap(x = dta, + mapLayout = ml, + interactive = FALSE, + colAreaVar = "LOAD", + sizeAreaVars = c("LOAD", "WIND", "SOLAR")) + expect_true("htmlwidget" %in% class(resPlotMap)) + valToValid <- .getDataFromPlotMap(area = "c", + time = "sam. 05 mai 2018
17:00", + variable = "LOAD", + htmlPlotMap = resPlotMap) + expect_gt(valToValid, 50000) + # with refStudy + resPlotMap <- plotMap(x = dta, + refStudy = dta, + mapLayout = ml, + interactive = FALSE, + colAreaVar = "LOAD", + sizeAreaVars = c("LOAD", "WIND", "SOLAR")) + expect_true("htmlwidget" %in% class(resPlotMap)) + valToValid <- .getDataFromPlotMap(area = "c", + time = "sam. 05 mai 2018
17:00", + variable = "LOAD", + htmlPlotMap = resPlotMap) + expect_equal(valToValid, 0) + # edit myData + data2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) + data2$areas[ , LOAD := as.double(LOAD)][area=="c", LOAD := as.double(LOAD +2500.0)] + resPlotMap2 <- plotMap(x = data2, + refStudy = dta, + mapLayout = ml, + interactive = FALSE, + colAreaVar = "LOAD", + sizeAreaVars = c("LOAD", "WIND", "SOLAR")) + expect_true("htmlwidget" %in% class(resPlotMap2)) + valToValid <- .getDataFromPlotMap(area = "c", + time = "sam. 05 mai 2018
17:00", + variable = "LOAD", + htmlPlotMap = resPlotMap2) + expect_equal(valToValid, 2500) +}) + +test_that("plotMap, no interactive, x is a list of antaresDataList and refStudy an antaresDataList", { + data1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) + dataList <- list(data1, data1, data1) + load(system.file("mapLayout/ml.rda", package = "antaresViz")) + resPlotMap <- plotMap(x = dataList, + mapLayout = ml, + interactive = FALSE, + colAreaVar = "LOAD", + sizeAreaVars = c("LOAD", "WIND", "SOLAR")) + expect_true("htmlwidget" %in% class(resPlotMap)) + valToValid <- .getDataFromPlotMap(area = "c", + time = "sam. 05 mai 2018
17:00", + variable = "LOAD", + htmlPlotMap = resPlotMap, + idWidget = 2) + expect_gt(valToValid, 50000) + # with refStudy + resPlotMap <- plotMap(x = dataList, + refStudy = data1, + mapLayout = ml, + interactive = FALSE, + colAreaVar = "LOAD", + sizeAreaVars = c("LOAD", "WIND", "SOLAR")) + expect_true("htmlwidget" %in% class(resPlotMap)) + valToValid <- .getDataFromPlotMap(area = "c", + time = "sam. 05 mai 2018
17:00", + variable = "LOAD", + htmlPlotMap = resPlotMap, + idWidget = 2) + expect_equal(valToValid, 0) + # edit myData + data2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) + data1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) + data2$areas[ , LOAD := as.double(LOAD)][area=="c", LOAD := as.double(LOAD +2500.0)] + dataList2 <- list(data1, data2, data1) + expect_equal(dataList2[[2]]$areas[area=="c", LOAD], dataList2[[1]]$areas[area=="c", LOAD] + 2500) + resPlotMap2 <- plotMap(x = dataList2, + refStudy = data1, + mapLayout = ml, + interactive = FALSE, + colAreaVar = "LOAD", + sizeAreaVars = c("LOAD", "WIND", "SOLAR")) + expect_true("htmlwidget" %in% class(resPlotMap2)) + valToValid <- .getDataFromPlotMap(area = "c", + time = "sam. 05 mai 2018
17:00", + variable = "LOAD", + htmlPlotMap = resPlotMap2, + idWidget = 2) + expect_equal(valToValid, 2500) +}) # test_that("plotMap, interactive, x and refStudy are antaresDataList", { # dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) diff --git a/tests/testthat/test-plotThermalGroupCapacities.R b/tests/testthat/test-plotThermalGroupCapacities.R index 4b792c7..8262b2f 100644 --- a/tests/testthat/test-plotThermalGroupCapacities.R +++ b/tests/testthat/test-plotThermalGroupCapacities.R @@ -1,10 +1,10 @@ -# context("plotThermalGroupCapacities") -# -# test_that("plotThermalGroupCapacities", { -# opts <- setSimulationPath(studyPath) -# GG <- plotThermalGroupCapacities( data = thermalGroupCapacities(opts)) -# -# expect_true("htmlwidget" %in% class(GG)) -# -# }) -# +context("plotThermalGroupCapacities") + +test_that("plotThermalGroupCapacities", { + opts <- setSimulationPath(studyPath) + GG <- plotThermalGroupCapacities( data = thermalGroupCapacities(opts)) + + expect_true("htmlwidget" %in% class(GG)) + +}) + diff --git a/tests/testthat/test-plotXY.R b/tests/testthat/test-plotXY.R index 537fcab..ccd9151 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 959bcb4..1f77b71 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-ts_plot.R b/tests/testthat/test-ts_plot.R index e1a290e..78af23e 100644 --- a/tests/testthat/test-ts_plot.R +++ b/tests/testthat/test-ts_plot.R @@ -1,168 +1,168 @@ -# context("tsPlot") -# -# test_that("tsPlot, 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), -# elem = list(x = dta, interactive = FALSE, elements = "a"), -# elemS = list(x = dta, interactive = FALSE, elements = c("a", "b")), -# linkS = list(x = dta, table = "links", interactive = FALSE, elements = c("a - a_offshore")), -# linkSVarSel = list(x = dta, table = "links", interactive = FALSE, -# elements = c("a - a_offshore"), -# variable = "FLOW LIN._std"), -# bar = list(x = dta, interactive = FALSE, elements = "all", type = "barplot"), -# monotone = list(x = dta, interactive = FALSE, elements = "all", type = "monotone"), -# density = list(x = dta, interactive = FALSE, elements = "all", type = "density"), -# cdf = list(x = dta, interactive = FALSE, elements = "all", type = "cdf") -# ) -# -# lapply(listArgs, function(X){ -# re1 <- do.call(tsPlot, X) -# expect_true(testClass(re1)) -# }) -# -# }) -# -# -# -# test_that("tsPlot, no interactive return error", { -# -# dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) -# -# expect_error(tsPlot(dta, interactive = FALSE, compare = "areas")) -# -# }) -# -# # test_that("tsPlot, work with compare", { -# # -# # dta <- readAntares(areas = "all", links = "all", showProgress = FALSE, mcYears = "all") -# # exList <- tsPlot(x = dta, .runApp = FALSE, interactive = TRUE, compare = "mcYear") -# # exList <- exList$init() -# # #to get a param exList$getParams("tables") -# # # exList$getValue("mcYear") -# # exList$setValue("mcYear", 1, chartId = 1, reactive = FALSE) -# # exList$setValue("mcYear", 2, chartId = 2, reactive = FALSE) -# # exList$updateCharts() -# # expect_equal(exList$getValue("tables"), "areas") -# # expect_equal(exList$getValue("main"), "") -# # expect_true(is(exList, "MWController")) -# # expect_equal(exList$ncharts, 2) -# # expect_equal(exList$ncol, 1) -# # expect_equal(exList$nrow, 2) -# # dataTsCompare <- .get_data_from_htmlwidget(exList, widgetsNumber = 1) -# # timeEditValue <- "2018-05-06T18:00:00.000Z" -# # indexHour <- grep(timeEditValue, dataTsCompare$hour) -# # expect_gt(indexHour, 180) -# # expect_equal(dataTsCompare$a[indexHour], 1627275) -# # -# # dataTsCompareMcYear2 <- .get_data_from_htmlwidget(exList, widgetsNumber = 2) -# # expect_equal(dataTsCompareMcYear2$a[indexHour], 1432100) -# # -# # }) +context("tsPlot") + +test_that("tsPlot, 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), + elem = list(x = dta, interactive = FALSE, elements = "a"), + elemS = list(x = dta, interactive = FALSE, elements = c("a", "b")), + linkS = list(x = dta, table = "links", interactive = FALSE, elements = c("a - a_offshore")), + linkSVarSel = list(x = dta, table = "links", interactive = FALSE, + elements = c("a - a_offshore"), + variable = "FLOW LIN._std"), + bar = list(x = dta, interactive = FALSE, elements = "all", type = "barplot"), + monotone = list(x = dta, interactive = FALSE, elements = "all", type = "monotone"), + density = list(x = dta, interactive = FALSE, elements = "all", type = "density"), + cdf = list(x = dta, interactive = FALSE, elements = "all", type = "cdf") + ) + + lapply(listArgs, function(X){ + re1 <- do.call(tsPlot, X) + expect_true(testClass(re1)) + }) + +}) + + + +test_that("tsPlot, no interactive return error", { + + dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) + + expect_error(tsPlot(dta, interactive = FALSE, compare = "areas")) + +}) + +# test_that("tsPlot, work with compare", { # -# test_that("tsPlot, no interactive, x and refStudy are antaresDataTable", { -# myData1 <- readAntares(links = "all", showProgress = FALSE) -# myData2 <- readAntares(links = "all", showProgress = FALSE) -# myLink <- "a - a_offshore" -# DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") -# tsDa1 <- tsPlot(x = myData1, -# table = "links", -# elements = myLink, -# type = "ts", -# interactive = FALSE) -# dataTsDa1 <- .get_data_from_htmlwidget(tsDa1) -# timeEditValue <- "2018-04-25T00:00:00.000Z" -# indexHour <- grep(timeEditValue, dataTsDa1$hour) -# expect_gt(indexHour, 2) -# expect_equal(dataTsDa1$`a - a_offshore`[indexHour], -9) -# tsDa2 <- tsPlot(x = myData1, -# refStudy = myData2, -# table = "links", -# elements = myLink, -# type = "ts", -# interactive = FALSE) -# dataTsDa2 <- .get_data_from_htmlwidget(tsDa2) -# expect_equal(dataTsDa2$`a - a_offshore`[indexHour], 0) -# -# table <- "areas" -# myArea <- "b" -# myData1 <- readAntares(areas = myArea, showProgress = FALSE) -# myData2 <- readAntares(areas = myArea, showProgress = FALSE) -# tsDa1 <- tsPlot(x = myData1, -# table = table, -# elements = myArea, -# type = "ts", -# interactive = FALSE) -# dataTsDa1 <- .get_data_from_htmlwidget(tsDa1) -# expect_equal(dataTsDa1[[myArea]][[indexHour]], 2427150) -# tsDa2 <- tsPlot(x = myData1, -# refStudy = myData2, -# table = table, -# elements = myArea, -# type = "ts", -# interactive = FALSE) -# dataTsDa2 <- .get_data_from_htmlwidget(tsDa2) -# expect_equal(dataTsDa2[[myArea]][[indexHour]], 0) -# }) +# dta <- readAntares(areas = "all", links = "all", showProgress = FALSE, mcYears = "all") +# exList <- tsPlot(x = dta, .runApp = FALSE, interactive = TRUE, compare = "mcYear") +# exList <- exList$init() +# #to get a param exList$getParams("tables") +# # exList$getValue("mcYear") +# exList$setValue("mcYear", 1, chartId = 1, reactive = FALSE) +# exList$setValue("mcYear", 2, chartId = 2, reactive = FALSE) +# exList$updateCharts() +# expect_equal(exList$getValue("tables"), "areas") +# expect_equal(exList$getValue("main"), "") +# expect_true(is(exList, "MWController")) +# expect_equal(exList$ncharts, 2) +# expect_equal(exList$ncol, 1) +# expect_equal(exList$nrow, 2) +# dataTsCompare <- .get_data_from_htmlwidget(exList, widgetsNumber = 1) +# timeEditValue <- "2018-05-06T18:00:00.000Z" +# indexHour <- grep(timeEditValue, dataTsCompare$hour) +# expect_gt(indexHour, 180) +# expect_equal(dataTsCompare$a[indexHour], 1627275) # -# test_that("tsPlot, no interactive, x and refStudy are antaresDataList", { -# myArea <- "b" -# myLink <- "a - a_offshore" -# myData1 <- readAntares(links = myLink, areas = myArea, showProgress = FALSE, mcYears = 1) -# myData2 <- readAntares(links = myLink, areas = myArea, showProgress = FALSE, mcYears = 1) -# DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") -# tsDa1 <- tsPlot(x = myData1, -# table = "links", -# elements = myLink, -# type = "ts", -# interactive = FALSE) -# dataTsDa1 <- .get_data_from_htmlwidget(tsDa1) -# timeEditValue <- "2018-04-25T00:00:00.000Z" -# indexHour <- grep(timeEditValue, dataTsDa1$hour) -# expect_gt(indexHour, 2) -# expect_equal(dataTsDa1$`a - a_offshore`[indexHour], -10) -# tsDa2 <- tsPlot(x = myData1, -# refStudy = myData2, -# table = "links", -# elements = myLink, -# type = "ts", -# interactive = FALSE) -# dataTsDa2 <- .get_data_from_htmlwidget(tsDa2) -# expect_equal(dataTsDa2$`a - a_offshore`[indexHour], 0) +# dataTsCompareMcYear2 <- .get_data_from_htmlwidget(exList, widgetsNumber = 2) +# expect_equal(dataTsCompareMcYear2$a[indexHour], 1432100) # -# #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)] -# } -# tsDa2 <- tsPlot(x = myData1, -# refStudy = myData2, -# table = "links", -# elements = myLink, -# type = "ts", -# interactive = FALSE) -# dataTsDa2 <- .get_data_from_htmlwidget(tsDa2) -# expect_equal(dataTsDa2$`a - a_offshore`[indexHour], -2500) -# # }) +test_that("tsPlot, no interactive, x and refStudy are antaresDataTable", { + myData1 <- readAntares(links = "all", showProgress = FALSE) + myData2 <- readAntares(links = "all", showProgress = FALSE) + myLink <- "a - a_offshore" + DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") + tsDa1 <- tsPlot(x = myData1, + table = "links", + elements = myLink, + type = "ts", + interactive = FALSE) + dataTsDa1 <- .get_data_from_htmlwidget(tsDa1) + timeEditValue <- "2018-04-25T00:00:00.000Z" + indexHour <- grep(timeEditValue, dataTsDa1$hour) + expect_gt(indexHour, 2) + expect_equal(dataTsDa1$`a - a_offshore`[indexHour], -9) + tsDa2 <- tsPlot(x = myData1, + refStudy = myData2, + table = "links", + elements = myLink, + type = "ts", + interactive = FALSE) + dataTsDa2 <- .get_data_from_htmlwidget(tsDa2) + expect_equal(dataTsDa2$`a - a_offshore`[indexHour], 0) + + table <- "areas" + myArea <- "b" + myData1 <- readAntares(areas = myArea, showProgress = FALSE) + myData2 <- readAntares(areas = myArea, showProgress = FALSE) + tsDa1 <- tsPlot(x = myData1, + table = table, + elements = myArea, + type = "ts", + interactive = FALSE) + dataTsDa1 <- .get_data_from_htmlwidget(tsDa1) + expect_equal(dataTsDa1[[myArea]][[indexHour]], 2427150) + tsDa2 <- tsPlot(x = myData1, + refStudy = myData2, + table = table, + elements = myArea, + type = "ts", + interactive = FALSE) + dataTsDa2 <- .get_data_from_htmlwidget(tsDa2) + expect_equal(dataTsDa2[[myArea]][[indexHour]], 0) +}) + +test_that("tsPlot, no interactive, x and refStudy are antaresDataList", { + myArea <- "b" + myLink <- "a - a_offshore" + myData1 <- readAntares(links = myLink, areas = myArea, showProgress = FALSE, mcYears = 1) + myData2 <- readAntares(links = myLink, areas = myArea, showProgress = FALSE, mcYears = 1) + DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") + tsDa1 <- tsPlot(x = myData1, + table = "links", + elements = myLink, + type = "ts", + interactive = FALSE) + dataTsDa1 <- .get_data_from_htmlwidget(tsDa1) + timeEditValue <- "2018-04-25T00:00:00.000Z" + indexHour <- grep(timeEditValue, dataTsDa1$hour) + expect_gt(indexHour, 2) + expect_equal(dataTsDa1$`a - a_offshore`[indexHour], -10) + tsDa2 <- tsPlot(x = myData1, + refStudy = myData2, + table = "links", + elements = myLink, + type = "ts", + interactive = FALSE) + dataTsDa2 <- .get_data_from_htmlwidget(tsDa2) + expect_equal(dataTsDa2$`a - a_offshore`[indexHour], 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)] + } + tsDa2 <- tsPlot(x = myData1, + refStudy = myData2, + table = "links", + elements = myLink, + type = "ts", + interactive = FALSE) + dataTsDa2 <- .get_data_from_htmlwidget(tsDa2) + expect_equal(dataTsDa2$`a - a_offshore`[indexHour], -2500) + +}) + # describe("tsPlot, no interactive, x is a list of antaresDataList and refStudy an antaresDataList", { # myData1 <- readAntares(links = "all", areas = "all", showProgress = FALSE) # myData2 <- readAntares(links = "all", areas = "all", showProgress = FALSE) # myData3 <- readAntares(links = "all", areas = "all", showProgress = FALSE) # myData4 <- readAntares(links = "all", areas = "all", showProgress = FALSE) -# +# # myDataList <- list(myData2, myData3, myData4) # myLink <- "a - a_offshore" # mytables <- "links" # myVariable <- "FLOW LIN." # DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") -# TsDaList <- tsPlot(x = myDataList, -# table = mytables, +# TsDaList <- tsPlot(x = myDataList, +# table = mytables, # elements = myLink, # type = "ts", # interactive = FALSE, @@ -174,10 +174,10 @@ # indexHour <- grep(timeEditValue, dataTsDaList$hour) # expect_gt(indexHour, 2) # expect_equal(dataTsDaList$`a - a_offshore`[indexHour], -9) -# #with a refStudy +# #with a refStudy # TsDaList <- tsPlot(x = myDataList, # refStudy = myData1, -# table = mytables, +# table = mytables, # elements = myLink, # type = "ts", # interactive = FALSE, @@ -206,11 +206,11 @@ # describe("tsPlot, interactive, x and refStudy are antaresDataTable", { # myData1 <- readAntares(links = "all", showProgress = FALSE) # myData2 <- readAntares(links = "all", showProgress = FALSE) -# myLink <- "a - a_offshore" +# myLink <- "a - a_offshore" # DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") -# # no interactive -# tsDa1 <- tsPlot(x = myData1, -# table = "links", +# # no interactive +# tsDa1 <- tsPlot(x = myData1, +# table = "links", # elements = myLink, # type = "ts", # interactive = FALSE) @@ -219,9 +219,9 @@ # indexHour <- grep(timeEditValue, dataTsDa1$hour) # expect_gt(indexHour, 2) # expect_equal(dataTsDa1$`a - a_offshore`[indexHour], -9) -# # interactive -# tsDa1Int <- tsPlot(x = myData1, -# table = "links", +# # interactive +# tsDa1Int <- tsPlot(x = myData1, +# table = "links", # elements = myLink, # type = "ts", # interactive = TRUE, @@ -240,13 +240,13 @@ # indexHour <- grep(timeEditValue, dataTsDa1$hour) # expect_gt(indexHour, 2) # expect_lt(indexHour, 50) -# # BUG with interactive -# ## we must remove 24 hours ? -# expect_equal(dataTsDAInt$`a - a_offshore`[indexHour - 24], -9) -# # interactive with refStudy -# tsDa1Int <- tsPlot(x = myData1, +# # BUG with interactive +# ## we must remove 24 hours ? +# expect_equal(dataTsDAInt$`a - a_offshore`[indexHour - 24], -9) +# # interactive with refStudy +# tsDa1Int <- tsPlot(x = myData1, # refStudy = myData2, -# table = "links", +# table = "links", # elements = myLink, # type = "ts", # interactive = TRUE, @@ -257,7 +257,7 @@ # tsDa1Int$setValue("mcYear", "average", reactive = FALSE) # dataTsDAInt <- .get_data_from_htmlwidget(tsDa1Int) # expect_equal(dataTsDAInt$`a - a_offshore`[indexHour - 24], 0) -# +# # # edit myData2 to have a diff != 0 # ## pb timeZone local (PC, Travis, etc) # for (i in 0:5){ @@ -266,9 +266,9 @@ # timeEditPlus <- as.Date(timeEditValue) + timeEditShift # myData2[ (time == timeEditMinus | time == timeEditPlus) & link == myLink, `FLOW LIN.` := as.integer(`FLOW LIN.` + 2500)] # } -# tsDa1Int <- tsPlot(x = myData2, +# tsDa1Int <- tsPlot(x = myData2, # refStudy = myData1, -# table = "links", +# table = "links", # elements = myLink, # type = "ts", # interactive = TRUE, @@ -284,11 +284,11 @@ # describe("tsPlot, interactive, x and refStudy are antaresDataList", { # myData1 <- readAntares(links = "all", areas = "all", showProgress = FALSE) # myData2 <- readAntares(links = "all", areas = "all", showProgress = FALSE) -# myArea <- "b" +# myArea <- "b" # DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") -# # no interactive -# tsDa1 <- tsPlot(x = myData1, -# table = "areas", +# # no interactive +# tsDa1 <- tsPlot(x = myData1, +# table = "areas", # elements = myArea, # type = "ts", # interactive = FALSE) @@ -297,9 +297,9 @@ # indexHour <- grep(timeEditValue, dataTsDa1$hour) # expect_gt(indexHour, 2) # expect_equal(dataTsDa1$b[indexHour], 2427150) -# # interactive -# tsDa1Int <- tsPlot(x = myData1, -# table = "areas", +# # interactive +# tsDa1Int <- tsPlot(x = myData1, +# table = "areas", # elements = myArea, # type = "ts", # interactive = TRUE, @@ -321,13 +321,13 @@ # indexHour <- grep(timeEditValue, dataTsDa1$hour) # expect_gt(indexHour, 2) # expect_lt(indexHour, 50) -# # BUG with interactive -# ## we must remove 24 hours ? -# expect_equal(dataTsDAInt$b[indexHour - 24], 2427150) -# # interactive with refStudy -# tsDa1Int <- tsPlot(x = myData1, +# # BUG with interactive +# ## we must remove 24 hours ? +# expect_equal(dataTsDAInt$b[indexHour - 24], 2427150) +# # interactive with refStudy +# tsDa1Int <- tsPlot(x = myData1, # refStudy = myData2, -# table = "areas", +# table = "areas", # elements = myArea, # type = "ts", # interactive = TRUE, @@ -338,7 +338,7 @@ # tsDa1Int$setValue("mcYear", "average", reactive = FALSE) # dataTsDAInt <- .get_data_from_htmlwidget(tsDa1Int) # expect_equal(dataTsDAInt$b[indexHour - 24], 0) -# +# # # edit myData2 to have a diff != 0 # ## pb timeZone local (PC, Travis, etc) # for (i in 0:5){ @@ -347,9 +347,9 @@ # timeEditPlus <- as.Date(timeEditValue) + timeEditShift # myData2$areas[ (time == timeEditMinus | time == timeEditPlus) & area == myArea, `OV. COST` := as.integer(`OV. COST` + 2500)] # } -# tsDa1Int <- tsPlot(x = myData2, +# tsDa1Int <- tsPlot(x = myData2, # refStudy = myData1, -# table = "areas", +# table = "areas", # elements = myArea, # type = "ts", # interactive = TRUE, @@ -371,11 +371,11 @@ # skip_if_not(.runTsPlotTest) # suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) # optsH5 <- setSimulationPath(pathtemp) -# myLink <- "a - a_offshore" +# myLink <- "a - a_offshore" # DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") -# # no interactive -# tsDa1 <- tsPlot(x = optsH5, -# table = "links", +# # no interactive +# tsDa1 <- tsPlot(x = optsH5, +# table = "links", # elements = myLink, # type = "ts", # interactive = FALSE) @@ -384,10 +384,10 @@ # indexHour <- grep(timeEditValue, dataTsDa1$hour) # expect_gt(indexHour, 2) # expect_equal(dataTsDa1$`a - a_offshore`[indexHour], -9) -# #ref Study -# tsDa1 <- tsPlot(x = optsH5, +# #ref Study +# tsDa1 <- tsPlot(x = optsH5, # refStudy = optsH5, -# table = "links", +# table = "links", # elements = myLink, # type = "ts", # interactive = FALSE) @@ -395,7 +395,7 @@ # indexHour <- grep(timeEditValue, dataTsDa1$hour) # expect_gt(indexHour, 2) # expect_equal(dataTsDa1$`a - a_offshore`[indexHour], 0) -# # Edit H5 file +# # Edit H5 file # ## create a new folder h5 # pathInitial <- file.path(dirname(pathtemp), basename(pathtemp)) # pathNewH5 <- file.path(pathInitial, "testH5") @@ -405,22 +405,22 @@ # #write the study # #windows pb ? pathNewH5 <- gsub("/", "\\", pathNewH5, fixed = TRUE) # optsData <- antaresRead::setSimulationPath(path = studyPath) -# suppressWarnings(writeAntaresH5(path = pathNewH5, opts = optsData, +# suppressWarnings(writeAntaresH5(path = pathNewH5, opts = optsData, # overwrite = TRUE, supressMessages = TRUE)) -# +# # pathNewH5File <- file.path(pathNewH5, list.files(pathNewH5)) # .h5Antares_edit_variable( -# pathH5 = pathNewH5File, -# link = myLink, -# timeId = 1:100, -# antVar = "FLOW LIN.", +# pathH5 = pathNewH5File, +# link = myLink, +# timeId = 1:100, +# antVar = "FLOW LIN.", # newValue = 15000 # ) -# +# # optsH5New <- setSimulationPath(path = pathNewH5File) -# tsDa1 <- tsPlot(x = optsH5New, +# tsDa1 <- tsPlot(x = optsH5New, # refStudy = optsH5, -# table = "links", +# table = "links", # elements = myLink, # type = "ts", # interactive = FALSE) @@ -435,11 +435,11 @@ # skip_if_not(.runTsPlotTest) # 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) @@ -451,8 +451,8 @@ # optsData <- antaresRead::setSimulationPath(path = studyPath) # suppressWarnings( # writeAntaresH5( -# path = pathNewH5, -# opts = optsData, +# path = pathNewH5, +# opts = optsData, # overwrite = TRUE, # supressMessages = TRUE) # ) @@ -463,10 +463,10 @@ # newValueFlow <- 15000 # myLink <- getLinks()[1] # .h5Antares_edit_variable( -# pathH5 = pathH5FileToEdit, -# link = myLink, -# timeId = 1:100, -# antVar = "FLOW LIN.", +# pathH5 = pathH5FileToEdit, +# link = myLink, +# timeId = 1:100, +# antVar = "FLOW LIN.", # newValue = newValueFlow # ) # optsList <- list() @@ -479,15 +479,15 @@ # #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 +# 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") -# tsDa1 <- tsPlot(x = optsList, +# tsDa1 <- tsPlot(x = optsList, # refStudy = optsH5, -# table = "links", +# table = "links", # elements = myLink, # type = "ts", # interactive = FALSE) @@ -505,11 +505,11 @@ # skip_if_not(.runTsPlotTest) # suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) # optsH5 <- setSimulationPath(pathtemp) -# myLink <- "a - a_offshore" +# myLink <- "a - a_offshore" # DR <- c("2018-04-24 00:00:00 UTC", "2018-04-26 00:00:00 UTC") -# # no interactive -# tsDa1 <- tsPlot(x = optsH5, -# table = "links", +# # no interactive +# tsDa1 <- tsPlot(x = optsH5, +# table = "links", # elements = myLink, # type = "ts", # interactive = FALSE) @@ -530,7 +530,7 @@ # expect_true(is(tsDa1Int, "MWController")) # expect_equal(tsDa1Int$ncharts, 1) # expect_equal(tsDa1Int$ncol, 1) -# expect_equal(tsDa1Int$nrow, 1) +# expect_equal(tsDa1Int$nrow, 1) # expect_true(is((tsDa1Int$getValue("x_tranform")[[1]]), "antaresData")) # tsDa1Int$setValue("mcYear", 1, reactive = TRUE) # tsDa1Int$setValue("tables", "areas", reactive = TRUE) @@ -551,7 +551,7 @@ # indexHour <- grep(timeEditValue, dataTsDa1$hour) # expect_gt(indexHour, 2) # expect_equal(dataTsDa1$b[indexHour], 60262) -# # Edit H5 file +# # Edit H5 file # ## create a new folder h5 # pathInitial <- file.path(dirname(pathtemp), basename(pathtemp)) # pathNewH5 <- file.path(pathInitial, "testH5") @@ -561,32 +561,32 @@ # #write the study # #windows pb ? pathNewH5 <- gsub("/", "\\", pathNewH5, fixed = TRUE) # optsData <- antaresRead::setSimulationPath(path = studyPath) -# suppressWarnings(writeAntaresH5(path = pathNewH5, opts = optsData, +# suppressWarnings(writeAntaresH5(path = pathNewH5, opts = optsData, # overwrite = TRUE, supressMessages = TRUE)) # pathNewH5File <- file.path(pathNewH5, list.files(pathNewH5)) # .h5Antares_edit_variable( -# pathH5 = pathNewH5File, -# area = "b", -# timeId = 1:100, -# antVar = "LOAD", +# pathH5 = pathNewH5File, +# area = "b", +# timeId = 1:100, +# antVar = "LOAD", # newValue = 15000, # mcYear = 1 # ) # optsH5New <- setSimulationPath(path = pathNewH5File) -# myData <- readAntares(areas = "b", -# select = "LOAD", +# myData <- readAntares(areas = "b", +# select = "LOAD", # opts = optsH5New, # mcYears = 1) -# myDataRef <- readAntares(areas = "b", -# select = "LOAD", +# myDataRef <- readAntares(areas = "b", +# select = "LOAD", # opts = optsH5, # mcYears = 1) # expect_equal(myData[area == "b" & timeId == 2737, LOAD], 15000) # expect_gt(myDataRef[area == "b" & timeId == 2737, LOAD], 16000) -# -# diffValue <- myData[area == "b" & timeId == 2737, LOAD] - +# +# diffValue <- myData[area == "b" & timeId == 2737, LOAD] - # myDataRef[area == "b" & timeId == 2737, LOAD] -# tsDa1Int <- tsPlot(x = optsH5New, +# tsDa1Int <- tsPlot(x = optsH5New, # refStudy = optsH5, # type = "ts", # interactive = TRUE, @@ -598,7 +598,7 @@ # expect_true(is(tsDa1Int, "MWController")) # expect_equal(tsDa1Int$ncharts, 1) # expect_equal(tsDa1Int$ncol, 1) -# expect_equal(tsDa1Int$nrow, 1) +# expect_equal(tsDa1Int$nrow, 1) # tsDa1Int$setValue("mcYear", 1, reactive = TRUE) # tsDa1Int$setValue("tables", "areas", reactive = TRUE) # tsDa1Int$setValue("elements", "b", reactive = FALSE) @@ -613,7 +613,7 @@ # indexHour <- grep(timeEditValue, dataTsDa1$hour) # expect_equal(dataTsDa1$b[indexHour], diffValue) # # for links, no refStudy -# tsDa1Int <- tsPlot(x = optsH5New, +# tsDa1Int <- tsPlot(x = optsH5New, # type = "ts", # interactive = TRUE, # .runApp = FALSE, @@ -624,7 +624,7 @@ # expect_true(is(tsDa1Int, "MWController")) # expect_equal(tsDa1Int$ncharts, 1) # expect_equal(tsDa1Int$ncol, 1) -# expect_equal(tsDa1Int$nrow, 1) +# expect_equal(tsDa1Int$nrow, 1) # tsDa1Int$setValue("mcYear", 1, reactive = TRUE) # tsDa1Int$setValue("tables", "links", reactive = TRUE) # tsDa1Int$setValue("elements", myLink, reactive = FALSE) @@ -641,7 +641,7 @@ # indexHour <- grep(timeEditValue, dataTsDa1$hour) # expect_equal(dataTsDa1$`a - a_offshore`[indexHour], -10) # # for links, with refStudy -# tsDa1IntRef <- tsPlot(x = optsH5New, +# tsDa1IntRef <- tsPlot(x = optsH5New, # refStudy = optsH5, # type = "ts", # interactive = TRUE, @@ -653,7 +653,7 @@ # expect_true(is(tsDa1IntRef, "MWController")) # expect_equal(tsDa1IntRef$ncharts, 1) # expect_equal(tsDa1IntRef$ncol, 1) -# expect_equal(tsDa1IntRef$nrow, 1) +# expect_equal(tsDa1IntRef$nrow, 1) # expect_true(is((tsDa1IntRef$getValue("x_tranform")[[1]]), "antaresData")) # tsDa1IntRef$setValue("mcYear", 1, reactive = TRUE) # expect_equal(tsDa1IntRef$getValue("mcYear"), 1) @@ -683,7 +683,7 @@ # skip_if_not(.runTsPlotTest) # 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)) @@ -693,14 +693,14 @@ # 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, +# path = pathNewH5, +# opts = optsData, # overwrite = TRUE, # supressMessages = TRUE) # ) @@ -713,10 +713,10 @@ # myVar <- "FLOW LIN." # for (mcYearToTest in mcYearToTestList){ # .h5Antares_edit_variable( -# pathH5 = pathH5FileToEdit, +# pathH5 = pathH5FileToEdit, # link = myLink, -# timeId = 1:100, -# antVar = myVar, +# timeId = 1:100, +# antVar = myVar, # newValue = newValueFlow, # mcYear = mcYearToTest # ) @@ -726,7 +726,7 @@ # for (i in 1:length(listFolderToCreate)){ # pathOptsI <- file.path(pathInitial, listFolderToCreate[[i]]) # optsList[[i]] <- setSimulationPath(path = pathOptsI) -# antaresDataListH5[[i]] <- readAntares(links = myLink, +# antaresDataListH5[[i]] <- readAntares(links = myLink, # mcYear = mcYearToTest, # opts = optsList[[i]]) # } @@ -741,18 +741,18 @@ # } # expect_equal(antaresDataListH5[[1]]$`FLOW LIN.`[[indexHour]], valFlow) # expect_equal(antaresDataListH5[[3]]$`FLOW LIN.`[[indexHour]], valFlow) -# +# # if(!is.null(mcYearToTest)){ -# expect_error(tsPlot(x = optsList, -# table = "links", +# expect_error(tsPlot(x = optsList, +# table = "links", # elements = myLink, # type = "ts", # interactive = FALSE, # mcYear = mcYearToTest), # "You can't use mcYear for h5 file when interactive is set to FALSE. You can use mcYearh5.") # } -# tsPlotNoInt <- tsPlot(x = optsList, -# table = "links", +# tsPlotNoInt <- tsPlot(x = optsList, +# table = "links", # elements = myLink, # type = "ts", # interactive = FALSE, @@ -775,7 +775,7 @@ # expect_true(is(tsPlotInt, "MWController")) # expect_equal(tsPlotInt$ncharts, 3) # expect_equal(tsPlotInt$ncol, 2) -# expect_equal(tsPlotInt$nrow, 2) +# expect_equal(tsPlotInt$nrow, 2) # tsPlotInt$setValue("mcYear", mcYearToTest, reactive = TRUE) # tsPlotInt$setValue("tables", "links", reactive = TRUE) # tsPlotInt$setValue("elements", myLink, reactive = TRUE) @@ -806,7 +806,7 @@ # expect_equal(datatsPlotInt$`a - a_offshore`[[indexHour]], 50000) # datatsPlotInt2 <- .get_data_from_htmlwidget(tsPlotInt, widgetsNumber = 1) # indexHour <- grep(timeEditValue, datatsPlotInt2$hour) -# expect_equal(datatsPlotInt2$`a - a_offshore`[[indexHour]], valFlow) +# expect_equal(datatsPlotInt2$`a - a_offshore`[[indexHour]], valFlow) # #interactive with refStudy # tsPlotIntRef <- tsPlot(x = optsList, # refStudy = optsH5, @@ -821,7 +821,7 @@ # expect_true(is(tsPlotIntRef, "MWController")) # expect_equal(tsPlotIntRef$ncharts, 3) # expect_equal(tsPlotIntRef$ncol, 2) -# expect_equal(tsPlotIntRef$nrow, 2) +# expect_equal(tsPlotIntRef$nrow, 2) # tsPlotIntRef$setValue("mcYear", mcYearToTest, reactive = TRUE) # tsPlotIntRef$setValue("tables", "links", reactive = TRUE) # tsPlotIntRef$setValue("elements", myLink, reactive = TRUE) @@ -853,7 +853,7 @@ # expect_equal(datatsPlotIntRef$`a - a_offshore`[[indexHour]], 50000-(valFlow)) # datatsPlotIntRef2 <- .get_data_from_htmlwidget(tsPlotIntRef, widgetsNumber = 1) # indexHour <- grep(timeEditValue, datatsPlotIntRef2$hour) -# expect_equal(datatsPlotIntRef2$`a - a_offshore`[[indexHour]], 0) +# expect_equal(datatsPlotIntRef2$`a - a_offshore`[[indexHour]], 0) # } # } # }) diff --git a/tests/testthat/test-zzCleanTests.R b/tests/testthat/test-zzCleanTests.R index 24f79b7..2e23689 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