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

Create action to change shunt compensator position #2497

Merged
merged 7 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
@@ -0,0 +1,38 @@
/**
* 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/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.security.action;

/**
* @author Miora Vedelago <miora.ralambotiana at rte-france.com>
*/
public class ShuntCompensatorPositionAction extends AbstractAction {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Position or section?


public static final String NAME = "SHUNT_COMPENSATOR_POSITION";

private final String shuntCompensatorId;
private final int sectionCount;

ShuntCompensatorPositionAction(String id, String shuntCompensatorId, int sectionCount) {
super(id);
this.shuntCompensatorId = shuntCompensatorId;
this.sectionCount = sectionCount;
}

@Override
public String getType() {
return NAME;
}

public String getShuntCompensatorId() {
return shuntCompensatorId;
}

public int getSectionCount() {
return sectionCount;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* 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/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.security.action;

/**
* @author Miora Vedelago <miora.ralambotiana at rte-france.com>
*/
public class ShuntCompensatorPositionActionBuilder {

private String id;
private String shuntCompensatorId;
private Integer sectionCount = null;

public ShuntCompensatorPositionAction build() {
if (sectionCount == null) {
throw new IllegalArgumentException("sectionCount in undefined");
}
if (sectionCount < 0) {
miovd marked this conversation as resolved.
Show resolved Hide resolved
throw new IllegalArgumentException("sectionCount should be positive for a shunt compensator");
}
return new ShuntCompensatorPositionAction(id, shuntCompensatorId, sectionCount);
}

public ShuntCompensatorPositionActionBuilder withId(String id) {
this.id = id;
return this;
}

public ShuntCompensatorPositionActionBuilder withShuntCompensatorId(String shuntCompensatorId) {
this.shuntCompensatorId = shuntCompensatorId;
return this;
}

public ShuntCompensatorPositionActionBuilder withSectionCount(int sectionCount) {
this.sectionCount = sectionCount;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ private void configureActionsSerialization() {
registerActionType(GeneratorAction.class, GeneratorAction.NAME, new GeneratorActionSerializer(), new GeneratorActionDeserializer());
registerActionType(LoadAction.class, LoadAction.NAME, new LoadActionSerializer(), new LoadActionDeserializer());
registerActionType(HvdcAction.class, HvdcAction.NAME, new HvdcActionSerializer(), new HvdcActionDeserializer());
registerActionType(GeneratorAction.class, GeneratorAction.NAME,
new GeneratorActionSerializer(), new GeneratorActionDeserializer());
registerActionType(LoadAction.class, LoadAction.NAME,
new LoadActionSerializer(), new LoadActionDeserializer());
registerActionType(ShuntCompensatorPositionAction.class, ShuntCompensatorPositionAction.NAME,
new ShuntCompensatorPositionActionSerializer(), new ShuntCompensatorPositionActionDeserializer());
}

private <T> void registerActionType(Class<T> actionClass, String typeName, JsonSerializer<T> serializer, JsonDeserializer<T> deserializer) {
Expand Down
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/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.security.json.action;

import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.powsybl.commons.json.JsonUtil;
import com.powsybl.security.action.ShuntCompensatorPositionAction;
import com.powsybl.security.action.ShuntCompensatorPositionActionBuilder;

import java.io.IOException;

/**
* @author Miora Vedelago <miora.ralambotiana at rte-france.com>
*/
public class ShuntCompensatorPositionActionDeserializer extends StdDeserializer<ShuntCompensatorPositionAction> {

public ShuntCompensatorPositionActionDeserializer() {
super(ShuntCompensatorPositionAction.class);
}

private static class ParsingContext {
String id;
String shuntCompensatorId;
Integer sectionCount = null;
}

@Override
public ShuntCompensatorPositionAction deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {
miovd marked this conversation as resolved.
Show resolved Hide resolved
ParsingContext context = new ParsingContext();
JsonUtil.parsePolymorphicObject(jsonParser, name -> {
switch (name) {
case "type":
if (!ShuntCompensatorPositionAction.NAME.equals(jsonParser.nextTextValue())) {
throw JsonMappingException.from(jsonParser, "Expected type " + ShuntCompensatorPositionAction.NAME);
}
return true;
case "id":
context.id = jsonParser.nextTextValue();
return true;
case "shuntCompensatorId":
context.shuntCompensatorId = jsonParser.nextTextValue();
return true;
case "sectionCount":
jsonParser.nextToken();
context.sectionCount = jsonParser.getValueAsInt();
return true;
default:
return false;
}
});
return new ShuntCompensatorPositionActionBuilder()
.withId(context.id)
.withShuntCompensatorId(context.shuntCompensatorId)
.withSectionCount(context.sectionCount)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* 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/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.security.json.action;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.powsybl.security.action.ShuntCompensatorPositionAction;

import java.io.IOException;

/**
* @author Miora Vedelago <miora.ralambotiana at rte-france.com>
*/
public class ShuntCompensatorPositionActionSerializer extends StdSerializer<ShuntCompensatorPositionAction> {

public ShuntCompensatorPositionActionSerializer() {
super(ShuntCompensatorPositionAction.class);
}

@Override
public void serialize(ShuntCompensatorPositionAction action, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField("type", action.getType());
jsonGenerator.writeStringField("id", action.getId());
jsonGenerator.writeStringField("shuntCompensatorId", action.getShuntCompensatorId());
jsonGenerator.writeNumberField("sectionCount", action.getSectionCount());
jsonGenerator.writeEndObject();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ void actionRoundTrip() throws IOException {
.withActivePowerSetpoint(12.0)
.withRelativeValue(true)
.build());
actions.add(new ShuntCompensatorPositionActionBuilder().withId("id22").withShuntCompensatorId("shuntId1").withSectionCount(5).build());
ActionList actionList = new ActionList(actions);
roundTripTest(actionList, ActionList::writeJsonFile, ActionList::readJsonFile, "/ActionFileTest.json");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,10 @@
"acEmulationEnabled" : false,
"activePowerSetpoint" : 12.0,
"relativeValue" : true
}, {
"type" : "SHUNT_COMPENSATOR_POSITION",
"id" : "id22",
"shuntCompensatorId" : "shuntId1",
"sectionCount" : 5
} ]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version" : "1.0",
miovd marked this conversation as resolved.
Show resolved Hide resolved
"version" : "1.1",
"actions" : [ {
"type" : "SWITCH",
"id" : "id1",
Expand Down Expand Up @@ -30,27 +30,27 @@
"type" : "PHASE_TAP_CHANGER_TAP_POSITION",
"id" : "id5",
"transformerId" : "transformerId1",
"value" : 5,
"tapPosition" : 5,
"relativeValue" : true,
"side" : "TWO"
}, {
"type" : "PHASE_TAP_CHANGER_TAP_POSITION",
"id" : "id6",
"transformerId" : "transformerId2",
"value" : 12,
"tapPosition" : 12,
"relativeValue" : false
}, {
"type" : "PHASE_TAP_CHANGER_TAP_POSITION",
"id" : "id7",
"transformerId" : "transformerId3",
"value" : -5,
"tapPosition" : -5,
"relativeValue" : true,
"side" : "ONE"
}, {
"type" : "PHASE_TAP_CHANGER_TAP_POSITION",
"id" : "id8",
"transformerId" : "transformerId3",
"value" : 2,
"tapPosition" : 2,
"relativeValue" : false,
"side" : "THREE"
}, {
Expand Down Expand Up @@ -87,14 +87,14 @@
"type" : "RATIO_TAP_CHANGER_TAP_POSITION",
"id" : "id14",
"transformerId" : "transformerId4",
"value" : 2,
"tapPosition" : 2,
"relativeValue" : false,
"side" : "THREE"
}, {
"type" : "RATIO_TAP_CHANGER_TAP_POSITION",
"id" : "id15",
"transformerId" : "transformerId5",
"value" : 1,
"tapPosition" : 1,
"relativeValue" : true
}, {
"type" : "RATIO_TAP_CHANGER_REGULATION",
Expand Down Expand Up @@ -162,5 +162,10 @@
"acEmulationEnabled" : false,
"activePowerSetpoint" : 12.0,
"relativeValue" : true
}, {
"type" : "SHUNT_COMPENSATOR_POSITION",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, it's a bit strange to have new type of actions in v1.0 (or in v1.1), but it seems that this kind of forward-compatibility is the way the versions are dealt with here.

"id" : "id22",
"shuntCompensatorId" : "shuntId1",
"sectionCount" : 5
} ]
}