com.powsybl.dataframe.network.AbstractNetworkDataframeMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pypowsybl Show documentation
Show all versions of pypowsybl Show documentation
A C interface to powsybl, for pypowsybl implementation
The newest version!
/**
* Copyright (c) 2021-2022, 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.dataframe.network;
import com.powsybl.dataframe.*;
import com.powsybl.dataframe.update.UpdatingDataframe;
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.Network;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
/**
* @author Sylvain Leclerc {@literal }
*/
public abstract class AbstractNetworkDataframeMapper extends AbstractDataframeMapper implements NetworkDataframeMapper {
private final boolean addProperties;
protected AbstractNetworkDataframeMapper(List> seriesMappers, boolean addProperties) {
super(seriesMappers);
this.addProperties = addProperties;
}
@Override
public void createDataframe(Network network, DataframeHandler dataframeHandler, DataframeFilter dataframeFilter, NetworkDataframeContext context) {
List items = getFilteredItems(network, dataframeFilter, context);
List> mappers = new ArrayList<>(getSeriesMappers(dataframeFilter));
if (addProperties) {
mappers.addAll(getPropertiesSeries(items, dataframeFilter));
}
dataframeHandler.allocate(mappers.size());
mappers.forEach(mapper -> mapper.createSeries(items, dataframeHandler, context));
}
protected List getFilteredItems(Network network, DataframeFilter dataframeFilter, NetworkDataframeContext context) {
Optional optionalUpdatingDataframe = dataframeFilter.getSelectingDataframe();
if (optionalUpdatingDataframe.isEmpty()) {
return getItems(network, context);
} else {
UpdatingDataframe selectedDataframe = optionalUpdatingDataframe.get();
return IntStream.range(0, selectedDataframe.getRowCount()).mapToObj(i -> getItem(network, selectedDataframe, i, context)).collect(Collectors.toList());
}
}
private List> getPropertiesSeries(List items, DataframeFilter dataframeFilter) {
Stream propertyNames = items.stream()
.map(Identifiable.class::cast)
.filter(Identifiable::hasProperty)
.flatMap(e -> e.getPropertyNames().stream())
.distinct();
return propertyNames
.map(property -> new StringSeriesMapper(property, t -> ((Identifiable>) t).getProperty(property), false))
.filter(mapper -> filterMapper(mapper, dataframeFilter))
.collect(Collectors.toList());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy