Skip to content

Commit

Permalink
init csa profile contingencies import (#763)
Browse files Browse the repository at this point in the history
* init csa profile contingencies import

* add test files

* add example data zip and some classes

* add contingency creation

* corrections

* corrections sparql file

* correcti disclaimer format

* update sparql requests and unit tests

* update contingency creator + tu

* pom.xml cleaning

* add new test files + update exists method and ids

* add tie line processing

* TU for contingencies integration from CSA_TestConfiguration_TC2_Draft_v14Apr2023.zip

* removing unzipped test case, changes oncontingencies integration

* add doc, error case for invalid head of files, TU

* updates for code review

* add contingencyId in CsaProfileContingencyCreationContext

* updates after code reviews

* updates after master merge

* update for tie-lines and logger

* createAndAddContingencies private

* updates after code reviews
  • Loading branch information
jipea authored Jul 13, 2023
1 parent 56f78dc commit f46003c
Show file tree
Hide file tree
Showing 27 changed files with 1,652 additions and 21 deletions.
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>
</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

0 comments on commit f46003c

Please sign in to comment.