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

fix return impacts when active power control modification #378

Merged
merged 9 commits into from
Dec 1, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -765,37 +765,47 @@ public Reporter modifyActivePowerControlAttributes(ActivePowerControl<?> activeP
Reporter subReporter,
Reporter subReporterSetpoints) {
List<Report> reports = new ArrayList<>();
double oldDroop = Double.NaN;
boolean oldParticipate = false;
double droop = droopInfo != null ? droopInfo.getValue() : Double.NaN;
if (activePowerControl != null) {
oldDroop = activePowerControl.getDroop();
oldParticipate = activePowerControl.isParticipate();
}

if (participateInfo != null) {
activePowerControlAdder
.withParticipate(participateInfo.getValue());
reports.add(ModificationUtils.getInstance().buildModificationReport(activePowerControl != null ? activePowerControl.isParticipate() : null,
participateInfo.getValue(),
"Participate"));
} else {
activePowerControlAdder
.withParticipate(oldParticipate);
}

if (droopInfo != null) {
activePowerControlAdder
.withDroop(droop);
reports.add(ModificationUtils.getInstance().buildModificationReport(oldDroop,
droop,
"Droop"));
double oldDroop = activePowerControl.getDroop();
boolean oldParticipate = activePowerControl.isParticipate();
if (participateInfo != null) {
activePowerControl.setParticipate(participateInfo.getValue());
reports.add(ModificationUtils.getInstance().buildModificationReport(oldParticipate,
participateInfo.getValue(),
"Participate"));
}
if (droopInfo != null) {
activePowerControl.setDroop(droop);
reports.add(ModificationUtils.getInstance().buildModificationReport(oldDroop,
droop,
"Droop"));
}
} else {
// create new active power control extension if not exist
if (participateInfo != null) {
activePowerControlAdder
.withParticipate(participateInfo.getValue());
reports.add(ModificationUtils.getInstance().buildModificationReport(false,
Copy link
Contributor

Choose a reason for hiding this comment

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

won't this possibly make a report with the same old and new value

participateInfo.getValue(),
"Participate"));
} else {
activePowerControlAdder
.withParticipate(false);
}
if (droopInfo != null) {
activePowerControlAdder
.withDroop(droop);
reports.add(ModificationUtils.getInstance().buildModificationReport(Double.NaN,
droop,
"Droop"));
} else {
activePowerControlAdder
.withDroop(Double.NaN);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't this slightly better ?

activePowerControlAdder.withDroop(droop);
if (droopInfo != null) {            
    reports.add(ModificationUtils.getInstance().buildModificationReport(Double.NaN, droop, "Droop"));
}

activePowerControlAdder
.withDroop(oldDroop);
.add();
}
activePowerControlAdder
.add();

Reporter subReporterSetpoints2 = subReporterSetpoints;
if (subReporterSetpoints == null && !reports.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.junit.Test;
import org.junit.jupiter.api.Tag;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.util.CollectionUtils;

import java.util.*;
Expand Down Expand Up @@ -217,6 +218,40 @@ public void testDroopUnchanged() throws Exception {
assertEquals(18f, createdModification.getDroop().getValue());
}

@Test
public void testImpactsAfterActivePowerControlModifications() throws Exception {
BatteryModificationInfos batteryModificationInfos = (BatteryModificationInfos) buildModification();
String modificationToCreateJson = mapper.writeValueAsString(batteryModificationInfos);
mockMvc.perform(post(getNetworkModificationUri()).content(modificationToCreateJson).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andReturn();
Battery battery = getNetwork().getBattery("v3Battery");
assertEquals(0.1f, battery.getExtension(ActivePowerControl.class).getDroop());
assertEquals(true, battery.getExtension(ActivePowerControl.class).isParticipate());
//modify only droop
batteryModificationInfos.setDroop(new AttributeModification<>(0.5f, OperationType.SET));
modificationToCreateJson = mapper.writeValueAsString(batteryModificationInfos);
MvcResult mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(modificationToCreateJson).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andReturn();
//check impacts
String resultAsString = mvcResult.getResponse().getContentAsString();
NetworkModificationResult networkModificationResult = mapper.readValue(resultAsString, NetworkModificationResult.class);
assertEquals(1, networkModificationResult.getNetworkImpacts().size());
assertEquals(1, networkModificationResult.getImpactedSubstationsIds().size());
assertEquals("[s2]", networkModificationResult.getImpactedSubstationsIds().toString());
//modify only participate
batteryModificationInfos.setParticipate(new AttributeModification<>(false, OperationType.SET));
modificationToCreateJson = mapper.writeValueAsString(batteryModificationInfos);
mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(modificationToCreateJson).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andReturn();
//check impacts
resultAsString = mvcResult.getResponse().getContentAsString();
networkModificationResult = mapper.readValue(resultAsString, NetworkModificationResult.class);
assertEquals(1, networkModificationResult.getNetworkImpacts().size());
assertEquals(1, networkModificationResult.getImpactedSubstationsIds().size());
assertEquals("[s2]", networkModificationResult.getImpactedSubstationsIds().toString());

Meklo marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
public void testMinQGreaterThanMaxQ() throws Exception {
BatteryModificationInfos batteryModificationInfos = (BatteryModificationInfos) buildModification();
Expand Down