public TimeLimitEntry([NotNull] string name, [NotNull] TimeLimit timeLimit, [CanBeNull] TraitTag tag, TimeSpan beginTime) { Name = name; TimeLimit = timeLimit; Tag = tag; BeginTime = beginTime; }
public void HouseholdTemplateGenerationTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var sim = new Simulator(db.ConnectionString); var gen = sim.HouseholdTemplates.CreateNewItem(db.ConnectionString); gen.NewHHName = "hh"; var entry = gen.AddEntry(sim.TraitTags[0], 5, 10); TraitTag tt = sim.TraitTags[0]; gen.AddPerson(sim.Persons[0], tt); entry.AddPerson(sim.Persons[0]); gen.SaveToDB(); gen.GenerateHouseholds(sim, true, new List <STTraitLimit>()); foreach (var household in gen.GeneratedHouseholds) { Logger.Info(household.Name); foreach (var trait in household.Traits) { Logger.Info("\t" + trait.HouseholdTrait.Name); } } db.Cleanup(); } }
public TraitTagPresenter( [NotNull] ApplicationPresenter applicationPresenter, [NotNull] TraitTagView view, [NotNull] TraitTag tag) : base(view, "ThisTag.HeaderString", tag, applicationPresenter) { _thisTag = tag; _usedIn = new ObservableCollection <UsedIn>(); RefreshUsedIn(); }
public void AddMoreDesiresTest() { Config.IsInUnitTesting = true; CalcParameters parameters = CalcParametersFactory.MakeGoodDefaults(); HouseholdKey key = new HouseholdKey("hh5"); var persons = new List <ModularHouseholdPerson>(); var p = new Person("blub", 1, 1, 1, 1, PermittedGender.Male, string.Empty, string.Empty, Guid.NewGuid().ToStrGuid()); var tt = new TraitTag("traittag", "", TraitLimitType.NoLimit, TraitPriority.All, Guid.NewGuid().ToStrGuid()); var mhp = new ModularHouseholdPerson(null, -1, p.PrettyName, "", p, tt, Guid.NewGuid().ToStrGuid()); persons.Add(mhp); var hhVacations = new List <VacationTimeframe>(); Random r = new Random(1); NormalRandom nr = new NormalRandom(0, 1, r); //DeviceCategoryPicker picker = new DeviceCategoryPicker(r,null); //var parameters = new CalcFactoryParameters(picker); //CalcFactoryParameters.SetSkipChecking(true); //var cloc = new CalcLocation("cloc", 1, Guid.NewGuid().ToStrGuid()); //var mock = new Mock<ILogFile>(); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults(); VacationDtoFactory vfac = new VacationDtoFactory(calcParameters, r); CalcPersonDtoFactory cpf = new CalcPersonDtoFactory(parameters, r, nr, vfac); var hhtDesires = new List <ModularHousehold.PersonTraitDesireEntry>(); var d = new Desire("desire", 1, 1, 1, string.Empty, 1, false, 1, "", Guid.NewGuid().ToStrGuid()); var hhtDesire = new HHTDesire(1, 1, 1, d, HealthStatus.Healthy, 1, 1, string.Empty, "name", 1, 100, PermittedGender.All, Guid.NewGuid().ToStrGuid()); var hht = new HouseholdTrait("blub", null, "", "", "", 1, 1, 1, 1, 1, TimeType.Day, 1, 1, TimeType.Day, 1, 1, EstimateType.FromCalculations, "", Guid.NewGuid().ToStrGuid()); hhtDesires.Add( new ModularHousehold.PersonTraitDesireEntry( ModularHouseholdTrait.ModularHouseholdTraitAssignType.Age, null, hhtDesire, hht)); //var sharedDesireValues = new Dictionary<Desire, SharedDesireValue>(); var cpersons = cpf.MakePersonDtos(persons, key, hhVacations, hhtDesires, "hhname"); cpersons.Count.Should().Be(1); var cp = cpersons[0]; //CalcPersonFactory.AddTraitDesires(hhtDesires, cpersons, 1, "name", sharedDesireValues); cp.Desires.Count.Should().Be(1); cp.Desires.Count.Should().Be(1); p.PrettyName.Should().Be(cp.Name); p.Age.Should().Be(cp.Age); // id 1 for the dictionary Assert.Equal(d.PrettyName, cp.Desires[0].Name); }
private static TraitTag GetTraitTagByName([NotNull] Simulator sim, [CanBeNull] string tagName) { TraitTag tag = null; if (tagName != null) { tag = sim.TraitTags.FindFirstByName(tagName); if (tag == null) { throw new LPGException("Tagname " + tagName + " not found."); } } return(tag); }
private static void AddTimeLimitEntry([NotNull] Simulator sim, [ItemNotNull][NotNull] List <TimeLimitEntry> timeLimits, [NotNull] string timelimitName, [NotNull] string newName, [CanBeNull] string tagName, TimeSpan beginSpan) { var aff = sim.TimeLimits.FindFirstByName(timelimitName); if (aff == null) { throw new LPGException("Time Limit not found: " + timelimitName); } TraitTag tag = GetTraitTagByName(sim, tagName); timeLimits.Add(new TimeLimitEntry(newName, aff, tag, beginSpan)); }
public void TraitTagTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { db.ClearTable(TraitTag.TableName); var cat = new CategoryDBBase <TraitTag>("Household Trait Tags"); TraitTag.LoadFromDatabase(cat.It, db.ConnectionString, false); (cat.MyItems.Count).Should().Be(0); cat.CreateNewItem(db.ConnectionString); cat.SaveToDB(); var tags = new ObservableCollection <TraitTag>(); TraitTag.LoadFromDatabase(tags, db.ConnectionString, false); (tags.Count).Should().Be(1); db.Cleanup(); } }
private void BtnAddPerson_Click([CanBeNull] object sender, [CanBeNull] RoutedEventArgs e) { if (Presenter.SelectedPerson == null) { return; } TraitTag tag = null; if (CmbLivingPatterns.SelectedItem != null) { tag = (TraitTag)CmbLivingPatterns.SelectedItem; } Presenter.ThisTemplate.AddPerson(Presenter.SelectedPerson, tag); Presenter.RefreshPersons(); }
public void SwapTagTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { Simulator sim = new Simulator(db.ConnectionString); ModularHousehold mhh = sim.ModularHouseholds.It[0]; ModularHouseholdPerson mhhPerson = mhh.Persons[0]; Person dstPerson = mhhPerson.Person; TraitTag dstTag = sim.TraitTags.It[10]; int traitsBefore = mhh.Traits.Count; mhh.SwapPersons(mhhPerson, dstPerson, dstTag); int traitsAfter = mhh.Traits.Count; (traitsAfter).Should().Be(traitsBefore); db.Cleanup(); } }
private void CheckLivingPatternTraits([NotNull] ModularHousehold mhh, [NotNull] TraitTag tagForAll) { if (!PerformCleanupChecks) { return; } foreach (var mhhPerson in mhh.Persons) { if (mhhPerson.TraitTag == null) { throw new DataIntegrityException( "The person " + mhhPerson.Person.PrettyName + " has no trait tag set.", mhh); } var traitsWithMissingTags = new List <HouseholdTrait>(); var personTraits = mhh.Traits.Where(x => x.DstPerson == mhhPerson.Person).ToList(); foreach (var personTrait in personTraits) { if (personTrait.HouseholdTrait == null) { throw new DataIntegrityException("HouseholdTrait was null"); } if (personTrait.HouseholdTrait.Tags.Any(x => x.Tag == tagForAll)) { //all is good since this trait was for everything continue; } if (personTrait.HouseholdTrait.Tags.Any(x => mhhPerson.TraitTag.Name.StartsWith(x.Name))) { //the person will have the most specific tag, the traits can be more generic continue; } traitsWithMissingTags.Add(personTrait.HouseholdTrait); } if (traitsWithMissingTags.Count > 0) { var elementsToOpen = new List <BasicElement> { mhh }; elementsToOpen.AddRange(traitsWithMissingTags); throw new DataIntegrityException( "The opened traits have no matching trait tag for " + mhhPerson.TraitTag, elementsToOpen); } } }
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(); } }
private static ModularHousehold GenerateEmptyHousehold([NotNull] Simulator sim, [NotNull] HouseholdTemplate template, [NotNull] Random r, ref int min, ref int max, int i1) { try { var chh = sim.ModularHouseholds.CreateNewItem(sim.ConnectionString); var nameoffset = 1; //name finding while (sim.ModularHouseholds.IsNameTaken(template.NewHHName + " " + (i1 + nameoffset).ToString("D2", CultureInfo.CurrentCulture))) { nameoffset++; } if (i1 == 0) { min = nameoffset; } if (i1 == template.Count - 1) { max = nameoffset + i1; } chh.Name = template.NewHHName + " " + (i1 + nameoffset).ToString("D2", CultureInfo.CurrentCulture); //other settings chh.Source = "Generated by " + template.Name + " at " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString(); chh.CreationType = CreationType.TemplateCreated; chh.EnergyIntensityType = template.EnergyIntensityType; chh.GeneratorID = template.IntID; //add persons //TODO: fix this foreach (var person in template.Persons) { TraitTag livingpattern = person.LivingPattern; string[] components = livingpattern?.Name.Split('/'); if (components?.Length == 3) { string basename = livingpattern.Name.Substring(0, livingpattern.Name.Length - components[2].Length); List <TraitTag> possibleTags = sim.TraitTags.It .Where(x => x.Name.StartsWith(basename, StringComparison.InvariantCultureIgnoreCase)).ToList(); if (possibleTags.Count > 1) { livingpattern = possibleTags[r.Next(possibleTags.Count)]; } } chh.AddPerson(person.Person, livingpattern); } var vac = GenerateVacation(template, r, sim, chh.Name); chh.Vacation = vac; chh.SaveToDB(); return(chh); } catch (Exception ex) { Logger.Exception(ex); throw; } }
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); } }
public void HouseholdTraitTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { db.ClearTable(HouseholdTrait.TableName); db.ClearTable(HHTAutonomousDevice.TableName); db.ClearTable(HHTDesire.TableName); db.ClearTable(HHTLocation.TableName); db.ClearTable(HHTAffordance.TableName); db.ClearTable(HHTTag.TableName); var timeBasedProfiles = db.LoadTimeBasedProfiles(); var dateBasedProfiles = db.LoadDateBasedProfiles(); var devices = db.LoadRealDevices(out ObservableCollection <DeviceCategory> deviceCategories, out _, out ObservableCollection <VLoadType> loadTypes, timeBasedProfiles); var timeLimits = db.LoadTimeLimits(dateBasedProfiles); var desires = db.LoadDesires(); var deviceActionGroups = db.LoadDeviceActionGroups(); var deviceActions = db.LoadDeviceActions(timeBasedProfiles, devices, loadTypes, deviceActionGroups); var locations = db.LoadLocations(devices, deviceCategories, loadTypes); var variables = db.LoadVariables(); var affordances = db.LoadAffordances(timeBasedProfiles, out _, deviceCategories, devices, desires, loadTypes, timeLimits, deviceActions, deviceActionGroups, locations, variables); var hht = new HouseholdTrait("blub", null, "blub", db.ConnectionString, "none", 1, 100, 10, 1, 1, TimeType.Day, 1, 1, TimeType.Day, 1, 0, EstimateType.Theoretical, "", Guid.NewGuid().ToStrGuid()); hht.SaveToDB(); var hht2 = new HouseholdTrait("blub2", null, "blub2", db.ConnectionString, "none", 1, 100, 10, 1, 1, TimeType.Day, 1, 1, TimeType.Day, 1, 0, EstimateType.Theoretical, "", Guid.NewGuid().ToStrGuid()); hht2.SaveToDB(); var loc = new Location("loc1", -1, db.ConnectionString, Guid.NewGuid().ToStrGuid()); hht.AddAutomousDevice(devices[0], timeBasedProfiles[0], 0, loadTypes[0], timeLimits[0], loc, 0, VariableCondition.Equal, variables[0]); var hhtl = hht.AddLocation(locations[0]); hht.SaveToDB(); var tag = new TraitTag("tag", db.ConnectionString, TraitLimitType.NoLimit, TraitPriority.Mandatory, Guid.NewGuid().ToStrGuid()); tag.SaveToDB(); hht.AddTag(tag); hht.AddAffordanceToLocation(hhtl, affordances[0], timeLimits[0], 100, 0, 0, 0, 0); hht.SaveToDB(); hht.AddDesire(desires[0], 1, "Healthy", 1, 1, 0, 100, PermittedGender.All); hht.SaveToDB(); hht.AddTrait(hht2); hht.SaveToDB(); (hht.SubTraits.Count).Should().Be(1); var hhts = new ObservableCollection <HouseholdTrait>(); var tags = db.LoadTraitTags(); HouseholdTrait.LoadFromDatabase(hhts, db.ConnectionString, locations, affordances, devices, deviceCategories, timeBasedProfiles, loadTypes, timeLimits, desires, deviceActions, deviceActionGroups, tags, false, variables); (hhts.Count).Should().Be(2); var hht3 = hhts[0]; (hht3.MinimumPersonsInCHH).Should().Be(1); (hht3.MaximumPersonsInCHH).Should().Be(100); (hht3.Desires.Count).Should().Be(1); (hht3.SubTraits.Count).Should().Be(1); (hht3.Classification).Should().Be("none"); (hht3.Tags.Count).Should().Be(1); (hht3.Tags[0].Tag.Name).Should().Be("tag"); foreach (var trait in hhts) { trait.DeleteFromDB(); } hhts.Clear(); Logger.Info("Loading again..."); HouseholdTrait.LoadFromDatabase(hhts, db.ConnectionString, locations, affordances, devices, deviceCategories, timeBasedProfiles, loadTypes, timeLimits, desires, deviceActions, deviceActionGroups, tags, false, variables); (hhts.Count).Should().Be(0); db.Cleanup(); } }
private static List <Settlement> Create([ItemNotNull][NotNull] List <SimpleModularHousehold> simpleHHs, [NotNull] Simulator sim, [NotNull] GlobalOptions globalOptions) { var finishedHHs = new List <ModularHousehold>(); var finishedHouses = new List <House>(); foreach (var smhh in simpleHHs) { var name = globalOptions.HouseholdName + " - " + smhh.Name; var oldMhh = sim.ModularHouseholds.It.FirstOrDefault(x => x.Name == name); if (oldMhh != null) { sim.ModularHouseholds.DeleteItem(oldMhh); Logger.Warning("Deleted the previously created household with the name " + name); } var mhh = sim.ModularHouseholds.CreateNewItem(sim.ConnectionString); finishedHHs.Add(mhh); mhh.EnergyIntensityType = globalOptions.EnergyIntensityType; mhh.Name = name; Logger.Info("Created a household named: " + mhh.Name); mhh.Description = globalOptions.Description ?? ""; mhh.DeviceSelection = sim.DeviceSelections.It.First(x => x.PrettyName == globalOptions.DeviceSelection); mhh.Vacation = sim.Vacations.It.FirstOrDefault(x => x.PrettyName == smhh.Vacation); mhh.SaveToDB(); foreach (var tagName in globalOptions.Tags) { var tag = sim.HouseholdTags.It.FirstOrDefault(x => x.PrettyName == tagName); if (tag == null) { throw new LPGException("Could not recognize Tag: " + tagName); } mhh.AddHouseholdTag(tag); } if (mhh.Vacation == null) { throw new LPGException("Could not identify vacation with the name: " + smhh.Vacation); } var personCount = 0; foreach (SimplePerson sp in smhh.Persons.Values) { if (sp.Traits.Count > 0) { var personName = sp.Name + " - " + smhh.Name; var oldPerson = sim.Persons.It.FirstOrDefault(x => x.Name == personName); if (oldPerson != null) { sim.Persons.DeleteItem(oldPerson); Logger.Warning("Deleted the previously created person with the name " + personName); } var p = sim.Persons.CreateNewItem(sim.ConnectionString); p.Name = personName; p.Age = sp.Age; p.AverageSicknessDuration = sp.SicknessDuration; p.Gender = sp.Gender?.ToLower(CultureInfo.CurrentCulture) == "male" ? PermittedGender.Male : PermittedGender.Female; p.SickDays = sp.AverageSickDays; personCount++; TraitTag tag = sim.TraitTags.FindFirstByName(sp.TraitTag); if (tag == null) { throw new LPGException("Tag not found"); } mhh.AddPerson(p, tag); foreach (var traitName in sp.Traits) { var trait = sim.HouseholdTraits.It.FirstOrDefault(x => x.PrettyName == traitName); if (trait == null) { trait = sim.HouseholdTraits.It.FirstOrDefault(x => x.PrettyNameOld == traitName); } if (trait == null) { throw new LPGException("Could not find a trait with the name: " + traitName); } mhh.AddTrait(trait, ModularHouseholdTrait.ModularHouseholdTraitAssignType.Name, p); } Logger.Info("Added " + sp.Traits.Count + " traits to the person " + p.PrettyName); p.SaveToDB(); } else { Logger.Info("Person " + sp.Name + " has no traits for " + smhh.Name); } } Logger.Info("Imported " + personCount + " persons."); var house = MakeHouse(sim, globalOptions, smhh, mhh); finishedHouses.Add(house); } var resultingSettlements = new List <Settlement>(); Logger.Info("Finished creating households."); // now make the settlement for the modular household testing Logger.Info("Creating a settlement"); var settlementName = "Test settlement for imported " + globalOptions.HouseholdName; var oldSett = sim.Settlements.It.FirstOrDefault(x => x.Name == settlementName); if (oldSett != null) { sim.Settlements.DeleteItem(oldSett); Logger.Warning("Deleted old settlement " + settlementName); } var sett = sim.Settlements.CreateNewItem(sim.ConnectionString); foreach (var modularHousehold in finishedHHs) { sett.AddHousehold(modularHousehold, 1); } sett.Name = settlementName; sett.SaveToDB(); resultingSettlements.Add(sett); // make the settlement for the house testing Logger.Info("Creating a settlement for the houses"); var houseSettlementName = "Test settlement for imported houses for " + globalOptions.HouseholdName; var oldHouseSett = sim.Settlements.It.FirstOrDefault(x => x.Name == houseSettlementName); if (oldHouseSett != null) { sim.Settlements.DeleteItem(oldHouseSett); Logger.Warning("Deleted old house settlement " + houseSettlementName); } var houseSett = sim.Settlements.CreateNewItem(sim.ConnectionString); foreach (var house in finishedHouses) { houseSett.AddHousehold(house, 1); } houseSett.Name = houseSettlementName; houseSett.SaveToDB(); resultingSettlements.Add(houseSett); return(resultingSettlements); }
public static List <ModularHousehold> RunCalculationTests([NotNull] Simulator sim) { var allhh = new List <ModularHousehold>(); Logger.Info("Starting sync"); foreach (var templatePerson in sim.TemplatePersons.It) { var personCode = templatePerson.Name.Substring(0, 4); if (!personCode.StartsWith("TP", StringComparison.Ordinal)) { Logger.Warning("Ignoring " + templatePerson.Name + " because name doesn't start with TP"); continue; } // Person var p = sim.Persons.It.FirstOrDefault(x => x.Name == templatePerson.Name); if (p == null) { Logger.Info("Creating person " + templatePerson.Name); p = sim.Persons.CreateNewItem(sim.ConnectionString); } else { Logger.Warning("Person " + templatePerson.Name + " already existed."); } p.Name = templatePerson.Name; p.Gender = templatePerson.Gender; p.Age = templatePerson.Age; p.SickDays = templatePerson.SickDays; p.Description = "Created to test the template person " + templatePerson.Name; p.SaveToDB(); // modular Household var chh = sim.ModularHouseholds.It.FirstOrDefault(x => x.Name == templatePerson.Name); if (chh == null) { Logger.Info("Creating modular household " + templatePerson.Name); chh = sim.ModularHouseholds.CreateNewItem(sim.ConnectionString); } else { Logger.Warning("Modular Household " + templatePerson.Name + " already existed."); } chh.Name = templatePerson.Name; chh.Vacation = sim.Vacations[1]; chh.SaveToDB(); chh.Description = "Created to test the template person " + templatePerson.Name; if (templatePerson.BaseHousehold == null) { throw new LPGException("base household was null"); } //TODO: add traittag to template person ModularHouseholdPerson mhhperson = templatePerson.BaseHousehold.Persons.FirstOrDefault(x => x.Person == templatePerson.BasePerson); TraitTag tt = null; if (mhhperson != null) { tt = mhhperson.TraitTag; } else { Logger.Error("no tag"); } chh.AddPerson(p, tt); allhh.Add(chh); var i = 0; foreach (var personTrait in templatePerson.Traits) { if (personTrait.Trait.Name.Contains("boardgame")) { continue; } chh.AddTrait(personTrait.Trait, ModularHouseholdTrait.ModularHouseholdTraitAssignType.Name, p); i++; } Logger.Info("Added " + i + " traits."); var traits = templatePerson.Traits.Select(x => x.Trait).ToList(); var traitsToDelete = new List <ModularHouseholdTrait>(); i = 0; foreach (var chhtrait in chh.Traits) { if (!traits.Contains(chhtrait.HouseholdTrait)) { traitsToDelete.Add(chhtrait); i++; } } foreach (var trait in traitsToDelete) { chh.DeleteTraitFromDB(trait); } Logger.Info("Deleted " + i + " traits."); } return(allhh); }
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); }