Skip to content

Commit

Permalink
fix(bc): display matrix index according to frequency (#2196)
Browse files Browse the repository at this point in the history
Fix [ANT-2364]
  • Loading branch information
MartinBelthle authored Oct 22, 2024
1 parent 67c2d14 commit a5d4231
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ class BindingConstraints(FolderNode):

def build(self) -> TREE:
cfg = self.config
frequency_mapping = {
BindingConstraintFrequency.HOURLY: MatrixFrequency.HOURLY,
BindingConstraintFrequency.DAILY: MatrixFrequency.DAILY,
BindingConstraintFrequency.WEEKLY: MatrixFrequency.DAILY,
}
if cfg.version < 870:
default_matrices = {
BindingConstraintFrequency.HOURLY: default_bc_hourly_86,
Expand All @@ -53,7 +58,7 @@ def build(self) -> TREE:
binding.id: InputSeriesMatrix(
self.context,
self.config.next_file(f"{binding.id}.txt"),
freq=MatrixFrequency(binding.time_step),
freq=frequency_mapping[binding.time_step],
nb_columns=3,
default_empty=default_matrices[binding.time_step],
)
Expand All @@ -73,7 +78,7 @@ def build(self) -> TREE:
children[matrix_id] = InputSeriesMatrix(
self.context,
self.config.next_file(f"{matrix_id}.txt"),
freq=MatrixFrequency(binding.time_step),
freq=frequency_mapping[binding.time_step],
nb_columns=1 if term in ["lt", "gt"] else None,
default_empty=default_matrices[binding.time_step],
)
Expand Down
30 changes: 20 additions & 10 deletions tests/integration/studies_blueprint/test_study_matrix_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ def test_get_study_matrix_index(
user_access_token: str,
internal_study_id: str,
) -> None:
user_access_token = {"Authorization": f"Bearer {user_access_token}"}
client.headers = {"Authorization": f"Bearer {user_access_token}"}

# Check the matrix index for Thermal clusters
# ===========================================

# Check the Common matrix index
res = client.get(
f"/v1/studies/{internal_study_id}/matrixindex",
headers=user_access_token,
params={"path": "input/thermal/prepro/fr/01_solar/modulation"},
)
assert res.status_code == 200, res.json()
Expand All @@ -52,9 +51,7 @@ def test_get_study_matrix_index(

# Check the TS Generator matrix index
res = client.get(
f"/v1/studies/{internal_study_id}/matrixindex",
headers=user_access_token,
params={"path": "input/thermal/prepro/fr/01_solar/data"},
f"/v1/studies/{internal_study_id}/matrixindex", params={"path": "input/thermal/prepro/fr/01_solar/data"}
)
assert res.status_code == 200, res.json()
actual = res.json()
Expand All @@ -69,9 +66,7 @@ def test_get_study_matrix_index(

# Check the time series
res = client.get(
f"/v1/studies/{internal_study_id}/matrixindex",
headers=user_access_token,
params={"path": "input/thermal/series/fr/01_solar/series"},
f"/v1/studies/{internal_study_id}/matrixindex", params={"path": "input/thermal/series/fr/01_solar/series"}
)
assert res.status_code == 200, res.json()
actual = res.json()
Expand All @@ -87,7 +82,7 @@ def test_get_study_matrix_index(
# Check the default matrix index
# ==============================

res = client.get(f"/v1/studies/{internal_study_id}/matrixindex", headers=user_access_token)
res = client.get(f"/v1/studies/{internal_study_id}/matrixindex")
assert res.status_code == 200
actual = res.json()
expected = {
Expand All @@ -103,10 +98,25 @@ def test_get_study_matrix_index(

res = client.get(
f"/v1/studies/{internal_study_id}/matrixindex",
headers=user_access_token,
params={"path": "output/20201014-1427eco/economy/mc-all/areas/es/details-daily"},
)
assert res.status_code == 200
actual = res.json()
expected = {"first_week_size": 7, "start_date": "2018-01-01 00:00:00", "steps": 7, "level": "daily"}
assert actual == expected

# Check the matrix index for a weekly binding constraint
# =========================================================================

res = client.post(
f"/v1/studies/{internal_study_id}/bindingconstraints", json={"name": "bc_1", "timeStep": "weekly"}
)
res.raise_for_status()

res = client.get(
f"/v1/studies/{internal_study_id}/matrixindex", params={"path": "input/bindingconstraints/bc_1"}
)
assert res.status_code == 200
actual = res.json()
expected = {"first_week_size": 7, "start_date": "2018-01-01 00:00:00", "steps": 365, "level": "daily"}
assert actual == expected

0 comments on commit a5d4231

Please sign in to comment.