Skip to content

Commit 8c6329a

Browse files
KKamel67kemihak
andauthored
New numbering system in API mode (ex : 7.0, 8.2, 9.2, ...) (#327)
* Compliant with new numbering system in API mode * add unit tests * API does not send "7" or "8" anymore but "7.0" or "8.0" * Antares Web sends 7.0 instead of 7 * Convert Antares version to numeric * Get antares version from info/general/version cause output mode version will be different from input mode version * Update NEWS.md to have a more clear message (breaking change due to Antares Web) --------- Co-authored-by: kemihak <kamel.kemiha@rte-france.com>
1 parent e55efa6 commit 8c6329a

5 files changed

Lines changed: 76 additions & 21 deletions

File tree

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ BUGFIXES :
1111
* `.getSimOptionsAPI()` reads and returns the new converted study version format (ex : 9.0 => 900) in output mode
1212
* `simulation_variables_names_by_supprt.csv` update to read the new thermal output variable `MIN GEN - MWh` available since 9.2 version
1313

14+
BREAKING CHANGES :
15+
* `.getInputOptionsAPI()` Since Antares Web 2.33.0, new numbering system in API mode (ex : 7.0, 8.2, 9.2, ...)
16+
17+
1418
# antaresRead 3.0.0
1519

1620
BUGFIXES :

R/setSimulationPath.R

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ setSimulationPath <- function(path, simulation = NULL) {
537537

538538
p <- params$general
539539

540-
first_month_in_year <- tolower(as.character(p[["first-month-in-year"]]))
540+
first_month_in_year <- tolower(as.character(p[["first-month-in-year"]]))
541541
is_january_first_month_in_year <- first_month_in_year == "january"
542542

543543
# Extract year from the "horizon" parameter.
@@ -713,24 +713,20 @@ setSimulationPath <- function(path, simulation = NULL) {
713713
#' @keywords internal
714714
.transform_antares_version <- function(antares_version) {
715715
antares_version <- format(antares_version, nsmall = 2)
716-
716+
717717
# Split major and minor parts
718718
antares_version_splitted <- unlist(strsplit(antares_version, split = "\\."))
719-
719+
720720
major <- antares_version_splitted[1]
721721
minor <- antares_version_splitted[2]
722-
722+
723723
# max 1 digit for minor
724724
if (nchar(minor) > 2)
725725
stop("Invalid antares_version format, good format is like '9.99'",
726726
call. = FALSE)
727-
727+
728728
# convert to numeric for package understanding
729729
num_version <- round(as.numeric(antares_version)*100)
730730

731731
return(num_version)
732732
}
733-
734-
735-
736-

R/setSimulationPathAPI.R

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,17 @@
6262

6363
# Get basic information about the simulation
6464
params <- read_secure_json(file.path(simPath, "about-the-study", "parameters"), ...)
65-
65+
6666
info <- read_secure_json(file.path(simPath, "info", "general"), ...)
6767

6868
# Where are located the results ?
6969
simDataPath <- file.path(simPath, tolower(as.character(info$mode)))
70-
70+
antares_version <- info$version
71+
72+
if (antares_version < 600 & antares_version >= 9) {
73+
antares_version <- .transform_antares_version(antares_version = antares_version)
74+
}
75+
7176
mc_ind_path <- file.path(simDataPath, "mc-ind&depth=1")
7277

7378
synthesis <- .getSuccess(file.path(simDataPath, "mc-all&depth=1"), ...)
@@ -166,7 +171,7 @@
166171
yearByYear = yearByYear,
167172
scenarios = scenarios,
168173
mcYears = mcYears,
169-
antaresVersion = paths$version,
174+
antaresVersion = antares_version,
170175
areaList = areaList,
171176
districtList = gsub("^@ ?", "", districtList),
172177
linkList = linkList[linkList %in% linksDef$link],
@@ -206,10 +211,8 @@
206211
data.frame(link = paste(Y, "-", to), from = Y, to = to, stringsAsFactors = TRUE)
207212

208213
}, allLinks, names(allLinks)))
209-
210-
# info <- read_secure_json(studyPath, ...)
211-
212-
antaresVersion <- paths$version
214+
215+
antaresVersion <- .transform_antares_version(antares_version = paths$version)
213216
params <- read_secure_json(file.path(studyPath, "settings", "generaldata"), ...)
214217

215218
# Areas with clusters
@@ -309,7 +312,7 @@ setSimulationPathAPI <- function(host, study_id, token, simulation = NULL,
309312
if (missing(token)) {
310313
stop("Please specify your access token")
311314
}
312-
315+
313316
valid_host <- tryCatch({
314317
.getSuccess(file.path(host, "health"), token = "", timeout = timeout, config = httr_config)
315318
}, error = function(e) FALSE)
@@ -319,7 +322,7 @@ setSimulationPathAPI <- function(host, study_id, token, simulation = NULL,
319322
}
320323

321324
stopifnot(timeout > 0)
322-
325+
323326
check_study <- tryCatch({
324327
read_secure_json(file.path(host, "v1/studies", study_id), token = token,
325328
timeout = timeout, config = httr_config

tests/testthat/test-setSimulationPath.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,24 @@ test_that("Check version pb (9.2*100)<920 TRUE ?", {
289289
.transform_antares_version("9.2")<920
290290
)
291291
})
292+
293+
294+
test_that("Check that if version x < version y, then converted version x is < converted version y", {
295+
296+
ant_version <- c(7.0,
297+
7.1,
298+
7.2,
299+
8.0,
300+
8.1,
301+
8.2,
302+
8.3,
303+
8.4,
304+
8.5,
305+
8.6,
306+
8.7,
307+
8.8,
308+
9.2,
309+
9.3)
310+
ant_version_converted <- sapply(ant_version, .transform_antares_version)
311+
expect_true(all(diff(ant_version_converted) > 0))
312+
})

tests/testthat/test-setSimulationPathAPI.R

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ test_that("getSimOptionsAPI return antares version in right format", {
55
# --- root
66
"sim/info/general" = list(
77
mode = "adequacy",
8-
#version = 930,
8+
version=9.3,
99
name = "test",
1010
date = "today"
1111
),
@@ -33,10 +33,41 @@ test_that("getSimOptionsAPI return antares version in right format", {
3333
.readLinksDef = function(x) data.frame(link="fr-de", from="fr", to="de"),
3434
.package = "antaresRead"
3535
)
36-
36+
3737
# when
38-
res <- .getSimOptionsAPI(paths = list(version=930, simPath="sim"))
38+
res <- .getSimOptionsAPI(paths = list(simPath="sim"))
3939

4040
# then
4141
expect_equal(res$antaresVersion, 930)
4242
})
43+
44+
45+
test_that("getInputOptionsAPI return antares version in right format", {
46+
# given
47+
fixtures <- list(
48+
49+
# --- root
50+
"study/general" = list(
51+
name = "test",
52+
date = "today"
53+
),
54+
55+
"input/areas/list" = c("fr", "de"),
56+
"input/areas/sets" = list("@district1" = "district1"),
57+
"input/links&depth=1" = list("de" = "de - fr", "fr" = "de - fr")
58+
)
59+
60+
testthat::local_mocked_bindings(
61+
read_secure_json = function(url, ...) fixtures[[url]],
62+
.package = "antaresRead"
63+
)
64+
65+
res <- .getInputOptionsAPI(paths = list(version=7.1, studyPath="study", inputPath="input"))
66+
expect_equal(res$antaresVersion, 710)
67+
68+
res <- .getInputOptionsAPI(paths = list(version=7.0, studyPath="study", inputPath="input"))
69+
expect_equal(res$antaresVersion, 700)
70+
71+
res <- .getInputOptionsAPI(paths = list(version=9.3, studyPath="study", inputPath="input"))
72+
expect_equal(res$antaresVersion, 930)
73+
})

0 commit comments

Comments
 (0)