Skip to content

Commit

Permalink
Merge branch 'master' into versioneye
Browse files Browse the repository at this point in the history
  • Loading branch information
geofjamg committed Dec 1, 2016
2 parents 1f2d15d + 76b8332 commit 81d7a82
Show file tree
Hide file tree
Showing 28 changed files with 2,047 additions and 1,941 deletions.
@@ -1,5 +1,6 @@
/**
* Copyright (c) 2016, All partners of the iTesla project (http://www.itesla-project.eu/consortium)
* Copyright (c) 2016, 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/.
Expand All @@ -17,20 +18,38 @@ public enum ExportScope {
ONLY_MAIN_CC_AND_CONNECTABLE_GENERATORS_AND_SHUNTS,
ONLY_MAIN_CC_AND_CONNECTABLE_GENERATORS_AND_SHUNTS_AND_ALL_LOADS,
}

public enum ExportActionType {
CURATIVE("curative"),
PREVENTIVE("preventive");

private final String label;

private ExportActionType(String label) {
this.label = label;
}

public String getLabel() {
return label;
}
}

private ExportScope exportScope;

private boolean exportXNodes;

private ExportActionType actionType;

private boolean exportRatioTapChangerVoltageTarget;

public AmplExportConfig(ExportScope exportScope, boolean exportXNodes) {
this(exportScope, exportXNodes, false);
public AmplExportConfig(ExportScope exportScope, boolean exportXNodes, ExportActionType actionType) {
this(exportScope, exportXNodes, actionType, false);
}

public AmplExportConfig(ExportScope exportScope, boolean exportXNodes, boolean exportRatioTapChangerVoltageTarget) {
public AmplExportConfig(ExportScope exportScope, boolean exportXNodes, ExportActionType actionType, boolean exportRatioTapChangerVoltageTarget) {
this.exportScope = exportScope;
this.exportXNodes = exportXNodes;
this.actionType = actionType;
this.exportRatioTapChangerVoltageTarget = exportRatioTapChangerVoltageTarget;
}

Expand All @@ -50,6 +69,10 @@ public void setExportXNodes(boolean exportXNodes) {
this.exportXNodes = exportXNodes;
}

public ExportActionType getActionType() {
return actionType;
}

public boolean isExportRatioTapChangerVoltageTarget() {
return exportRatioTapChangerVoltageTarget;
}
Expand Down
@@ -1,5 +1,6 @@
/**
* Copyright (c) 2016, All partners of the iTesla project (http://www.itesla-project.eu/consortium)
* Copyright (c) 2016, 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/.
Expand Down Expand Up @@ -37,7 +38,7 @@ public void export(Network network, Properties parameters, DataSource dataSource
throw new ITeslaException("network is null");
}
try {
new AmplNetworkWriter(network, dataSource, new AmplExportConfig(AmplExportConfig.ExportScope.ONLY_MAIN_CC_AND_CONNECTABLE_GENERATORS_AND_SHUNTS, false)).write();
new AmplNetworkWriter(network, dataSource, new AmplExportConfig(AmplExportConfig.ExportScope.ONLY_MAIN_CC_AND_CONNECTABLE_GENERATORS_AND_SHUNTS, false, AmplExportConfig.ExportActionType.CURATIVE)).write();
} catch (IOException e) {
throw new ITeslaException(e);
}
Expand Down

Large diffs are not rendered by default.

@@ -1,5 +1,6 @@
/**
* Copyright (c) 2016, All partners of the iTesla project (http://www.itesla-project.eu/consortium)
* Copyright (c) 2016, 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/.
Expand All @@ -26,7 +27,8 @@ public enum AmplSubset implements IntCounter {
TEMPORARY_CURRENT_LIMIT(1),
THREE_WINDINGS_TRANSFO(1),
FAULT(1),
CURATIVE_ACTION(1);
CURATIVE_ACTION(1),
PREVENTIVE_ACTION(1);

private final int initialValue;

Expand Down
Expand Up @@ -33,7 +33,7 @@ public void write() throws Exception {
Network network = EurostagTutorialExample1Factory.create();

MemDataSource dataSource = new MemDataSource();
new AmplNetworkWriter(network, dataSource, new AmplExportConfig(AmplExportConfig.ExportScope.ALL, true))
new AmplNetworkWriter(network, dataSource, new AmplExportConfig(AmplExportConfig.ExportScope.ALL, true, AmplExportConfig.ExportActionType.CURATIVE))
.write();

assertEqualsToRef(dataSource, "_network_substations", "eurostag-tutorial-example1-substations.txt");
Expand Down
File renamed without changes.
File renamed without changes.
Expand Up @@ -18,19 +18,24 @@ public class CutEurostagNamingStrategy implements EurostagNamingStrategy {
public void fillDictionary(EurostagDictionary dictionary, NameType nameType, Set<String> iidmIds) {
iidmIds.forEach(iidmId -> {
if (!dictionary.iidmIdExists(iidmId)) {
String esgId = iidmId.length() > nameType.getLength() ? iidmId.substring(0, nameType.getLength())
: Strings.padEnd(iidmId, nameType.getLength(), ' ');
int counter = 0;
while (dictionary.esgIdExists(esgId)) {
String counterStr = Integer.toString(counter++);
if (counterStr.length() > nameType.getLength()) {
throw new RuntimeException("Renaming fatal error " + iidmId + " -> " + esgId);
}
esgId = esgId.substring(0, nameType.getLength() - counterStr.length()) + counterStr;
}
String esgId = getEsgId(dictionary, nameType, iidmId);
dictionary.add(iidmId, esgId);
}
});
}

protected String getEsgId(EurostagDictionary dictionary, NameType nameType, String iidmId) {
String esgId = iidmId.length() > nameType.getLength() ? iidmId.substring(0, nameType.getLength())
: Strings.padEnd(iidmId, nameType.getLength(), ' ');
int counter = 0;
while (dictionary.esgIdExists(esgId)) {
String counterStr = Integer.toString(counter++);
if (counterStr.length() > nameType.getLength()) {
throw new RuntimeException("Renaming fatal error " + iidmId + " -> " + esgId);
}
esgId = esgId.substring(0, nameType.getLength() - counterStr.length()) + counterStr;
}
return esgId;
}
}

@@ -0,0 +1,117 @@
/**
* Copyright (c) 2016, All partners of the iTesla project (http://www.itesla-project.eu/consortium)
* 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/.
*/
package eu.itesla_project.iidm.eurostag.export;

import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
* @author Christian Biasuzzi <christian.biasuzzi@techrain.it>
*/
public class DicoEurostagNamingStrategy implements EurostagNamingStrategy {

private static final Logger LOGGER = LoggerFactory.getLogger(DicoEurostagNamingStrategy.class);

private BiMap<String, String> dicoMap = HashBiMap.create();

private CutEurostagNamingStrategy defaultStrategy = new CutEurostagNamingStrategy();

class DicoCsvReader {

private static final String SEPARATOR = ";";

private final Reader source;

DicoCsvReader(Reader source) {
this.source = source;
}

List<List<String>> readDicoMappings() throws IOException {
try (BufferedReader reader = new BufferedReader(source)) {
return reader.lines()
.skip(1)
.map(line -> Arrays.asList(line.split(SEPARATOR)))
.collect(Collectors.toList());
}
}
}

public DicoEurostagNamingStrategy(Path dicoFile) {
if ((dicoFile == null) || (!Files.isRegularFile(dicoFile))) {
String errMsg = "csv file does not exist or is not valid: " + dicoFile;
LOGGER.error(errMsg);
throw new RuntimeException(errMsg);
} else {
LOGGER.debug("reading iidm-esgid mapping from csv file " + dicoFile);
// Note: csv files's first line is skipped, it is expected to be a header line
List<List<String>> dicoMappings;
try {
Reader reader = Files.newBufferedReader(dicoFile, Charset.forName("UTF-8"));
DicoCsvReader dicoReader = new DicoCsvReader(reader);
dicoMappings = dicoReader.readDicoMappings();
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
throw new RuntimeException(e);
}

int count = 1;
for (List<String> row : dicoMappings) {
count++;
String iidmId = row.get(0).trim();
String esgId = row.get(1).trim();
if (esgId.length() > NameType.GENERATOR.getLength()) {
String errMsg = "esgId: " + esgId + " 's length > " + NameType.GENERATOR.getLength() + ". Line " + count + " in " + dicoFile.toString();
throw new RuntimeException(errMsg);
}
if ("".equals(iidmId) || "".equals(esgId)) {
String errMsg = "either iidmId or esgId or both are empty strings. Line " + count + " in " + dicoFile.toString();
LOGGER.error(errMsg);
throw new RuntimeException(errMsg);
}
if (dicoMap.containsKey(esgId)) {
String errMsg = "esgId: " + esgId + " already mapped.";
LOGGER.error(errMsg);
throw new RuntimeException(errMsg);
}
dicoMap.put(iidmId, esgId);
}
}
}

@Override
public void fillDictionary(EurostagDictionary dictionary, NameType nameType, Set<String> iidmIds) {
iidmIds.forEach(iidmId -> {
if (!dictionary.iidmIdExists(iidmId)) {
String esgId;
if ((nameType == NameType.GENERATOR) && (dicoMap.containsKey(iidmId))) {
esgId = dicoMap.get(iidmId);
} else {
esgId = defaultStrategy.getEsgId(dictionary, nameType, iidmId);
if (nameType == NameType.GENERATOR) {
LOGGER.warn(" dico mapping not found for iidmId: '{}'; esgId: '{}' generated using CutName strategy", iidmId, esgId);
}
}
dictionary.add(iidmId, esgId);
LOGGER.debug("iidmId: '{}' ; esgId: '{}'", iidmId, esgId);
}
});
}
}

@@ -0,0 +1,27 @@
package eu.itesla_project.iidm.eurostag.export;

import eu.itesla_project.commons.config.ModuleConfig;
import eu.itesla_project.commons.config.PlatformConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.file.Path;

/**
* @author Christian Biasuzzi <christian.biasuzzi@techrain.it>
*/
public class DicoEurostagNamingStrategyFactory implements EurostagNamingStrategyFactory {
private static final Logger LOGGER = LoggerFactory.getLogger(DicoEurostagNamingStrategyFactory.class);

@Override
public EurostagNamingStrategy create() {
ModuleConfig config = PlatformConfig.defaultConfig().getModuleConfigIfExists("eurostag-naming-strategy-dico");
if (config != null) {
Path dicoFile = config.getPathProperty("dicoFile", null);
LOGGER.info("property dicoFile: {}", dicoFile);
return new DicoEurostagNamingStrategy(dicoFile);
} else {
return new CutEurostagNamingStrategy();
}
}
}
Expand Up @@ -26,12 +26,11 @@
import java.util.stream.Collectors;

/**
*
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public class EurostagDictionary {

private static final EurostagNamingStrategy NAMING_STRATEGY = new CutEurostagNamingStrategy();
private static final EurostagNamingStrategy NAMING_STRATEGY = new DicoEurostagNamingStrategyFactory().create();

private final BiMap<String, String> iidmId2esgId;

Expand Down Expand Up @@ -100,11 +99,11 @@ public static EurostagDictionary create(Network network, BranchParallelIndexes p
return dictionary;
}

public EurostagDictionary() {
private EurostagDictionary() {
this(new HashMap<>());
}

public EurostagDictionary(Map<String, String> iidmId2esgId) {
private EurostagDictionary(Map<String, String> iidmId2esgId) {
this.iidmId2esgId = HashBiMap.create(iidmId2esgId);
}

Expand Down
@@ -0,0 +1,17 @@
package eu.itesla_project.iidm.eurostag.export;
/**
* Copyright (c) 2016, RTE
* 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/.
*/

/**
*
* @author Christian Biasuzzi <christian.biasuzzi@techrain.it>
*/
public interface EurostagNamingStrategyFactory {

EurostagNamingStrategy create();

}

0 comments on commit 81d7a82

Please sign in to comment.