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 fix_histodb_forecastdiff
- Loading branch information
Showing
18 changed files
with
360 additions
and
4 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
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
105 changes: 105 additions & 0 deletions
105
...export/src/main/java/eu/itesla_project/iidm/ddb/eurostag_imp_exp/DynamicDatabaseMock.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,105 @@ | ||
/** | ||
* 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.ddb.eurostag_imp_exp; | ||
|
||
import com.google.common.base.Strings; | ||
import com.google.common.io.ByteStreams; | ||
import com.google.common.io.CharStreams; | ||
import eu.itesla_project.iidm.network.Bus; | ||
import eu.itesla_project.iidm.network.Generator; | ||
import eu.itesla_project.iidm.network.Network; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.*; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
/** | ||
* @author Christian Biasuzzi <christian.biasuzzi@techrain.it> | ||
*/ | ||
class DynamicDatabaseMock implements DynamicDatabaseClient { | ||
|
||
private static final String MINIMAL_DTA_TEMPLATE = "/sim_min.dta"; | ||
private static final List<String> MOCK_REG_FILES_PREFIXES = Arrays.asList("dummefd", "dummycm"); | ||
private static final List<String> REG_EXTENSIONS = Arrays.asList("fri", "frm", "par", "pcp", "rcp"); | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(DynamicDatabaseMock.class); | ||
|
||
@Override | ||
public void dumpDtaFile(Path workingDir, String fileName, Network network, Map<String, Character> parallelIndexes, String eurostagVersion, Map<String, String> iidm2eurostagId) { | ||
Objects.requireNonNull(workingDir); | ||
Objects.requireNonNull(fileName); | ||
Objects.requireNonNull(network); | ||
Objects.requireNonNull(parallelIndexes); | ||
Objects.requireNonNull(eurostagVersion); | ||
Objects.requireNonNull(iidm2eurostagId); | ||
|
||
//uses the first connected generator that is available in the iidm2eurostag map | ||
Generator generator = network.getGeneratorStream() | ||
.filter(gen -> ((iidm2eurostagId.containsKey(gen.getId())) && (gen.getTerminal().isConnected()))) | ||
.findFirst() | ||
.orElseThrow(() -> new RuntimeException("could not find a suitable generator in network: " + network + ", to be used in: " + fileName)); | ||
|
||
Bus bus = generator.getTerminal().getBusBreakerView().getConnectableBus(); | ||
if ((bus == null) || (!iidm2eurostagId.containsKey(bus.getId()))) { | ||
throw new RuntimeException("suitable node not found"); | ||
} | ||
String mappedGenName = formatString8(iidm2eurostagId.get(generator.getId())); | ||
String mappedNodeName = formatString8(iidm2eurostagId.get(bus.getId())); | ||
|
||
LOGGER.info("generator: iidm {}, eurostag {}", generator.getId(), mappedGenName); | ||
LOGGER.info("node: iidm {}, eurostag {}", generator.getTerminal().getBusBreakerView().getConnectableBus().getId(), mappedNodeName); | ||
|
||
try { | ||
try (final Reader reader = new InputStreamReader(getClass().getResourceAsStream(MINIMAL_DTA_TEMPLATE))) { | ||
String dtaContents = CharStreams.toString(reader); | ||
|
||
//change the connection node name, according to the current network and the iidm2eurostag mapping | ||
String newDtaContents = dtaContents | ||
.replace("NODENAME", mappedNodeName) | ||
.replace("MINIMALI", mappedGenName); | ||
try (BufferedWriter writer = Files.newBufferedWriter(workingDir.resolve(fileName))) { | ||
writer.write(newDtaContents); | ||
} | ||
} | ||
//copy the regulators dummy files | ||
MOCK_REG_FILES_PREFIXES.stream() | ||
.flatMap(filePrefix -> REG_EXTENSIONS.stream().map(fileSuffix -> filePrefix + "." + fileSuffix)) | ||
.forEach(filename -> { | ||
try (final InputStream reader = getClass().getResourceAsStream("/" + filename)) { | ||
LOGGER.info("copying regulator file: {}", filename); | ||
Files.write(workingDir.resolve(filename), ByteStreams.toByteArray(reader)); | ||
} catch (IOException e) { | ||
LOGGER.error(e.getMessage(), e); | ||
throw new RuntimeException(e.getMessage(), e); | ||
} | ||
}); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e.getMessage(), e); | ||
} | ||
} | ||
|
||
private String formatString8(String string) { | ||
return Strings.padEnd((string.length() > 8) ? string.substring(0, 8) : string, 8, ' '); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "mock DDB"; | ||
} | ||
|
||
@Override | ||
public String getVersion() { | ||
return null; | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...main/java/eu/itesla_project/iidm/ddb/eurostag_imp_exp/IIDMDynamicDatabaseMockFactory.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,19 @@ | ||
/** | ||
* 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.ddb.eurostag_imp_exp; | ||
|
||
/** | ||
* @author Christian Biasuzzi <christian.biasuzzi@techrain.it> | ||
*/ | ||
public class IIDMDynamicDatabaseMockFactory implements DynamicDatabaseClientFactory { | ||
|
||
@Override | ||
public DynamicDatabaseClient create(boolean cache) { | ||
return new DynamicDatabaseMock(); | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
iidm-ddb/iidm-ddb-eurostag-import-export/src/main/resources/dummefd.fri
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,5 @@ | ||
HEADER 15/02/17 5.1 | ||
70 84 | ||
0 | ||
0 | ||
0 |
25 changes: 25 additions & 0 deletions
25
iidm-ddb/iidm-ddb-eurostag-import-export/src/main/resources/dummefd.frm
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,25 @@ | ||
HEADER 15/02/17 5.1 | ||
70 84 | ||
1 | ||
? | ||
? | ||
? | ||
? | ||
? | ||
? | ||
? | ||
_EFD | ||
? | ||
? | ||
? | ||
? | ||
? | ||
$EFD | ||
1 | ||
-805 | ||
-522 | ||
26 | ||
0 | ||
1 | ||
0 | ||
0 |
7 changes: 7 additions & 0 deletions
7
iidm-ddb/iidm-ddb-eurostag-import-export/src/main/resources/dummefd.par
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,7 @@ | ||
HEADER 15/02/17 5.1 | ||
|
||
_end_comment_ | ||
|
||
DUMMEFD 1 | ||
|
||
|
Binary file added
BIN
+48 Bytes
iidm-ddb/iidm-ddb-eurostag-import-export/src/main/resources/dummefd.pcp
Binary file not shown.
Binary file added
BIN
+2.08 KB
iidm-ddb/iidm-ddb-eurostag-import-export/src/main/resources/dummefd.rcp
Binary file not shown.
5 changes: 5 additions & 0 deletions
5
iidm-ddb/iidm-ddb-eurostag-import-export/src/main/resources/dummycm.fri
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,5 @@ | ||
HEADER 15/02/17 5.1 | ||
70 84 | ||
0 | ||
0 | ||
0 |
25 changes: 25 additions & 0 deletions
25
iidm-ddb/iidm-ddb-eurostag-import-export/src/main/resources/dummycm.frm
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,25 @@ | ||
HEADER 15/02/17 5.1 | ||
70 84 | ||
1 | ||
? | ||
? | ||
? | ||
? | ||
? | ||
? | ||
? | ||
_CM | ||
? | ||
? | ||
? | ||
? | ||
? | ||
$CM | ||
2 | ||
-535 | ||
-312 | ||
26 | ||
0 | ||
2 | ||
0 | ||
0 |
7 changes: 7 additions & 0 deletions
7
iidm-ddb/iidm-ddb-eurostag-import-export/src/main/resources/dummycm.par
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,7 @@ | ||
HEADER 15/02/17 5.1 | ||
|
||
_end_comment_ | ||
|
||
DUMMYCM 1 | ||
|
||
|
Binary file added
BIN
+48 Bytes
iidm-ddb/iidm-ddb-eurostag-import-export/src/main/resources/dummycm.pcp
Binary file not shown.
Binary file added
BIN
+2.08 KB
iidm-ddb/iidm-ddb-eurostag-import-export/src/main/resources/dummycm.rcp
Binary file not shown.
27 changes: 27 additions & 0 deletions
27
iidm-ddb/iidm-ddb-eurostag-import-export/src/main/resources/sim_min.dta
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 @@ | ||
HEADER 15/02/17 5.1 | ||
|
||
M6 U 0. 0. | ||
MINIMALI NODENAME 100000. 1. 1. 1. 0. 4. | ||
0. 0.3 1. 0.5 4. | ||
1. 1 3 3 | ||
N 0 0 0 0 0 100000. 100000. | ||
|
||
|
||
RAMINIMALI | ||
DUMMYCM 1 | ||
|
||
|
||
RVMINIMALI | ||
DUMMEFD 1 | ||
|
||
|
||
LOADP CH | ||
|
||
VOLTA1 1. 1. 1. 1. 0. 0. | ||
|
||
|
||
|
||
|
||
CH | ||
CH W | ||
|
84 changes: 84 additions & 0 deletions
84
iidm-ddb/iidm-ddb-eurostag-import-export/src/test/java/TestDynamicDatabaseMock.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,84 @@ | ||
/** | ||
* 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/. | ||
*/ | ||
|
||
import com.google.common.io.CharStreams; | ||
import com.google.common.jimfs.Configuration; | ||
import com.google.common.jimfs.Jimfs; | ||
import eu.itesla_project.iidm.ddb.eurostag_imp_exp.DynamicDatabaseClient; | ||
import eu.itesla_project.iidm.ddb.eurostag_imp_exp.IIDMDynamicDatabaseMockFactory; | ||
import eu.itesla_project.iidm.network.Network; | ||
import eu.itesla_project.iidm.network.test.EurostagTutorialExample1Factory; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
import java.io.InputStreamReader; | ||
import java.nio.file.FileSystem; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* @author Christian Biasuzzi <christian.biasuzzi@techrain.it> | ||
*/ | ||
public class TestDynamicDatabaseMock { | ||
|
||
private FileSystem fileSystem; | ||
|
||
private static final String DTA_FILENAME = "sim.dta"; | ||
private static final List<String> REGULATORS_FILENAMES = Arrays.asList("dummefd.fri", | ||
"dummefd.frm", | ||
"dummefd.par", | ||
"dummefd.pcp", | ||
"dummefd.rcp", | ||
"dummycm.fri", | ||
"dummycm.frm", | ||
"dummycm.par", | ||
"dummycm.pcp", | ||
"dummycm.rcp"); | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
fileSystem = Jimfs.newFileSystem(Configuration.unix()); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
fileSystem.close(); | ||
} | ||
|
||
@Test | ||
public void test_00() throws Exception { | ||
Network network = EurostagTutorialExample1Factory.create(); | ||
|
||
Map<String, String> iidm2eurostag = new HashMap<>(); | ||
iidm2eurostag.put("GEN", "GEN"); | ||
iidm2eurostag.put("NGEN", "NGEN"); | ||
|
||
Path workingDir = Files.createDirectory(fileSystem.getPath("/workingdir")); | ||
|
||
DynamicDatabaseClient ddbClient = new IIDMDynamicDatabaseMockFactory().create(false); | ||
ddbClient.dumpDtaFile(workingDir, DTA_FILENAME, network, new HashMap<String, Character>(), "mock", iidm2eurostag); | ||
|
||
File expectedDtaFile = new File(getClass().getResource("/sim_test00.dta").toURI()); | ||
Path testFile = workingDir.resolve(DTA_FILENAME); | ||
|
||
assertEquals(CharStreams.toString(new InputStreamReader(Files.newInputStream(expectedDtaFile.toPath()))), | ||
CharStreams.toString(new InputStreamReader(Files.newInputStream(testFile)))); | ||
|
||
REGULATORS_FILENAMES.stream() | ||
.forEach(filename -> assertTrue(Files.isRegularFile(workingDir.resolve(filename)))); | ||
} | ||
|
||
} |
Oops, something went wrong.