Search in sources :

Example 1 with DlmsMeterValueDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto in project open-smart-grid-platform by OSGP.

the class MeterReadsGasMappingTest method testMeterReadsGasMappingTest.

// Test the mapping of a complete MeterReadsGasDto object
@Test
public void testMeterReadsGasMappingTest() {
    // build test data
    final DlmsMeterValueDto consumption = new DlmsMeterValueDto(new BigDecimal(1.0), DlmsUnitTypeDto.M3);
    final MeterReadsGasResponseDto meterReadsGasDto = new MeterReadsGasResponseDto(new Date(), consumption, new Date());
    // actual mapping
    final MeterReadsGas meterReadsGas = this.monitoringMapper.map(meterReadsGasDto, MeterReadsGas.class);
    // test mapping
    assertThat(meterReadsGas).isNotNull();
    assertThat(meterReadsGas.getLogTime()).isEqualTo(meterReadsGasDto.getLogTime());
    assertThat(meterReadsGas.getCaptureTime()).isEqualTo(meterReadsGasDto.getCaptureTime());
    final BigDecimal bigDecimal1 = consumption.getValue();
    final BigDecimal bigDecimal2 = meterReadsGas.getConsumption().getValue();
    assertThat(bigDecimal1.compareTo(bigDecimal2) == 0).isTrue();
    assertThat(meterReadsGas.getConsumption().getOsgpUnit()).isEqualTo(OsgpUnit.M3);
}
Also used : MeterReadsGas(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.MeterReadsGas) MeterReadsGasResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.MeterReadsGasResponseDto) BigDecimal(java.math.BigDecimal) Date(java.util.Date) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto) Test(org.junit.jupiter.api.Test)

Example 2 with DlmsMeterValueDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto in project open-smart-grid-platform by OSGP.

the class DlmsMeterValueConverterTest method testCalculate.

@Test
public void testCalculate() {
    final MonitoringMapper calculator = new MonitoringMapper();
    DlmsMeterValueDto response = new DlmsMeterValueDto(BigDecimal.valueOf(123456), DlmsUnitTypeDto.KWH);
    assertThat(calculator.map(response, OsgpMeterValue.class).getValue()).isEqualTo(BigDecimal.valueOf(123.456d));
    assertThat(calculator.map(response, OsgpMeterValue.class).getOsgpUnit()).isEqualTo(OsgpUnit.KWH);
    response = new DlmsMeterValueDto(BigDecimal.valueOf(123456), DlmsUnitTypeDto.M3);
    assertThat(calculator.map(response, OsgpMeterValue.class).getValue()).isEqualTo(BigDecimal.valueOf(123456d));
    assertThat(calculator.map(response, OsgpMeterValue.class).getOsgpUnit()).isEqualTo(OsgpUnit.M3);
    response = new DlmsMeterValueDto(BigDecimal.valueOf(123456), DlmsUnitTypeDto.M3_CORR);
    assertThat(calculator.map(response, OsgpMeterValue.class).getValue()).isEqualTo(BigDecimal.valueOf(123456d));
    assertThat(calculator.map(response, OsgpMeterValue.class).getOsgpUnit()).isEqualTo(OsgpUnit.M3);
    response = new DlmsMeterValueDto(BigDecimal.valueOf(123456), DlmsUnitTypeDto.MONTH);
    try {
        calculator.map(response, OsgpMeterValue.class);
        fail("dlms unit A not supported, expected IllegalArgumentException");
    } catch (final IllegalArgumentException ex) {
    }
}
Also used : OsgpMeterValue(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.OsgpMeterValue) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto) Test(org.junit.jupiter.api.Test)

Example 3 with DlmsMeterValueDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto in project open-smart-grid-platform by OSGP.

the class PeriodicMeterReadContainerMappingTest method testWithNonEmptyList.

// Test if mapping with a non-empty List succeeds
@Test
public void testWithNonEmptyList() {
    // build test data
    final DlmsMeterValueDto activeEnergyImport = new DlmsMeterValueDto(new BigDecimal(1.0), DlmsUnitTypeDto.M3);
    final DlmsMeterValueDto activeEnergyExport = new DlmsMeterValueDto(new BigDecimal(1.0), DlmsUnitTypeDto.M3);
    final Set<AmrProfileStatusCodeFlagDto> amrProfileStatusCodeFlagSet = new TreeSet<>();
    amrProfileStatusCodeFlagSet.add(AmrProfileStatusCodeFlagDto.CRITICAL_ERROR);
    final AmrProfileStatusCodeDto amrProfileStatusCodeDto = new AmrProfileStatusCodeDto(amrProfileStatusCodeFlagSet);
    final PeriodicMeterReadsResponseItemDto periodicMeterReadsDto = new PeriodicMeterReadsResponseItemDto(new Date(), activeEnergyImport, activeEnergyExport, amrProfileStatusCodeDto);
    final List<PeriodicMeterReadsResponseItemDto> meterReads = new ArrayList<>();
    meterReads.add(periodicMeterReadsDto);
    final PeriodTypeDto periodType = PeriodTypeDto.DAILY;
    final PeriodicMeterReadsResponseDto periodicMeterReadsContainerDto = new PeriodicMeterReadsResponseDto(periodType, meterReads);
    // actual mapping
    final PeriodicMeterReadsContainer periodicMeterReadsContainer = this.monitoringMapper.map(periodicMeterReadsContainerDto, PeriodicMeterReadsContainer.class);
    // test mapping
    assertThat(periodicMeterReadsContainer).isNotNull();
    assertThat(periodicMeterReadsContainer.getPeriodType().name()).isEqualTo(periodicMeterReadsContainerDto.getPeriodType().name());
    assertThat(periodicMeterReadsContainer.getPeriodicMeterReads().size()).isEqualTo(periodicMeterReadsContainerDto.getPeriodicMeterReads().size());
    assertThat(periodicMeterReadsContainer.getPeriodicMeterReads().get(0).getLogTime()).isEqualTo(periodicMeterReadsContainerDto.getPeriodicMeterReads().get(0).getLogTime());
    assertThat(periodicMeterReadsContainer.getPeriodicMeterReads().get(0).getActiveEnergyImport().getValue()).isEqualTo(new BigDecimal("1.0"));
    assertThat(periodicMeterReadsContainer.getPeriodicMeterReads().get(0).getActiveEnergyImport().getOsgpUnit()).isEqualTo(OsgpUnit.M3);
    assertThat(periodicMeterReadsContainer.getPeriodicMeterReads().get(0).getActiveEnergyExport().getValue()).isEqualTo(new BigDecimal("1.0"));
    assertThat(periodicMeterReadsContainer.getPeriodicMeterReads().get(0).getActiveEnergyExport().getOsgpUnit()).isEqualTo(OsgpUnit.M3);
    assertThat(periodicMeterReadsContainer.getPeriodicMeterReads().get(0).getAmrProfileStatusCode().getAmrProfileStatusCodeFlags().size()).isEqualTo(periodicMeterReadsContainerDto.getPeriodicMeterReads().get(0).getAmrProfileStatusCode().getAmrProfileStatusCodeFlags().size());
    assertThat(periodicMeterReadsContainer.getPeriodicMeterReads().get(0).getAmrProfileStatusCode().getAmrProfileStatusCodeFlags().contains(AmrProfileStatusCodeFlag.CRITICAL_ERROR)).isTrue();
}
Also used : AmrProfileStatusCodeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeDto) PeriodicMeterReadsResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsResponseItemDto) PeriodTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto) AmrProfileStatusCodeFlagDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeFlagDto) ArrayList(java.util.ArrayList) PeriodicMeterReadsResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsResponseDto) BigDecimal(java.math.BigDecimal) Date(java.util.Date) TreeSet(java.util.TreeSet) PeriodicMeterReadsContainer(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PeriodicMeterReadsContainer) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto) Test(org.junit.jupiter.api.Test)

Example 4 with DlmsMeterValueDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto in project open-smart-grid-platform by OSGP.

the class PeriodicMeterReadsContainerGasMappingTest method testWithNonEmptyList.

// Test if mapping with a non-empty List succeeds
@Test
public void testWithNonEmptyList() {
    // build test data
    final DlmsMeterValueDto consumption = new DlmsMeterValueDto(new BigDecimal(1.0), DlmsUnitTypeDto.M3);
    final Set<AmrProfileStatusCodeFlagDto> amrProfileStatusCodeFlagSet = new TreeSet<>();
    amrProfileStatusCodeFlagSet.add(AmrProfileStatusCodeFlagDto.CRITICAL_ERROR);
    final AmrProfileStatusCodeDto amrProfileStatusCodeDto = new AmrProfileStatusCodeDto(amrProfileStatusCodeFlagSet);
    final PeriodicMeterReadsGasResponseItemDto periodicMeterReadsGasDto = new PeriodicMeterReadsGasResponseItemDto(new Date(), consumption, new Date(), amrProfileStatusCodeDto);
    final List<PeriodicMeterReadsGasResponseItemDto> meterReads = new ArrayList<>();
    meterReads.add(periodicMeterReadsGasDto);
    final PeriodTypeDto periodType = PeriodTypeDto.DAILY;
    final PeriodicMeterReadGasResponseDto periodicMeterReadsContainerDto = new PeriodicMeterReadGasResponseDto(periodType, meterReads);
    // actual mapping
    final PeriodicMeterReadsContainerGas periodicMeterReadsContainerGas = this.monitoringMapper.map(periodicMeterReadsContainerDto, PeriodicMeterReadsContainerGas.class);
    // test mapping
    assertThat(periodicMeterReadsContainerGas).withFailMessage("Mapping must take place. So the result cannot be null.").isNotNull();
    assertThat(periodicMeterReadsContainerGas.getPeriodType().name()).withFailMessage("After the mapping the name of the period must be the same.").isEqualTo(periodicMeterReadsContainerDto.getPeriodType().name());
    assertThat(periodicMeterReadsContainerGas.getPeriodicMeterReadsGas().size()).withFailMessage("The number of periodic meter reads before and after the mapping must be equal.").isEqualTo(periodicMeterReadsContainerDto.getPeriodicMeterReadsGas().size());
    assertThat(periodicMeterReadsContainerGas.getPeriodicMeterReadsGas().get(0).getLogTime()).withFailMessage("After the mapping the log time of the first entry must be the same.").isEqualTo(periodicMeterReadsContainerDto.getPeriodicMeterReadsGas().get(0).getLogTime());
    assertThat(periodicMeterReadsContainerGas.getPeriodicMeterReadsGas().get(0).getCaptureTime()).withFailMessage("After the mapping the capture time of the first entry must be the same.").isEqualTo(periodicMeterReadsContainerDto.getPeriodicMeterReadsGas().get(0).getCaptureTime());
    assertThat(periodicMeterReadsContainerGas.getPeriodicMeterReadsGas().get(0).getConsumption().getValue()).withFailMessage("After the mapping the consumption must be equal.").isEqualTo(new BigDecimal("1.0"));
    assertThat(periodicMeterReadsContainerGas.getPeriodicMeterReadsGas().get(0).getConsumption().getOsgpUnit()).withFailMessage("After the mapping the osgp unit value must be the same.").isEqualTo(OsgpUnit.M3);
    assertThat(periodicMeterReadsContainerGas.getPeriodicMeterReadsGas().get(0).getAmrProfileStatusCode().getAmrProfileStatusCodeFlags().size()).withFailMessage("After the mapping the size of the arm profile status code flags must be the same.").isEqualTo(periodicMeterReadsContainerDto.getPeriodicMeterReadsGas().get(0).getAmrProfileStatusCode().getAmrProfileStatusCodeFlags().size());
    assertThat(periodicMeterReadsContainerGas.getPeriodicMeterReadsGas().get(0).getAmrProfileStatusCode().getAmrProfileStatusCodeFlags().contains(AmrProfileStatusCodeFlag.CRITICAL_ERROR)).withFailMessage("After the mapping the amr profile status code flags must contain the CRITICAL_ERROR flag.").isTrue();
}
Also used : AmrProfileStatusCodeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeDto) PeriodTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto) PeriodicMeterReadsGasResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsGasResponseItemDto) AmrProfileStatusCodeFlagDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeFlagDto) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) Date(java.util.Date) TreeSet(java.util.TreeSet) PeriodicMeterReadGasResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadGasResponseDto) PeriodicMeterReadsContainerGas(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PeriodicMeterReadsContainerGas) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto) Test(org.junit.jupiter.api.Test)

Example 5 with DlmsMeterValueDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto in project open-smart-grid-platform by OSGP.

the class DlmsHelper method getScaledMeterValue.

public DlmsMeterValueDto getScaledMeterValue(final DataObject value, final DataObject scalerUnitObject, final String description) throws ProtocolAdapterException {
    LOGGER.debug(this.getDebugInfo(value));
    LOGGER.debug(this.getDebugInfo(scalerUnitObject));
    final Long rawValue = this.readLong(value, description);
    if (rawValue == null) {
        return null;
    }
    if (!scalerUnitObject.isComplex()) {
        throw new ProtocolAdapterException("complex data (structure) expected while retrieving scaler and unit." + this.getDebugInfo(scalerUnitObject));
    }
    final List<DataObject> dataObjects = scalerUnitObject.getValue();
    if (dataObjects.size() != 2) {
        throw new ProtocolAdapterException("expected 2 values while retrieving scaler and unit." + this.getDebugInfo(scalerUnitObject));
    }
    final int scaler = this.readLongNotNull(dataObjects.get(0), description).intValue();
    final DlmsUnitTypeDto unit = DlmsUnitTypeDto.getUnitType(this.readLongNotNull(dataObjects.get(1), description).intValue());
    // determine value
    BigDecimal scaledValue = BigDecimal.valueOf(rawValue);
    if (scaler != 0) {
        scaledValue = scaledValue.multiply(BigDecimal.valueOf(Math.pow(10, scaler)));
    }
    return new DlmsMeterValueDto(scaledValue, unit);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) DlmsUnitTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsUnitTypeDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) BigDecimal(java.math.BigDecimal) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto)

Aggregations

DlmsMeterValueDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto)14 Test (org.junit.jupiter.api.Test)9 BigDecimal (java.math.BigDecimal)8 Date (java.util.Date)8 GetResult (org.openmuc.jdlms.GetResult)4 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)4 AmrProfileStatusCodeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeDto)4 CosemDateTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)4 MeterReadsGasResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.MeterReadsGasResponseDto)4 ArrayList (java.util.ArrayList)3 OsgpMeterValue (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.OsgpMeterValue)3 ActiveEnergyValuesDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ActiveEnergyValuesDto)3 PeriodTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto)3 PeriodicMeterReadsResponseItemDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsResponseItemDto)3 TreeSet (java.util.TreeSet)2 DateTime (org.joda.time.DateTime)2 AttributeAddress (org.openmuc.jdlms.AttributeAddress)2 DataObject (org.openmuc.jdlms.datatypes.DataObject)2 ActiveEnergyValues (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ActiveEnergyValues)2 MeterReadsGas (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.MeterReadsGas)2