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

build: v2.15.4 #1771

Merged
merged 8 commits into from
Oct 25, 2023
4 changes: 2 additions & 2 deletions antarest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

# Standard project metadata

__version__ = "2.15.3"
__version__ = "2.15.4"
__author__ = "RTE, Antares Web Team"
__date__ = "2023-10-12"
__date__ = "2023-10-25"
# noinspection SpellCheckingInspection
__credits__ = "(c) Réseau de Transport de l’Électricité (RTE)"

Expand Down
2 changes: 1 addition & 1 deletion antarest/study/business/district_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def create_district(
output=dto.output,
comments=dto.comments,
base_filter=DistrictBaseFilter.remove_all,
filter_items=areas,
filter_items=list(areas),
command_context=self.storage_service.variant_study_service.command_factory.command_context,
)
execute_or_add_commands(study, file_study, [command], self.storage_service)
Expand Down
1 change: 0 additions & 1 deletion antarest/study/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,6 @@ def _create_edit_study_command(
elif isinstance(tree_node, RawFileNode):
if url.split("/")[-1] == "comments":
return UpdateComments(
target=url,
comments=data,
command_context=context,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,12 @@ def extract_district(self, study: FileStudy, district_id: str) -> List[ICommand]
study_config = study.config
study_tree = study.tree
district_config = study_config.sets[district_id]
base_filter = DistrictBaseFilter.add_all if district_config.inverted_set else DistrictBaseFilter.remove_all
district_fetched_config = study_tree.get(["input", "areas", "sets", district_id])
study_commands.append(
CreateDistrict(
name=district_config.name,
metadata={},
base_filter=DistrictBaseFilter.add_all
if district_config.inverted_set
else DistrictBaseFilter.remove_all,
base_filter=base_filter,
filter_items=district_config.areas or [],
output=district_config.output,
comments=district_fetched_config.get("comments", None),
Expand All @@ -331,9 +329,11 @@ def extract_district(self, study: FileStudy, district_id: str) -> List[ICommand]

def extract_comments(self, study: FileStudy) -> List[ICommand]:
study_tree = study.tree
content = cast(bytes, study_tree.get(["settings", "comments"]))
comments = content.decode("utf-8")
return [
UpdateComments(
comments=study_tree.get(["settings", "comments"]),
comments=comments,
command_context=self.command_context,
)
]
Expand Down Expand Up @@ -392,8 +392,8 @@ def generate_update_comments(
self,
study_tree: FileStudyTree,
) -> ICommand:
url = ["settings", "comments"]
comments = study_tree.get(url)
content = cast(bytes, study_tree.get(["settings", "comments"]))
comments = content.decode("utf-8")
return UpdateComments(
comments=comments,
command_context=self.command_context,
Expand Down Expand Up @@ -444,8 +444,7 @@ def generate_update_district(
district_config = study_config.sets[district_id]
district_fetched_config = study_tree.get(["input", "areas", "sets", district_id])
return UpdateDistrict(
name=district_config.name,
metadata={},
id=district_config.name,
base_filter=DistrictBaseFilter.add_all if district_config.inverted_set else DistrictBaseFilter.remove_all,
filter_items=district_config.areas or [],
output=district_config.output,
Expand Down
31 changes: 21 additions & 10 deletions antarest/study/storage/variantstudy/model/command/create_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,30 @@


class CreateCluster(ICommand):
"""
Command used to create a thermal cluster in an area.
"""

# Overloaded metadata
# ===================

command_name = CommandName.CREATE_THERMAL_CLUSTER
version = 1

# Command parameters
# ==================

area_id: str
cluster_name: str
parameters: Dict[str, str]
prepro: Optional[Union[List[List[MatrixData]], str]] = None
modulation: Optional[Union[List[List[MatrixData]], str]] = None

def __init__(self, **data: Any) -> None:
super().__init__(command_name=CommandName.CREATE_THERMAL_CLUSTER, version=1, **data)

@validator("cluster_name")
def validate_cluster_name(cls, val: str) -> str:
valid_name = transform_name_to_id(val, lower=False)
if valid_name != val:
raise ValueError("Area name must only contains [a-zA-Z0-9],&,-,_,(,) characters")
raise ValueError("Cluster name must only contains [a-zA-Z0-9],&,-,_,(,) characters")
return val

@validator("prepro", always=True)
Expand All @@ -57,29 +67,30 @@ def validate_modulation(
return validate_matrix(v, values)

def _apply_config(self, study_data: FileStudyTreeConfig) -> Tuple[CommandOutput, Dict[str, Any]]:
# Search the Area in the configuration
if self.area_id not in study_data.areas:
return (
CommandOutput(
status=False,
message=f"Area '{self.area_id}' does not exist",
message=f"Area '{self.area_id}' does not exist in the study configuration.",
),
dict(),
{},
)
cluster_id = transform_name_to_id(self.cluster_name)
for cluster in study_data.areas[self.area_id].thermals:
if cluster.id == cluster_id:
return (
CommandOutput(
status=False,
message=f"Cluster '{self.cluster_name}' already exist",
message=f"Thermal cluster '{cluster_id}' already exists in the area '{self.area_id}'.",
),
dict(),
{},
)
study_data.areas[self.area_id].thermals.append(Cluster(id=cluster_id, name=self.cluster_name))
return (
CommandOutput(
status=True,
message=f"Cluster '{self.cluster_name}' added to area '{self.area_id}'",
message=f"Thermal cluster '{cluster_id}' added to area '{self.area_id}'.",
),
{"cluster_id": cluster_id},
)
Expand Down Expand Up @@ -123,7 +134,7 @@ def _apply(self, study_data: FileStudy) -> CommandOutput:

def to_dto(self) -> CommandDTO:
return CommandDTO(
action=CommandName.CREATE_THERMAL_CLUSTER.value,
action=self.command_name.value,
args={
"area_id": self.area_id,
"cluster_name": self.cluster_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,23 @@


class CreateRenewablesCluster(ICommand):
"""
Command used to create a renewable cluster in an area.
"""

# Overloaded metadata
# ===================

command_name = CommandName.CREATE_RENEWABLES_CLUSTER
version = 1

# Command parameters
# ==================

area_id: str
cluster_name: str
parameters: Dict[str, str]

def __init__(self, **data: Any) -> None:
super().__init__(
command_name=CommandName.CREATE_RENEWABLES_CLUSTER,
version=1,
**data,
)

@validator("cluster_name")
def validate_cluster_name(cls, val: str) -> str:
valid_name = transform_name_to_id(val, lower=False)
Expand All @@ -43,20 +49,33 @@ def _apply_config(self, study_data: FileStudyTreeConfig) -> Tuple[CommandOutput,
)
return CommandOutput(status=False, message=message), {}

# Search the Area in the configuration
if self.area_id not in study_data.areas:
message = f"Area '{self.area_id}' does not exist"
return CommandOutput(status=False, message=message), {}
return (
CommandOutput(
status=False,
message=f"Area '{self.area_id}' does not exist in the study configuration.",
),
{},
)

cluster_id = transform_name_to_id(self.cluster_name)
for cluster in study_data.areas[self.area_id].renewables:
if cluster.id == cluster_id:
message = f"Renewable cluster '{self.cluster_name}' already exist"
return CommandOutput(status=False, message=message), {}
return (
CommandOutput(
status=False,
message=f"Renewable cluster '{cluster_id}' already exists in the area '{self.area_id}'.",
),
{},
)

study_data.areas[self.area_id].renewables.append(Cluster(id=cluster_id, name=self.cluster_name))
message = f"Renewable cluster '{self.cluster_name}' added to area '{self.area_id}'"
return (
CommandOutput(status=True, message=message),
CommandOutput(
status=True,
message=f"Renewable cluster '{cluster_id}' added to area '{self.area_id}'.",
),
{"cluster_id": cluster_id},
)

Expand Down Expand Up @@ -94,7 +113,7 @@ def _apply(self, study_data: FileStudy) -> CommandOutput:

def to_dto(self) -> CommandDTO:
return CommandDTO(
action=CommandName.CREATE_RENEWABLES_CLUSTER.value,
action=self.command_name.value,
args={
"area_id": self.area_id,
"cluster_name": self.cluster_name,
Expand Down
5 changes: 2 additions & 3 deletions antarest/study/web/raw_studies_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,11 @@ def get_study(
extra={"user": current_user.id},
)
parameters = RequestParameters(user=current_user)

resource_path = pathlib.PurePosixPath(path)
output = study_service.get(uuid, str(resource_path), depth=depth, formatted=formatted, params=parameters)
output = study_service.get(uuid, path, depth=depth, formatted=formatted, params=parameters)

if isinstance(output, bytes):
# Guess the suffix form the target data
resource_path = pathlib.PurePosixPath(path)
parent_cfg = study_service.get(uuid, str(resource_path.parent), depth=2, formatted=True, params=parameters)
child = parent_cfg[resource_path.name]
suffix = pathlib.PurePosixPath(child).suffix
Expand Down
22 changes: 22 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
Antares Web Changelog
=====================

v2.15.4 (2023-10-25)
--------------------

### Tests

* **commands:** refactored study variant command unit tests, improved coverage, and fixed deprecated attribute usage ([8bd0bdf](https://github.com/AntaresSimulatorTeam/AntaREST/commit/8bd0bdf93c1a9ef0ee12570cb7d398ba7212b2fe))


### Bug Fixes

* **results-ui:** display results for a specific year [`#1779`](https://github.com/AntaresSimulatorTeam/AntaREST/pull/1779)
* **ui-study:** remove popup to prevent close after variant creation [`#1773`](https://github.com/AntaresSimulatorTeam/AntaREST/pull/1773)
* **raw:** fix HTTP exception when going on debug view [`#1769`](https://github.com/AntaresSimulatorTeam/AntaREST/pull/1769)


### Contributors

<a href="https://github.com/laurent-laporte-pro">laurent-laporte-pro</a>,
<a href="https://github.com/MartinBelthle">MartinBelthle</a>



v2.15.3 (2023-10-12)
--------------------

Expand Down
2 changes: 1 addition & 1 deletion scripts/update_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def upgrade_version(new_version: str, new_date: str) -> None:
if fullpath.is_file():
print(f"- updating '{fullpath.relative_to(PROJECT_DIR)}'...")
text = fullpath.read_text(encoding="utf-8")
patched = re.sub(search, replace, text, count=1)
patched = re.sub(search, replace, text, count=2)
fullpath.write_text(patched, encoding="utf-8")

# Patching release date
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name="AntaREST",
version="2.15.3",
version="2.15.4",
description="Antares Server",
long_description=Path("README.md").read_text(encoding="utf-8"),
long_description_content_type="text/markdown",
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ sonar.exclusions=antarest/gui.py,antarest/main.py
sonar.python.coverage.reportPaths=coverage.xml
sonar.python.version=3.8
sonar.javascript.lcov.reportPaths=webapp/coverage/lcov.info
sonar.projectVersion=2.15.3
sonar.projectVersion=2.15.4
sonar.coverage.exclusions=antarest/gui.py,antarest/main.py,antarest/singleton_services.py,antarest/worker/archive_worker_service.py,webapp/**/*
10 changes: 10 additions & 0 deletions tests/integration/raw_studies_blueprint/test_fetch_raw_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import http
import itertools
import json
import pathlib
import shutil
Expand Down Expand Up @@ -167,3 +168,12 @@ def test_get_study(
)
assert res.status_code == 200
assert np.isnan(res.json()["data"][0]).any()

# Iterate over all possible combinations of path and depth
for path, depth in itertools.product([None, "", "/"], [0, 1, 2]):
res = client.get(
f"/v1/studies/{study_id}/raw",
params={"path": path, "depth": depth},
headers=headers,
)
assert res.status_code == 200, f"Error for path={path} and depth={depth}"
Loading
Loading