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

init csa profile contingencies import #763

Merged
merged 25 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5430403
init csa profile contingencies import
jipea Jun 2, 2023
0463668
add test files
jipea Jun 5, 2023
0040aa7
add example data zip and some classes
jipea Jun 8, 2023
d11d40a
add contingency creation
jipea Jun 13, 2023
e291efd
corrections
jipea Jun 13, 2023
da6b39f
corrections sparql file
jipea Jun 16, 2023
9c31fd7
correcti disclaimer format
jipea Jun 16, 2023
a9a00e8
update sparql requests and unit tests
jipea Jun 19, 2023
b21de63
update contingency creator + tu
jipea Jun 19, 2023
c2c9685
pom.xml cleaning
jipea Jun 23, 2023
88116ab
add new test files + update exists method and ids
jipea Jun 26, 2023
bc77cba
add tie line processing
jipea Jun 28, 2023
15eb4c5
TU for contingencies integration from CSA_TestConfiguration_TC2_Draft…
jipea Jun 29, 2023
556ee6d
removing unzipped test case, changes oncontingencies integration
jipea Jun 30, 2023
bf27230
add doc, error case for invalid head of files, TU
jipea Jun 30, 2023
b636d43
updates for code review
jipea Jul 3, 2023
43725e7
add contingencyId in CsaProfileContingencyCreationContext
jipea Jul 3, 2023
2767e7a
updates after code reviews
jipea Jul 4, 2023
51a7d32
Merge branch 'master' into import-contingencies-csa-profiles
jipea Jul 4, 2023
47af6ca
updates after master merge
jipea Jul 4, 2023
96967b2
update for tie-lines and logger
jipea Jul 4, 2023
4ccea90
createAndAddContingencies private
jipea Jul 5, 2023
de5a847
Merge branch 'master' into import-contingencies-csa-profiles
jipea Jul 12, 2023
85ca3bc
updates after code reviews
jipea Jul 13, 2023
4d2992f
Merge branch 'import-contingencies-csa-profiles' of https://github.co…
jipea Jul 13, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package com.farao_community.farao.data.cne_exporter_commons;
package com.farao_community.farao.commons;

import java.util.Arrays;

Expand Down Expand Up @@ -80,4 +80,3 @@ public static TsoEICode fromEICode(String eiCode) {
return Arrays.stream(TsoEICode.values()).filter(tsoEICode -> tsoEICode.eiCode.equals(eiCode)).findAny().orElseThrow();
}
}

4 changes: 3 additions & 1 deletion data/crac-creation/crac-creator-cim/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<excludePackageNames>com.farao_community.farao.data.crac_creation.creator.cim.xsd.*:com.farao_community.farao.data.crac_creation.creator.cim.xsd:eu.entsoe.*</excludePackageNames>
<excludePackageNames>
com.farao_community.farao.data.crac_creation.creator.cim.xsd.*:com.farao_community.farao.data.crac_creation.creator.cim.xsd:eu.entsoe.*
</excludePackageNames>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.TieLine;

import static com.farao_community.farao.data.crac_creation.creator.cim.crac_creator.CimConstants.CONTINGENCY_SERIES_BUSINESS_TYPE;

import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import static com.farao_community.farao.data.crac_creation.creator.cim.crac_creator.CimConstants.CONTINGENCY_SERIES_BUSINESS_TYPE;

/**
* @author Godelaine de Montmorillon {@literal <godelaine.demontmorillon at rte-france.com>}
*/
Expand Down Expand Up @@ -67,8 +67,8 @@ public void createAndAddContingencies() {
private void addContingency(ContingencySeries cimContingency) {
String createdContingencyId = cimContingency.getMRID();
ContingencyAdder contingencyAdder = crac.newContingency()
.withId(createdContingencyId)
.withName(cimContingency.getName());
.withId(createdContingencyId)
.withName(cimContingency.getName());

if (cimContingency.getRegisteredResource().isEmpty()) {
cimContingencyCreationContexts.add(CimContingencyCreationContext.notImported(createdContingencyId, cimContingency.getName(), ImportStatus.INCOMPLETE_DATA, "No registered resources"));
Expand Down
106 changes: 106 additions & 0 deletions data/crac-creation/crac-creator-csa-profiles/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2022, 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/.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>farao-crac-creation</artifactId>
<groupId>com.farao-community.farao</groupId>
<version>4.5.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>farao-crac-creator-csa-profiles</artifactId>
<name>CRAC creator - CSA Profiles</name>
<description>CRAC creator implementation for CRAC specific to CSA profiles</description>
<packaging>jar</packaging>

<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<configuration>
<args>
<arg>-Xinheritance</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>${maven.jvnet.jaxb2-basics.version}</version>
</plugin>
</plugins>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>farao-crac-creator-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>farao-crac-creation-util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>farao-crac-io-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>farao-crac-util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-rio-rdfxml</artifactId>
<version>4.2.2</version>
jipea marked this conversation as resolved.
Show resolved Hide resolved
</dependency>

<!-- Runtime dependencies -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>farao-crac-impl</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-triple-store-impl-rdf4j</artifactId>
<version>${powsybl.core.version}</version>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-iidm-impl</artifactId>
<version>${powsybl.core.version}</version>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-cgmes-conversion</artifactId>
<version>${powsybl.core.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright (c) 2023, 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.farao_community.farao.data.crac_creation.creator.csa_profile;

import com.farao_community.farao.commons.logs.FaraoLoggerProvider;
import com.farao_community.farao.data.crac_creation.creator.csa_profile.crac_creator.CsaProfileConstants;
import com.farao_community.farao.data.native_crac_api.NativeCrac;
import com.powsybl.triplestore.api.PropertyBags;
import com.powsybl.triplestore.api.QueryCatalog;
import com.powsybl.triplestore.api.TripleStore;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* @author Jean-Pierre Arnould {@literal <jean-pierre.arnould at rte-france.com>}
*/
public class CsaProfileCrac implements NativeCrac {

private final TripleStore tripleStoreCsaProfileCrac;

private final QueryCatalog queryCatalogCsaProfileCrac;

public CsaProfileCrac(TripleStore tripleStoreCsaProfileCrac) {
this.tripleStoreCsaProfileCrac = tripleStoreCsaProfileCrac;
this.queryCatalogCsaProfileCrac = new QueryCatalog(CsaProfileConstants.SPARQL_FILE_CSA_PROFILE);
}

@Override
public String getFormat() {
return "CsaProfileCrac";
}

public PropertyBags getContingencies() {
return this.queryTripleStore(Arrays.asList(CsaProfileConstants.REQUEST_ORDINARY_CONTINGENCY, CsaProfileConstants.REQUEST_EXCEPTIONAL_CONTINGENCY, CsaProfileConstants.REQUEST_OUT_OF_RANGE_CONTINGENCY), tripleStoreCsaProfileCrac.contextNames());
}

public PropertyBags getContingencyEquipments() {
return this.queryTripleStore(CsaProfileConstants.REQUEST_CONTINGENCY_EQUIPMENT);
}

private PropertyBags queryTripleStore(String queryKey) {
return this.queryTripleStore(queryKey, new HashSet<>());
}

private PropertyBags queryTripleStore(List<String> queryKeys, Set<String> contexts) {
PropertyBags mergedPropertyBags = new PropertyBags();
for (String queryKey : queryKeys) {
mergedPropertyBags.addAll(queryTripleStore(queryKey, contexts));
}
return mergedPropertyBags;
}

/**
* execute query on the whole tripleStore or on each context included in the set
*
* @param queryKey : query name in the sparql file
* @param contexts : list of contexts where the query will be executed (if empty, the query is executed on the whole tripleStore
* @return
*/
private PropertyBags queryTripleStore(String queryKey, Set<String> contexts) {
String query = queryCatalogCsaProfileCrac.get(queryKey);
if (query == null) {
FaraoLoggerProvider.TECHNICAL_LOGS.warn("Query [{}] not found in catalog", queryKey);
return new PropertyBags();
}

if (contexts.isEmpty()) {
return tripleStoreCsaProfileCrac.query(query);
}

PropertyBags multiContextsPropertyBags = new PropertyBags();
for (String context : contexts) {
String contextQuery = String.format(query, context);
multiContextsPropertyBags.addAll(tripleStoreCsaProfileCrac.query(contextQuery));
}
return multiContextsPropertyBags;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2023, 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.farao_community.farao.data.crac_creation.creator.csa_profile.crac_creator;

/**
* @author Jean-Pierre Arnould {@literal <jean-pierre.arnould at rte-france.com>}
*/
public final class CsaProfileConstants {

private CsaProfileConstants() {
}

/**
* constants to read rdf files
*/

public static final String EXTENSION_FILE_CSA_PROFILE = "zip";

public static final String RDF_BASE_URL = "http://entsoe.eu";

public static final String TRIPLESTORE_RDF4J_NAME = "rdf4j";

/**
* constants to access triplestore data
*/

public static final String SPARQL_FILE_CSA_PROFILE = "csa_profile.sparql";

/**
* constants to request file headers
*/

public static final String REQUEST_HEADER_START_DATE = "startDate";

public static final String REQUEST_HEADER_END_DATE = "endDate";

public static final String REQUEST_HEADER_KEYWORD = "keyword";

/**
* constants to request contingencies
*/

public static final String REQUEST_CONTINGENCY = "contingency";

public static final String REQUEST_ORDINARY_CONTINGENCY = "ordinaryContingency";

public static final String REQUEST_EXCEPTIONAL_CONTINGENCY = "exceptionalContingency";

public static final String REQUEST_OUT_OF_RANGE_CONTINGENCY = "outOfRangeContingency";

public static final String REQUEST_CONTINGENCY_EQUIPMENT = "contingencyEquipment";

public static final String REQUEST_CONTINGENCIES_NAME = "name";

public static final String REQUEST_CONTINGENCIES_EQUIPMENT_OPERATOR = "idEquipmentOperator";

public static final String REQUEST_CONTINGENCIES_EQUIPMENT_ID = "contingencyEquipmentId";

public static final String REQUEST_CONTINGENCIES_MUST_STUDY = "normalMustStudy";

public static final String REQUEST_CONTINGENCIES_CONTINGENT_STATUS = "contingentStatus";

public static final String IMPORTED_CONTINGENT_STATUS = "http://iec.ch/TC57/CIM100#ContingencyEquipmentStatusKind.outOfService";

public static final String CONTINGENCY_FILE_KEYWORD = "CO";

}
Loading