Skip to content

Commit

Permalink
Merge branch 'master' into online_script_print_logfile_name
Browse files Browse the repository at this point in the history
  • Loading branch information
mathbagu committed Oct 19, 2016
2 parents ea2ceb4 + 5717dd7 commit 0cf7015
Show file tree
Hide file tree
Showing 22 changed files with 83 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -49,7 +49,7 @@
/target/
/ucte-import/target/
/ucte-network/target/
/ucte-util/target/
/entsoe-util/target/
/wca-integration/target/
/case-repository/target/
/network-merge/target/
Expand Down
2 changes: 1 addition & 1 deletion case-repository/pom.xml
Expand Up @@ -36,7 +36,7 @@
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ucte-util</artifactId>
<artifactId>entsoe-util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down
Expand Up @@ -9,7 +9,7 @@
import com.google.common.collect.Multimap;
import eu.itesla_project.commons.config.PlatformConfig;
import eu.itesla_project.iidm.import_.Importers;
import eu.itesla_project.ucte.util.UcteGeographicalCode;
import eu.itesla_project.entsoe.util.EntsoeGeographicalCode;

import java.nio.file.Path;
import java.util.Collection;
Expand All @@ -20,7 +20,7 @@
*/
public class EntsoeAndXmlCaseRepositoryConfig extends EntsoeCaseRepositoryConfig {

public EntsoeAndXmlCaseRepositoryConfig(Path rootDir, Multimap<UcteGeographicalCode, String> forbiddenFormatsByGeographicalCode) {
public EntsoeAndXmlCaseRepositoryConfig(Path rootDir, Multimap<EntsoeGeographicalCode, String> forbiddenFormatsByGeographicalCode) {
super(rootDir, forbiddenFormatsByGeographicalCode);
}

Expand Down
Expand Up @@ -16,8 +16,8 @@
import eu.itesla_project.iidm.import_.Importers;
import eu.itesla_project.iidm.network.Country;
import eu.itesla_project.iidm.network.Network;
import eu.itesla_project.ucte.util.UcteFileName;
import eu.itesla_project.ucte.util.UcteGeographicalCode;
import eu.itesla_project.entsoe.util.EntsoeFileName;
import eu.itesla_project.entsoe.util.EntsoeGeographicalCode;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.Interval;
Expand Down Expand Up @@ -106,15 +106,15 @@ private ImportContext(Importer importer, ReadOnlyDataSource ds) {
}

// because D1 snapshot does not exist and forecast replacement is not yet implemented
private static Collection<UcteGeographicalCode> forCountryHacked(Country country) {
return UcteGeographicalCode.forCountry(country).stream()
.filter(ucteGeographicalCode -> ucteGeographicalCode != UcteGeographicalCode.D1)
private static Collection<EntsoeGeographicalCode> forCountryHacked(Country country) {
return EntsoeGeographicalCode.forCountry(country).stream()
.filter(EntsoeGeographicalCode -> EntsoeGeographicalCode != EntsoeGeographicalCode.D1)
.collect(Collectors.toList());
}

private <R> R scanRepository(DateTime date, CaseType type, Country country, Function<List<ImportContext>, R> handler) {
Collection<UcteGeographicalCode> geographicalCodes = country != null ? forCountryHacked(country)
: Collections.singleton(UcteGeographicalCode.UX);
Collection<EntsoeGeographicalCode> geographicalCodes = country != null ? forCountryHacked(country)
: Collections.singleton(EntsoeGeographicalCode.UX);
for (EntsoeFormat format : formats) {
Path formatDir = config.getRootDir().resolve(format.getDirName());
if (Files.exists(formatDir)) {
Expand All @@ -125,7 +125,7 @@ private <R> R scanRepository(DateTime date, CaseType type, Country country, Func
.resolve(String.format("%02d", date.getDayOfMonth()));
if (Files.exists(dayDir)) {
List<ImportContext> importContexts = null;
for (UcteGeographicalCode geographicalCode : geographicalCodes) {
for (EntsoeGeographicalCode geographicalCode : geographicalCodes) {
Collection<String> forbiddenFormats = config.getForbiddenFormatsByGeographicalCode().get(geographicalCode);
if (!forbiddenFormats.contains(format.getImporter().getFormat())) {
for (int i = 9; i >= 0; i--) {
Expand Down Expand Up @@ -224,27 +224,27 @@ private void browse(Path dir, Consumer<Path> handler) {

@Override
public Set<DateTime> dataAvailable(CaseType type, Set<Country> countries, Interval interval) {
Set<UcteGeographicalCode> geographicalCodes = new HashSet<>();
Set<EntsoeGeographicalCode> geographicalCodes = new HashSet<>();
if (countries == null) {
geographicalCodes.add(UcteGeographicalCode.UX);
geographicalCodes.add(EntsoeGeographicalCode.UX);
} else {
for (Country country : countries) {
geographicalCodes.addAll(forCountryHacked(country));
}
}
Multimap<DateTime, UcteGeographicalCode> dates = HashMultimap.create();
Multimap<DateTime, EntsoeGeographicalCode> dates = HashMultimap.create();
for (EntsoeFormat format : formats) {
Path formatDir = config.getRootDir().resolve(format.getDirName());
if (Files.exists(formatDir)) {
Path typeDir = formatDir.resolve(type.name());
if (Files.exists(typeDir)) {
browse(typeDir, path -> {
UcteFileName ucteFileName = UcteFileName.parse(path.getFileName().toString());
UcteGeographicalCode geographicalCode = ucteFileName.getGeographicalCode();
EntsoeFileName entsoeFileName = EntsoeFileName.parse(path.getFileName().toString());
EntsoeGeographicalCode geographicalCode = entsoeFileName.getGeographicalCode();
if (geographicalCode != null
&& !config.getForbiddenFormatsByGeographicalCode().get(geographicalCode).contains(format.getImporter().getFormat())
&& interval.contains(ucteFileName.getDate())) {
dates.put(ucteFileName.getDate(), geographicalCode);
&& interval.contains(entsoeFileName.getDate())) {
dates.put(entsoeFileName.getDate(), geographicalCode);
}
});
}
Expand Down
Expand Up @@ -12,7 +12,7 @@
import eu.itesla_project.commons.config.ModuleConfig;
import eu.itesla_project.commons.config.PlatformConfig;
import eu.itesla_project.iidm.import_.Importers;
import eu.itesla_project.ucte.util.UcteGeographicalCode;
import eu.itesla_project.entsoe.util.EntsoeGeographicalCode;

import java.nio.file.Path;
import java.util.Collection;
Expand All @@ -26,7 +26,7 @@ public class EntsoeCaseRepositoryConfig {

private final Path rootDir;

private final Multimap<UcteGeographicalCode, String> forbiddenFormatsByGeographicalCode;
private final Multimap<EntsoeGeographicalCode, String> forbiddenFormatsByGeographicalCode;

public static EntsoeCaseRepositoryConfig load() {
return load(PlatformConfig.defaultConfig());
Expand All @@ -43,8 +43,8 @@ static EntsoeCaseRepositoryConfig load(PlatformConfig platformConfig, Collection
static EntsoeCaseRepositoryConfig load(String moduleConfigName, PlatformConfig platformConfig, Collection<String> supportedFormats) {
ModuleConfig config = platformConfig.getModuleConfig(moduleConfigName);
Path rootDir = config.getPathProperty("rootDir");
Multimap<UcteGeographicalCode, String> forbiddenFormatsByCountry = HashMultimap.create();
for (UcteGeographicalCode geographicalCode : UcteGeographicalCode.values()) {
Multimap<EntsoeGeographicalCode, String> forbiddenFormatsByCountry = HashMultimap.create();
for (EntsoeGeographicalCode geographicalCode : EntsoeGeographicalCode.values()) {
List<String> forbiddenFormats = config.getStringListProperty("forbiddenFormats_" + geographicalCode, Collections.emptyList());
if (forbiddenFormats.size() > 0) {
forbiddenFormatsByCountry.putAll(geographicalCode, forbiddenFormats);
Expand All @@ -53,7 +53,7 @@ static EntsoeCaseRepositoryConfig load(String moduleConfigName, PlatformConfig p
return new EntsoeCaseRepositoryConfig(rootDir, checkedFormats(forbiddenFormatsByCountry, supportedFormats));
}

private static Multimap<UcteGeographicalCode, String> checkedFormats(Multimap<UcteGeographicalCode, String> forbiddenFormatsByGeographicalCode,
private static Multimap<EntsoeGeographicalCode, String> checkedFormats(Multimap<EntsoeGeographicalCode, String> forbiddenFormatsByGeographicalCode,
Collection<String> supportedFormats) {
// check that formats are valids
for (String format : forbiddenFormatsByGeographicalCode.values()) {
Expand All @@ -64,7 +64,7 @@ private static Multimap<UcteGeographicalCode, String> checkedFormats(Multimap<Uc
return forbiddenFormatsByGeographicalCode;
}

public EntsoeCaseRepositoryConfig(Path rootDir, Multimap<UcteGeographicalCode, String> forbiddenFormatsByGeographicalCode) {
public EntsoeCaseRepositoryConfig(Path rootDir, Multimap<EntsoeGeographicalCode, String> forbiddenFormatsByGeographicalCode) {
this.rootDir = rootDir;
this.forbiddenFormatsByGeographicalCode = forbiddenFormatsByGeographicalCode;
}
Expand All @@ -73,7 +73,7 @@ public Path getRootDir() {
return rootDir;
}

public Multimap<UcteGeographicalCode, String> getForbiddenFormatsByGeographicalCode() {
public Multimap<EntsoeGeographicalCode, String> getForbiddenFormatsByGeographicalCode() {
return forbiddenFormatsByGeographicalCode;
}

Expand Down
Expand Up @@ -12,7 +12,7 @@
import eu.itesla_project.iidm.import_.Importer;
import eu.itesla_project.iidm.network.Country;
import eu.itesla_project.iidm.network.Network;
import eu.itesla_project.ucte.util.UcteGeographicalCode;
import eu.itesla_project.entsoe.util.EntsoeGeographicalCode;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.nio.file.ShrinkWrapFileSystems;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
Expand All @@ -34,9 +34,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
Expand Down Expand Up @@ -177,8 +175,8 @@ public void tearDown() throws Exception {
@Test
public void testLoad() throws Exception {
// check that, when cim and ucte is forbidden for france, xml is loaded
caseRepository.getConfig().getForbiddenFormatsByGeographicalCode().put(UcteGeographicalCode.FR, "CIM1");
caseRepository.getConfig().getForbiddenFormatsByGeographicalCode().put(UcteGeographicalCode.FR, "UCTE");
caseRepository.getConfig().getForbiddenFormatsByGeographicalCode().put(EntsoeGeographicalCode.FR, "CIM1");
caseRepository.getConfig().getForbiddenFormatsByGeographicalCode().put(EntsoeGeographicalCode.FR, "UCTE");
assertTrue(caseRepository.load(DateTime.parse("2013-01-14T00:15:00+01:00"), CaseType.SN, Country.FR).equals(Collections.singletonList(xmlNetwork)));
}

Expand All @@ -192,8 +190,8 @@ public void testDataAvailable() throws Exception {
public void testLoadXiidm() throws Exception {
// check that, when cim and ucte is forbidden for france, xml is loaded
// file suffix .xiidm
caseRepository.getConfig().getForbiddenFormatsByGeographicalCode().put(UcteGeographicalCode.FR, "CIM1");
caseRepository.getConfig().getForbiddenFormatsByGeographicalCode().put(UcteGeographicalCode.FR, "UCTE");
caseRepository.getConfig().getForbiddenFormatsByGeographicalCode().put(EntsoeGeographicalCode.FR, "CIM1");
caseRepository.getConfig().getForbiddenFormatsByGeographicalCode().put(EntsoeGeographicalCode.FR, "UCTE");
assertTrue(caseRepository.load(DateTime.parse("2016-02-02T01:15:00+01:00"), CaseType.SN, Country.FR).equals(Collections.singletonList(xmlNetwork)));
}

Expand Down
Expand Up @@ -9,7 +9,7 @@
import com.google.common.collect.Sets;
import eu.itesla_project.commons.config.InMemoryPlatformConfig;
import eu.itesla_project.commons.config.MapModuleConfig;
import eu.itesla_project.ucte.util.UcteGeographicalCode;
import eu.itesla_project.entsoe.util.EntsoeGeographicalCode;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.nio.file.ShrinkWrapFileSystems;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
Expand Down Expand Up @@ -57,9 +57,9 @@ public void testLoad() throws Exception {
config = EntsoeCaseRepositoryConfig.load(platformConfig, Arrays.asList("CIM1", "UCTE"));
assertTrue(config.getRootDir().toString().equals("/config"));
assertTrue(config.getForbiddenFormatsByGeographicalCode().size() == 2);
assertTrue(config.getForbiddenFormatsByGeographicalCode().get(UcteGeographicalCode.FR).equals(Sets.newHashSet("CIM1")));
assertTrue(config.getForbiddenFormatsByGeographicalCode().get(UcteGeographicalCode.BE).equals(Sets.newHashSet("CIM1")));
assertTrue(config.getForbiddenFormatsByGeographicalCode().get(UcteGeographicalCode.D2).isEmpty());
assertTrue(config.getForbiddenFormatsByGeographicalCode().get(EntsoeGeographicalCode.FR).equals(Sets.newHashSet("CIM1")));
assertTrue(config.getForbiddenFormatsByGeographicalCode().get(EntsoeGeographicalCode.BE).equals(Sets.newHashSet("CIM1")));
assertTrue(config.getForbiddenFormatsByGeographicalCode().get(EntsoeGeographicalCode.D2).isEmpty());
}

@Test
Expand Down
Expand Up @@ -12,7 +12,7 @@
import eu.itesla_project.iidm.import_.Importer;
import eu.itesla_project.iidm.network.Country;
import eu.itesla_project.iidm.network.Network;
import eu.itesla_project.ucte.util.UcteGeographicalCode;
import eu.itesla_project.entsoe.util.EntsoeGeographicalCode;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.nio.file.ShrinkWrapFileSystems;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
Expand Down Expand Up @@ -170,7 +170,7 @@ public void testLoad() throws Exception {
assertTrue(caseRepository.load(DateTime.parse("2013-01-14T00:15:00+01:00"), CaseType.SN, Country.FR).equals(Collections.singletonList(cimNetwork)));

// check that if cim is vorbidden for france, uct is loaded
caseRepository.getConfig().getForbiddenFormatsByGeographicalCode().put(UcteGeographicalCode.FR, "CIM1");
caseRepository.getConfig().getForbiddenFormatsByGeographicalCode().put(EntsoeGeographicalCode.FR, "CIM1");
assertTrue(caseRepository.load(DateTime.parse("2013-01-14T00:15:00+01:00"), CaseType.SN, Country.FR).equals(Collections.singletonList(uctNetwork)));

assertTrue(caseRepository.load(DateTime.parse("2013-01-15T00:15:00+01:00"), CaseType.SN, Country.DE).size() == 4);
Expand Down
2 changes: 1 addition & 1 deletion cim1-import/pom.xml
Expand Up @@ -52,7 +52,7 @@
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ucte-util</artifactId>
<artifactId>entsoe-util</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
Expand Down
Expand Up @@ -10,7 +10,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Multimap;
import eu.itesla_project.iidm.network.*;
import eu.itesla_project.ucte.util.UcteFileName;
import eu.itesla_project.entsoe.util.EntsoeFileName;
import org.jgrapht.UndirectedGraph;
import org.jgrapht.alg.ConnectivityInspector;
import org.jgrapht.graph.Pseudograph;
Expand Down Expand Up @@ -1191,11 +1191,11 @@ Network convert() {
}
}

UcteFileName ucteFileName = UcteFileName.parse(fileName);
EntsoeFileName entsoeFileName = EntsoeFileName.parse(fileName);

Network network = NetworkFactory.create(fileName, FORMAT);
network.setCaseDate(ucteFileName.getDate());
network.setForecastDistance(ucteFileName.getForecastDistance());
network.setCaseDate(entsoeFileName.getDate());
network.setForecastDistance(entsoeFileName.getForecastDistance());

// Ends of transformers need to be in the same substation in the IIDM model, so check that a mapping is
// not needed
Expand Down
Expand Up @@ -92,6 +92,8 @@ public LocalComputationManager(LocalComputationConfig config) throws IOException
this.config = Objects.requireNonNull(config, "config is null");
status = new LocalComputationResourcesStatus(config.getAvailableCore());
permits = new Semaphore(config.getAvailableCore());
//make sure the localdir exists
Files.createDirectories(config.getLocalDir());
commonDir = new WorkingDirectory(config.getLocalDir(), "itesla_common_", false);
LOGGER.info(config.toString());
}
Expand Down
6 changes: 3 additions & 3 deletions ucte-util/pom.xml → entsoe-util/pom.xml
Expand Up @@ -18,10 +18,10 @@
<version>0.1-SNAPSHOT</version>
</parent>

<artifactId>ucte-util</artifactId>
<artifactId>entsoe-util</artifactId>

<name>UCTE util</name>
<description>Utilities for working with UCTE data</description>
<name>ENTSO-E util</name>
<description>Utilities for working with ENTSO-E data</description>

<dependencies>
<dependency>
Expand Down
Expand Up @@ -4,7 +4,7 @@
* 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.ucte.util;
package eu.itesla_project.entsoe.util;

import eu.itesla_project.iidm.network.Country;

Expand Down
Expand Up @@ -4,7 +4,7 @@
* 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.ucte.util;
package eu.itesla_project.entsoe.util;

import eu.itesla_project.commons.config.PlatformConfig;
import eu.itesla_project.iidm.network.Country;
Expand Down
Expand Up @@ -4,7 +4,7 @@
* 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.ucte.util;
package eu.itesla_project.entsoe.util;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
Expand All @@ -16,20 +16,20 @@
*
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public class UcteFileName {
public class EntsoeFileName {

private static final Pattern DATE_REGEX = Pattern.compile(".*(\\d{4})[- /._]?(\\d{2})[- /._]?(\\d{2})[- /._]?(\\d{2})[- /._]?(\\d{2}).*");

private final DateTime date;

private final int forecastDistance;

private final UcteGeographicalCode geographicalCode;
private final EntsoeGeographicalCode geographicalCode;

public static UcteFileName parse(String str) {
public static EntsoeFileName parse(String str) {
DateTime date = DateTime.now();
int forecastDistance = 0;
UcteGeographicalCode geographicalCode = null;
EntsoeGeographicalCode geographicalCode = null;
Matcher m = DATE_REGEX.matcher(str);
if (m.matches()) {
// time zone is Europe/Paris
Expand All @@ -48,13 +48,13 @@ public static UcteFileName parse(String str) {
}
}
if (str.length() >= 19) {
geographicalCode = UcteGeographicalCode.valueOf(str.substring(18, 20));
geographicalCode = EntsoeGeographicalCode.valueOf(str.substring(18, 20));
}

return new UcteFileName(date, forecastDistance, geographicalCode);
return new EntsoeFileName(date, forecastDistance, geographicalCode);
}

private UcteFileName(DateTime date, int forecastDistance, UcteGeographicalCode geographicalCode) {
private EntsoeFileName(DateTime date, int forecastDistance, EntsoeGeographicalCode geographicalCode) {
this.date = date;
this.forecastDistance = forecastDistance;
this.geographicalCode = geographicalCode;
Expand All @@ -68,7 +68,7 @@ public int getForecastDistance() {
return forecastDistance;
}

public UcteGeographicalCode getGeographicalCode() {
public EntsoeGeographicalCode getGeographicalCode() {
return geographicalCode;
}

Expand Down

0 comments on commit 0cf7015

Please sign in to comment.