Skip to content

Commit

Permalink
add more specific logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Seddik Yengui committed Nov 9, 2023
1 parent 37a1fe4 commit d737c5c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ public enum Operator {
SUBTRACTION,
MULTIPLICATION,
DIVISION,
MODULUS
PERCENTAGE
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ private void applyFormulaOnFilterEquipments(Network network,
var filterEquipments = exportFilters.get(filterInfos.getId());
filterEquipments.getIdentifiableAttributes().forEach(attributes -> applyFormula(network,
attributes.getId(),
formulaInfos));
formulaInfos,
formulaReports));

formulaReports.add(Report.builder()
.withKey("byFormulaModificationFormulaFilter_" + formulaReports.size())
Expand Down Expand Up @@ -134,7 +135,8 @@ private Map<UUID, FilterEquipments> getUuidFilterEquipmentsMap(Network network,

private void applyFormula(Network network,
String identifiableId,
FormulaInfos formulaInfos) {
FormulaInfos formulaInfos,
List<Report> reports) {
Identifiable<?> identifiable = network.getIdentifiable(identifiableId);
Double value1 = formulaInfos.getFieldOrValue1().getRefOrValue(identifiable);
Double value2 = formulaInfos.getFieldOrValue2().getRefOrValue(identifiable);
Expand All @@ -148,6 +150,16 @@ private void applyFormula(Network network,
newValue);
default -> throw new NetworkModificationException(NetworkModificationException.Type.BY_FORMULA_MODIFICATION_ERROR, "Unsupported equipment");
}

reports.add(Report.builder()
.withKey("EquipmentModifiedReport_" + reports.size())
.withDefaultMessage(String.format(" %s id : %s, new value of %s : %s",
modificationInfos.getIdentifiableType(),
identifiable.getId(),
formulaInfos.getEditedField(),
newValue))
.withSeverity(TypedValue.TRACE_SEVERITY)
.build());
}

private Double applyOperation(Operator operator, Double value1, Double value2) {
Expand All @@ -167,7 +179,7 @@ private Double applyOperation(Operator operator, Double value1, Double value2) {
yield value1 / value2;
}
}
case MODULUS -> value1 % value2;
case PERCENTAGE -> value1 * (value2 / 100);
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ public void testCopy() throws Exception {
}

void checkCreationApplicationStatus(ByFormulaModificationInfos byFormulaModificationInfos,
NetworkModificationResult.ApplicationStatus withErrors) throws Exception {
NetworkModificationResult.ApplicationStatus applicationStatus) throws Exception {
String modificationToCreateJson = mapper.writeValueAsString(byFormulaModificationInfos);

MvcResult mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(modificationToCreateJson).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andReturn();

Optional<NetworkModificationResult> networkModificationResult = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { });
assertTrue(networkModificationResult.isPresent());
assertEquals(withErrors, networkModificationResult.get().getApplicationStatus());
assertEquals(applicationStatus, networkModificationResult.get().getApplicationStatus());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ List<FormulaInfos> getFormulaInfos() {

FormulaInfos formulaInfos2 = getFormulaInfo(BatteryField.MINIMUM_ACTIVE_POWER.name(),
List.of(filter3),
Operator.MODULUS,
minActivePowerRef,
ReferenceFieldOrValue.builder().value(30.).build());
Operator.PERCENTAGE,
ReferenceFieldOrValue.builder().value(30.).build(),
minActivePowerRef);

FormulaInfos formulaInfos3 = getFormulaInfo(BatteryField.ACTIVE_POWER_SET_POINT.name(),
List.of(filter5),
Expand Down Expand Up @@ -228,11 +228,6 @@ List<FormulaInfos> getUpdatedFormulaInfos() {
.name("filter3")
.build();

var filter4 = FilterInfos.builder()
.id(FILTER_ID_4)
.name("filter4")
.build();

var filter5 = FilterInfos.builder()
.id(FILTER_ID_5)
.name("filter5")
Expand All @@ -248,9 +243,9 @@ List<FormulaInfos> getUpdatedFormulaInfos() {

FormulaInfos formulaInfos2 = FormulaInfos.builder()
.editedField(BatteryField.MINIMUM_ACTIVE_POWER.name())
.fieldOrValue1(ReferenceFieldOrValue.builder().equipmentField(BatteryField.MINIMUM_ACTIVE_POWER.name()).build())
.fieldOrValue2(ReferenceFieldOrValue.builder().value(35.).build())
.operator(Operator.MODULUS)
.fieldOrValue1(ReferenceFieldOrValue.builder().value(35.).build())
.fieldOrValue2(ReferenceFieldOrValue.builder().equipmentField(BatteryField.MINIMUM_ACTIVE_POWER.name()).build())
.operator(Operator.PERCENTAGE)
.filters(List.of(filter3))
.build();

Expand Down Expand Up @@ -279,13 +274,13 @@ protected void assertAfterNetworkModificationCreation() {
assertEquals(380, getNetwork().getBattery(BATTERY_ID_3).getTargetP(), 0);
assertEquals(400, getNetwork().getBattery(BATTERY_ID_4).getMaxP(), 0);

assertEquals(20, getNetwork().getBattery(BATTERY_ID_5).getMinP(), 0);
assertEquals(15, getNetwork().getBattery(BATTERY_ID_5).getMinP(), 0);
assertEquals(70, getNetwork().getBattery(BATTERY_ID_5).getTargetQ(), 0);
ActivePowerControl activePowerControl5 = getNetwork().getBattery(BATTERY_ID_5).getExtension(ActivePowerControl.class);
assertNotNull(activePowerControl5);
assertEquals(8, activePowerControl5.getDroop(), 0);

assertEquals(20, getNetwork().getBattery(BATTERY_ID_6).getMinP(), 0);
assertEquals(60, getNetwork().getBattery(BATTERY_ID_6).getMinP(), 0);
}

@Override
Expand Down

0 comments on commit d737c5c

Please sign in to comment.