Skip to content

Commit

Permalink
Merge branch 'master' into ddb_mock_svc
Browse files Browse the repository at this point in the history
  • Loading branch information
mathbagu committed Mar 28, 2017
2 parents 03fd977 + b349617 commit 5bd33af
Show file tree
Hide file tree
Showing 61 changed files with 4,742 additions and 666 deletions.
@@ -1,6 +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)
* Copyright (c) 2016-2017, 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 @@ -1207,13 +1207,17 @@ private void writeStaticVarCompensators(AmplExportContext context) throws IOExce
!append,
LOCALE,
new Column("num"),
new Column("fault"),
new Column(config.getActionType().getLabel()),
new Column("id"))) {
List<String> skipped = new ArrayList<>();
for (StaticVarCompensator svc : network.getStaticVarCompensators()) {
// FIXME
String id = svc.getId();
int num = mapper.getInt(AmplSubset.STATIC_VAR_COMPENSATOR, id);
formatter.writeCell(num)
.writeCell(faultNum)
.writeCell(actionNum)
.writeCell(id);
}
if (skipped.size() > 0) {
Expand Down Expand Up @@ -1398,13 +1402,17 @@ private void writeHVDCLines(AmplExportContext context) throws IOException {
!append,
LOCALE,
new Column("num"),
new Column("fault"),
new Column(config.getActionType().getLabel()),
new Column("id"))) {
List<String> skipped = new ArrayList<>();
for (HvdcLine hvdcLine : network.getHvdcLines()) {
// FIXME
String id = hvdcLine.getId();
int num = mapper.getInt(AmplSubset.HVDC_LINE, id);
formatter.writeCell(num)
.writeCell(faultNum)
.writeCell(actionNum)
.writeCell(id);
}
if (skipped.size() > 0) {
Expand Down
4 changes: 2 additions & 2 deletions ampl-export/src/test/resources/lcc-test-case.txt
@@ -1,3 +1,3 @@
#HVDC lines (hvdctest/InitialState)
#"num" "id"
1 "L"
#"num" "fault" "curative" "id"
1 0 0 "L"
4 changes: 2 additions & 2 deletions ampl-export/src/test/resources/svc-test-case.txt
@@ -1,3 +1,3 @@
#Static VAR compensators (svcTestCase/InitialState)
#"num" "id"
1 "SVC2"
#"num" "fault" "curative" "id"
1 0 0 "SVC2"
4 changes: 2 additions & 2 deletions ampl-export/src/test/resources/vsc-test-case.txt
@@ -1,3 +1,3 @@
#HVDC lines (hvdctest/InitialState)
#"num" "id"
1 "L"
#"num" "fault" "curative" "id"
1 0 0 "L"
17 changes: 14 additions & 3 deletions eurostag-ech-export/pom.xml
Expand Up @@ -21,30 +21,41 @@
<name>Eurostag ech export</name>

<dependencies>
<!-- Compilation dependencies -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>eu.itesla_project</groupId>
<artifactId>commons</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>eu.itesla_project</groupId>
<artifactId>iidm-api</artifactId>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>eurostag-network</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>com.google.jimfs</groupId>
<artifactId>jimfs</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
Expand Down
@@ -1,5 +1,6 @@
/**
* Copyright (c) 2016, All partners of the iTesla project (http://www.itesla-project.eu/consortium)
* Copyright (c) 2017, 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 @@ -9,24 +10,35 @@
import com.google.common.base.Strings;

import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public class CutEurostagNamingStrategy implements EurostagNamingStrategy {
@Override
public void fillDictionary(EurostagDictionary dictionary, NameType nameType, Set<String> iidmIds) {
EurostagEchExportConfig config = dictionary.getConfig();
String forbiddenChars = config.getForbiddenCharactersString();
Character replacementChar = config.getForbiddenCharactersReplacement();
String regex = (forbiddenChars.length() > 0) ? "[" + Pattern.quote(forbiddenChars) + "]" : null;
String repl = Matcher.quoteReplacement(replacementChar.toString());

iidmIds.forEach(iidmId -> {
if (!dictionary.iidmIdExists(iidmId)) {
String esgId = getEsgId(dictionary, nameType, iidmId);
String esgId = getEsgId(dictionary, nameType, iidmId, regex, repl);
dictionary.add(iidmId, esgId);
}
});
}

protected String getEsgId(EurostagDictionary dictionary, NameType nameType, String iidmId) {
private String getEsgId(EurostagDictionary dictionary, NameType nameType, String iidmId, String regex, String repl) {
String esgId = iidmId.length() > nameType.getLength() ? iidmId.substring(0, nameType.getLength())
: Strings.padEnd(iidmId, nameType.getLength(), ' ');
if (regex != null) {
esgId = esgId.replaceAll(regex, repl);
}
int counter = 0;
while (dictionary.esgIdExists(esgId)) {
String counterStr = Integer.toString(counter++);
Expand Down
@@ -1,5 +1,6 @@
/**
* Copyright (c) 2016, All partners of the iTesla project (http://www.itesla-project.eu/consortium)
* Copyright (c) 2017, 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,9 +18,7 @@
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.*;
import java.util.stream.Collectors;

/**
Expand All @@ -31,7 +30,7 @@ public class DicoEurostagNamingStrategy implements EurostagNamingStrategy {

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

private CutEurostagNamingStrategy defaultStrategy = new CutEurostagNamingStrategy();
private final CutEurostagNamingStrategy defaultStrategy = new CutEurostagNamingStrategy();

class DicoCsvReader {

Expand Down Expand Up @@ -97,21 +96,24 @@ public DicoEurostagNamingStrategy(Path dicoFile) {

@Override
public void fillDictionary(EurostagDictionary dictionary, NameType nameType, Set<String> iidmIds) {
iidmIds.forEach(iidmId -> {
//partition the iidmIds set in two: tiidms with a dico mapping and iidms without a dico mapping
Map<Boolean, List<String>> dicoPartioned =
iidmIds.stream().collect(Collectors.partitioningBy(iidmId -> dicoMap.containsKey(iidmId)));

//first process the entry that are in the dico mapping
dicoPartioned.get(true).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);
}
}
String esgId = dicoMap.get(iidmId);
LOGGER.debug("dico mapping found for iidmId: '{}'; esgId: '{}'", iidmId, esgId);
dictionary.add(iidmId, esgId);
LOGGER.debug("iidmId: '{}' ; esgId: '{}'", iidmId, esgId);
}
});

//then process the entry that aren't, with the default strategy
if (dicoPartioned.get(false).size() > 0) {
LOGGER.warn("dico mapping not found for iidmId ids: {}", dicoPartioned.get(false));
defaultStrategy.fillDictionary(dictionary, nameType, new HashSet(dicoPartioned.get(false)));
}
}
}

@@ -1,5 +1,6 @@
/**
* Copyright (c) 2016, All partners of the iTesla project (http://www.itesla-project.eu/consortium)
* Copyright (c) 2017, 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 @@ -19,10 +20,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

/**
Expand All @@ -34,8 +32,10 @@ public class EurostagDictionary {

private final BiMap<String, String> iidmId2esgId;

private final EurostagEchExportConfig config;

public static EurostagDictionary create(Network network, BranchParallelIndexes parallelIndexes, EurostagEchExportConfig config) {
EurostagDictionary dictionary = new EurostagDictionary();
EurostagDictionary dictionary = new EurostagDictionary(config);

dictionary.addIfNotExist(EchUtil.FAKE_NODE_NAME1, EchUtil.FAKE_NODE_NAME1);
dictionary.addIfNotExist(EchUtil.FAKE_NODE_NAME2, EchUtil.FAKE_NODE_NAME2);
Expand Down Expand Up @@ -99,12 +99,15 @@ public static EurostagDictionary create(Network network, BranchParallelIndexes p
return dictionary;
}

private EurostagDictionary() {
this(new HashMap<>());
private EurostagDictionary(EurostagEchExportConfig config) {
this(new HashMap<>(), config);
}

private EurostagDictionary(Map<String, String> iidmId2esgId) {
private EurostagDictionary(Map<String, String> iidmId2esgId, EurostagEchExportConfig config) {
Objects.requireNonNull(iidmId2esgId);
Objects.requireNonNull(config);
this.iidmId2esgId = HashBiMap.create(iidmId2esgId);
this.config = config;
}

public void add(String iidmId, String esgId) {
Expand Down Expand Up @@ -180,4 +183,8 @@ public void dump(Path file) {
}
}

public EurostagEchExportConfig getConfig() {
return config;
}

}
@@ -1,32 +1,57 @@
/**
* Copyright (c) 2016, All partners of the iTesla project (http://www.itesla-project.eu/consortium)
* Copyright (c) 2017, 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/.
*/
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.util.Objects;

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

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

private static final String EUROSTAG_ECH_EXPORT_CONFIG = "eurostag-ech-export";

private final static String DEFAULT_FORBIDDEN_CHARACTERS = "/%()^$,;?";
private final static Character DEFAULT_FORBIDDEN_CHARACTERS_REPLACEMENT = '#';
private final static boolean DEFAULT_NOGENERATORMINMAXQ = false;
private final static boolean DEFAULT_NOSWITCH = false;

private boolean noGeneratorMinMaxQ;

private boolean noSwitch;

private final String forbiddenCharacters;

private final Character forbiddenCharactersReplacement;

public EurostagEchExportConfig() {
this(false, false);
this(false, false, DEFAULT_FORBIDDEN_CHARACTERS, DEFAULT_FORBIDDEN_CHARACTERS_REPLACEMENT);
}

public EurostagEchExportConfig(boolean noGeneratorMinMaxQ) {
this(noGeneratorMinMaxQ, false);
this(noGeneratorMinMaxQ, false, DEFAULT_FORBIDDEN_CHARACTERS, DEFAULT_FORBIDDEN_CHARACTERS_REPLACEMENT);
}

public EurostagEchExportConfig(boolean noGeneratorMinMaxQ, boolean noSwitch) {
public EurostagEchExportConfig(boolean noGeneratorMinMaxQ, boolean noSwitch, String forbiddenCharacters, Character forbiddenCharactersReplacement) {
this.forbiddenCharacters = Objects.requireNonNull(forbiddenCharacters, "forbiddenCharacters string must be not null");
this.forbiddenCharactersReplacement = Objects.requireNonNull(forbiddenCharactersReplacement, "forbiddenCharactersReplacement (single char) string must not be null");
this.noGeneratorMinMaxQ = noGeneratorMinMaxQ;
this.noSwitch = noSwitch;
if (forbiddenCharacters.contains(forbiddenCharactersReplacement.toString())) {
throw new IllegalArgumentException("forbiddenCharactersReplacement " + forbiddenCharactersReplacement + " must not appear also in the forbiddenCharacters string: " + forbiddenCharacters);
}
}

public boolean isNoGeneratorMinMaxQ() {
Expand All @@ -37,4 +62,43 @@ public boolean isNoSwitch() {
return noSwitch;
}

public String getForbiddenCharactersString() {
return forbiddenCharacters;
}

public Character getForbiddenCharactersReplacement() {
return forbiddenCharactersReplacement;
}

public static EurostagEchExportConfig load() {
return load(PlatformConfig.defaultConfig());
}

public static EurostagEchExportConfig load(PlatformConfig platformConfig) {
if (platformConfig.moduleExists(EUROSTAG_ECH_EXPORT_CONFIG)) {
ModuleConfig config = platformConfig.getModuleConfig(EUROSTAG_ECH_EXPORT_CONFIG);
boolean noGeneratorMinMaxQ = config.getBooleanProperty("noGeneratorMinMaxQ", DEFAULT_NOGENERATORMINMAXQ);
boolean noSwitch = config.getBooleanProperty("noSwitch", DEFAULT_NOSWITCH);
String forbiddenCharacters = config.getStringProperty("forbiddenCharacters", DEFAULT_FORBIDDEN_CHARACTERS);
String replacementCharString = config.getStringProperty("forbiddenCharactersReplacement", DEFAULT_FORBIDDEN_CHARACTERS_REPLACEMENT.toString());
if (replacementCharString.length() != 1) {
throw new IllegalArgumentException("forbiddenCharactersReplacement must be a single character: " + replacementCharString);
}
Character forbiddenCharactersReplacement = replacementCharString.charAt(0);
return new EurostagEchExportConfig(noGeneratorMinMaxQ, noSwitch, forbiddenCharacters, forbiddenCharactersReplacement);
} else {
LOGGER.warn("no eurostag-ech-export config found: Using defaults.");
return new EurostagEchExportConfig(DEFAULT_NOGENERATORMINMAXQ, DEFAULT_NOSWITCH, DEFAULT_FORBIDDEN_CHARACTERS, DEFAULT_FORBIDDEN_CHARACTERS_REPLACEMENT);
}
}

@Override
public String toString() {
return getClass().getSimpleName() + " [noGeneratorMinMaxQ=" + noGeneratorMinMaxQ +
", noSwitch=" + noSwitch +
", forbiddenCharacters=" + forbiddenCharacters +
", forbiddenCharactersReplacement=" + forbiddenCharactersReplacement +
"]";
}

}

0 comments on commit 5bd33af

Please sign in to comment.