-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Thomas Bouquet <[email protected]>
- Loading branch information
Showing
5 changed files
with
97 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/StateIdHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (c) 2025, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package com.powsybl.openrao.data.crac.impl; | ||
|
||
import com.powsybl.contingency.Contingency; | ||
import com.powsybl.openrao.data.crac.api.Instant; | ||
|
||
import java.time.OffsetDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
/** | ||
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>} | ||
*/ | ||
public final class StateIdHelper { | ||
private StateIdHelper() { | ||
} | ||
|
||
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmm"); | ||
|
||
public static String getStateId(Contingency contingency, Instant instant, OffsetDateTime timestamp) { | ||
String idWithContingency = contingency == null ? instant.getId() : contingency.getId() + " - " + instant.getId(); | ||
return timestamp == null ? idWithContingency : idWithContingency + " - " + timestamp.format(DATE_TIME_FORMATTER); | ||
} | ||
|
||
public static String getStateId(Instant instant, OffsetDateTime timestamp) { | ||
return getStateId(null, instant, timestamp); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/StateIdHelperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (c) 2025, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package com.powsybl.openrao.data.crac.impl; | ||
|
||
import com.powsybl.contingency.Contingency; | ||
import com.powsybl.openrao.data.crac.api.Instant; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
import java.time.OffsetDateTime; | ||
import java.time.ZoneOffset; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>} | ||
*/ | ||
class StateIdHelperTest { | ||
private Contingency contingency; | ||
private Instant instant; | ||
private OffsetDateTime timestamp; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
contingency = Mockito.mock(Contingency.class); | ||
Mockito.when(contingency.getId()).thenReturn("contingency"); | ||
instant = Mockito.mock(Instant.class); | ||
Mockito.when(instant.getId()).thenReturn("instant"); | ||
timestamp = OffsetDateTime.of(2025, 2, 12, 9, 18, 0, 0, ZoneOffset.UTC); | ||
} | ||
|
||
@Test | ||
void testIdWithContingencyAndTimestamp() { | ||
assertEquals("contingency - instant - 202502120918", StateIdHelper.getStateId(contingency, instant, timestamp)); | ||
} | ||
|
||
@Test | ||
void testIdWithContingency() { | ||
assertEquals("contingency - instant", StateIdHelper.getStateId(contingency, instant, null)); | ||
} | ||
|
||
@Test | ||
void testIdWithTimestamp() { | ||
assertEquals("instant - 202502120918", StateIdHelper.getStateId(instant, timestamp)); | ||
} | ||
|
||
@Test | ||
void testBasicId() { | ||
assertEquals("instant", StateIdHelper.getStateId(instant, null)); | ||
} | ||
} |