Search in sources :

Example 1 with TimePeriodDto

use of com.alliander.osgp.dto.valueobjects.TimePeriodDto in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850PowerUsageHistoryCommand method getPowerUsageHistoryDataFromDevice.

public List<PowerUsageDataDto> getPowerUsageHistoryDataFromDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final PowerUsageHistoryMessageDataContainerDto powerUsageHistoryContainer, final List<DeviceOutputSetting> deviceOutputSettingsLightRelays) throws ProtocolAdapterException {
    final Function<List<PowerUsageDataDto>> function = new Function<List<PowerUsageDataDto>>() {

        @Override
        public List<PowerUsageDataDto> apply(final DeviceMessageLog deviceMessageLog) throws Exception {
            final HistoryTermTypeDto historyTermType = powerUsageHistoryContainer.getHistoryTermType();
            if (historyTermType != null) {
                LOGGER.info("device: {}, ignoring HistoryTermType ({}) determining power usage history", deviceConnection.getDeviceIdentification(), historyTermType);
            }
            final TimePeriodDto timePeriod = powerUsageHistoryContainer.getTimePeriod();
            final List<PowerUsageDataDto> powerUsageHistoryData = new ArrayList<>();
            for (final DeviceOutputSetting deviceOutputSetting : deviceOutputSettingsLightRelays) {
                final List<PowerUsageDataDto> powerUsageData = Iec61850PowerUsageHistoryCommand.this.getPowerUsageHistoryDataFromRelay(iec61850Client, deviceConnection, timePeriod, deviceOutputSetting, deviceMessageLog);
                powerUsageHistoryData.addAll(powerUsageData);
            }
            DeviceMessageLoggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
            /*
                 * This way of gathering leads to PowerUsageData elements per
                 * relay. If it is necessary to only include one PowerUsageData
                 * element for the device, where data for the different relays
                 * is combined in the SsldData.relayData some sort of merge
                 * needs to be performed.
                 * 
                 * This can either be a rework of the list currently returned,
                 * or it can be a list constructed based on an altered return
                 * type from getPowerUsageHistoryDataFromRelay (for instance a
                 * Map of Date to a Map of Relay Index to Total Lighting
                 * Minutes).
                 */
            return powerUsageHistoryData;
        }
    };
    return iec61850Client.sendCommandWithRetry(function, "GetPowerUsageHistory", deviceConnection.getDeviceIdentification());
}
Also used : Function(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function) DeviceMessageLog(com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog) HistoryTermTypeDto(com.alliander.osgp.dto.valueobjects.HistoryTermTypeDto) ArrayList(java.util.ArrayList) DeviceOutputSetting(com.alliander.osgp.core.db.api.iec61850.entities.DeviceOutputSetting) ArrayList(java.util.ArrayList) List(java.util.List) PowerUsageDataDto(com.alliander.osgp.dto.valueobjects.PowerUsageDataDto) TimePeriodDto(com.alliander.osgp.dto.valueobjects.TimePeriodDto)

Aggregations

DeviceMessageLog (com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog)1 Function (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function)1 DeviceOutputSetting (com.alliander.osgp.core.db.api.iec61850.entities.DeviceOutputSetting)1 HistoryTermTypeDto (com.alliander.osgp.dto.valueobjects.HistoryTermTypeDto)1 PowerUsageDataDto (com.alliander.osgp.dto.valueobjects.PowerUsageDataDto)1 TimePeriodDto (com.alliander.osgp.dto.valueobjects.TimePeriodDto)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1