public static List <ModularHousehold> GenerateHouseholds([NotNull] Simulator sim, bool generateSettlement, [ItemNotNull][NotNull] List <STTraitLimit> limits, [NotNull] HouseholdTemplate template) { if (template == null) { throw new LPGException("No template was assigned when calling the GenerateHouseholds-Function"); } if (template.Persons.Count == 0) { Logger.Error("The household template " + template.Name + " has no persons. This isn't going to work."); return(new List <ModularHousehold>()); } if (template.Vacations.Count == 0 && template.TemplateVacationType == TemplateVacationType.FromList) { Logger.Error("The household template " + template.Name + " has no vacations. This isn't going to work."); return(new List <ModularHousehold>()); } try { var r = new Random(); var min = 1; var max = 0; var createdHH = new List <ModularHousehold>(); var numberofPersons = template.Persons.Count; for (var i = 0; i < template.Count; i++) { ModularHousehold chh = null; var i1 = i; Logger.Get().SafeExecuteWithWait(() => chh = GenerateEmptyHousehold(sim, template, r, ref min, ref max, i1)); createdHH.Add(chh); chh.SaveToDB(); AddDesiredTraits(sim, limits, template, r, numberofPersons, chh); chh.SaveToDB(); foreach (var hhTemplateTag in template.TemplateTags) { chh.AddHouseholdTag(hhTemplateTag.Tag); } template.GeneratedHouseholds.Add(chh); Logger.Info("Created household " + chh.Name); } MakeSettlement(sim, generateSettlement, template, min, max, createdHH); return(createdHH); } catch (Exception e) { Logger.Exception(e); throw; } }
public void ModularHouseholdTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { db.ClearTable(ModularHousehold.TableName); db.ClearTable(ModularHouseholdTrait.TableName); db.ClearTable(ModularHouseholdPerson.TableName); var persons = new ObservableCollection <Person>(); var result = new ObservableCollection <ModularHousehold>(); var householdTraits = new ObservableCollection <HouseholdTrait>(); 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(); householdTraits.Add(hht); var deviceSelections = new ObservableCollection <DeviceSelection>(); var ds = new DeviceSelection("ds", null, "bla", db.ConnectionString, Guid.NewGuid().ToStrGuid()); ds.SaveToDB(); deviceSelections.Add(ds); var vacations = db.LoadVacations(); var hhTags = db.LoadHouseholdTags(); var traitTags = db.LoadTraitTags(); ModularHousehold.LoadFromDatabase(result, db.ConnectionString, householdTraits, deviceSelections, false, persons, vacations, hhTags, traitTags); (result.Count).Should().Be(0); var chh = new ModularHousehold("blub", null, "blub", db.ConnectionString, ds, "src", null, null, EnergyIntensityType.Random, CreationType.ManuallyCreated, Guid.NewGuid().ToStrGuid()); chh.SaveToDB(); chh.AddTrait(hht, ModularHouseholdTrait.ModularHouseholdTraitAssignType.Age, null); chh.SaveToDB(); result.Clear(); ModularHousehold.LoadFromDatabase(result, db.ConnectionString, householdTraits, deviceSelections, false, persons, vacations, hhTags, traitTags); (result.Count).Should().Be(1); (result[0].Traits.Count).Should().Be(1); db.Cleanup(); } }