private void CheckDeviceActionsAllInSameCategory([NotNull] DeviceActionGroup actionGroup,
                                                         [NotNull][ItemNotNull] ObservableCollection <DeviceAction> allActions, [NotNull] Simulator sim)
        {
            // collect all used groups

            var devicesInActions = actionGroup.GetRealDevices(allActions);

            if (devicesInActions.Count == 0)
            {
                throw new LPGException("Bug in device action check. Please report!");
            }
            var cat = devicesInActions[0].DeviceCategory;

            if (devicesInActions[0].DeviceCategory == null)
            {
                throw new LPGException("Device Category was null");
            }
            var devicesInCategory = devicesInActions[0].DeviceCategory.GetRealDevices(allActions);

            if (cat == null)
            {
                throw new LPGException("Category was null");
            }
            foreach (var realDevice in devicesInActions)
            {
                if (!devicesInCategory.Contains(realDevice))
                {
                    FindMissingDevice(cat, actionGroup.GetDeviceActions(allActions), actionGroup, sim);
                }
            }
            foreach (var realDevice in devicesInCategory)
            {
                if (!devicesInActions.Contains(realDevice))
                {
                    FindMissingDevice(cat, actionGroup.GetDeviceActions(allActions), actionGroup, sim);
                }
            }
        }
示例#2
0
        private DeviceAction PickDeviceActionFromGroupAtHHLocation([NotNull] DeviceActionGroup deviceActionGroup,
                                                                   [NotNull][ItemNotNull] List <IAssignableDevice> allDevLocations, EnergyIntensityType energyIntensity, [NotNull] Location targetLoc,
                                                                   [NotNull][ItemNotNull] ObservableCollection <DeviceAction> allDeviceActions)
        {
            // check if there is already such a device
            // first get all device actions in the group
            var deviceActions = deviceActionGroup.GetDeviceActions(allDeviceActions);
            //then get all devices in all device actions
            var devices = deviceActions.Select(da => da.Device).ToList();

            //then find if any of the locations already has a device for any of the device actions
            foreach (var device in allDevLocations)
            {
                if (devices.Contains(device))
                {
                    var devac = deviceActions.Single(x => x.Device == device);
                    Logger.Debug(
                        "Picked " + devac.Name + " from " + targetLoc.Name + " since the device for it was already there.");
                    return(devac);
                }
            }
            return(PickDeviceFromGroup(deviceActionGroup, energyIntensity, allDeviceActions, targetLoc.IntID));
        }
示例#3
0
        private DeviceAction PickDeviceFromGroup([NotNull] DeviceActionGroup deviceGroup, EnergyIntensityType energyIntensity,
                                                 [NotNull][ItemNotNull] ObservableCollection <DeviceAction> allDeviceActions, int locationID)
        {
            var deviceActions = deviceGroup.GetDeviceActions(allDeviceActions);

            if (deviceActions.Count == 0)
            {
                throw new DataIntegrityException("The device action group " + deviceGroup.Name +
                                                 " has no devices but it is used. A device could not be picked from it.");
            }
            if (deviceActions[0].Device == null)
            {
                throw new LPGException("Device was null");
            }
            var usedDeviceCategory = deviceActions[0].Device.DeviceCategory;

            if (usedDeviceCategory == null)
            {
                throw new LPGException("usedDeviceCategory was null");
            }
            var ldt2 = new LocationDeviceTuple(usedDeviceCategory, locationID);

            if (_pickedDevices.ContainsKey(ldt2))
            {
                // find the device picked earlier
                var rd = _pickedDevices[ldt2];
                deviceActions = deviceActions.Where(x => x.Device == rd).ToList();
                if (deviceActions.Count == 0)
                {
                    throw new DataIntegrityException(
                              "The device action group " + deviceGroup.Name + " has no entry for the device " +
                              rd.PrettyName +
                              ". Please fix.", rd);
                }
            }
            DeviceAction pickedDevice = null;

            // look for this device group in the device selection
            if (_deviceSelection != null && _deviceSelection.Actions.Count > 0)
            {
                foreach (var item in _deviceSelection.Actions)
                {
                    if (item.DeviceActionGroup == deviceGroup)
                    {
                        pickedDevice = item.DeviceAction;
                    }
                }
            }
            if (pickedDevice == null)
            {
                switch (energyIntensity)
                {
                case EnergyIntensityType.Random:
                    var dstval = _random.Next(deviceActions.Count);
                    pickedDevice = deviceActions[dstval];
                    break;

                case EnergyIntensityType.EnergySaving: {
                    var pickeDeviceAction = deviceActions[0];
                    foreach (var deviceAction in deviceActions)
                    {
                        if (pickeDeviceAction.CalculateWeightedEnergyUse() >
                            deviceAction.CalculateWeightedEnergyUse())
                        {
                            pickeDeviceAction = deviceAction;
                        }
                    }
                    pickedDevice = pickeDeviceAction;
                }
                break;

                case EnergyIntensityType.EnergySavingPreferMeasured: {
                    var actions           = TryToGetMeasured(deviceActions);
                    var pickeDeviceAction = actions[0];
                    foreach (var deviceAction in actions)
                    {
                        if (pickeDeviceAction.CalculateWeightedEnergyUse() >
                            deviceAction.CalculateWeightedEnergyUse())
                        {
                            pickeDeviceAction = deviceAction;
                        }
                    }
                    pickedDevice = pickeDeviceAction;
                }
                break;

                case EnergyIntensityType.EnergyIntensive: {
                    var pickeDeviceAction = deviceActions[0];
                    foreach (var deviceAction in deviceActions)
                    {
                        if (pickeDeviceAction.CalculateWeightedEnergyUse() <
                            deviceAction.CalculateWeightedEnergyUse())
                        {
                            pickeDeviceAction = deviceAction;
                        }
                    }
                    pickedDevice = pickeDeviceAction;
                }
                break;

                case EnergyIntensityType.EnergyIntensivePreferMeasured: {
                    var actions           = TryToGetMeasured(deviceActions);
                    var pickeDeviceAction = actions[0];
                    foreach (var deviceAction in deviceActions)
                    {
                        if (pickeDeviceAction.CalculateWeightedEnergyUse() <
                            deviceAction.CalculateWeightedEnergyUse())
                        {
                            pickeDeviceAction = deviceAction;
                        }
                    }
                    pickedDevice = pickeDeviceAction;
                }
                break;

                default:
                    throw new LPGException("Unknown EnergyIntensityType");
                }
            }
            Logger.Debug(
                "Picked " + pickedDevice.Name + " from " + deviceActions.Count + " device actions in the group.");
            if (pickedDevice == null)
            {
                throw new LPGException("Picked device was null");
            }
            return(pickedDevice);
        }