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 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 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(); } }
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(); } }
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 void AddTimepoint(TimeSpan ts, double value) { _tp.AddNewTimepoint(ts, value); _tp.SaveToDB(); }