Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: Geoffroy Jamgotchian <[email protected]>
  • Loading branch information
geofjamg committed Oct 11, 2019
0 parents commit e3f58b1
Show file tree
Hide file tree
Showing 343 changed files with 62,443 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Maven projects
cgmes-dl/target
cgmes-dl/cgmes-dl-conversion/target
cgmes-dl/cgmes-iidm-extensions/target
cgmes-gl/target
cgmes-gl/cgmes-gl-conversion/target
cgmes-gl/cgmes-gl-iidm-extensions/target
substation-diagram/substation-diagram-cgmes/target
substation-diagram/substation-diagram-core/target
substation-diagram/substation-diagram-util/target
substation-diagram/substation-diagram-view/target
substation-diagram/target
substation-webviewer/target
target

# IntelliJ
/.idea
*.iml

# Compilation settings
install.cfg

# Eclipse projects
.classpath
.project
org.eclipse.core.resources.prefs
org.eclipse.jdt.core.prefs
org.eclipse.m2e.core.prefs
org.eclipse.jdt.groovy.core.prefs
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
language: java

dist: trusty
sudo: required

jdk:
- oraclejdk8

addons:
sonarcloud:
organization: "powsybl-ci-github"
token:
secure: ${SONAR_TOKEN}

install:
# Build powsybl-core
- git clone https://github.com/powsybl/powsybl-core powsybl/powsybl-core
- pushd powsybl/powsybl-core && mvn --batch-mode -DskipTests install && popd

script:
- mvn --batch-mode -Pjacoco,checks clean verify sonar:sonar
373 changes: 373 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '{build}'
os: Windows Server 2012
install:
- ps: |
Add-Type -AssemblyName System.IO.Compression.FileSystem
if (!(Test-Path -Path "C:\maven" )) {
(new-object System.Net.WebClient).DownloadFile(
'http://www.us.apache.org/dist/maven/maven-3/3.2.5/binaries/apache-maven-3.2.5-bin.zip',
'C:\maven-bin.zip'
)
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\maven-bin.zip", "C:\maven")
}
- cmd: SET M2_HOME=C:\maven\apache-maven-3.2.5
- cmd: SET PATH=%M2_HOME%\bin;%JAVA_HOME%\bin;%PATH%
before_build:
- git clone https://github.com/powsybl/powsybl-core.git powsybl/powsybl-core
- ps: |
pushd powsybl/powsybl-core
mvn -DskipTests install --batch-mode
popd
build_script:
- mvn clean package --batch-mode
39 changes: 39 additions & 0 deletions base-voltage-color/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2019, 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/.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-single-line-diagram</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<artifactId>powsybl-base-voltage-color</artifactId>
<name>Base Voltages color configuration</name>

<dependencies>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-commons</artifactId>
<version>${powsyblcore.version}</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
* Copyright (c) 2019, 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 com.powsybl.basevoltage;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;

import com.powsybl.commons.config.PlatformConfig;

/**
*
* @author Massimo Ferraro <[email protected]>
*/
public class BaseVoltageColor {

private static final String CONFIG_FILE = "base-voltages.yml";

private final BaseVoltagesConfig config;

public BaseVoltageColor(Path configFile) throws IOException {
Objects.requireNonNull(configFile);
Yaml yaml = new Yaml(new Constructor(BaseVoltagesConfig.class));
InputStream configInputStream = Files.newInputStream(configFile);
config = yaml.load(configInputStream);
}

public BaseVoltageColor() throws IOException {
this(PlatformConfig.defaultConfig().getConfigDir().resolve(CONFIG_FILE));
}

public List<String> getProfiles() {
return config.getBaseVoltages()
.stream()
.map(BaseVoltageConfig::getProfile)
.distinct()
.collect(Collectors.toList());
}

public String getDefaultProfile() {
return config.getDefaultProfile();
}

public List<String> getBaseVoltageNames(String profile) {
Objects.requireNonNull(profile);
return config.getBaseVoltages()
.stream()
.filter(baseVoltage -> baseVoltage.getProfile().equals(profile))
.map(BaseVoltageConfig::getName)
.collect(Collectors.toList());
}

public String getBaseVoltageName(double voltage, String profile) {
Objects.requireNonNull(profile);
return config.getBaseVoltages()
.stream()
.filter(baseVoltage -> baseVoltage.getProfile().equals(profile)
&& baseVoltage.getMinValue() <= voltage
&& baseVoltage.getMaxValue() > voltage)
.map(BaseVoltageConfig::getName)
.findFirst()
.orElse(null);
}

public String getColor(String baseVoltageName, String profile) {
Objects.requireNonNull(baseVoltageName);
Objects.requireNonNull(profile);
return config.getBaseVoltages()
.stream()
.filter(baseVoltage -> baseVoltage.getProfile().equals(profile)
&& baseVoltage.getName().equals(baseVoltageName))
.map(BaseVoltageConfig::getColor)
.findFirst()
.orElse(null);
}

public String getColor(double voltage, String profile) {
Objects.requireNonNull(profile);
return config.getBaseVoltages()
.stream()
.filter(baseVoltage -> baseVoltage.getProfile().equals(profile)
&& baseVoltage.getMinValue() <= voltage
&& baseVoltage.getMaxValue() > voltage)
.map(BaseVoltageConfig::getColor)
.findFirst()
.orElse(null);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Copyright (c) 2019, 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 com.powsybl.basevoltage;

/**
*
* @author Massimo Ferraro <[email protected]>
*/
public class BaseVoltageConfig {

private String name;
private double minValue;
private double maxValue;
private String color;
private String profile;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public double getMinValue() {
return minValue;
}

public void setMinValue(double minValue) {
this.minValue = minValue;
}

public double getMaxValue() {
return maxValue;
}

public void setMaxValue(double maxValue) {
this.maxValue = maxValue;
}

public String getColor() {
return color;
}

public void setColor(String color) {
this.color = color;
}

public String getProfile() {
return profile;
}

public void setProfile(String profile) {
this.profile = profile;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (c) 2019, 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 com.powsybl.basevoltage;

import java.util.List;

/**
*
* @author Massimo Ferraro <[email protected]>
*/
public class BaseVoltagesConfig {

private List<BaseVoltageConfig> baseVoltages;
private String defaultProfile;

public List<BaseVoltageConfig> getBaseVoltages() {
return baseVoltages;
}

public void setBaseVoltages(List<BaseVoltageConfig> baseVoltages) {
this.baseVoltages = baseVoltages;
}

public String getDefaultProfile() {
return defaultProfile;
}

public void setDefaultProfile(String defaultProfile) {
this.defaultProfile = defaultProfile;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Copyright (c) 2019, 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 com.powsybl.basevoltage;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;

import org.junit.Test;

/**
*
* @author Massimo Ferraro <[email protected]>
*/
public class BaseVoltageColorTest {

@Test
public void test() throws IOException, URISyntaxException {
Path configFile = Paths.get(getClass().getResource("/base-voltages.yml").toURI());
BaseVoltageColor baseVoltageColor = new BaseVoltageColor(configFile);
// getProfiles
assertEquals(Arrays.asList("RTE"), baseVoltageColor.getProfiles());
// getDefaultProfile
assertEquals("RTE", baseVoltageColor.getDefaultProfile());
// getBaseVoltageNames
assertEquals(Arrays.asList("400", "225"), baseVoltageColor.getBaseVoltageNames("RTE"));
// getBaseVoltageName
assertNull(baseVoltageColor.getBaseVoltageName(500, "RTE"));
assertEquals("400", baseVoltageColor.getBaseVoltageName(450, "RTE"));
assertEquals("400", baseVoltageColor.getBaseVoltageName(400, "RTE"));
assertEquals("400", baseVoltageColor.getBaseVoltageName(300, "RTE"));
assertEquals("225", baseVoltageColor.getBaseVoltageName(250, "RTE"));
assertEquals("225", baseVoltageColor.getBaseVoltageName(180, "RTE"));
assertNull(baseVoltageColor.getBaseVoltageName(150, "RTE"));
// getColor by name
assertEquals("#BBBBBBB", baseVoltageColor.getColor("400", "RTE"));
assertEquals("#AAAAAAA", baseVoltageColor.getColor("225", "RTE"));
assertNull(baseVoltageColor.getColor("150", "RTE"));
// getColor by voltage
assertNull(baseVoltageColor.getColor(500, "RTE"));
assertEquals("#BBBBBBB", baseVoltageColor.getColor(450, "RTE"));
assertEquals("#BBBBBBB", baseVoltageColor.getColor(400, "RTE"));
assertEquals("#BBBBBBB", baseVoltageColor.getColor(300, "RTE"));
assertEquals("#AAAAAAA", baseVoltageColor.getColor(250, "RTE"));
assertEquals("#AAAAAAA", baseVoltageColor.getColor(180, "RTE"));
assertNull(baseVoltageColor.getColor(150, "RTE"));
}

}
Loading

0 comments on commit e3f58b1

Please sign in to comment.