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 8 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
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 @@ -16,13 +16,13 @@
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.Network;

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.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 @@ -64,8 +64,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
146 changes: 146 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,146 @@
<?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.2.7-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>
<plugin>
<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.*
jipea marked this conversation as resolved.
Show resolved Hide resolved
</excludePackageNames>
</configuration>
jipea marked this conversation as resolved.
Show resolved Hide resolved
</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>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
jipea marked this conversation as resolved.
Show resolved Hide resolved
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
jipea marked this conversation as resolved.
Show resolved Hide resolved
<scope>compile</scope>
</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>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
jipea marked this conversation as resolved.
Show resolved Hide resolved
<scope>runtime</scope>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-config-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-cgmes-conversion</artifactId>
<version>${powsybl.core.version}</version>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-iidm-impl</artifactId>
<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-ucte-converter</artifactId>
<scope>test</scope>
</dependency>
jipea marked this conversation as resolved.
Show resolved Hide resolved
<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,66 @@
/*
* 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.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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.List;

/**
* @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;

private static final Logger LOGGER = LoggerFactory.getLogger(CsaProfileCrac.class);
jipea marked this conversation as resolved.
Show resolved Hide resolved

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

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

private PropertyBags queryTripleStore(String queryKey) {
String query = queryCatalogCsaProfileCrac.get(queryKey);
if (query == null) {
LOGGER.warn("Query [{}] not found in catalog", queryKey);
return new PropertyBags();
}
return tripleStoreCsaProfileCrac.query(query);
}

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

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

public PropertyBags getContingencyEquipments() {
return this.queryTripleStore(CsaProfileConstants.REQUEST_CONTINGENCY_EQUIPMENT);
pet-mit marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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 RDF_FORMAT_CSA_PROFILE = "ApplicationProfiles_NC_RDFS_SHACL_v2_2_v28Mar2023_UMLv90.zip";
//public static final String RDF_FORMAT_CSA_PROFILE = "RDFS/ContingencyProfile_v2_2_RDFSv2020_24Mar2023.rdf";

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";

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_RDFID = "rdfId";

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";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* 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;

import com.farao_community.farao.data.crac_api.Crac;
import com.farao_community.farao.data.crac_creation.creator.api.CracCreationContext;
import com.farao_community.farao.data.crac_creation.creator.api.CracCreationReport;
import com.farao_community.farao.data.crac_creation.creator.csa_profile.crac_creator.contingency.CsaProfileContingencyCreationContext;

import java.time.OffsetDateTime;
import java.util.Set;
import java.util.stream.Collectors;

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

private Crac crac;

private boolean isCreationSuccessful;

private Set<CsaProfileContingencyCreationContext> contingencyCreationContexts;

private final CracCreationReport creationReport;

private final OffsetDateTime timeStamp;

private final String networkName;

CsaProfileCracCreationContext(Crac crac, OffsetDateTime timeStamp, String networkName) {
this.crac = crac;
creationReport = new CracCreationReport();
this.timeStamp = timeStamp;
this.networkName = networkName;
}

@Override
public boolean isCreationSuccessful() {
return this.isCreationSuccessful;
}

@Override
public Crac getCrac() {
return this.crac;
}

@Override
public OffsetDateTime getTimeStamp() {
return this.timeStamp;
}

@Override
public String getNetworkName() {
return this.networkName;
}

public void setContingencyCreationContexts(Set<CsaProfileContingencyCreationContext> contingencyCreationContexts) {
jipea marked this conversation as resolved.
Show resolved Hide resolved
this.contingencyCreationContexts = contingencyCreationContexts.stream().collect(Collectors.toSet());
}

@Override
public CracCreationReport getCreationReport() {
return this.creationReport;
}

CsaProfileCracCreationContext creationFailure() {
this.isCreationSuccessful = false;
this.crac = null;
return this;
}

CsaProfileCracCreationContext creationSuccess(Crac crac) {
this.isCreationSuccessful = true;
this.crac = crac;
return this;
}
}
Loading