Skip to content

Commit

Permalink
LDEPF disturbances and faults recording: interface between the settin…
Browse files Browse the repository at this point in the history
…g file reading and the SCD file (#262)

Signed-off-by: Samir Romdhani <[email protected]>
  • Loading branch information
samirromdhani authored Mar 28, 2023
1 parent 7c2bdcd commit 8b3e0ac
Show file tree
Hide file tree
Showing 5 changed files with 338 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-FileCopyrightText: 2023 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

package org.lfenergy.compas.sct.commons.dto;

import java.util.List;

/**
* Represents a list of LDEPF settings
* This is a functional interface whose functional method is getLDEPFSettings
* the type of the input to the operation
*
* @param <T> the type of the result of the LDEPFSettings
*
* @see org.lfenergy.compas.sct.commons.util.SettingLDEPFCsvHelper
*/
@FunctionalInterface
public interface LDEPFSettings<T> {

/**
* This method provides list of LDEPF settings
*/
List<T> getSettings();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// SPDX-FileCopyrightText: 2023 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

package org.lfenergy.compas.sct.commons.util;

import com.opencsv.bean.CsvBindByPosition;
import lombok.ToString;
import org.lfenergy.compas.sct.commons.dto.LDEPFSettings;

import java.io.Reader;
import java.util.List;


/**
* This class is an implementation example for interface LDEPFSettings.
* It relies on a CSV file.
*
* @see CsvUtils
*/
public class SettingLDEPFCsvHelper implements LDEPFSettings<SettingLDEPFCsvHelper.SettingLDEPF> {

private final List<SettingLDEPF> settings ;

/**
* Constructor
* @param reader input
*/
public SettingLDEPFCsvHelper(Reader reader) {
this.settings = CsvUtils.parseRows(reader, SettingLDEPF.class).stream().toList();
}

@Override
public List<SettingLDEPF> getSettings() {
return this.settings;
}

@ToString
public static class SettingLDEPF {
@CsvBindByPosition(position = 0)
private String rteIedType;
@CsvBindByPosition(position = 1)
private String iedRedundancy;
@CsvBindByPosition(position = 2)
private String iedInstance;
@CsvBindByPosition(position = 3)
private String channelShortLabel;
@CsvBindByPosition(position = 4)
private String channelMREP;
@CsvBindByPosition(position = 5)
private String channelLevModQ;
@CsvBindByPosition(position = 6)
private String channelLevModLevMod;
@CsvBindByPosition(position = 7)
private String bapVariant;
@CsvBindByPosition(position = 8)
private String bapIgnoredValue;
@CsvBindByPosition(position = 9)
private String ldInst;
@CsvBindByPosition(position = 10)
private String lnPrefix;
@CsvBindByPosition(position = 11)
private String lnName;
@CsvBindByPosition(position = 12)
private String lnInst;
@CsvBindByPosition(position = 13)
private String doName;
@CsvBindByPosition(position = 14)
private String doInst;
@CsvBindByPosition(position = 15)
private String sdoName;
@CsvBindByPosition(position = 16)
private String daName;
@CsvBindByPosition(position = 17)
private String daType;
@CsvBindByPosition(position = 18)
private String dabType;
@CsvBindByPosition(position = 19)
private String bdaName;
@CsvBindByPosition(position = 20)
private String sbdaName;
@CsvBindByPosition(position = 21)
private String channelAnalogNum;
@CsvBindByPosition(position = 22)
private String channelDigitalNum;
@CsvBindByPosition(position = 23)
private String opt;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-FileCopyrightText: 2023 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

package org.lfenergy.compas.sct.commons.dto;

import org.junit.jupiter.api.Test;
import org.lfenergy.compas.sct.commons.util.CsvUtils;
import org.lfenergy.compas.sct.commons.util.SettingLDEPFCsvHelper;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Objects;
import static org.assertj.core.api.Assertions.assertThat;

class LDEPFSettingsTest {

@Test
void getLDEPFSettings_should_return_settings() {
//Given
String fileName = "LDEPF_Setting_file.csv";
InputStream inputStream = Objects.requireNonNull(CsvUtils.class.getClassLoader().getResourceAsStream(fileName), "Resource not found: " + fileName);
InputStreamReader reader = new InputStreamReader(inputStream);
LDEPFSettings<SettingLDEPFCsvHelper.SettingLDEPF> ldepfSettings = new SettingLDEPFCsvHelper(reader);
// When
// Then
assertThat(ldepfSettings.getSettings()).hasSize(161);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-FileCopyrightText: 2023 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

package org.lfenergy.compas.sct.commons.util;

import org.junit.jupiter.api.Test;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Objects;

import static org.assertj.core.api.Assertions.assertThat;


class SettingLDEPFCsvHelperTest {

@Test
void readCsvFile_should_return_settings() {
// Given
String fileName = "LDEPF_Setting_file.csv";
InputStream inputStream = Objects.requireNonNull(CsvUtils.class.getClassLoader().getResourceAsStream(fileName), "Resource not found: " + fileName);
InputStreamReader reader = new InputStreamReader(inputStream);
// When
// Then
SettingLDEPFCsvHelper settingLDEPFCsvHelper = new SettingLDEPFCsvHelper(reader);
assertThat(settingLDEPFCsvHelper.getSettings()).hasSize(161);
}
}
Loading

0 comments on commit 8b3e0ac

Please sign in to comment.