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

Csa/refactor/profile header check #820

Merged
merged 8 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -17,6 +17,26 @@ public final class CsaProfileConstants {
private CsaProfileConstants() {
}

/**
* CSA Profiles keywords
*/
public enum CsaProfile {
ASSESSED_ELEMENT("AE"),
CONTINGENCY("CO"),
EQUIPMENT_RELIABILITY("ER"),
REMEDIAL_ACTION("RA");

CsaProfile(String keyword) {
this.keyword = keyword;
}

private final String keyword;

public String getKeyword() {
return this.keyword;
}
}

/**
* constants to read rdf files
*/
Expand Down Expand Up @@ -69,15 +89,12 @@ private CsaProfileConstants() {

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

public static final String CONTINGENCY_FILE_KEYWORD = "CO";

/**
* remedial actions
*/

public static final String REMEDIAL_ACTION_NAME = "name";
public static final String REMEDIAL_ACTION_MESSAGE = "Remedial action ";
public static final String REMEDIAL_ACTION_FILE_KEYWORD = "RA";
public static final String GRID_STATE_ALTERATION_REMEDIAL_ACTION = "gridStateAlterationRemedialAction";
public static final String TOPOLOGY_ACTION = "topologyAction";
public static final String ROTATING_MACHINE_ACTION = "rotatingMachineAction";
Expand All @@ -93,22 +110,64 @@ private CsaProfileConstants() {
public static final String SWITCH = "switchId";
public static final String NORMAL_ENABLED = "normalEnabled";
public static final String GRID_ALTERATION_PROPERTY_REFERENCE = "propertyReference";
public static final String PROPERTY_REFERENCE_SWITCH_OPEN = "http://energy.referencedata.eu/PropertyReference/Switch.open";
public static final String PROPERTY_REFERENCE_ROTATING_MACHINE = "http://energy.referencedata.eu/PropertyReference/RotatingMachine.p";
public static final String PROPERTY_REFERENCE_TAP_POSITION = "http://energy.referencedata.eu/PropertyReference/TapChanger.step";

public static final String ROTATING_MACHINE = "rotatingMachineId";
public enum PropertyReference {
SWITCH("Switch.open"),
ROTATING_MACHINE("RotatingMachine.p"),
TAP_CHANGER("TapChanger.step");

public static final String TAP_CHANGER = "tapChangerId";
PropertyReference(String name) {
this.name = name;
}

public static final String NORMAL_VALUE = "normalValue";
private final String name;
private static final String URL = "http://energy.referencedata.eu/PropertyReference/";

@Override
public String toString() {
return PropertyReference.URL + this.name;
}
}

public static final String ROTATING_MACHINE = "rotatingMachineId";
public static final String TAP_CHANGER = "tapChangerId";
public static final String NORMAL_VALUE = "normalValue";
public static final String STATIC_PROPERTY_RANGE_VALUE_KIND = "valueKind";
public static final String STATIC_PROPERTY_RANGE_DIRECTION = "direction";
public static final String DIRECTION_NONE = "http://entsoe.eu/ns/nc#RelativeDirectionKind.none";
public static final String DIRECTION_DOWN = "http://entsoe.eu/ns/nc#RelativeDirectionKind.down";
public static final String DIRECTION_UP = "http://entsoe.eu/ns/nc#RelativeDirectionKind.up";
public static final String VALUE_KIND_ABSOLUTE = "http://entsoe.eu/ns/nc#ValueOffsetKind.absolute";

public enum RelativeDirectionKind {
NONE("none"),
DOWN("down"),
UP("up");

RelativeDirectionKind(String name) {
this.name = name;
}

private final String name;
private static final String URL = ENTSOE_NS_NC_URL + "#RelativeDirectionKind.";

@Override
public String toString() {
return RelativeDirectionKind.URL + this.name;
}
}

public enum ValueOffsetKind {
ABSOLUTE("absolute");

ValueOffsetKind(String name) {
this.name = name;
}

private final String name;
private static final String URL = ENTSOE_NS_NC_URL + "#ValueOffsetKind.";

@Override
public String toString() {
return ValueOffsetKind.URL + this.name;
}
}

public enum RemedialActionKind {
CURATIVE("curative"),
Expand Down Expand Up @@ -172,8 +231,6 @@ public String toString() {

public static final String REQUEST_VOLTAGE_LIMIT_IS_INFINITE_DURATION = "isInfiniteDuration";

public static final String ASSESSED_ELEMENT_FILE_KEYWORD = "AE";

public static final String ENTSOE_NS_NC_URL = "http://entsoe.eu/ns/nc";

public static final List<String> CURRENT_LIMIT_POSSIBLE_ALIASES_BY_TYPE_LEFT = List.of("CGMES.Terminal1", "CGMES.Terminal_Boundary_1");
Expand Down Expand Up @@ -219,12 +276,12 @@ public String toString() {
}
}

public enum LimitDirectionKind {
public enum OperationalLimitDirectionKind {
ABSOLUTE("absoluteValue"),
HIGH("high"),
LOW("low");

LimitDirectionKind(String direction) {
OperationalLimitDirectionKind(String direction) {
this.direction = direction;
}

Expand All @@ -233,16 +290,14 @@ public enum LimitDirectionKind {

@Override
public String toString() {
return LimitDirectionKind.URL + this.direction;
return OperationalLimitDirectionKind.URL + this.direction;
}
}

/**
* requests for angle cnec
*/

public static final String EQUIPMENT_RELIABILITY_FILE_KEYWORD = "ER";
public static final String REQUEST_ANGLE_REFERENCE_TERMINAL = "AngleReferenceTerminal";
public static final String REQUEST_IS_FLOW_TO_REF_TERMINAL = "isFlowToRefTerminal";
public static final String REQUEST_ANGLE_LIMIT = "angleLimit";

Expand All @@ -262,4 +317,10 @@ public String toString() {
return this.type;
}
}

public enum HeaderValidity {
OK,
INVALID_KEYWORD,
INVALID_INTERVAL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@
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.api.ElementaryCreationContext;
import com.farao_community.farao.data.crac_creation.creator.csa_profile.crac_creator.cnec.CsaProfileCnecCreationContext;
import com.farao_community.farao.data.crac_creation.creator.csa_profile.crac_creator.contingency.CsaProfileContingencyCreationContext;
import com.farao_community.farao.data.crac_creation.creator.csa_profile.crac_creator.remedial_action.CsaProfileRemedialActionCreationContext;

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

/**
* @author Jean-Pierre Arnould {@literal <jean-pierre.arnould at rte-france.com>}
Expand All @@ -30,11 +26,11 @@ public class CsaProfileCracCreationContext implements CracCreationContext {

private boolean isCreationSuccessful;

private Set<CsaProfileContingencyCreationContext> contingencyCreationContexts;
private Set<CsaProfileElementaryCreationContext> contingencyCreationContexts;

private Set<CsaProfileRemedialActionCreationContext> remedialActionCreationContexts;
private Set<CsaProfileElementaryCreationContext> remedialActionCreationContexts;

private Set<CsaProfileCnecCreationContext> cnecCreationContexts;
private Set<CsaProfileElementaryCreationContext> cnecCreationContexts;

private CracCreationReport creationReport;

Expand Down Expand Up @@ -80,32 +76,32 @@ public String getNetworkName() {
return this.networkName;
}

public void setContingencyCreationContexts(Set<CsaProfileContingencyCreationContext> contingencyCreationContexts) {
this.contingencyCreationContexts = contingencyCreationContexts.stream().collect(Collectors.toSet());
public void setContingencyCreationContexts(Set<CsaProfileElementaryCreationContext> contingencyCreationContexts) {
this.contingencyCreationContexts = new HashSet<>(contingencyCreationContexts);
}

public Set<CsaProfileContingencyCreationContext> getContingencyCreationContexts() {
public Set<CsaProfileElementaryCreationContext> getContingencyCreationContexts() {
return new HashSet<>(this.contingencyCreationContexts);
}

public Set<CsaProfileRemedialActionCreationContext> getRemedialActionCreationContexts() {
public Set<CsaProfileElementaryCreationContext> getRemedialActionCreationContexts() {
return new HashSet<>(remedialActionCreationContexts);
}

public CsaProfileRemedialActionCreationContext getRemedialActionCreationContext(String nativeId) {
public CsaProfileElementaryCreationContext getRemedialActionCreationContext(String nativeId) {
return remedialActionCreationContexts.stream().filter(rac -> rac.getNativeId().equals(nativeId)).findFirst().orElse(null);
}

public void setRemedialActionCreationContexts(Set<CsaProfileRemedialActionCreationContext> remedialActionCreationContexts) {
public void setRemedialActionCreationContexts(Set<CsaProfileElementaryCreationContext> remedialActionCreationContexts) {
this.remedialActionCreationContexts = remedialActionCreationContexts;
}

public void setCnecCreationContexts(Set<CsaProfileCnecCreationContext> cnecCreationContexts) {
this.cnecCreationContexts = cnecCreationContexts.stream().collect(Collectors.toSet());
public void setCnecCreationContexts(Set<CsaProfileElementaryCreationContext> cnecCreationContexts) {
this.cnecCreationContexts = new HashSet<>(cnecCreationContexts);
}

public Set<CsaProfileCnecCreationContext> getCnecCreationContexts() {
return this.cnecCreationContexts.stream().collect(Collectors.toSet());
public Set<CsaProfileElementaryCreationContext> getCnecCreationContexts() {
return new HashSet<>(this.cnecCreationContexts);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,26 @@ public static void checkNormalEnabled(PropertyBag propertyBag, String remedialAc
}
}

public static CsaProfileConstants.HeaderValidity checkProfileHeader(PropertyBag propertyBag, CsaProfileConstants.CsaProfile csaProfileKeyword, OffsetDateTime importTimestamp) {
if (!checkProfileKeyword(propertyBag, csaProfileKeyword)) {
return CsaProfileConstants.HeaderValidity.INVALID_KEYWORD;
}
if (!checkProfileValidityInterval(propertyBag, importTimestamp)) {
return CsaProfileConstants.HeaderValidity.INVALID_INTERVAL;
}
return CsaProfileConstants.HeaderValidity.OK;
}

private static boolean checkProfileValidityInterval(PropertyBag propertyBag, OffsetDateTime importTimestamp) {
String startTime = propertyBag.get(CsaProfileConstants.REQUEST_HEADER_START_DATE);
String endTime = propertyBag.get(CsaProfileConstants.REQUEST_HEADER_END_DATE);
return isValidInterval(importTimestamp, startTime, endTime);
}

private static boolean checkProfileKeyword(PropertyBag propertyBag, CsaProfileConstants.CsaProfile csaProfileKeyword) {
String keyword = propertyBag.get(CsaProfileConstants.REQUEST_HEADER_KEYWORD);
return csaProfileKeyword.getKeyword().equals(keyword);
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.farao_community.farao.data.crac_creation.creator.csa_profile.crac_creator;

import com.farao_community.farao.data.crac_creation.creator.api.ElementaryCreationContext;
import com.farao_community.farao.data.crac_creation.creator.api.ImportStatus;

public final class CsaProfileElementaryCreationContext implements ElementaryCreationContext {
private final String nativeId;
private final String elementId;
private final String elementName;
private final ImportStatus importStatus;
private final String importStatusDetail;
private final boolean isAltered;

private CsaProfileElementaryCreationContext(String nativeId, String elementId, String elementName, ImportStatus importStatus, String importStatusDetail, boolean isAltered) {
this.nativeId = nativeId;
this.elementId = elementId;
this.elementName = elementName;
this.importStatus = importStatus;
this.importStatusDetail = importStatusDetail;
this.isAltered = isAltered;
}

public static CsaProfileElementaryCreationContext imported(String nativeId, String elementId, String elementName, String importStatusDetail, boolean isAltered) {
return new CsaProfileElementaryCreationContext(nativeId, elementId, elementName, ImportStatus.IMPORTED, importStatusDetail, isAltered);
}

public static CsaProfileElementaryCreationContext notImported(String nativeId, ImportStatus importStatus, String importStatusDetail) {
return new CsaProfileElementaryCreationContext(nativeId, null, null, importStatus, importStatusDetail, false);
}

@Override
public String getNativeId() {
return this.nativeId;
}

public String getElementId() {
return this.elementId;
}

public String getElementName() {
return this.elementName;
}

@Override
public boolean isImported() {
return ImportStatus.IMPORTED.equals(this.importStatus);
}

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

@Override
public ImportStatus getImportStatus() {
return this.importStatus;
}

@Override
public String getImportStatusDetail() {
return this.importStatusDetail;
}
}
Loading