Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ant1795v2 #261

Merged
merged 8 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: antaresRead
Type: Package
Title: Import, Manipulate and Explore the Results of an 'Antares' Simulation
Version: 2.7.2
Version: 2.8.0.9000
Authors@R: c(
person("Tatiana", "Vargas", email = "tatiana.vargas@rte-france.com", role = c("aut", "cre")),
person("Jalal-Edine", "ZAWAM", role = "aut"),
Expand Down
9 changes: 7 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
> Copyright © 2016 RTE Réseau de transport d’électricité

# antaresRead 2.7.3

BUGFIXES :
# antaresRead 2.8.0.9000
(cf. Antares v9 changelog)

BUGFIXES :
* `setSimulationPathAPI()` : encode URL before reading the data in simulation mode

BREAKING CHANGES :
* `setSimulationPathAPI()` : reads and returns the new converted study version format (ex : 9.0 => 900)


# antaresRead 2.7.2

NEW FEATURES:
Expand Down
36 changes: 36 additions & 0 deletions R/setSimulationPath.R
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ setSimulationPath <- function(path, simulation = NULL) {
linksDef <- data.table(linksDef)

antaresVersion <- readIniFile(file.path(studyPath, "study.antares"))$antares$version
# Convert the Antares number version (from 9.0)
if(antaresVersion<600 & antaresVersion>=9)
antaresVersion <- .transform_antares_version(antares_version = antaresVersion)

params <- readIniFile(file.path(studyPath, "settings/generaldata.ini"))

# Areas with thermal clusters
Expand Down Expand Up @@ -679,3 +683,35 @@ setSimulationPath <- function(path, simulation = NULL) {
return(list(binding = df_groups))
}
}

#' @title Convert the Antares number version
#' @description From V9.0, system version is 9.0 (2 digit for minor) instead of 900
#'
#' @param antares_version ``numeric` Antares number version.
#'
#' @return `numeric` value according to study version
#'
#' @keywords internal
.transform_antares_version <- function(antares_version) {
antares_version <- format(antares_version, nsmall = 2)

# Split major and minor parts
antares_version_splitted <- unlist(strsplit(antares_version, split = "\\."))

major <- antares_version_splitted[1]
minor <- antares_version_splitted[2]

# max 1 digit for minor
if (nchar(minor) > 2)
stop("Invalid antares_version format, good format is like '9.99'",
call. = FALSE)

# convert to numeric for package understanding
num_version <- as.numeric(antares_version)*100

return(num_version)
}




Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[antares]
version = 9.0
caption = study_name
created = 1702567142
lastsave = 1702634579
author = Unknown
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[antares]
version = 9.99
caption = study_name
created = 1702567142
lastsave = 1702634579
author = Unknown
18 changes: 18 additions & 0 deletions man/dot-transform_antares_version.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions tests/testthat/test-setSimulationPath.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,60 @@ test_that("New meta data for group dimension of binding constraints", {

expect_is(opts_study_test$binding, "data.table")
})

# v900----
## test private ----
test_that("read new format version from .antares file", {
test_path_files <- system.file("test_files", package = "antaresRead")

# "readIniFile" conversion problem (9.0 => 9)
antares_file <- file.path(test_path_files,
"antares_version_files",
"antares_version_float.antares")

file_to_read <- readIniFile(file = antares_file, stringsAsFactors = TRUE)

version_value <- file_to_read$antares$version

# test right conversion for package
expect_equal(.transform_antares_version(version_value), 900)

# exception max digit minor
expect_error(.transform_antares_version(9.111),
regexp = "Invalid antares_version format")

# read right format file (9.99)
antares_file <- file.path(test_path_files,
"antares_version_files",
"antares_version_float_2digit.antares")

file_to_read <- readIniFile(file = antares_file, stringsAsFactors = TRUE)

version_value <- file_to_read$antares$version

# test right conversion for package
expect_equal(.transform_antares_version(version_value), 999)
})

## study ----
test_that("read new format version from study", {
path <- setup_study_empty(dir_path = sourcedir_empty_study)
opts_study_test <- setSimulationPath(path)

# "hack" study and paste test file with version "9.0"
test_path_files <- system.file("test_files", package = "antaresRead")
antares_file <- file.path(test_path_files,
"antares_version_files",
"antares_version_float.antares")

# delete "study.antares"
file_to_remove <- file.path(opts_study_test$studyPath, "study.antares")
file.remove(file_to_remove)
file.copy(from = antares_file, to = file_to_remove)

# read study
study <- setSimulationPath(path)

# test right conversion for package
expect_equal(study$antaresVersion, 900)
})
Loading