Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into versioneye
- Loading branch information
Showing
28 changed files
with
2,047 additions
and
1,941 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 41 additions & 40 deletions
81
ampl-export/src/main/java/eu/itesla_project/iidm/export/ampl/AmplNetworkWriter.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
...port/src/main/java/eu/itesla_project/iidm/eurostag/export/DicoEurostagNamingStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
}); | ||
} | ||
} | ||
|
27 changes: 27 additions & 0 deletions
27
...c/main/java/eu/itesla_project/iidm/eurostag/export/DicoEurostagNamingStrategyFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...t/src/main/java/eu/itesla_project/iidm/eurostag/export/EurostagNamingStrategyFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
|
||
} |
Oops, something went wrong.