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 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();
            }
        }
Beispiel #4
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 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 TimeProfilePresenter([NotNull] ApplicationPresenter applicationPresenter, [NotNull] TimeProfileView view,
                             [NotNull] TimeBasedProfile tp)
     : base(view, "ThisProfile.HeaderString", tp, applicationPresenter)
 {
     _tp          = tp;
     _csvImporter = new CSVImporter(false);
     _usedIns     = new ObservableCollection <UsedIn>();
     TimeProfileTypes.Add(TimeProfileType.Relative);
     TimeProfileTypes.Add(TimeProfileType.Absolute);
     RefreshUsedIn();
 }
Beispiel #7
0
        public static CalcProfileDto GetCalcProfileDto([NotNull] TimeBasedProfile tp)
        {
            var cp = new CalcProfileDto(tp.Name, tp.IntID, (ProfileType)tp.TimeProfileType,
                                        tp.DataSource, Guid.NewGuid().ToStrGuid());

            foreach (var timeDataPoint in tp.ObservableDatapoints)
            {
                cp.AddNewTimepoint(timeDataPoint.Time, timeDataPoint.Value);
            }
            return(cp);
        }
        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();
        }
        public static CalcProfile GetCalcProfile([NotNull] TimeBasedProfile timeBasedProfile, TimeSpan ts)
        {
            CalcProfile cp = new CalcProfile(timeBasedProfile.Name, Guid.NewGuid().ToStrGuid(),
                                             ts, (ProfileType)timeBasedProfile.TimeProfileType, timeBasedProfile.DataSource);

            foreach (var dp in timeBasedProfile.ObservableDatapoints)
            {
                cp.AddNewTimepoint(dp.Time, dp.Value);
            }
            cp.ConvertToTimesteps();
            return(cp);
        }
        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();
            }
        }
        protected override void Run(Simulator sim)
        {
            var placeholder = sim.Timeprofiles.FindFirstByName("placeholder", FindMode.Partial);

            _placeholder = placeholder ?? throw new LPGException("Placeholder was null");
            foreach (var action in sim.DeviceActions.It)
            {
                CheckForUsage(action, sim);
                CheckElectricity(action);
                CheckDeviceActionGroup(action);
                CheckValidLoadtypesOnDeviceAction(action);
                CheckForDuplicateTimeProfiles(action);
                CheckforAllPlaceholders(action);
            }
        }
        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();
        }
        public DeviceActionProfile([CanBeNull] TimeBasedProfile timeprofile, [CanBeNull] int?id, decimal timeOffset,
                                   int deviceActionID,
                                   [NotNull] string deviceName, [CanBeNull] VLoadType vLoadType, [NotNull] string connectionString, double multiplier, StrGuid guid)
            : base(deviceName, TableName, connectionString, guid)
        {
            _deviceActionID = deviceActionID;
            _timeprofile    = timeprofile;
            ID          = id;
            _timeOffset = timeOffset;

            _vLoadType      = vLoadType;
            TypeDescription = "Device Action Device";
            if (_timeOffset < 0)
            {
                _timeOffset = 0;
            }
            _multiplier = multiplier;
        }
Beispiel #14
0
        public void CompleteAffordanceCreatorTest()
        {
            using (DatabaseSetup db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                Simulator        sim       = new Simulator(db.ConnectionString);
                VLoadType        lt        = sim.LoadTypes[0];
                DeviceCategory   dc        = sim.DeviceCategories[1];
                TimeBasedProfile tp        = sim.Timeprofiles[1];
                Location         loc       = sim.Locations[0];
                TraitTag         tag       = sim.TraitTags[0];
                TimeLimit        timeLimit = sim.TimeLimits[0];

                CompleteAffordanceAdd.CreateItems(sim, "aff", "Entertainment / desire", "device", "trait", lt, dc, tp, 1,
                                                  10, 1, 99, loc, tag, "traitclass", timeLimit, "affcategory", null, false, "newLocation");
                SimIntegrityChecker.Run(sim);
                db.Cleanup();
            }
        }
 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;
 }
        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();
            }
        }
Beispiel #17
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;
 }
 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();
     }
 }
 public void GetCalcProfileTest()
 {
     using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
     {
         var tp = new TimeBasedProfile("blub", 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);
         tp.AddNewTimepoint(new TimeSpan(0, 4, 0), 100, false);
         tp.AddNewTimepoint(new TimeSpan(0, 6, 0), 0, false);
         var ctp = CalcDeviceFactory.GetCalcProfile(tp, new TimeSpan(0, 0, 30));
         ctp.TimeSpanDataPoints.Count.Should().Be(4);
         ctp.StepValues.Count.Should().Be(12);
         var v = ctp.StepValues;
         v[0].Should().Be(1);
         v[1].Should().Be(1);
         v[2].Should().Be(1);
         v[3].Should().Be(1);
         db.Cleanup();
     }
 }
Beispiel #20
0
        public void LoadFromDatabaseTest()
        {
            using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                var tps = new ObservableCollection <TimeBasedProfile>();
                TimeBasedProfile.LoadFromDatabase(tps, db.ConnectionString, false);
                tps.Count.Should().BeGreaterThan(1);
                db.ClearTable(TimeBasedProfile.TableName);
                db.ClearTable(TimeDataPoint.TableName);
                tps.Clear();
                var tp = new TimeBasedProfile("hey", null, db.ConnectionString, TimeProfileType.Absolute,
                                              "fake", Guid.NewGuid().ToStrGuid());
                tp.SaveToDB();
                tp.AddNewTimepoint(new TimeSpan(1, 0, 0), 1);
                TimeBasedProfile.LoadFromDatabase(tps, db.ConnectionString, false);

                (tps.Count).Should().Be(1);
                (tps[0].TimeProfileType).Should().Be(TimeProfileType.Absolute);
                (tps[0].ObservableDatapoints.Count).Should().Be(1);
                db.Cleanup();
            }
        }
        public static void CreateItems([NotNull] Simulator sim, [NotNull] string affordanceName, [NotNull] string desirename, [NotNull] string devicename,
                                       [NotNull] string traitName, [NotNull] VLoadType loadType, [NotNull] DeviceCategory deviceCategory, [NotNull] TimeBasedProfile timeprofile,
                                       double desireWeight, double desireDecay, int minimumAge, int maximumAge, [NotNull] Location location,
                                       [NotNull] TraitTag traitTag, [NotNull] string traitClassification, [NotNull] TimeLimit timelimit, [NotNull] string affordanceCategory,
                                       [CanBeNull] ApplicationPresenter app, bool useExistingLocation, [NotNull] string locationName)
        {
            Location loc;

            if (useExistingLocation)
            {
                loc = location;
            }
            else
            {
                loc      = sim.Locations.CreateNewItem(sim.ConnectionString);
                loc.Name = locationName;
                loc.SaveToDB();
            }
            var aff = sim.Affordances.CreateNewItem(sim.ConnectionString);

            aff.Name          = affordanceName;
            aff.PersonProfile = timeprofile;
            aff.MinimumAge    = minimumAge;
            aff.MaximumAge    = maximumAge;
            aff.TimeLimit     = timelimit;
            aff.Red           = 255;
            aff.Blue          = 0;
            aff.AffCategory   = affordanceCategory;
            var device = sim.RealDevices.CreateNewItem(sim.ConnectionString);

            device.Name           = devicename;
            device.DeviceCategory = deviceCategory;
            device.AddLoad(loadType, 1, 0, 0);
            device.SaveToDB();

            aff.AddDeviceProfile(device, timeprofile, 0, sim.RealDevices.It, sim.DeviceCategories.It, loadType, 1);
            var desire = sim.Desires.CreateNewItem(sim.ConnectionString);

            desire.DefaultDecayRate = (decimal)desireDecay;
            desire.DefaultWeight    = (decimal)desireWeight;
            desire.Name             = desirename;
            desire.SaveToDB();
            aff.AddDesire(desire, 1, sim.Desires.It);
            if (loc.LocationDevices.Count > 0)
            {
                aff.NeedsLight = true;
            }
            aff.SaveToDB();
            var trait = sim.HouseholdTraits.CreateNewItem(sim.ConnectionString);

            trait.AddTag(traitTag);
            var webtag = sim.TraitTags.FindFirstByName("web", FindMode.Partial);

            if (webtag != null)
            {
                trait.AddTag(webtag);
            }
            trait.Name           = traitName;
            trait.Classification = traitClassification;
            trait.AddDesire(desire, (decimal)desireDecay, "all", 0.5M, (decimal)desireWeight, minimumAge, maximumAge,
                            PermittedGender.All);
            trait.AddLocation(loc);
            trait.AddAffordanceToLocation(loc, aff, null, 100, 0, 0, 0, 0);
            trait.CalculateEstimatedTimes();
            trait.SaveToDB();
            if (app != null)
            {
                app.OpenItem(aff);
                app.OpenItem(desire);
                app.OpenItem(device);
                app.OpenItem(trait);
            }
        }
Beispiel #22
0
        private static HouseTypeDevice AssignFields([NotNull] DataReader dr, [NotNull] string connectionString, bool ignoreMissingFields,
                                                    [NotNull] AllItemCollections aic)
        {
            var id                   = dr.GetIntFromLong("ID");
            var deviceID             = dr.GetInt("DeviceID");
            var assignableDeviceType = (AssignableDeviceType)dr.GetInt("AssignableDeviceType");

            IAssignableDevice device;

            switch (assignableDeviceType)
            {
            case AssignableDeviceType.Device:
                device = aic.RealDevices.FirstOrDefault(mydevice => mydevice.ID == deviceID);
                break;

            case AssignableDeviceType.DeviceCategory:
                device = aic.DeviceCategories.FirstOrDefault(mydeviceCat => mydeviceCat.ID == deviceID);
                break;

            case AssignableDeviceType.DeviceAction:
                device = aic.DeviceActions.FirstOrDefault(mydeviceCat => mydeviceCat.ID == deviceID);
                break;

            case AssignableDeviceType.DeviceActionGroup:
                device = aic.DeviceActionGroups.FirstOrDefault(mydeviceCat => mydeviceCat.ID == deviceID);
                break;

            default:
                throw new LPGException("Unknown AssignableDeviceType. This is a bug. Please report!");
            }

            var timeProfileID   = dr.GetNullableIntFromLongOrInt("TimeProfileID", false, ignoreMissingFields);
            TimeBasedProfile tp = null;

            if (timeProfileID != null)
            {
                tp = aic.TimeProfiles.FirstOrDefault(myTimeProfiles => myTimeProfiles.ID == timeProfileID);
            }
            var houseID           = dr.GetInt("HouseID");
            var dtID              = dr.GetIntFromLong("TimeLimitID", false, ignoreMissingFields);
            var standardDeviation = dr.GetDouble("StandardDeviation");
            var timeLimit         = aic.TimeLimits.FirstOrDefault(myDateTime => myDateTime.ID == dtID);

            if (timeLimit == null && aic.TimeLimits.Count > 0)
            {
                timeLimit = aic.TimeLimits.First();
            }
            var locationID = dr.GetIntFromLong("LocationID", false, ignoreMissingFields, -1);
            var loc        = aic.Locations.FirstOrDefault(vl => vl.ID == locationID);

            var       loadtypeID = dr.GetNullableIntFromLong("VLoadTypeID", false);
            VLoadType vlt        = null;

            if (loadtypeID != null)
            {
                vlt = aic.LoadTypes.FirstOrDefault(vl => vl.ID == loadtypeID);
            }
            var name = "(no name)";

            if (device != null)
            {
                name = device.Name;
            }
            if (timeLimit != null)
            {
                name += "[" + timeLimit.Name + "]";
            }

            var variableValue = dr.GetDouble("VariableValue", false, 0, ignoreMissingFields);
            var tc            =
                (VariableCondition)dr.GetIntFromLong("VariableCondition", false, ignoreMissingFields);
            var variableID = dr.GetIntFromLong("VariableID", false, ignoreMissingFields, -1);
            var variable   = aic.Variables.FirstOrDefault(x => x.ID == variableID);
            var guid       = GetGuid(dr, ignoreMissingFields);

            return(new HouseTypeDevice(id, device, tp, houseID, timeLimit, standardDeviation, vlt, connectionString,
                                       name, loc,
                                       variableValue, tc, variable, guid));
        }
        private static HHTAutonomousDevice AssignFields([NotNull] DataReader dr, [NotNull] string connectionString,
                                                        bool ignoreMissingFields, [NotNull] AllItemCollections aic)
        {
            var hhadID        = dr.GetIntFromLong("ID");
            var deviceID      = dr.GetIntFromLong("DeviceID");
            var timeProfileID = dr.GetNullableIntFromLong("TimeProfileID", false, ignoreMissingFields);
            var householdID   = dr.GetIntFromLong("HouseholdTraitID");
            var locationID    = dr.GetIntFromLong("LocationID", false, ignoreMissingFields, -1);
            var loc           = aic.Locations.FirstOrDefault(lt => lt.ID == locationID);

            var vLoadTypeID = dr.GetNullableIntFromLong("VLoadTypeID", false, ignoreMissingFields);

            VLoadType newloadType = null;

            if (vLoadTypeID != null)
            {
                newloadType = aic.LoadTypes.FirstOrDefault(lt => lt.ID == vLoadTypeID);
            }
            var timeLimitID = dr.GetNullableIntFromLong("TimeLimitID", false, ignoreMissingFields);

            if (timeLimitID == null && ignoreMissingFields)
            {
                timeLimitID = dr.GetNullableIntFromLong("DeviceTimeID", false, ignoreMissingFields);
            }
            TimeLimit newTimeLimit = null;

            if (timeLimitID != null)
            {
                newTimeLimit = aic.TimeLimits.FirstOrDefault(dt => dt.ID == timeLimitID);
            }
            var deviceType =
                (AssignableDeviceType)dr.GetIntFromLong("AssignableDeviceType", false, ignoreMissingFields);
            var timeStandardDeviation = dr.GetDecimal("TimeStandardDeviation", false, 0.1m, ignoreMissingFields);
            IAssignableDevice device;

            switch (deviceType)
            {
            case AssignableDeviceType.Device:
                device = aic.RealDevices.FirstOrDefault(mydevice => mydevice.ID == deviceID);
                break;

            case AssignableDeviceType.DeviceCategory:
                device = aic.DeviceCategories.FirstOrDefault(mydeviceCat => mydeviceCat.ID == deviceID);
                break;

            case AssignableDeviceType.DeviceAction:
                device = aic.DeviceActions.FirstOrDefault(mydeviceCat => mydeviceCat.ID == deviceID);
                break;

            case AssignableDeviceType.DeviceActionGroup:
                device = aic.DeviceActionGroups.FirstOrDefault(mydeviceCat => mydeviceCat.ID == deviceID);
                break;

            default:
                throw new LPGException("Forgotten assignable device type in HHTAutonomousDevice. Please report!");
            }
            TimeBasedProfile tp = null;

            if (timeProfileID != null)
            {
                tp = aic.TimeProfiles.FirstOrDefault(myTimeProfiles => myTimeProfiles.ID == timeProfileID);
            }
            var name = "(no name)";

            if (device != null)
            {
                name = device.Name;
            }

            var variableValue = dr.GetDouble("VariableValue", false, 0, ignoreMissingFields);
            var condition     =
                (VariableCondition)dr.GetIntFromLong("VariableCondition", false, ignoreMissingFields);
            var variableID = dr.GetIntFromLong("VariableID", false, ignoreMissingFields, -1);
            var variable   = aic.Variables.FirstOrDefault(x => x.ID == variableID);
            var guid       = GetGuid(dr, ignoreMissingFields);

            var hhad = new HHTAutonomousDevice(hhadID, device, tp, householdID, timeStandardDeviation,
                                               newloadType, newTimeLimit, connectionString, name, loc, variableValue,
                                               condition, variable, guid);

            return(hhad);
        }
Beispiel #24
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);
        }
Beispiel #25
0
        private static AffordanceDevice AssignFields([NotNull] DataReader dr, [NotNull] string connectionString, bool ignoreMissingFields,
                                                     [NotNull] AllItemCollections aic)
        {
            var id           = dr.GetIntFromLong("ID");
            var affordanceID = dr.GetInt("AffordanceID", false, -1, ignoreMissingFields);
            var deviceID     = dr.GetInt("DeviceID");

            var timeprofileID = dr.GetNullableIntFromLongOrInt("TimeprofileID", false, ignoreMissingFields);
            var timeOffset    = dr.GetDecimal("TimeOffset");
            var adt           =
                (AssignableDeviceType)dr.GetInt("AssignableDeviceType", false, (int)AssignableDeviceType.Device,
                                                true);
            var vloadtypeID = dr.GetNullableIntFromLong("VLoadTypeID", false, ignoreMissingFields);
            var vlt         = aic.LoadTypes.FirstOrDefault(lt => lt.ID == vloadtypeID);
            IAssignableDevice device;

            switch (adt)
            {
            case AssignableDeviceType.DeviceCategory:
                device = aic.DeviceCategories.FirstOrDefault(dc => dc.ID == deviceID);
                break;

            case AssignableDeviceType.Device:
                device = aic.RealDevices.FirstOrDefault(rd => rd.ID == deviceID);
                break;

            case AssignableDeviceType.DeviceAction:
                device = aic.DeviceActions.FirstOrDefault(rd => rd.ID == deviceID);
                break;

            case AssignableDeviceType.DeviceActionGroup:
                device = aic.DeviceActionGroups.FirstOrDefault(rd => rd.ID == deviceID);
                break;

            default: throw new LPGException("unknown device type");
            }
            TimeBasedProfile tp = null;

            if (timeprofileID != null)
            {
                tp = aic.TimeProfiles.FirstOrDefault(tpt => tpt.ID == timeprofileID);
            }
            var aff        = aic.Affordances.FirstOrDefault(affordance => affordance.ID == affordanceID);
            var deviceName = "(no device)";

            if (device != null)
            {
                deviceName = device.Name;
            }
            int?affid = null;

            if (aff != null)
            {
                affid = aff.IntID;
            }
            var probability = dr.GetDouble("Probability", false, 1, ignoreMissingFields);
            var guid        = GetGuid(dr, ignoreMissingFields);
            var tup         = new AffordanceDevice(device, tp, id, timeOffset, affid, aic.RealDevices,
                                                   aic.DeviceCategories, deviceName, vlt, connectionString, probability, guid)
            {
                ParentAffordance = aff
            };

            return(tup);
        }