use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.OsgpMeterValue in project open-smart-grid-platform by OSGP.
the class PeriodicMeterReadContainerMappingTest method mapsPeriodicMeterReadsResponseItemDto.
@Test
public void mapsPeriodicMeterReadsResponseItemDto() {
final Date logTime = new Date();
final ActiveEnergyValuesDto valuesDto = new ActiveEnergyValuesDto(new DlmsMeterValueDto(new BigDecimal("12.34"), DlmsUnitTypeDto.M3), new DlmsMeterValueDto(new BigDecimal("12.35"), DlmsUnitTypeDto.M3), new DlmsMeterValueDto(new BigDecimal("12.36"), DlmsUnitTypeDto.M3), new DlmsMeterValueDto(new BigDecimal("12.37"), DlmsUnitTypeDto.M3), new DlmsMeterValueDto(new BigDecimal("12.38"), DlmsUnitTypeDto.M3), new DlmsMeterValueDto(new BigDecimal("12.39"), DlmsUnitTypeDto.M3));
final AmrProfileStatusCodeDto amrProfileStatusCodeDto = new AmrProfileStatusCodeDto(new HashSet<>(asList(AmrProfileStatusCodeFlagDto.CRITICAL_ERROR, AmrProfileStatusCodeFlagDto.CLOCK_ADJUSTED)));
final PeriodicMeterReadsResponseItemDto source = new PeriodicMeterReadsResponseItemDto(logTime, valuesDto, amrProfileStatusCodeDto);
final PeriodicMeterReads readsResult = this.monitoringMapper.map(source, PeriodicMeterReads.class);
final ActiveEnergyValues expectedValues = new ActiveEnergyValues(new OsgpMeterValue(new BigDecimal("12.340"), OsgpUnit.M3), new OsgpMeterValue(new BigDecimal("12.350"), OsgpUnit.M3), new OsgpMeterValue(new BigDecimal("12.360"), OsgpUnit.M3), new OsgpMeterValue(new BigDecimal("12.370"), OsgpUnit.M3), new OsgpMeterValue(new BigDecimal("12.380"), OsgpUnit.M3), new OsgpMeterValue(new BigDecimal("12.390"), OsgpUnit.M3));
final AmrProfileStatusCode amrProfileStatusCode = new AmrProfileStatusCode(new HashSet<>(asList(AmrProfileStatusCodeFlag.CRITICAL_ERROR, AmrProfileStatusCodeFlag.CLOCK_ADJUSTED)));
final PeriodicMeterReads expectedReads = new PeriodicMeterReads(logTime, expectedValues, amrProfileStatusCode);
assertThat(readsResult).usingRecursiveComparison().isEqualTo(expectedReads);
}
use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.OsgpMeterValue in project open-smart-grid-platform by OSGP.
the class MonitoringMapperTest method convertsMeterReadsResponseDtoToMeterReads.
@Test
public void convertsMeterReadsResponseDtoToMeterReads() {
final Date logTime = new Date(123L * 24 * 60 * 60 * 1000);
final ActiveEnergyValuesDto activeEnergyValuesDto = new ActiveEnergyValuesDto(new DlmsMeterValueDto(new BigDecimal("12.34"), DlmsUnitTypeDto.M3), new DlmsMeterValueDto(new BigDecimal("12.35"), DlmsUnitTypeDto.M3), new DlmsMeterValueDto(new BigDecimal("12.36"), DlmsUnitTypeDto.M3), new DlmsMeterValueDto(new BigDecimal("12.37"), DlmsUnitTypeDto.M3), new DlmsMeterValueDto(new BigDecimal("12.38"), DlmsUnitTypeDto.M3), new DlmsMeterValueDto(new BigDecimal("12.39"), DlmsUnitTypeDto.M3));
final MeterReadsResponseDto source = new MeterReadsResponseDto(logTime, activeEnergyValuesDto);
final MeterReads result = this.mapper.map(source, MeterReads.class);
final ActiveEnergyValues activeEnergyValues = new ActiveEnergyValues(new OsgpMeterValue(new BigDecimal("12.340"), OsgpUnit.M3), new OsgpMeterValue(new BigDecimal("12.350"), OsgpUnit.M3), new OsgpMeterValue(new BigDecimal("12.360"), OsgpUnit.M3), new OsgpMeterValue(new BigDecimal("12.370"), OsgpUnit.M3), new OsgpMeterValue(new BigDecimal("12.380"), OsgpUnit.M3), new OsgpMeterValue(new BigDecimal("12.390"), OsgpUnit.M3));
final MeterReads expected = new MeterReads(logTime, activeEnergyValues);
assertThat(result).usingRecursiveComparison().isEqualTo(expected);
}
use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.OsgpMeterValue in project open-smart-grid-platform by OSGP.
the class DlmsMeterValueConverter method convert.
@Override
public OsgpMeterValue convert(final DlmsMeterValueDto source, final Type<? extends OsgpMeterValue> destinationType, final MappingContext context) {
if (source == null) {
return null;
}
final BigDecimal multiplier = this.getMultiplierToOsgpUnit(source.getDlmsUnit(), this.toStandardUnit(source.getDlmsUnit()));
final BigDecimal calculated = source.getValue().multiply(multiplier);
LOGGER.debug(String.format("calculated %s from %s", calculated, source));
return new OsgpMeterValue(calculated, this.toStandardUnit(source.getDlmsUnit()));
}
Aggregations