Esempio n. 1
0
 public HHEntry([NotNull] DBBase hh, [CanBeNull] Location loc, [NotNull] IAssignableDevice device, [NotNull] string type)
 {
     Household = hh;
     Location  = loc;
     Device    = device;
     Type      = type;
 }
Esempio n. 2
0
        public AffordanceDevice([CanBeNull] IAssignableDevice assignableDevice,
                                [CanBeNull] TimeBasedProfile timeProfile, [CanBeNull] int?id, decimal timeOffset, [CanBeNull] int?affordanceID,
                                [ItemNotNull][NotNull] ObservableCollection <RealDevice> simdevices, [ItemNotNull][NotNull] ObservableCollection <DeviceCategory> simdevcategories,
                                [NotNull] string deviceName, [CanBeNull] VLoadType loadType, [NotNull] string connectionString, double probability, StrGuid guid) : base(
                deviceName, TableName, connectionString, guid)
        {
            _assignableDevice = assignableDevice;
            _timeProfile      = timeProfile;
            ID            = id;
            _timeOffset   = timeOffset;
            _affordanceID = affordanceID;

            _loadType = loadType;
            if (!Config.IsInUnitTesting)
            {
                simdevices.CollectionChanged += SimdevicesOnCollectionChanged;
            }
            if (!Config.IsInUnitTesting)
            {
                simdevcategories.CollectionChanged += SimdevicesOnCollectionChanged;
            }
            TypeDescription = "Affordance Device";
            if (_timeOffset < 0)
            {
                _timeOffset = 0;
            }
            _probability = probability;
        }
 public AffordanceStandby([CanBeNull] IAssignableDevice assignableDevice, [CanBeNull] int?id, [CanBeNull] int?affordanceID,
                          [NotNull] string connectionString,
                          [NotNull] string deviceName, StrGuid guid) : base(deviceName, TableName, connectionString, guid)
 {
     _assignableDevice = assignableDevice;
     ID              = id;
     _affordanceID   = affordanceID;
     TypeDescription = "Affordance Standby Device";
 }
 public LocationDevice([CanBeNull] int?pID, [CanBeNull] IAssignableDevice adev, int locationID, [NotNull] string connectionString,
                       [NotNull] string name, StrGuid guid)
     : base(name, TableName, connectionString, guid)
 {
     TypeDescription = "Location Device";
     ID          = pID;
     _device     = adev;
     _locationID = locationID;
     LoadType    = null;
 }
        public void SynchronizeDataFromJson(JsonDto jto, Simulator sim)
        {
            var checkedProperties = new List <string>();

            ValidateAndUpdateValueAsNeeded(nameof(Device),
                                           checkedProperties,
                                           _device?.GetJsonReference().Guid, jto.Device.Guid,
                                           () => _device = sim.GetAssignableDeviceByGuid(jto.Device?.Guid) ??
                                                           throw new LPGException("Could not find a device with for  " + jto.Device));
            ValidateAndUpdateValueAsNeeded(nameof(Location),
                                           checkedProperties, Location?.Guid, jto.Location.Guid,
                                           () =>
                                           _location = sim.Locations.FindByGuid(jto.Location?.Guid));
            ValidateAndUpdateValueAsNeeded(nameof(TimeLimit),
                                           checkedProperties, TimeLimit?.Guid, jto.TimeLimit.Guid,
                                           () =>
                                           _timeLimit = sim.TimeLimits.FindByGuid(jto.TimeLimit?.Guid));
            ValidateAndUpdateValueAsNeeded(nameof(TimeProfile),
                                           checkedProperties,
                                           TimeProfile?.Guid, jto.TimeProfile?.Guid,
                                           () => _timeprofile = sim.Timeprofiles.FindByJsonReference(jto.TimeProfile));
            if (TimeStandardDeviation != jto.StandardDeviation)
            {
                _timeStandardDeviation = jto.StandardDeviation;
                NeedsUpdate            = true;
            }
            if (Variable?.Guid != jto.Variable?.Guid)
            {
                _variable   = sim.Variables.FindByGuid(jto.Variable?.Guid);
                NeedsUpdate = true;
            }
            if (VariableCondition != jto.VariableCondition)
            {
                _variableCondition = jto.VariableCondition;
                NeedsUpdate        = true;
            }
            // ReSharper disable once CompareOfFloatsByEqualityOperator
            if (VariableValue != jto.VariableValue)
            {
                _variableValue = jto.VariableValue;
                NeedsUpdate    = true;
            }
            if (LoadType?.Guid != jto.LoadType?.Guid)
            {
                _vLoadType  = sim.LoadTypes.FindByGuid(jto.Variable?.Guid);
                NeedsUpdate = true;
            }
            ValidateAndUpdateValueAsNeeded(nameof(Guid),
                                           checkedProperties,
                                           Guid, jto.Guid,
                                           () => Guid = jto.Guid);
            CheckIfAllPropertiesWereCovered(checkedProperties, this);
            SaveToDB();
        }
Esempio n. 6
0
        // this only checks for an affordance, if the desired device category is fullfilled by the devices
        // this selects a device from the list of previously selected and created devices
        public RealDevice GetDeviceDtoForAffordance(IAssignableDevice dev, IEnumerable <CalcDeviceDto> calcDevices,
                                                    int locationID, ObservableCollection <DeviceAction> allDeviceActions, List <DeviceCategoryDto> deviceCategories)
        {
            switch (dev.AssignableDeviceType)
            {
            case AssignableDeviceType.Device:
                return((RealDevice)dev);

            case AssignableDeviceType.DeviceCategory:
                var dc = (DeviceCategory)dev;
                var deviceCategoryDto = deviceCategories.Single(x => x.FullCategoryName == dc.FullPath);
                var ldt = new LocationDeviceTuple(dc, locationID);
                if (_pickedDevices.ContainsKey(ldt) && _pickedDevices[ldt] != null)
                {
                    return(_pickedDevices[ldt]);
                }
                var existingDevicesFromCategory = new List <CalcDeviceDto>();
                foreach (var calcDevice in calcDevices)
                {
                    if (calcDevice.DeviceCategoryGuid == deviceCategoryDto.Guid)
                    {
                        existingDevicesFromCategory.Add(calcDevice);
                    }
                }
                if (existingDevicesFromCategory.Count > 0)
                {
                    dc.RefreshSubDevices();
                    foreach (var realDevice in dc.SubDevices)
                    {
                        if (realDevice.Name == existingDevicesFromCategory[0].Name)
                        {
                            return(realDevice);
                        }
                    }
                    throw new LPGException("One device should have been picked!");
                }
                return(null);

            case AssignableDeviceType.DeviceAction: {
                var da = (DeviceAction)dev;
                return(da.Device);
            }

            case AssignableDeviceType.DeviceActionGroup: {
                var da = GetDeviceActionFromGroup(dev, calcDevices, allDeviceActions);
                return(da?.Device);
            }

            default:
                throw new LPGException("Missed a AssignableDeviceType");
            }
        }
Esempio n. 7
0
        public DeviceAction GetAutoDeviceActionFromGroup(IAssignableDevice dev,
                                                         List <IAssignableDevice> otherDevicesAtLocation, EnergyIntensityType energyIntensity,
                                                         ObservableCollection <DeviceAction> allDeviceActions, int locationID)
        {
            if (dev == null)
            {
                throw new LPGException("Device was null");
            }
            switch (dev.AssignableDeviceType)
            {
            case AssignableDeviceType.DeviceAction:
                return((DeviceAction)dev);

            case AssignableDeviceType.DeviceActionGroup:
                // schauen, ob schon zugeordnet
                var deviceActionGroup = (DeviceActionGroup)dev;
                var ldt = new LocationDeviceTuple(deviceActionGroup, locationID);
                if (_pickedDeviceActions.ContainsKey(ldt))
                {
                    return(_pickedDeviceActions[ldt]);
                }

                // pruefen, ob eins der anderen devices fuer diese group zutrifft
                var myActions = deviceActionGroup.GetDeviceActions(allDeviceActions);
                foreach (var deviceAction in myActions)
                {
                    if (otherDevicesAtLocation.Contains(deviceAction))
                    {
                        var action =
                            (DeviceAction)otherDevicesAtLocation.First(anondev => anondev == deviceAction);
                        _pickedDevices.Add(ldt, action.Device);
                        return(action);
                    }
                }
                // see if another device from the same device category was already picked
                // einfach eins aussuchen
                var pickdevAction = PickDeviceFromGroup(deviceActionGroup, energyIntensity, allDeviceActions,
                                                        locationID);
                _pickedDeviceActions.Add(ldt, pickdevAction);
                // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                // ReSharper disable once HeuristicUnreachableCode
                if (pickdevAction == null)
                {
                    // ReSharper disable once HeuristicUnreachableCode
                    throw new LPGException("Picked device was null");
                }
                return(pickdevAction);

            default:
                throw new LPGException("Forgotten AssignableDeviceType in GetAutoDeviceDevice. Please Report!");
            }
        }
        public void AddDevice([NotNull] IAssignableDevice device, bool save = true)
        {
            if (device.ConnectionString != ConnectionString)
            {
                throw new LPGException("A device from another DB was just added!");
            }
            var locdev = new LocationDevice(null, device, IntID, ConnectionString, device.Name, System.Guid.NewGuid().ToStrGuid());

            _locDevs.Add(locdev);
            if (save)
            {
                locdev.SaveToDB();
            }
            _locDevs.Sort();
        }
Esempio n. 9
0
        public RealDevice GetAutoDeviceDeviceFromDeviceCategoryOrDevice(IAssignableDevice dev,
                                                                        List <IAssignableDevice> alldevices, EnergyIntensityType energyIntensity,
                                                                        ObservableCollection <DeviceAction> deviceActions, int locationID)
        {
            if (dev == null)
            {
                throw new LPGException("Device was null");
            }

            // bereits ein realDevice
            switch (dev.AssignableDeviceType)
            {
            case AssignableDeviceType.Device:
                return((RealDevice)dev);

            case AssignableDeviceType.DeviceCategory:
                // schauen, ob schon zugeordnet
                var dc  = (DeviceCategory)dev;
                var ldt = new LocationDeviceTuple(dc, locationID);
                if (_pickedDevices.ContainsKey(ldt))
                {
                    return(_pickedDevices[ldt]);
                }

                // pruefen, ob eins der anderen devices fuer diese category zutrifft
                foreach (var assignableDevice in alldevices)
                {
                    if (assignableDevice.AssignableDeviceType == AssignableDeviceType.Device)
                    {
                        var rd = (RealDevice)assignableDevice;
                        if (rd.DeviceCategory == dc)
                        {
                            _pickedDevices.Add(ldt, rd);
                            return(rd);
                        }
                    }
                }

                // einfach eins aussuchen
                var pickdev = PickDeviceFromCategory(dc, energyIntensity, deviceActions);
                _pickedDevices.Add(ldt, pickdev);
                return(pickdev);

            default:
                throw new LPGException("Forgotten Assignable Device Type! Please Report.");
            }
        }
 public HHTAutonomousDevice([CanBeNull] int?pID, [CanBeNull] IAssignableDevice device,
                            [CanBeNull] TimeBasedProfile timeprofile, int householdTraitID, decimal timeStandardDeviation,
                            [CanBeNull] VLoadType vLoadType, [CanBeNull] TimeLimit timeLimit, [NotNull] string connectionString, [NotNull] string name,
                            [CanBeNull] Location location, double variableValue, VariableCondition variableCondition,
                            [CanBeNull] Variable variable, StrGuid guid) : base(name, TableName, connectionString, guid)
 {
     TypeDescription = "Household Trait Autonomous Device";
     ID                     = pID;
     _device                = device;
     _timeprofile           = timeprofile;
     _householdTraitID      = householdTraitID;
     _timeStandardDeviation = timeStandardDeviation;
     _vLoadType             = vLoadType;
     _timeLimit             = timeLimit;
     _location              = location;
     _variableValue         = variableValue;
     _variableCondition     = variableCondition;
     _variable              = variable;
 }
Esempio n. 11
0
 public HouseTypeDevice([CanBeNull] int?pID, [CanBeNull] IAssignableDevice adev, [CanBeNull] TimeBasedProfile profile,
                        int houseID,
                        [CanBeNull] TimeLimit timeLimit, double timeStandardDeviation, [CanBeNull] VLoadType loadType,
                        [NotNull] string connectionString, [NotNull] string name,
                        [CanBeNull] Location loc, double variableValue, VariableCondition variableCondition,
                        [CanBeNull] Variable variable, StrGuid guid)
     : base(name, TableName, connectionString, guid)
 {
     ID        = pID;
     _location = loc;
     _device   = adev;
     _profile  = profile;
     HouseID   = houseID;
     TimeLimit = timeLimit;
     _timeStandardDeviation = timeStandardDeviation;
     _loadType          = loadType;
     _variableValue     = variableValue;
     TypeDescription    = "House Type Device";
     _variableCondition = variableCondition;
     _variable          = variable;
 }
Esempio n. 12
0
        public DeviceAction GetDeviceActionFromGroup(IAssignableDevice dev, IEnumerable <CalcDeviceDto> calcDevices,
                                                     ObservableCollection <DeviceAction> allDeviceActions)
        {
            var deviceActionGroup = (DeviceActionGroup)dev;
            var deviceActions     = deviceActionGroup.GetDeviceActions(allDeviceActions);

            foreach (var calcDevice in calcDevices)
            {
                foreach (var deviceAction in deviceActions)
                {
                    if (deviceAction.Device == null)
                    {
                        throw new LPGException("Device was null");
                    }
                    if (calcDevice.Name == deviceAction.Device.Name)
                    {
                        return(deviceAction);
                    }
                }
            }
            return(null);
        }
Esempio n. 13
0
 public LocationDeviceTuple([NotNull] IAssignableDevice category, int locationID)
 {
     Category   = category;
     LocationID = locationID;
 }
Esempio n. 14
0
        // this tries to double check if it's a device selection that's already been done
        public RealDevice GetOrPickDevice(IAssignableDevice dev, Location devLocation,
                                          EnergyIntensityType energyIntensity, List <IAssignableDevice> allDevLocations,
                                          ObservableCollection <DeviceAction> allDeviceActions)
        {
            // if it's already a device, we are done
            switch (dev.AssignableDeviceType)
            {
            case AssignableDeviceType.Device:
                return((RealDevice)dev);

            case AssignableDeviceType.DeviceCategory: {
                // check if we already dealt with this category at this Location
                var dc  = (DeviceCategory)dev;
                var ldt = new LocationDeviceTuple(dc, devLocation.IntID);
                if (_pickedDevices.ContainsKey(ldt))     // && _pickedDevices[ldt] != null)
                {
                    return(_pickedDevices[ldt]);
                }
                // pick a new one
                var result = PickRealDeviceFromCategoryAtHHLocation(dc, allDevLocations, energyIntensity,
                                                                    devLocation, allDeviceActions);
                if (result != null)
                {
                    _pickedDevices.Add(ldt, result);
                }
                return(result);
            }

            case AssignableDeviceType.DeviceAction:
                return(((DeviceAction)dev).Device);

            case AssignableDeviceType.DeviceActionGroup: {
                // check if we already dealt with this group at this Location
                var deviceActionGroup = (DeviceActionGroup)dev;
                var ldt = new LocationDeviceTuple(deviceActionGroup, devLocation.IntID);
                if (_pickedDeviceActions.ContainsKey(ldt))     // && _pickedDevices[ldt] != null)
                {
                    return(_pickedDeviceActions[ldt].Device);
                }
                var firstDeviceAction = deviceActionGroup.GetDeviceActions(allDeviceActions).First();
                if (firstDeviceAction.Device == null)
                {
                    throw new LPGException("Device was null");
                }
                var usedDeviceCategory = firstDeviceAction.Device.DeviceCategory;
                if (usedDeviceCategory == null)
                {
                    throw new LPGException("used device category was null");
                }
                var ldt2 = new LocationDeviceTuple(usedDeviceCategory, devLocation.IntID);
                if (_pickedDevices.ContainsKey(ldt2))
                {
                    // find the device picked earlier
                    var rd = _pickedDevices[ldt2];
                    return(rd);
                }

                // pick a new one
                var result = PickDeviceActionFromGroupAtHHLocation(deviceActionGroup, allDevLocations,
                                                                   energyIntensity, devLocation, allDeviceActions);
                _pickedDeviceActions.Add(ldt, result);
                if (result == null)
                {
                    throw new LPGException("Device was null");
                }
                _pickedDevices.Add(ldt2, result.Device);
                return(result.Device);
            }

            default:
                throw new LPGException("Forgotten AssignableDeviceType. Please report!");
            }
        }
 public DeviceLocationTuple([NotNull] Location location, [NotNull] IAssignableDevice device)
 {
     Location = location;
     Device   = device;
 }
 public AffEntry([NotNull] Affordance affordance, [NotNull] IAssignableDevice devices)
 {
     Affordance = affordance;
     Device     = devices;
 }