Skip to content

Commit

Permalink
CGMES import: make substations property bags distinct when their regi…
Browse files Browse the repository at this point in the history
…on is defined twice (in BD and IGM)

Signed-off-by: VEDELAGO MIORA <miora.ralambotiana@rte-france.com>
  • Loading branch information
miovd committed Mar 20, 2023
1 parent 52770a1 commit 456d610
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public Network convert(Reporter reporter) {
cgmes.computedTerminals().forEach(t -> context.terminalMapping().buildTopologicalNodeCgmesTerminalsMapping(t));
cgmes.regulatingControls().forEach(p -> context.regulatingControlMapping().cacheRegulatingControls(p));

convert(cgmes.substations(), s -> new SubstationConversion(s, context));
convert(cgmes.substations().distinct("Substation", message -> context.ignored("PropertyBag", message)), s -> new SubstationConversion(s, context));
convert(cgmes.voltageLevels(), vl -> new VoltageLevelConversion(vl, context));
PropertyBags nodes = context.nodeBreaker()
? cgmes.connectivityNodes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;

/**
Expand All @@ -29,6 +31,19 @@ public PropertyBags(Collection<PropertyBag> ps) {
super(ps);
}

public PropertyBags distinct(String property, Consumer<Supplier<String>> ignoredLog) {
PropertyBags distinct = new PropertyBags();
forEach(bag -> {
if (distinct.stream().noneMatch(b -> b.getId(property).equals(bag.getId(property)))) {
distinct.add(bag);
} else {
ignoredLog.accept(() -> String.format("PropertyBag with property %s of value %s already exists. PropertyBag %s is ignored.",
property, bag.getId(property), bag.tabulate()));
}
});
return distinct;
}

public List<String> pluck(String property) {
return stream()
.map(r -> r.get(property))
Expand Down

0 comments on commit 456d610

Please sign in to comment.