public void IsAffordanceAvailableTestRealDeviceIsThere()
        {
            // Location: realdevice
            // affordance: same realdevice
            Config.IsInUnitTesting = true;
            var col           = new ColorRGB(255, 0, 0);
            var deviceActions = new ObservableCollection <DeviceAction>();
            var aff           = new Affordance("bla", null, null, false, PermittedGender.All, 1, col, string.Empty, null,
                                               string.Empty, string.Empty,
                                               true, true, 0, 100, false, ActionAfterInterruption.GoBackToOld, false, Guid.NewGuid().ToStrGuid(), BodilyActivityLevel.Low);
            var rd1         = new RealDevice("rd1", 1, string.Empty, null, string.Empty, false, false, string.Empty, Guid.NewGuid().ToStrGuid());
            var allDevices1 = new List <IAssignableDevice>
            {
                // check if only the device is there
                rd1
            };
            var connectionString = string.Empty;
            var lt = new VLoadType("lt", string.Empty, "bla", "blub", 1, 1, new TimeSpan(0, 1, 0), 1, connectionString,
                                   LoadTypePriority.Mandatory, true, Guid.NewGuid().ToStrGuid());
            var tbp = new TimeBasedProfile("name", 1, connectionString, TimeProfileType.Absolute, "data source", Guid.NewGuid().ToStrGuid());

            aff.AffordanceDevices.Add(new AffordanceDevice(rd1, tbp, null, 0, null,
                                                           new ObservableCollection <RealDevice>(),
                                                           new ObservableCollection <DeviceCategory>(), "name", lt, string.Empty, 1, Guid.NewGuid().ToStrGuid()));
            (aff.IsAffordanceAvailable(allDevices1, deviceActions)).Should().BeTrue();
        }
        public void DeviceCategoryPickerTestRealDevices()
        {
            Random               r   = new Random(5);
            DeviceSelection      ds  = new DeviceSelection("ds", 1, string.Empty, string.Empty, Guid.NewGuid().ToStrGuid());
            DeviceCategoryPicker dcp = new DeviceCategoryPicker(r, ds);
            ObservableCollection <RealDevice> allDevices = new ObservableCollection <RealDevice>();
            DeviceCategory dc = new DeviceCategory("dc", -1, "bla", false, allDevices, Guid.NewGuid().ToStrGuid());
            RealDevice     rd = new RealDevice("bla", 0, string.Empty, dc, "desc", false, true, string.Empty, Guid.NewGuid().ToStrGuid(), -1);

            allDevices.Add(rd);
            Location loc = new Location("bla", -1, string.Empty, Guid.NewGuid().ToStrGuid());
            List <IAssignableDevice> devices = new List <IAssignableDevice>
            {
                rd
            };
            ObservableCollection <DeviceAction> deviceActions = new ObservableCollection <DeviceAction>();

            Logger.Info("put in a rd, get back the same rd");
            RealDevice result = dcp.GetOrPickDevice(rd, loc, EnergyIntensityType.EnergyIntensive, devices, deviceActions);

            rd.Should().Be(result);
            // put in an dc with one rd, get the rd 1
            Logger.Info("put in a rd, get back null, since the rd is already there as hhdevloc");
            RealDevice result2 = dcp.GetOrPickDevice(dc, loc, EnergyIntensityType.EnergyIntensive, devices,
                                                     deviceActions);

            result2.Should().BeNull();
        }
示例#3
0
        public void RealDeviceLoadCreationAndSaveTest()
        {
            using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                var loadTypes        = db.LoadLoadTypes();
                var alldevices       = new ObservableCollection <RealDevice>();
                var deviceCategories = db.LoadDeviceCategories(alldevices, out var dcnone,
                                                               false);
                var profiles = db.LoadTimeBasedProfiles();

                RealDevice.LoadFromDatabase(alldevices, deviceCategories, dcnone, db.ConnectionString, loadTypes, profiles,
                                            false);

                db.ClearTable(RealDevice.TableName);
                db.ClearTable(RealDeviceLoadType.TableName);
                alldevices.Clear();
                RealDevice.LoadFromDatabase(alldevices, deviceCategories, dcnone, db.ConnectionString, loadTypes, profiles,
                                            false);
                (alldevices.Count).Should().Be(0);
                var rd = new RealDevice("bla", 3, "p1", null, "name", true, false, db.ConnectionString, Guid.NewGuid().ToStrGuid());
                rd.SaveToDB();
                alldevices.Clear();
                RealDevice.LoadFromDatabase(alldevices, deviceCategories, dcnone, db.ConnectionString, loadTypes, profiles,
                                            false);
                (alldevices.Count).Should().Be(1);
                var rd2 = new RealDevice("bla2", 3, "p1", null, "name", true, false, db.ConnectionString, Guid.NewGuid().ToStrGuid());
                rd2.SaveToDB();
                alldevices.Clear();
                RealDevice.LoadFromDatabase(alldevices, deviceCategories, dcnone, db.ConnectionString, loadTypes, profiles,
                                            false);
                (alldevices.Count).Should().Be(2);
                db.Cleanup();
            }
        }
        public void CalculateAverageEnergyUseTestAbsoluteProfile()
        {
            using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                Config.IsInUnitTesting = true;
                var rd2 = new RealDevice("rd2", 1, string.Empty, null, string.Empty, false, false,
                                         db.ConnectionString, Guid.NewGuid().ToStrGuid());
                var lt = new VLoadType("lt", string.Empty, "bla", "blub", 1, 1, new TimeSpan(0, 1, 0), 1,
                                       db.ConnectionString, LoadTypePriority.Mandatory, true, Guid.NewGuid().ToStrGuid());
                lt.SaveToDB();
                rd2.SaveToDB();
                rd2.AddLoad(lt, 666, 0, 0);
                var tp = new TimeBasedProfile("tp", null, db.ConnectionString,
                                              TimeProfileType.Absolute, "fake", Guid.NewGuid().ToStrGuid());
                tp.SaveToDB();
                tp.AddNewTimepoint(new TimeSpan(0, 0, 0), 100, false);
                tp.AddNewTimepoint(new TimeSpan(0, 2, 0), 0, false);

                var allActions = new ObservableCollection <DeviceAction>();

                var res = rd2.CalculateAverageEnergyUse(lt, allActions, tp, 1, 1);
                foreach (var keyValuePair in res)
                {
                    Logger.Info(keyValuePair.Item1 + ": " + keyValuePair.Item2);
                }
                (res.Count).Should().Be(1);
                var first = res.First();
                (first.Item2).Should().Be(200);
                db.Cleanup();
            }
        }
        public void HouseDeviceOrphanCreatingTest()
        {
            using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                db.ClearTable(HouseType.TableName);
                db.ClearTable(HouseTypeDevice.TableName);
                var loadTypes          = db.LoadLoadTypes();
                var devices            = new ObservableCollection <RealDevice>();
                var deviceCategories   = new ObservableCollection <DeviceCategory>();
                var timeBasedProfiles  = new ObservableCollection <TimeBasedProfile>();
                var timeLimits         = new ObservableCollection <TimeLimit>();
                var variables          = db.LoadVariables();
                var deviceActionGroups = db.LoadDeviceActionGroups();
                var deviceActions      = db.LoadDeviceActions(timeBasedProfiles,
                                                              devices, loadTypes, deviceActionGroups);
                var energyStorages = db.LoadEnergyStorages(loadTypes, variables);
                var trafoDevices   = db.LoadTransformationDevices(loadTypes,
                                                                  variables);

                var dateprofiles = db.LoadDateBasedProfiles();
                var generators   = db.LoadGenerators(loadTypes, dateprofiles);
                var houseTypes   = new ObservableCollection <HouseType>();
                var locations    = db.LoadLocations(devices, deviceCategories, loadTypes);
                HouseType.LoadFromDatabase(houseTypes, db.ConnectionString, devices, deviceCategories, timeBasedProfiles,
                                           timeLimits, loadTypes, trafoDevices, energyStorages, generators, false, locations, deviceActions,
                                           deviceActionGroups, variables);
                (houseTypes.Count).Should().Be(0);
                var housetype = new HouseType("haus1", "blub", 1000, 5, 10, loadTypes[0], db.ConnectionString, 1, 1,
                                              loadTypes[1], false, 0, false, 0, 1, 100, Guid.NewGuid().ToStrGuid());
                housetype.SaveToDB();
                var rd = new RealDevice("test", 1, "bla", null, "name", true, false, db.ConnectionString, Guid.NewGuid().ToStrGuid());
                rd.SaveToDB();
                devices.Add(rd);

                var dt = new TimeLimit("blub", db.ConnectionString, Guid.NewGuid().ToStrGuid());
                timeLimits.Add(dt);
                dt.SaveToDB();
                var tp = new TimeBasedProfile("blub", null, db.ConnectionString, TimeProfileType.Relative,
                                              "fake", Guid.NewGuid().ToStrGuid());
                timeBasedProfiles.Add(tp);
                tp.SaveToDB();
                housetype.AddHouseTypeDevice(rd, dt, tp, 1, loadTypes[0], locations[0], 0, VariableCondition.Equal,
                                             variables[0]);
                houseTypes.Clear();
                HouseType.LoadFromDatabase(houseTypes, db.ConnectionString, devices, deviceCategories, timeBasedProfiles,
                                           timeLimits, loadTypes, trafoDevices, energyStorages, generators, false, locations, deviceActions,
                                           deviceActionGroups, variables);
                (houseTypes.Count).Should().Be(1);
                var house3 = houseTypes[0];
                (house3.HouseDevices.Count).Should().Be(1);
                db.ClearTable(HouseType.TableName);
                houseTypes.Clear();
                HouseType.LoadFromDatabase(houseTypes, db.ConnectionString, devices, deviceCategories, timeBasedProfiles,
                                           timeLimits, loadTypes, trafoDevices, energyStorages, generators, false, locations, deviceActions,
                                           deviceActionGroups, variables);
                (houseTypes.Count).Should().Be(0);

                db.Cleanup();
            }
        }
 public void AddDevice(RealDevice rd)
 {
     if (PossibleDevices.Any(x => x.DeviceName == rd.Name))
     {
         return;
     }
     PossibleDevices.Add(new PossibleDevice(rd.Name, rd.DeviceCategory?.FullPath));
 }
 public DeviceTaggingEntry([NotNull] string name, int taggingSetID, [CanBeNull] DeviceTag tag,
                           [CanBeNull] RealDevice device,
                           [NotNull] string connectionString, [CanBeNull] int?pID, StrGuid guid) : base(name, pID, TableName, connectionString, guid)
 {
     _taggingSetID   = taggingSetID;
     _tag            = tag;
     _device         = device;
     TypeDescription = "Device Tagging Entry";
 }
        public void HouseLoadCreationAndSaveTest()
        {
            using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                Logger.Threshold = Severity.Warning;
                db.ClearTable(HouseType.TableName);
                db.ClearTable(HouseTypeDevice.TableName);
                var devices           = new ObservableCollection <RealDevice>();
                var deviceCategories  = new ObservableCollection <DeviceCategory>();
                var timeBasedProfiles = new ObservableCollection <TimeBasedProfile>();
                var timeLimits        = new ObservableCollection <TimeLimit>();
                var variables         = db.LoadVariables();
                var loadTypes         = db.LoadLoadTypes();
                var energyStorages    = db.LoadEnergyStorages(loadTypes, variables);
                var trafoDevices      = db.LoadTransformationDevices(loadTypes,
                                                                     variables);
                var dateprofiles = db.LoadDateBasedProfiles();
                var generators   = db.LoadGenerators(loadTypes, dateprofiles);

                var locations          = db.LoadLocations(devices, deviceCategories, loadTypes);
                var deviceActionGroups = db.LoadDeviceActionGroups();
                var deviceActions      = db.LoadDeviceActions(timeBasedProfiles,
                                                              devices, loadTypes, deviceActionGroups);
                var dt = new TimeLimit("blub", db.ConnectionString, Guid.NewGuid().ToStrGuid());
                dt.SaveToDB();
                timeLimits.Add(dt);
                var rd = new RealDevice("blub", 1, string.Empty, null, string.Empty, true, false, db.ConnectionString, Guid.NewGuid().ToStrGuid());
                rd.SaveToDB();
                devices.Add(rd);
                var tbp = new TimeBasedProfile("blub", null, db.ConnectionString, TimeProfileType.Relative,
                                               "fake", Guid.NewGuid().ToStrGuid());
                tbp.SaveToDB();
                timeBasedProfiles.Add(tbp);
                var tempP = new TemperatureProfile("blub", null, string.Empty, db.ConnectionString, Guid.NewGuid().ToStrGuid());
                tempP.SaveToDB();
                var houseTypes = new ObservableCollection <HouseType>();
                HouseType.LoadFromDatabase(houseTypes, db.ConnectionString, devices, deviceCategories, timeBasedProfiles,
                                           timeLimits, loadTypes, trafoDevices, energyStorages, generators, false, locations, deviceActions,
                                           deviceActionGroups, variables);
                (houseTypes.Count).Should().Be(0);
                var housetype = new HouseType("haus1", "blub", 1000, 5, 10, loadTypes[0], db.ConnectionString, 1, 1,
                                              loadTypes[1], false, 0, false, 0, 1, 100, Guid.NewGuid().ToStrGuid());
                housetype.SaveToDB();
                housetype.AddHouseTypeDevice(rd, dt, tbp, 1, loadTypes[0], locations[0], 0, VariableCondition.Equal,
                                             variables[0]);
                HouseType.LoadFromDatabase(houseTypes, db.ConnectionString, devices, deviceCategories, timeBasedProfiles,
                                           timeLimits, loadTypes, trafoDevices, energyStorages, generators, false, locations, deviceActions,
                                           deviceActionGroups, variables);
                (houseTypes.Count).Should().Be(1);
                (houseTypes[0].HouseDevices.Count).Should().Be(1);
                var house2 = houseTypes[0];
                (house2.Name).Should().Be("haus1");
                (house2.Description).Should().Be("blub");
                db.Cleanup();
            }
        }
 public DeviceSelectionItem([CanBeNull] int?pID, [CanBeNull] int?deviceSelectionID, [CanBeNull] DeviceCategory deviceCategory,
                            [CanBeNull] RealDevice device,
                            [NotNull] string connectionString, [NotNull] string name, StrGuid guid)
     : base(name, TableName, connectionString, guid)
 {
     ID = pID;
     _deviceCategory    = deviceCategory;
     _device            = device;
     _deviceSelectionID = deviceSelectionID;
     TypeDescription    = "Device Selection Item";
 }
        public void CalculateAverageEnergyUseTestDeviceAction()
        {
            using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                Config.IsInUnitTesting = true;
                var col     = new ColorRGB(255, 0, 0);
                var devices = new ObservableCollection <RealDevice>();
                var rd2     = new RealDevice("rd2", 1, string.Empty, null, string.Empty, false, false, db.ConnectionString, Guid.NewGuid().ToStrGuid());
                var lt      = new VLoadType("lt", string.Empty, "bla", "blub", 1, 1, new TimeSpan(0, 1, 0), 1,
                                            db.ConnectionString,
                                            LoadTypePriority.Mandatory, true, Guid.NewGuid().ToStrGuid());
                lt.SaveToDB();
                rd2.SaveToDB();
                rd2.AddLoad(lt, 666, 0, 0);

                devices.Add(rd2);

                var deviceCategories = new ObservableCollection <DeviceCategory>();
                var deviceActions    = new ObservableCollection <DeviceAction>();
                var aff = new Affordance("bla", null, null, false, PermittedGender.All, 1, col, string.Empty, null,
                                         string.Empty,
                                         db.ConnectionString, true, true, 0,
                                         100, false, ActionAfterInterruption.GoBackToOld, false, Guid.NewGuid().ToStrGuid(),
                                         BodilyActivityLevel.Low);
                aff.SaveToDB();

                var tp = new TimeBasedProfile("tp", null, db.ConnectionString, TimeProfileType.Relative, "fake", Guid.NewGuid().ToStrGuid());
                tp.SaveToDB();
                tp.AddNewTimepoint(new TimeSpan(0, 0, 0), 100, false);
                tp.AddNewTimepoint(new TimeSpan(0, 2, 0), 0, false);
                var dag = new DeviceActionGroup("dag", db.ConnectionString, string.Empty, Guid.NewGuid().ToStrGuid());
                dag.SaveToDB();
                var da = new DeviceAction("da", null, string.Empty, db.ConnectionString, dag, rd2, Guid.NewGuid().ToStrGuid());
                da.SaveToDB();
                da.AddDeviceProfile(tp, 0, lt, 1);
                deviceActions.Add(da);
                var tbp = new TimeBasedProfile("name", 1, db.ConnectionString, TimeProfileType.Absolute, "data source", Guid.NewGuid().ToStrGuid());
                aff.AddDeviceProfile(dag, tbp, 0, devices, deviceCategories, lt, 1);
                var res = aff.CalculateAverageEnergyUse(deviceActions);
                foreach (var keyValuePair in res)
                {
                    Logger.Info(keyValuePair.Key + ": " + keyValuePair.Value);
                }
                res.Count.Should().Be(1);
                var first = res.First();
                first.Value.Should().Be(666 * 2);
                db.Cleanup();
            }
        }
        public DevicePresenter([NotNull] ApplicationPresenter applicationPresenter, [NotNull] DeviceView view, [NotNull] RealDevice realDevice)
            : base(view, "ThisDevice.HeaderString", realDevice, applicationPresenter)
        {
            _realDevice = realDevice;
            DeviceCategoryPickerPresenter = new DeviceCategoryPickerPresenter(Sim,
                                                                              _realDevice.DeviceCategory, view.DeviceCategoryPicker1);
            view.DeviceCategoryPicker1.DataContext = DeviceCategoryPickerPresenter;
            DeviceCategoryPickerPresenter.Select();
            DeviceCategoryPickerPresenter.PropertyChanged += DcpOnPropertyChanged;
            _timeProfileTypes.Add(TimeProfileType.Relative);
            _timeProfileTypes.Add(TimeProfileType.Absolute);
            var u = ThisDevice.CalculateUsedIns(Sim);

            _usedIns.SynchronizeWithList(u);
        }
        public void IsAffordanceAvailableTestCheckDeviceActionGroupInDeviceActionGroup()
        {
            // Location: device action group
            // affordance: device Action Group
            Config.IsInUnitTesting = true;
            var col           = new ColorRGB(255, 0, 0);
            var deviceActions = new ObservableCollection <DeviceAction>();
            var aff           = new Affordance("bla", null, null, false, PermittedGender.All, 1, col, string.Empty, null,
                                               string.Empty, string.Empty,
                                               true, true, 0, 100, false, ActionAfterInterruption.GoBackToOld, false, Guid.NewGuid().ToStrGuid(), BodilyActivityLevel.Low);
            var rd1 = new RealDevice("rd1", 1, string.Empty, null, string.Empty, false, false, string.Empty, Guid.NewGuid().ToStrGuid());

            var dg = new DeviceActionGroup("group", string.Empty, string.Empty, Guid.NewGuid().ToStrGuid());
            var da = new DeviceAction("device action 1", null, "blub", string.Empty, dg, rd1, Guid.NewGuid().ToStrGuid());

            deviceActions.Add(da);
            var devices = new ObservableCollection <RealDevice>
            {
                rd1
            };
            // check if it works with a device category that has the device
            var dc1 = new DeviceCategory("dc1", 0, string.Empty, false, devices, Guid.NewGuid().ToStrGuid(), null, true);

            rd1.DeviceCategory = dc1;
            dc1.RefreshSubDevices();
            (dc1.SubDevices.Count).Should().Be(1);
            var connectionString = string.Empty;
            var lt = new VLoadType("lt", string.Empty, "bla", "blub", 1, 1, new TimeSpan(0, 1, 0), 1, connectionString,
                                   LoadTypePriority.Mandatory, true, Guid.NewGuid().ToStrGuid());
            var tbp = new TimeBasedProfile("name", 1, connectionString, TimeProfileType.Absolute, "data source", Guid.NewGuid().ToStrGuid());

            aff.AffordanceDevices.Add(new AffordanceDevice(dg, tbp, null, 0, null,
                                                           new ObservableCollection <RealDevice>(),
                                                           new ObservableCollection <DeviceCategory>(), "name", lt, string.Empty, 1, Guid.NewGuid().ToStrGuid()));
            var allDevices3 = new List <IAssignableDevice>
            {
                dg
            };

            if (da.DeviceActionGroup == null)
            {
                throw new LPGException("device action group was null");
            }
            var relevantDeviceActionGroup = da.DeviceActionGroup.GetDeviceActions(deviceActions);

            (relevantDeviceActionGroup.Count).Should().Be(1);
            (aff.IsAffordanceAvailable(allDevices3, deviceActions)).Should().BeTrue();
        }
示例#13
0
        private static void ElectricityChecks([NotNull] RealDevice device)
        {
            if (device.Loads.Any(x => string.Equals(x.LoadType?.Name, "electricity",
                                                    StringComparison.OrdinalIgnoreCase)))
            {
                if (
                    !device.Loads.Any(
                        x => string.Equals(x.LoadType?.Name, "apparent", StringComparison.OrdinalIgnoreCase)))
                {
                    throw new DataIntegrityException(
                              "The device " + device.PrettyName +
                              " is electric and missing the load type apparent. Please fix.", device);
                }
                if (
                    !device.Loads.Any(
                        x => string.Equals(x.LoadType?.Name, "reactive", StringComparison.OrdinalIgnoreCase)))
                {
                    throw new DataIntegrityException(
                              "The device " + device.PrettyName +
                              " is electric and missing the load type reactive. Please fix.", device);
                }
                var rdload =
                    device.Loads.First(
                        x => string.Equals(x.LoadType?.Name, "electricity", StringComparison.OrdinalIgnoreCase));
                var appLoad =
                    device.Loads.First(
                        x => string.Equals(x.LoadType?.Name, "apparent", StringComparison.OrdinalIgnoreCase));

                if (Math.Abs(appLoad.MaxPower - rdload.MaxPower) < Constants.Ebsilon ||
                    Math.Abs(appLoad.MaxPower) < Constants.Ebsilon || appLoad.MaxPower < rdload.MaxPower)
                {
                    throw new DataIntegrityException(
                              "The device " + device.Name + " has an invalid reactive power. Please fix.", device);
                }

                var reaLoad =
                    device.Loads.First(
                        x => string.Equals(x.LoadType?.Name, "reactive", StringComparison.OrdinalIgnoreCase));
                if (Math.Abs(reaLoad.MaxPower - rdload.MaxPower) < Constants.Ebsilon ||
                    Math.Abs(reaLoad.MaxPower) < Constants.Ebsilon || reaLoad.MaxPower > appLoad.MaxPower)
                {
                    throw new DataIntegrityException(
                              "The device " + device.Name + " has an invalid reactive power. Please fix.", device);
                }
            }
        }
 public void AffordanceStandbyTests1()
 {
     using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
     {
         Config.IsInUnitTesting = true;
         var col = new ColorRGB(255, 0, 0);
         var aff = new Affordance("bla", null, null, true, PermittedGender.Female, 0.1m, col,
                                  "AffordanceCategory", null, "desc", db.ConnectionString, true, true, 0, 99, false,
                                  ActionAfterInterruption.GoBackToOld, false, Guid.NewGuid().ToStrGuid(), BodilyActivityLevel.Low);
         aff.SaveToDB();
         aff.AffordanceStandbys.Count.Should().Be(0);
         var rd2 = new RealDevice("rd2", 1, string.Empty, null, string.Empty, false, false, db.ConnectionString, Guid.NewGuid().ToStrGuid());
         rd2.SaveToDB();
         aff.AddStandby(rd2);
         aff.AffordanceStandbys.Count.Should().Be(1);
         db.Cleanup();
     }
 }
示例#15
0
 private static void BasicChecks([NotNull] RealDevice device)
 {
     if (device.Loads.Count == 0)
     {
         throw new DataIntegrityException(
                   "The device " + device.Name + " has no loads. This isn't going to work!", device);
     }
     if (device.DeviceCategory == null)
     {
         throw new DataIntegrityException(
                   "The device " + device.Name + " has no device category. This is not allowed!", device);
     }
     if (device.Year < 1980 || device.Year > 2030)
     {
         throw new DataIntegrityException(
                   "The device " + device.PrettyName +
                   " has a year that is smaller than 1980 or larger than 2030. Please fix.", device);
     }
 }
        public void CalculateMaximumInternalTimeResolutionTestForDeviceAction()
        {
            using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                Config.IsInUnitTesting = true;
                var col     = new ColorRGB(255, 0, 0);
                var devices = new ObservableCollection <RealDevice>();
                var rd2     = new RealDevice("rd2", 1, string.Empty, null, string.Empty, false, false, db.ConnectionString, Guid.NewGuid().ToStrGuid());
                rd2.SaveToDB();
                devices.Add(rd2);

                var deviceCategories = new ObservableCollection <DeviceCategory>();
                var aff = new Affordance("bla", null, null, false, PermittedGender.All, 1, col, string.Empty, null,
                                         string.Empty,
                                         db.ConnectionString, true, true, 0, 100,
                                         false, ActionAfterInterruption.GoBackToOld, false, Guid.NewGuid().ToStrGuid(), BodilyActivityLevel.Low);
                aff.SaveToDB();

                var tp = new TimeBasedProfile("tp", null, db.ConnectionString, TimeProfileType.Relative, "fake", Guid.NewGuid().ToStrGuid());
                tp.SaveToDB();
                tp.AddNewTimepoint(new TimeSpan(0, 0, 0), 1, false);
                tp.AddNewTimepoint(new TimeSpan(0, 1, 0), 1, false);
                tp.AddNewTimepoint(new TimeSpan(0, 10, 0), 1, false);
                var lt = new VLoadType("lt", string.Empty, "bla", "blub", 1, 1, new TimeSpan(0, 1, 0), 1,
                                       db.ConnectionString,
                                       LoadTypePriority.Mandatory, true, Guid.NewGuid().ToStrGuid());
                lt.SaveToDB();
                var dag = new DeviceActionGroup("dag", db.ConnectionString, string.Empty, Guid.NewGuid().ToStrGuid());
                dag.SaveToDB();
                var da = new DeviceAction("da", null, string.Empty, db.ConnectionString, dag, rd2, Guid.NewGuid().ToStrGuid());
                da.SaveToDB();
                da.AddDeviceProfile(tp, 0, lt, 1);
                new ObservableCollection <DeviceAction>().Add(da);
                var tbp = new TimeBasedProfile("name", 1, db.ConnectionString, TimeProfileType.Absolute, "data source", Guid.NewGuid().ToStrGuid());
                aff.AddDeviceProfile(da, tbp, 0, devices, deviceCategories, lt, 1);

                var ts = aff.CalculateMaximumInternalTimeResolution();
                (ts.TotalSeconds).Should().Be(60);
                Logger.Info(ts.ToString());
                db.Cleanup();
            }
        }
示例#17
0
 public void RealDeviceTest()
 {
     using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
     {
         db.ClearTable(RealDevice.TableName);
         db.ClearTable(RealDeviceLoadType.TableName);
         var rdcat      = new CategoryDBBase <RealDevice>("blub");
         var rd         = rdcat.CreateNewItem(db.ConnectionString);
         var profiles   = db.LoadTimeBasedProfiles();
         var alldevices = db.LoadRealDevices(out var deviceCategories, out var dcNone,
                                             out var loadTypes, profiles);
         (alldevices.Count).Should().Be(1);
         alldevices.Clear();
         rdcat.DeleteItem(rd);
         RealDevice.LoadFromDatabase(alldevices, deviceCategories, dcNone, db.ConnectionString, loadTypes, profiles,
                                     false);
         (alldevices.Count).Should().Be(0);
         db.Cleanup();
     }
 }
        public void IsAffordanceAvailableTestAffordanceHasNoDevice()
        {
            // Location: realdevice
            // affordance: nothing
            Config.IsInUnitTesting = true;
            var col           = new ColorRGB(255, 0, 0);
            var deviceActions = new ObservableCollection <DeviceAction>();
            var aff           = new Affordance("bla", null, null, false, PermittedGender.All, 1, col, string.Empty, null,
                                               string.Empty, string.Empty,
                                               true, true, 0, 100, false, ActionAfterInterruption.GoBackToOld, false, Guid.NewGuid().ToStrGuid(),
                                               BodilyActivityLevel.Low);
            var rd2 = new RealDevice("rd2", 1, string.Empty, null, string.Empty, false, false, string.Empty, Guid.NewGuid().ToStrGuid());
            // check if the device is not there
            var allDevices2 = new List <IAssignableDevice>
            {
                rd2
            };
            var result = aff.IsAffordanceAvailable(allDevices2, deviceActions);

            (result).Should().BeFalse();
        }
 public void LoadFromDatabaseTest()
 {
     using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
     {
         var affdev             = new ObservableCollection <AffordanceDevice>();
         var deviceCategories   = new ObservableCollection <DeviceCategory>();
         var realDevices        = new ObservableCollection <RealDevice>();
         var timeBasedProfiles  = new ObservableCollection <TimeBasedProfile>();
         var affordances        = new ObservableCollection <Affordance>();
         var dateBasedProfiles  = db.LoadDateBasedProfiles();
         var timeLimits         = db.LoadTimeLimits(dateBasedProfiles);
         var loadtypes          = db.LoadLoadTypes();
         var deviceActionGroups = db.LoadDeviceActionGroups();
         var deviceActions      = new ObservableCollection <DeviceAction>();
         db.ClearTable(AffordanceDevice.TableName);
         AffordanceDevice.LoadFromDatabase(affdev, db.ConnectionString, deviceCategories, realDevices,
                                           timeBasedProfiles, affordances, loadtypes, deviceActions, deviceActionGroups, false);
         affdev.Count.Should().Be(0);
         var rd = new RealDevice("blub", 1, "1", null, "name", true, false, db.ConnectionString, Guid.NewGuid().ToStrGuid());
         rd.SaveToDB();
         realDevices.Add(rd);
         var tp = new TimeBasedProfile("blub", null, db.ConnectionString, TimeProfileType.Relative,
                                       "fake", Guid.NewGuid().ToStrGuid());
         tp.SaveToDB();
         timeBasedProfiles.Add(tp);
         var aff = new Affordance("blub", tp, null, true, PermittedGender.All, 0, new ColorRGB(255, 0, 0),
                                  "bla", timeLimits[0], string.Empty, db.ConnectionString, false, false, 0, 99, false,
                                  ActionAfterInterruption.GoBackToOld, false, Guid.NewGuid().ToStrGuid(), BodilyActivityLevel.Low);
         aff.SaveToDB();
         affordances.Add(aff);
         var newaffdev = new AffordanceDevice(rd, tp, null, 0, aff.ID, realDevices, deviceCategories,
                                              "blub", loadtypes[0], db.ConnectionString, 1, Guid.NewGuid().ToStrGuid());
         newaffdev.SaveToDB();
         AffordanceDevice.LoadFromDatabase(affdev, db.ConnectionString, deviceCategories, realDevices,
                                           timeBasedProfiles, affordances, loadtypes, deviceActions, deviceActionGroups, false);
         affdev.Count.Should().Be(1);
         affdev[0].LoadType.Should().Be(loadtypes[0]);
         db.Cleanup();
     }
 }
示例#20
0
        protected override void OnOpenGlInit(GlInterface gl, int fb)
        {
            try
            {
#if USE_OPENTK
                engine = new Engine(new OpenTKDevice(), new Configuration(), this);
#else
                IDevice device;
                var     real = new RealDevice(gl);
#if DEBUG && DEBUG_OPENGL
                device = new DebugDevice(real);
#else
                device = new RealDeviceWrapper(real);
#endif
                engine = new Engine(device, new Configuration(), this);
#endif
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        public void AffordanceStandbyTests2()
        {
            using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                db.ClearTable(Affordance.TableName);
                db.ClearTable(AffordanceStandby.TableName);
                db.ClearTable(AffordanceDevice.TableName);
                db.ClearTable(AffordanceDesire.TableName);
                db.ClearTable(AffordanceSubAffordance.TableName);
                db.ClearTable(AffordanceTaggingEntry.TableName);
                db.ClearTable(HHTAffordance.TableName);
                db.ClearTable(AffVariableRequirement.TableName);

                Config.IsInUnitTesting = true;
                var col = new ColorRGB(255, 0, 0);
                var aff = new Affordance("bla", null, null, true, PermittedGender.Female, 0.1m, col,
                                         "AffordanceCategory", null, "desc", db.ConnectionString, true, true, 0, 99, false,
                                         ActionAfterInterruption.GoBackToOld, false, Guid.NewGuid().ToStrGuid(), BodilyActivityLevel.Low);
                aff.SaveToDB();
                aff.AffordanceStandbys.Count.Should().Be(0);
                var rd2 = new RealDevice("rd2", 1, string.Empty, null, string.Empty, false, false, db.ConnectionString, Guid.NewGuid().ToStrGuid());
                rd2.SaveToDB();
                aff.AddStandby(rd2);
                aff.SaveToDB();
                aff.AffordanceStandbys.Count.Should().Be(1);
                var sim2             = new Simulator(db.ConnectionString);
                var loadedAffordance = sim2.Affordances.It[0];
                loadedAffordance.AffordanceStandbys.Count.Should().Be(1);
                loadedAffordance.AffordanceStandbys[0].Device?.Name.Should().Be("rd2");
                loadedAffordance.DeleteStandby(loadedAffordance.AffordanceStandbys[0]);
                loadedAffordance.AffordanceStandbys.Count.Should().Be(0);
                var sim3 = new Simulator(db.ConnectionString);
                var affordanceLoaded2 = sim3.Affordances.It[0];
                affordanceLoaded2.AffordanceStandbys.Count.Should().Be(0);
                db.Cleanup();
            }
        }
        public void DeviceCategoryPickerDeviceActionGroupAutoDev()
        {
            Random               r      = new Random(2);
            DeviceSelection      ds     = new DeviceSelection("ds", 1, string.Empty, string.Empty, Guid.NewGuid().ToStrGuid());
            DeviceCategoryPicker picker = new DeviceCategoryPicker(r, ds);
            // device stuff
            ObservableCollection <RealDevice> allDevices = new ObservableCollection <RealDevice>();
            DeviceCategory    dc  = new DeviceCategory("dc", -1, "bla", false, allDevices, Guid.NewGuid().ToStrGuid());
            RealDevice        rd1 = new RealDevice("device1", 0, string.Empty, dc, "desc", false, true, string.Empty, Guid.NewGuid().ToStrGuid(), -1);
            RealDevice        rd2 = new RealDevice("device2", 0, string.Empty, dc, "desc", false, true, string.Empty, Guid.NewGuid().ToStrGuid(), -1);
            DeviceActionGroup dag = new DeviceActionGroup("Dag1", string.Empty, "blub", Guid.NewGuid().ToStrGuid(), -1);
            DeviceAction      da1 = new DeviceAction("da1", -1, "blub", string.Empty, dag, rd1, Guid.NewGuid().ToStrGuid());
            DeviceAction      da2 = new DeviceAction("da2", -1, "blub", string.Empty, dag, rd2, Guid.NewGuid().ToStrGuid());
            ObservableCollection <DeviceAction> deviceActions = new ObservableCollection <DeviceAction>
            {
                da1,
                da2
            };

            allDevices.Add(rd1);
            List <IAssignableDevice> otherDevicesAtLocation = new List <IAssignableDevice>
            {
                dag
            };

            DeviceAction pickedDeviceAction = picker.GetAutoDeviceActionFromGroup(dag, otherDevicesAtLocation,
                                                                                  EnergyIntensityType.Random, deviceActions, 5);

            Logger.Info("Device Action 1 " + pickedDeviceAction);
            for (int i = 0; i < 50; i++)
            {
                DeviceAction deviceAction2 = picker.GetAutoDeviceActionFromGroup(dag, otherDevicesAtLocation,
                                                                                 EnergyIntensityType.Random, deviceActions, 5);
                Logger.Info("Device Action  " + i + " " + deviceAction2);
                pickedDeviceAction.Should().Be(deviceAction2);
            }
        }
示例#23
0
        public static List <CalcDeviceLoadDto> MakeCalcDeviceLoads([NotNull] RealDevice device,
                                                                   [NotNull] CalcLoadTypeDtoDictionary ltdtodict)
        {
            var deviceLoads = new List <CalcDeviceLoadDto>();

            foreach (var realDeviceLoadType in device.Loads)
            {
                if (realDeviceLoadType.LoadType == null)
                {
                    throw new LPGException("Loadtype was null");
                }

                if (ltdtodict.SimulateLoadtype(realDeviceLoadType.LoadType))
                {
                    var cdl = new CalcDeviceLoadDto(realDeviceLoadType.Name, realDeviceLoadType.IntID,
                                                    ltdtodict.Ltdtodict[realDeviceLoadType.LoadType].Name, ltdtodict.Ltdtodict[realDeviceLoadType.LoadType].Guid,
                                                    realDeviceLoadType.AverageYearlyConsumption, realDeviceLoadType.StandardDeviation,
                                                    Guid.NewGuid().ToStrGuid(), realDeviceLoadType.MaxPower);
                    deviceLoads.Add(cdl);
                }
            }

            return(deviceLoads);
        }
示例#24
0
        private static void CheckDeviceActionLoads([NotNull][ItemNotNull] ObservableCollection <DeviceAction> actions, [NotNull] RealDevice device)
        {
            foreach (var action in actions)
            {
                if (action.Device == device)
                {
                    foreach (var profile in action.Profiles)
                    {
                        if (profile.Timeprofile?.TimeProfileType == TimeProfileType.Absolute)
                        {
                            for (var i = 0; i < device.Loads.Count; i++)
                            {
                                var load = device.Loads[i];
                                if (load.LoadType == profile.VLoadType)
                                {
                                    var newMax = profile.Timeprofile.Maxiumum * profile.Multiplier;
                                    if (newMax > load.MaxPower)
                                    {
                                        if (profile.VLoadType == null)
                                        {
                                            throw new LPGException("Loadtype was null");
                                        }

                                        /*throw new DataIntegrityException("The device " + device.Name + " has a maximum power of " + load.MaxPower +
                                         * " " + load.LoadType.UnitOfPower + "  for " +
                                         * load.LoadType + " which is less than the " +
                                         * "maxmium of " + profile.Timeprofile.Maxiumum.ToString("N2", CultureInfo.CurrentCulture) + " " +
                                         * load.LoadType.UnitOfPower +
                                         * " in the profile " + profile.Timeprofile.Name +
                                         * " from the device action " + action.Name + ". Please fix.", device)*/
                                        var roundedmax = Math.Ceiling(newMax * 10) / 10.0;
                                        var mbr        =
                                            MessageWindowHandler.Mw.ShowYesNoMessage(
                                                "The device " + device.Name + " has a maximum power of " +
                                                load.MaxPower +
                                                " " + load.LoadType?.UnitOfPower + "  for " + load.LoadType +
                                                " which is less than the " + "maximum of " +
                                                newMax.ToString("N2", CultureInfo.CurrentCulture) + " " +
                                                load.LoadType?.UnitOfPower + " in the profile " +
                                                profile.Timeprofile.Name + " from the device action \"" + action.Name +
                                                "\". Set to " + roundedmax + "?", "Change?");
                                        if (mbr == LPGMsgBoxResult.Yes)
                                        {
                                            device.AddLoad(profile.VLoadType, roundedmax, load.StandardDeviation,
                                                           load.AverageYearlyConsumption);
                                            i = 0;
                                        }

                                        if (mbr == LPGMsgBoxResult.No)
                                        {
                                            List <BasicElement> elements = new List <BasicElement>();
                                            elements.Add(action);
                                            elements.Add(device);
                                            throw new DataIntegrityException("Please fix.", elements);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
示例#25
0
        private List <LoadingEntry> GetLoadingActions(bool ignoreMissingTables)
        {
            var actions = new List <LoadingEntry>
            {
                new LoadingEntry("Loadtypes",
                                 () => VLoadType.LoadFromDatabase(LoadTypes.MyItems, ConnectionString, ignoreMissingTables),
                                 LoadTypes),
                new LoadingEntry("Holidays",
                                 () => Holiday.LoadFromDatabase(Holidays.MyItems, ConnectionString, ignoreMissingTables), Holidays),
                new LoadingEntry("Variables",
                                 () => Variable.LoadFromDatabase(Variables.It, ConnectionString, ignoreMissingTables), Variables),

                new LoadingEntry("Date Based Profiles",
                                 () => DateBasedProfile.LoadFromDatabase(DateBasedProfiles.MyItems, ConnectionString,
                                                                         ignoreMissingTables), DateBasedProfiles),
                new LoadingEntry("Vacations",
                                 () => Vacation.LoadFromDatabase(Vacations.MyItems, ConnectionString, ignoreMissingTables),
                                 Vacations),
                new LoadingEntry("Desires",
                                 () => Desire.LoadFromDatabase(Desires.MyItems, ConnectionString, ignoreMissingTables), Desires),
                new LoadingEntry("Time Profiles",
                                 () => TimeBasedProfile.LoadFromDatabase(Timeprofiles.MyItems, ConnectionString, ignoreMissingTables),
                                 Timeprofiles),
                new LoadingEntry("Temperature Profiles",
                                 () => TemperatureProfile.LoadFromDatabase(TemperatureProfiles.MyItems, ConnectionString,
                                                                           ignoreMissingTables), TemperatureProfiles),
                new LoadingEntry("Generators",
                                 () => Generator.LoadFromDatabase(Generators.MyItems, ConnectionString, LoadTypes.MyItems,
                                                                  DateBasedProfiles.MyItems, ignoreMissingTables), Generators),
                new LoadingEntry("Energy Storages",
                                 () => EnergyStorage.LoadFromDatabase(EnergyStorages.MyItems, ConnectionString, LoadTypes.MyItems, Variables.MyItems,
                                                                      ignoreMissingTables), EnergyStorages),
                new LoadingEntry("Transformation Devices",
                                 () => TransformationDevice.LoadFromDatabase(TransformationDevices.MyItems, ConnectionString,
                                                                             LoadTypes.MyItems, Variables.MyItems, ignoreMissingTables), TransformationDevices),
                new LoadingEntry("Device Categories", () =>
                {
                    DeviceCategory.LoadFromDatabase(DeviceCategories.MyItems, out _dcnone, ConnectionString,
                                                    RealDevices.MyItems, ignoreMissingTables);
                    DeviceCategories.DeviceCategoryNone = _dcnone;
                }, DeviceCategories),

                new LoadingEntry("Real Devices",
                                 () => RealDevice.LoadFromDatabase(RealDevices.MyItems, DeviceCategories.MyItems,
                                                                   DeviceCategories.DeviceCategoryNone, ConnectionString, LoadTypes.MyItems, Timeprofiles.MyItems,
                                                                   ignoreMissingTables), RealDevices),
                new LoadingEntry("Device Action Groups",
                                 () => DeviceActionGroup.LoadFromDatabase(DeviceActionGroups.MyItems, ConnectionString,
                                                                          ignoreMissingTables), DeviceActionGroups),
                new LoadingEntry("Device Actions",
                                 () => DeviceAction.LoadFromDatabase(DeviceActions.MyItems, ConnectionString, Timeprofiles.MyItems,
                                                                     RealDevices.MyItems, LoadTypes.MyItems, DeviceActionGroups.MyItems, ignoreMissingTables),
                                 DeviceActions),
                new LoadingEntry("Device Tagging Sets",
                                 () => DeviceTaggingSet.LoadFromDatabase(DeviceTaggingSets.MyItems, ConnectionString,
                                                                         ignoreMissingTables, RealDevices.MyItems, LoadTypes.It), DeviceTaggingSets),
                new LoadingEntry("Persons",
                                 () => Person.LoadFromDatabase(Persons.MyItems, ConnectionString,
                                                               ignoreMissingTables), Persons),
                new LoadingEntry("Locations",
                                 () => Location.LoadFromDatabase(Locations.MyItems, ConnectionString, RealDevices.MyItems,
                                                                 DeviceCategories.MyItems, LoadTypes.MyItems, ignoreMissingTables), Locations),
                new LoadingEntry("Time Limits",
                                 () => TimeLimit.LoadFromDatabase(TimeLimits.MyItems, DateBasedProfiles.MyItems, ConnectionString,
                                                                  ignoreMissingTables), TimeLimits),
                new LoadingEntry("Geographic Locations",
                                 () => GeographicLocation.LoadFromDatabase(GeographicLocations.MyItems, ConnectionString,
                                                                           Holidays.MyItems, TimeLimits.MyItems, ignoreMissingTables), GeographicLocations),
                new LoadingEntry("Subaffordances",
                                 () => SubAffordance.LoadFromDatabase(SubAffordances.MyItems, ConnectionString, Desires.MyItems,
                                                                      ignoreMissingTables, Locations.It, Variables.It), SubAffordances),
                new LoadingEntry("Affordances",
                                 () => Affordance.LoadFromDatabase(Affordances.MyItems, ConnectionString, Timeprofiles.MyItems,
                                                                   DeviceCategories.MyItems, RealDevices.MyItems, Desires.MyItems, SubAffordances.MyItems,
                                                                   LoadTypes.MyItems, TimeLimits.MyItems, DeviceActions.MyItems, DeviceActionGroups.MyItems,
                                                                   Locations.It, ignoreMissingTables, Variables.It), Affordances),
                new LoadingEntry("Affordance Tagging Sets",
                                 () => AffordanceTaggingSet.LoadFromDatabase(AffordanceTaggingSets.MyItems, ConnectionString,
                                                                             ignoreMissingTables, Affordances.MyItems, LoadTypes.It), AffordanceTaggingSets),
                new LoadingEntry("Trait Tags",
                                 () => TraitTag.LoadFromDatabase(TraitTags.MyItems, ConnectionString, ignoreMissingTables),
                                 TraitTags),
                new LoadingEntry("Household Traits",
                                 () => HouseholdTrait.LoadFromDatabase(HouseholdTraits.MyItems, ConnectionString, Locations.MyItems,
                                                                       Affordances.MyItems, RealDevices.MyItems, DeviceCategories.MyItems, Timeprofiles.MyItems,
                                                                       LoadTypes.MyItems, TimeLimits.MyItems, Desires.MyItems, DeviceActions.It, DeviceActionGroups.It,
                                                                       TraitTags.It, ignoreMissingTables, Variables.It), HouseholdTraits),
                new LoadingEntry("Device Selections",
                                 () => DeviceSelection.LoadFromDatabase(DeviceSelections.MyItems, ConnectionString,
                                                                        DeviceCategories.MyItems, RealDevices.MyItems, DeviceActions.It, DeviceActionGroups.It,
                                                                        ignoreMissingTables), DeviceSelections),
                new LoadingEntry("Household Tags",
                                 () => HouseholdTag.LoadFromDatabase(HouseholdTags.It, ConnectionString, ignoreMissingTables),
                                 HouseholdTags),
                new LoadingEntry("Modular Households",
                                 () => ModularHousehold.LoadFromDatabase(ModularHouseholds.MyItems, ConnectionString,
                                                                         HouseholdTraits.MyItems, DeviceSelections.MyItems, ignoreMissingTables, Persons.MyItems,
                                                                         Vacations.It, HouseholdTags.It, TraitTags.It), ModularHouseholds),
                new LoadingEntry("Household Templates",
                                 () => HouseholdTemplate.LoadFromDatabase(HouseholdTemplates.MyItems, ConnectionString,
                                                                          HouseholdTraits.MyItems, ignoreMissingTables, Persons.MyItems, TraitTags.It, Vacations.It,
                                                                          HouseholdTags.It, DateBasedProfiles.It), HouseholdTemplates),
                new LoadingEntry("Template Persons",
                                 () => TemplatePerson.LoadFromDatabase(TemplatePersons.It, ConnectionString, HouseholdTraits.It,
                                                                       ignoreMissingTables, ModularHouseholds.It, Persons.It), TemplatePersons),
                new LoadingEntry("Household Plans",
                                 () => HouseholdPlan.LoadFromDatabase(HouseholdPlans.MyItems, ConnectionString, ignoreMissingTables,
                                                                      Persons.MyItems, AffordanceTaggingSets.MyItems, ModularHouseholds.MyItems),
                                 HouseholdPlans),
                new LoadingEntry("House Types",
                                 () => HouseType.LoadFromDatabase(HouseTypes.MyItems, ConnectionString, RealDevices.MyItems,
                                                                  DeviceCategories.MyItems, Timeprofiles.MyItems, TimeLimits.MyItems, LoadTypes.MyItems,
                                                                  TransformationDevices.MyItems, EnergyStorages.MyItems, Generators.MyItems, ignoreMissingTables,
                                                                  Locations.MyItems, DeviceActions.It, DeviceActionGroups.It, Variables.It), HouseTypes),
                new LoadingEntry("Transportation Device Categories",
                                 () => TransportationDeviceCategory.LoadFromDatabase(TransportationDeviceCategories.It, ConnectionString,
                                                                                     ignoreMissingTables), TransportationDeviceCategories),
                new LoadingEntry("Sites",
                                 () => Site.LoadFromDatabase(Sites.It,
                                                             ConnectionString, ignoreMissingTables,
                                                             Locations.It), Sites),
                new LoadingEntry("Transportation Devices",
                                 () => TransportationDevice.LoadFromDatabase(TransportationDevices.It, ConnectionString, ignoreMissingTables,
                                                                             TransportationDeviceCategories.It, LoadTypes.It), TransportationDevices),

                new LoadingEntry("Transportation Device Sets",
                                 () => TransportationDeviceSet.LoadFromDatabase(TransportationDeviceSets.It, ConnectionString,
                                                                                ignoreMissingTables, TransportationDevices.It), TransportationDeviceSets),

                new LoadingEntry("Travel Routes",
                                 () => TravelRoute.LoadFromDatabase(TravelRoutes.It, ConnectionString, ignoreMissingTables,
                                                                    TransportationDeviceCategories.It, Sites.It), TravelRoutes),

                new LoadingEntry("Travel Route Sets",
                                 () => TravelRouteSet.LoadFromDatabase(TravelRouteSets.It, ConnectionString, ignoreMissingTables,
                                                                       TravelRoutes.It), TravelRouteSets),
                new LoadingEntry("Charging Station Sets",
                                 () => ChargingStationSet.LoadFromDatabase(ChargingStationSets.It,
                                                                           ConnectionString, ignoreMissingTables,
                                                                           LoadTypes.It, TransportationDeviceCategories.It, Sites.It), ChargingStationSets),

                new LoadingEntry("Houses",
                                 () => House.LoadFromDatabase(Houses.MyItems, ConnectionString, TemperatureProfiles.MyItems,
                                                              GeographicLocations.MyItems, HouseTypes.MyItems,
                                                              ModularHouseholds.MyItems, ChargingStationSets.MyItems,
                                                              TransportationDeviceSets.MyItems, TravelRouteSets.MyItems,
                                                              ignoreMissingTables), Houses),
                new LoadingEntry("Settlements",
                                 () => Settlement.LoadFromDatabase(Settlements.MyItems, ConnectionString,
                                                                   TemperatureProfiles.MyItems, GeographicLocations.MyItems, ModularHouseholds.MyItems, Houses.MyItems,
                                                                   ignoreMissingTables), Settlements),
                new LoadingEntry("Settlement Templates",
                                 () => SettlementTemplate.LoadFromDatabase(SettlementTemplates.It, ConnectionString,
                                                                           HouseholdTemplates.It, HouseTypes.It, ignoreMissingTables, TemperatureProfiles.It,
                                                                           GeographicLocations.It, HouseholdTags.It, HouseholdTraits.It), SettlementTemplates),
                new LoadingEntry("Settings",
                                 () => MyGeneralConfig = GeneralConfig.LoadFromDatabase(ConnectionString, ignoreMissingTables), null),
                new LoadingEntry("Calculation Outcomes",
                                 () => CalculationOutcome.LoadFromDatabase(CalculationOutcomes.MyItems, ConnectionString,
                                                                           ignoreMissingTables), CalculationOutcomes)
            };

            return(actions);
        }
示例#26
0
        // the real picking function that selects a device
        public RealDevice PickDeviceFromCategory(DeviceCategory deviceCategory, EnergyIntensityType energyIntensity,
                                                 ObservableCollection <DeviceAction> deviceActions)
        {
            deviceCategory.RefreshSubDevices();
            var rds = deviceCategory.SubDevices;

            if (rds.Count == 0)
            {
                throw new DataIntegrityException("The device category " + deviceCategory.Name +
                                                 " has no devices but it is used. A device could not be picked from it.");
            }
            RealDevice pickedDevice = null;

            // look for this device category in the device selection
            if (_deviceSelection != null && _deviceSelection.Items.Count > 0)
            {
                foreach (var item in _deviceSelection.Items)
                {
                    if (item.DeviceCategory == deviceCategory)
                    {
                        pickedDevice = item.Device;
                    }
                }
            }
            if (pickedDevice == null)
            {
                switch (energyIntensity)
                {
                case EnergyIntensityType.Random:
                    var dstval = _random.Next(rds.Count);
                    pickedDevice = rds[dstval];
                    break;

                case EnergyIntensityType.EnergySaving:
                    pickedDevice = rds[0];
                    foreach (var t in rds)
                    {
                        if (pickedDevice.WeightedEnergyIntensity > t.WeightedEnergyIntensity)
                        {
                            pickedDevice = t;
                        }
                    }
                    break;

                case EnergyIntensityType.EnergySavingPreferMeasured:
                    var devices = GetMeasuredDevicesFromRealDevices(deviceActions, rds);
                    pickedDevice = devices[0];
                    foreach (var t in devices)
                    {
                        if (pickedDevice.WeightedEnergyIntensity > t.WeightedEnergyIntensity)
                        {
                            pickedDevice = t;
                        }
                    }
                    break;

                case EnergyIntensityType.EnergyIntensive:
                    pickedDevice = rds[0];
                    foreach (var t in rds)
                    {
                        if (pickedDevice.WeightedEnergyIntensity < t.WeightedEnergyIntensity)
                        {
                            pickedDevice = t;
                        }
                    }
                    break;

                case EnergyIntensityType.EnergyIntensivePreferMeasured:
                    var rdevices = GetMeasuredDevicesFromRealDevices(deviceActions, rds);
                    pickedDevice = rdevices[0];
                    foreach (var t in rdevices)
                    {
                        if (pickedDevice.WeightedEnergyIntensity < t.WeightedEnergyIntensity)
                        {
                            pickedDevice = t;
                        }
                    }
                    break;

                case EnergyIntensityType.AsOriginal:
                    throw new DataIntegrityException("Not permitted energy intensity type here: As Original");

                default:
                    throw new DataIntegrityException("Unknown EnergyIntensityType");
                }
            }

            Logger.Debug("Picked " + pickedDevice + " from " + rds.Count + " devices.");
            return(pickedDevice);
        }
示例#27
0
        public void MakeCalcLocationsTestWithDeviceCategory()
        {
            using WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass());
            var            builder        = new ContainerBuilder();
            var            r              = new Random(1);
            CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(2018, 1, 1)
                                            .SetEndDate(new DateTime(2018, 1, 1, 2, 0, 0)).SetSettlingDays(0).EnableShowSettlingPeriod();
            //CalcFactoryParameters.SetSkipChecking(true);
            //var nr = new NormalRandom(0, 1, r);
            var locations = new List <Location>();
            var loc       = new Location("loc", 1, string.Empty, Guid.NewGuid().ToStrGuid());

            locations.Add(loc);
            var devices = new ObservableCollection <RealDevice>();

            var dc  = new DeviceCategory("dc", -1, string.Empty, false, devices, Guid.NewGuid().ToStrGuid(), 1, true);
            var rd  = new RealDevice("rd", 1, string.Empty, dc, string.Empty, false, false, string.Empty, Guid.NewGuid().ToStrGuid(), 1);
            var rd2 = new RealDevice("rd2", 1, string.Empty, dc, string.Empty, false, false, string.Empty, Guid.NewGuid().ToStrGuid(), 1);

            dc.SubDevices.Add(rd);
            loc.AddDevice(dc, false);
            loc.AddDevice(rd2, false);
            var deviceLocationDict = new Dictionary <CalcLocationDto, List <IAssignableDevice> >();

            List <DeviceCategoryDto> devcat = new List <DeviceCategoryDto> {
                new DeviceCategoryDto(dc.FullPath, Guid.NewGuid().ToStrGuid())
            };

            devices.Add(rd);
            devices.Add(rd2);
            //var dict =new Dictionary<CalcLocation, List<IAssignableDevice>>();
            var allDeviceActions = new ObservableCollection <DeviceAction>();

            //var locdict = new Dictionary<Location, CalcLocation>();
            builder.Register(x => new CalcLoadTypeDtoDictionary(new Dictionary <VLoadType, CalcLoadTypeDto>())).As <CalcLoadTypeDtoDictionary>()
            .SingleInstance();
            builder.Register(x => new CalcLoadTypeDictionary(new Dictionary <CalcLoadTypeDto, CalcLoadType>())).As <CalcLoadTypeDictionary>()
            .SingleInstance();
            builder.Register(x => new DeviceCategoryPicker(r, null)).As <IDeviceCategoryPicker>().SingleInstance();
            builder.Register(x => calcParameters).As <CalcParameters>().SingleInstance();
            //builder.RegisterType<CalcLocationFactory>().As<CalcLocationFactory>().SingleInstance();
            Mock <IOnlineDeviceActivationProcessor> odapmock = new Mock <IOnlineDeviceActivationProcessor>();

            builder.Register(x => odapmock.Object).As <IOnlineDeviceActivationProcessor>().SingleInstance();
            builder.Register(x => r).As <Random>().SingleInstance();
            var idl = wd.InputDataLogger;

            builder.Register(x => idl).As <IInputDataLogger>().SingleInstance();
            string path = wd.WorkingDirectory;

            builder.Register(x => new FileFactoryAndTracker(path, "HH1", idl)).As <FileFactoryAndTracker>()
            .SingleInstance();
            builder.Register(x => new SqlResultLoggingService(path)).As <SqlResultLoggingService>().SingleInstance();
            builder.Register(x => new DateStampCreator(x.Resolve <CalcParameters>())).As <DateStampCreator>().SingleInstance();
            builder.Register(x => new DateStampCreator(x.Resolve <CalcParameters>())).As <DateStampCreator>().SingleInstance();
            builder.Register(x => new OnlineLoggingData(x.Resolve <DateStampCreator>(), x.Resolve <IInputDataLogger>(), x.Resolve <CalcParameters>()))
            .As <OnlineLoggingData>().SingleInstance();
            builder.Register(x => new LogFile(calcParameters,
                                              x.Resolve <FileFactoryAndTracker>())).As <ILogFile>().SingleInstance();
            builder.RegisterType <CalcDeviceFactory>().As <CalcDeviceFactory>().SingleInstance();
            builder.RegisterType <CalcLocationFactory>().As <CalcLocationFactory>().SingleInstance();
            builder.RegisterType <CalcPersonFactory>().As <CalcPersonFactory>().SingleInstance();
            builder.RegisterType <CalcModularHouseholdFactory>().As <CalcModularHouseholdFactory>().SingleInstance();
            builder.RegisterType <CalcLocationDtoFactory>().As <CalcLocationDtoFactory>();
            builder.RegisterType <InputDataLogger>().As <InputDataLogger>().SingleInstance();
            builder.RegisterType <CalcRepo>().As <CalcRepo>().SingleInstance();
            var container = builder.Build();

            using (var scope = container.BeginLifetimeScope()) {
                var             cldt        = scope.Resolve <CalcLocationDtoFactory>();
                var             calcRepo    = scope.Resolve <CalcRepo>();
                LocationDtoDict calclocdict = new LocationDtoDict();
                var             locdtos     = cldt.MakeCalcLocations(locations,
                                                                     new HouseholdKey("HH1"),
                                                                     EnergyIntensityType.EnergySaving,
                                                                     deviceLocationDict,
                                                                     allDeviceActions,
                                                                     calclocdict,
                                                                     devcat);

                CalcLocationFactory clf = scope.Resolve <CalcLocationFactory>();
                DtoCalcLocationDict dtl = new DtoCalcLocationDict();
                var clocations          = clf.MakeCalcLocations(locdtos, dtl, calcRepo);

                clocations.Count.Should().Be(1);
                clocations[0].LightDevices.Count.Should().Be(2);
                foreach (var device in clocations[0].LightDevices)
                {
                    Logger.Info(device.Name);
                }
            }

            wd.CleanUp();
        }
示例#28
0
        public void MakeCalcLocationsTestWithDevice()
        {
            var            builder        = new ContainerBuilder();
            var            r              = new Random(1);
            CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(2018, 1, 1)
                                            .SetEndDate(new DateTime(2018, 1, 1, 2, 0, 0)).SetSettlingDays(0).EnableShowSettlingPeriod();
            var picker = new DeviceCategoryPicker(r, null);

            builder.Register(x => picker).As <DeviceCategoryPicker>().SingleInstance();
            //var nr = new NormalRandom(0, 1, r);
            var locations = new List <Location>();
            var loc       = new Location("loc", 1, string.Empty, Guid.NewGuid().ToStrGuid());

            locations.Add(loc);
            var devices = new ObservableCollection <RealDevice>();
            var dc      = new DeviceCategory("dc", -1, string.Empty, false, devices, Guid.NewGuid().ToStrGuid(), 1, true);
            List <DeviceCategoryDto> devcat = new List <DeviceCategoryDto> {
                new DeviceCategoryDto(dc.FullPath, Guid.NewGuid().ToStrGuid())
            };
            var rd = new RealDevice("rd", 1, string.Empty, dc, string.Empty, false, false, string.Empty, Guid.NewGuid().ToStrGuid(), 1);

            loc.AddDevice(rd, false);
            var deviceLocationDict = new Dictionary <CalcLocationDto, List <IAssignableDevice> >();
            var allDeviceActions   = new ObservableCollection <DeviceAction>();

            //CalcLoadTypeDictionary cltd = CalcLoadTypeFactory.MakeLoadTypes(new ObservableCollection<VLoadType>(),calcParameters.InternalStepsize, calcParameters.LoadTypePriority);
            builder.Register(x => new DateStampCreator(x.Resolve <CalcParameters>())).As <DateStampCreator>().SingleInstance();
            builder.Register(x => new CalcLoadTypeDtoDictionary(new Dictionary <VLoadType, CalcLoadTypeDto>())).As <CalcLoadTypeDtoDictionary>()
            .SingleInstance();
            builder.Register(x => new CalcLoadTypeDictionary(new Dictionary <CalcLoadTypeDto, CalcLoadType>())).As <CalcLoadTypeDictionary>()
            .SingleInstance();
            builder.Register(x => new DeviceCategoryPicker(r, null)).As <IDeviceCategoryPicker>().SingleInstance();
            builder.Register(_ => calcParameters).As <CalcParameters>().SingleInstance();
            //builder.RegisterType<CalcLocationFactory>().As<CalcLocationFactory>().SingleInstance();
            Mock <IOnlineDeviceActivationProcessor> odapmock = new Mock <IOnlineDeviceActivationProcessor>();

            builder.Register(x => odapmock.Object).As <IOnlineDeviceActivationProcessor>().SingleInstance();
            builder.Register(x => r).As <Random>().SingleInstance();
            builder.RegisterType <CalcDeviceFactory>().As <CalcDeviceFactory>().SingleInstance();
            builder.RegisterType <CalcLocationFactory>().As <CalcLocationFactory>().SingleInstance();
            builder.RegisterType <CalcLocationDtoFactory>().As <CalcLocationDtoFactory>();
            builder.RegisterType <CalcRepo>().As <CalcRepo>().SingleInstance();
            var container = builder.Build();

            using var scope = container.BeginLifetimeScope();
            var             calcRepo    = scope.Resolve <CalcRepo>();
            var             cldt        = scope.Resolve <CalcLocationDtoFactory>();
            LocationDtoDict calclocdict = new LocationDtoDict();
            var             locdtos     = cldt.MakeCalcLocations(locations,
                                                                 new HouseholdKey("HH1"),
                                                                 EnergyIntensityType.EnergyIntensive,
                                                                 deviceLocationDict,
                                                                 allDeviceActions,
                                                                 calclocdict,
                                                                 devcat);

            //CalcDeviceFactory cdf = scope.Resolve<CalcDeviceFactory>();
            CalcLocationFactory clf = scope.Resolve <CalcLocationFactory>();
            DtoCalcLocationDict dtl = new DtoCalcLocationDict();
            var clocations          = clf.MakeCalcLocations(locdtos, dtl, calcRepo);

            clocations.Count.Should().Be(1);
            clocations[0].LightDevices.Count.Should().Be(2);
        }