Skip to content

Commit

Permalink
Merge branch 'main' into too_many_logs
Browse files Browse the repository at this point in the history
  • Loading branch information
annetill authored Oct 18, 2023
2 parents b45d34d + f4d55bd commit e74e9f0
Show file tree
Hide file tree
Showing 14 changed files with 314 additions and 524 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,12 @@ public void updateSeries(T object, UpdatingDataframe updatingDataframe) {
}
String seriesName = column.getName();
SeriesMapper<U> mapper = seriesMappers.get(seriesName);
ColumnUpdater<U> updater;
switch (column.getType()) {
case STRING:
updater = new StringColumnUpdater<>(updatingDataframe.getStrings(seriesName), mapper);
break;
case DOUBLE:
updater = new DoubleColumnUpdater<>(updatingDataframe.getDoubles(seriesName), mapper);
break;
case INT:
updater = new IntColumnUpdater<>(updatingDataframe.getInts(seriesName), mapper);
break;
default:
throw new IllegalStateException("Unexpected series type for update: " + column.getType());
}
ColumnUpdater<U> updater = switch (column.getType()) {
case STRING -> new StringColumnUpdater<>(updatingDataframe.getStrings(seriesName), mapper);
case DOUBLE -> new DoubleColumnUpdater<>(updatingDataframe.getDoubles(seriesName), mapper);
case INT -> new IntColumnUpdater<>(updatingDataframe.getInts(seriesName), mapper);
default -> throw new IllegalStateException("Unexpected series type for update: " + column.getType());
};
updaters.add(updater);
}

Expand All @@ -152,16 +144,12 @@ public Collection<SeriesMapper<U>> getSeriesMappers(DataframeFilter dataframeFil
}

protected boolean filterMapper(SeriesMapper<U> mapper, DataframeFilter dataframeFilter) {
switch (dataframeFilter.getAttributeFilterType()) {
case DEFAULT_ATTRIBUTES:
return mapper.getMetadata().isDefaultAttribute() || mapper.getMetadata().isIndex();
case INPUT_ATTRIBUTES:
return dataframeFilter.getInputAttributes().contains(mapper.getMetadata().getName()) || mapper.getMetadata().isIndex();
case ALL_ATTRIBUTES:
return true;
default:
throw new IllegalStateException("Unexpected attribute filter type: " + dataframeFilter.getAttributeFilterType());
}
return switch (dataframeFilter.getAttributeFilterType()) {
case DEFAULT_ATTRIBUTES -> mapper.getMetadata().isDefaultAttribute() || mapper.getMetadata().isIndex();
case INPUT_ATTRIBUTES ->
dataframeFilter.getInputAttributes().contains(mapper.getMetadata().getName()) || mapper.getMetadata().isIndex();
case ALL_ATTRIBUTES -> true;
};
}

protected abstract List<U> getItems(T object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,14 @@ static NetworkDataframeMapper generators() {
.build();
}

private static String getRegulatedElementId(Injection injection) {
private static String getRegulatedElementId(Injection<?> injection) {
Terminal terminal;
if (injection instanceof Generator) {
terminal = ((Generator) injection).getRegulatingTerminal();
} else if (injection instanceof VscConverterStation) {
terminal = ((VscConverterStation) injection).getRegulatingTerminal();
} else if (injection instanceof StaticVarCompensator) {
terminal = ((StaticVarCompensator) injection).getRegulatingTerminal();
if (injection instanceof Generator generator) {
terminal = generator.getRegulatingTerminal();
} else if (injection instanceof VscConverterStation converterStation) {
terminal = converterStation.getRegulatingTerminal();
} else if (injection instanceof StaticVarCompensator svc) {
terminal = svc.getRegulatingTerminal();
} else {
throw new UnsupportedOperationException(String.format("%s is neither a generator, a vsc station or a var static compensator", injection.getId()));
}
Expand All @@ -292,7 +292,7 @@ private static String getRegulatedElementId(Injection injection) {
return terminal.getConnectable() != null ? terminal.getConnectable().getId() : null;
}

private static void setRegulatedElement(Injection injection, String elementId) {
private static void setRegulatedElement(Injection<?> injection, String elementId) {
Network network = injection.getNetwork();
Identifiable<?> identifiable = network.getIdentifiable(elementId);
if (identifiable instanceof Injection) {
Expand Down Expand Up @@ -420,10 +420,9 @@ static NetworkDataframeMapper shuntsNonLinear() {
static Triple<String, ShuntCompensatorNonLinearModel.Section, Integer> getShuntSectionNonlinear(Network network, UpdatingDataframe dataframe, int index) {
ShuntCompensator shuntCompensator = network.getShuntCompensator(dataframe.getStringValue("id", index)
.orElseThrow(() -> new PowsyblException("id is missing")));
if (!(shuntCompensator.getModel() instanceof ShuntCompensatorNonLinearModel)) {
if (!(shuntCompensator.getModel() instanceof ShuntCompensatorNonLinearModel shuntNonLinear)) {
throw new PowsyblException("shunt with id " + shuntCompensator.getId() + "has not a non linear model");
} else {
ShuntCompensatorNonLinearModel shuntNonLinear = (ShuntCompensatorNonLinearModel) shuntCompensator.getModel();
int section = dataframe.getIntValue("section", index)
.orElseThrow(() -> new PowsyblException("section is missing"));
return Triple.of(shuntCompensator.getId(), shuntNonLinear.getAllSections().get(section), section);
Expand Down Expand Up @@ -970,30 +969,32 @@ private static Terminal getTerminal(Network network, UpdatingDataframe dataframe
}
SideEnum side = SideEnum.valueOf(sideStr);
switch (side) {
case ONE:
case ONE -> {
if (connectable instanceof Branch) {
return ((Branch<?>) connectable).getTerminal(Branch.Side.ONE);
} else if (connectable instanceof ThreeWindingsTransformer) {
return ((ThreeWindingsTransformer) connectable).getTerminal(ThreeWindingsTransformer.Side.ONE);
} else if (connectable instanceof ThreeWindingsTransformer twt) {
return twt.getTerminal(ThreeWindingsTransformer.Side.ONE);
} else {
throw new PowsyblException("no side ONE for this element");
}
case TWO:
}
case TWO -> {
if (connectable instanceof Branch) {
return ((Branch<?>) connectable).getTerminal(Branch.Side.TWO);
} else if (connectable instanceof ThreeWindingsTransformer) {
return ((ThreeWindingsTransformer) connectable).getTerminal(ThreeWindingsTransformer.Side.TWO);
} else if (connectable instanceof ThreeWindingsTransformer twt) {
return twt.getTerminal(ThreeWindingsTransformer.Side.TWO);
} else {
throw new PowsyblException("no side TWO for this element");
}
case THREE:
if (connectable instanceof ThreeWindingsTransformer) {
return ((ThreeWindingsTransformer) connectable).getTerminal(ThreeWindingsTransformer.Side.THREE);
}
case THREE -> {
if (connectable instanceof ThreeWindingsTransformer twt) {
return twt.getTerminal(ThreeWindingsTransformer.Side.THREE);
} else {
throw new PowsyblException("no side THREE for this element");
}
default:
throw new PowsyblException("side must be ONE, TWO or THREE");
}
default -> throw new PowsyblException("side must be ONE, TWO or THREE");
}
}

Expand Down Expand Up @@ -1149,11 +1150,11 @@ private static NetworkDataframeMapper aliases() {
return NetworkDataframeMapperBuilder.ofStream(NetworkDataframes::getAliasesData)
.stringsIndex("id", pair -> pair.getLeft().getId())
.strings("alias", Pair::getRight)
.strings("alias_type", pair -> ((Optional<String>) pair.getLeft().getAliasType(pair.getRight())).orElse(""))
.strings("alias_type", pair -> pair.getLeft().getAliasType(pair.getRight()).orElse(""))
.build();
}

private static Stream<Pair<Identifiable, String>> getAliasesData(Network network) {
private static Stream<Pair<Identifiable<?>, String>> getAliasesData(Network network) {
return network.getIdentifiables().stream()
.flatMap(identifiable -> identifiable.getAliases().stream()
.map(alias -> Pair.of(identifiable, alias)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private static void createLimits(LoadingLimitsAdder adder, int row, OperationalL
if (acceptableDuration == -1) {
applyIfPresent(series.getValues(), row, adder::setPermanentLimit);
} else {
LoadingLimitsAdder.TemporaryLimitAdder temporaryLimitAdder = adder.beginTemporaryLimit()
LoadingLimitsAdder.TemporaryLimitAdder<?> temporaryLimitAdder = adder.beginTemporaryLimit()
.setAcceptableDuration(acceptableDuration);
applyIfPresent(series.getNames(), row, temporaryLimitAdder::setName);
applyIfPresent(series.getValues(), row, temporaryLimitAdder::setValue);
Expand Down Expand Up @@ -195,26 +195,23 @@ public ActivePowerLimitsAdder newActivePowerLimits() {
}

private static Branch.Side toBranchSide(TemporaryLimitData.Side side) {
switch (side) {
case ONE:
return Branch.Side.ONE;
case TWO:
return Branch.Side.TWO;
default:
throw new PowsyblException("Invalid value for branch side: " + side);
}
return switch (side) {
case ONE -> Branch.Side.ONE;
case TWO -> Branch.Side.TWO;
default -> throw new PowsyblException("Invalid value for branch side: " + side);
};
}

private static FlowsLimitsHolder getLimitsHolder(Network network, IdentifiableType identifiableType, String elementId, TemporaryLimitData.Side side) {
switch (identifiableType) {
case LINE:
case TWO_WINDINGS_TRANSFORMER:
case LINE, TWO_WINDINGS_TRANSFORMER -> {
Branch<?> branch = network.getBranch(elementId);
if (branch == null) {
throw new PowsyblException("Branch " + elementId + " does not exist.");
}
return getBranchAsFlowsLimitsHolder(branch, toBranchSide(side));
case DANGLING_LINE:
}
case DANGLING_LINE -> {
DanglingLine dl = network.getDanglingLine(elementId);
if (dl == null) {
throw new PowsyblException("Dangling line " + elementId + " does not exist.");
Expand All @@ -223,37 +220,31 @@ private static FlowsLimitsHolder getLimitsHolder(Network network, IdentifiableTy
throw new PowsyblException("Invalid value for dangling line side: " + side + ", must be NONE");
}
return dl;
case THREE_WINDINGS_TRANSFORMER:
}
case THREE_WINDINGS_TRANSFORMER -> {
ThreeWindingsTransformer transformer = network.getThreeWindingsTransformer(elementId);
if (transformer == null) {
throw new PowsyblException("Three windings transformer " + elementId + " does not exist.");
}
switch (side) {
case ONE:
return transformer.getLeg1();
case TWO:
return transformer.getLeg2();
case THREE:
return transformer.getLeg3();
default:
throw new PowsyblException("Invalid value for three windings transformer side: " + side);
}
default:
throw new PowsyblException("Cannot create operational limits for element of type " + identifiableType);
return switch (side) {
case ONE -> transformer.getLeg1();
case TWO -> transformer.getLeg2();
case THREE -> transformer.getLeg3();
default -> throw new PowsyblException("Invalid value for three windings transformer side: " + side);
};
}
default ->
throw new PowsyblException("Cannot create operational limits for element of type " + identifiableType);
}
}

private static LoadingLimitsAdder getAdder(Network network, IdentifiableType identifiableType, String elementId, LimitType type, TemporaryLimitData.Side side) {
FlowsLimitsHolder limitsHolder = getLimitsHolder(network, identifiableType, elementId, side);
switch (type) {
case CURRENT:
return limitsHolder.newCurrentLimits();
case ACTIVE_POWER:
return limitsHolder.newActivePowerLimits();
case APPARENT_POWER:
return limitsHolder.newApparentPowerLimits();
default:
throw new PowsyblException(String.format("Limit type %s does not exist.", type));
}
return switch (type) {
case CURRENT -> limitsHolder.newCurrentLimits();
case ACTIVE_POWER -> limitsHolder.newActivePowerLimits();
case APPARENT_POWER -> limitsHolder.newApparentPowerLimits();
default -> throw new PowsyblException(String.format("Limit type %s does not exist.", type));
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private ActivePowerControl getOrThrow(Network network, String id) {
@Override
public NetworkDataframeMapper createMapper() {
return NetworkDataframeMapperBuilder.ofStream(this::itemsStream, this::getOrThrow)
.stringsIndex("id", ext -> ((Identifiable) ext.getExtendable()).getId())
.stringsIndex("id", ext -> ((Identifiable<?>) ext.getExtendable()).getId())
.doubles("droop", ActivePowerControl::getDroop, (c, d) -> c.setDroop((float) d))
.booleans("participate", ActivePowerControl::isParticipate, ActivePowerControl::setParticipate)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ private static class BranchObservabilitySeries {

void create(Network network, int row) {
String id = this.id.get(row);
Branch branch = network.getBranch(id);
Branch<?> branch = network.getBranch(id);
if (branch == null) {
throw new PowsyblException("Invalid branch id : could not find " + id);
}
BranchObservabilityAdder adder = (BranchObservabilityAdder) branch.newExtension(BranchObservabilityAdder.class);
BranchObservabilityAdder<?> adder = (BranchObservabilityAdder<?>) branch.newExtension(BranchObservabilityAdder.class);
SeriesUtils.applyBooleanIfPresent(observable, row, adder::withObservable);
SeriesUtils.applyIfPresent(p1StandardDeviation, row, adder::withStandardDeviationP1);
SeriesUtils.applyBooleanIfPresent(p1Redundant, row, adder::withRedundantP1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ private Stream<BranchObservability> itemsStream(Network network) {
.filter(Objects::nonNull);
}

private BranchObservability getOrThrow(Network network, String id) {
Branch branch = network.getBranch(id);
private BranchObservability<?> getOrThrow(Network network, String id) {
Branch<?> branch = network.getBranch(id);
if (branch == null) {
throw new PowsyblException("Invalid branch id : could not find " + id);
}
Expand All @@ -56,7 +56,7 @@ public ExtensionInformation getExtensionInformation() {
@Override
public NetworkDataframeMapper createMapper() {
return NetworkDataframeMapperBuilder.ofStream(this::itemsStream, this::getOrThrow)
.stringsIndex("id", branchObservability -> ((Branch) branchObservability.getExtendable()).getId())
.stringsIndex("id", branchObservability -> ((Branch<?>) branchObservability.getExtendable()).getId())
.booleans("observable", BranchObservability::isObservable)
.doubles("p1_standard_deviation", branchObservability -> branchObservability.getQualityP1() != null ?
branchObservability.getQualityP1().getStandardDeviation() : Double.NaN,
Expand Down
Loading

0 comments on commit e74e9f0

Please sign in to comment.