public void RegisterMarried(PersonWithMetadata parent1, PersonWithMetadata parent2) { var father = parent1; var mother = parent2; if (parent1.IsFemale && !parent2.IsFemale) { father = parent2; mother = parent1; } var howManyOtherChildrenFather = _numberOfOtherChildrenForMarriedCouples(father); var howManyOtherChildrenMother = _numberOfOtherChildrenForMarriedCouples(mother); var couple = new Couple { FatherNin = father.Person.NIN, MotherNin = mother.Person.NIN, FatherSn = father.Person.Sn, MotherSn = mother.Person.Sn }; AddToCoupleCache(couple, ParentRelationshipSearch.KeyMarriedParents(father, mother), false); if (howManyOtherChildrenFather > 0) { AddToParentCacheReturnKey(howManyOtherChildrenFather, father); } if (howManyOtherChildrenMother > 0) { AddToParentCacheReturnKey(howManyOtherChildrenMother, mother); } }
public static double GetCorrelation(PersonWithMetadata person, SynteticModel model, string valueString1, string valueString2) { if (model.Statistics.GetClosestStatisticByAgeQuant(person)?.Correlations == null) { return(model.Statistics.Correlations.GetValue(valueString1, valueString2).Value); } return(model.Statistics.GetClosestStatisticByAgeQuant(person).Correlations.GetValue(valueString1, valueString2).Value); }
public PersonPreg(Person person) { _person = person; DateWhenNameRegistered = NameModel.GetDateWhenNameRegistered(person); MaidenName = person.WithoutLegalCapacity; //"låner" WithoutLegalCapacity, siden det ikke brukes var isFemale = CommonFunctions.IsFemale(person.NIN); GenderBackingValue = isFemale.HasValue ? (isFemale.Value ? 0 : 1) : 0; UpdatedDate = PersonWithMetadata.GetLastUpdated(person); CreatedDate = PersonWithMetadata.GetCreatedDate(person); }
public static PersonWithMetadata GetInitialPerson(IdentificatorModel inIdentificatorModel, int?predefinedAge = null, bool?predefinedIsFemale = null) { var p = new PersonWithMetadata() { Person = new Person(), PredefinedAge = predefinedAge, PrefinedIsFemale = predefinedIsFemale }; p.Age = predefinedAge ?? inIdentificatorModel.GetRandomAge()(); p.AgeQuants = BaseModel.GetAgeQuant(p.Age); return(p); }
public bool SetParents(ParentRelationshipSearch next, PersonWithMetadata child, Randomizer randy) { if (next.Married) { var success = SetCouple(next, child, GetNewMarriedCouple, randy); MarriedSuccess.Add(success); return(success); } else { var success = SetCouple(next, child, GetNewCouple, randy); NonMarriedSuccess.Add(success); return(success); } }
private string AddToParentCacheReturnKey(int howManyChildren, PersonWithMetadata match) { var keyMe = RelationshipSearch.KeyMe(match); if (!_parents.ContainsKey(keyMe)) { _parents.Add(keyMe, new List <Parent>()); } _parents[keyMe].Add(new Parent { Nin = match.Person.NIN, Sn = match.Person.Sn, RemainingNumberOfChildren = howManyChildren }); return(keyMe); }
private void SetCityzenship(PersonWithMetadata nextPerson) { var sample = MultivariateBinaryGenerator.Sample(PersonStatisticKeys.HasCitizenship, nextPerson.BooleanSamples, Model.Statistics.GetClosestStatisticByAgeQuant(nextPerson).Citizenship_And_CitizenshipCode, _randomizer); if (sample == null || !sample.Contains("_")) { return; } var splitted = sample.Split('_'); nextPerson.Person.Citizenship = splitted[0] == "null" ? null : splitted[0]; nextPerson.Person.CitizenshipCode = splitted[1] == "null" ? null : splitted[1]; nextPerson.Person.DateCitizenship = Model.Statistics.GetClosestStatisticByAgeQuant(nextPerson).DateCitizenship.GetDateTimeFromModel(nextPerson, nextPerson.Person.Citizenship); }
public static string KeyMarriedParents(PersonWithMetadata father, PersonWithMetadata mother) { var pc = new ParentRelationshipSearch(); pc.Mother = new RelationshipSearch { IsLookingForAgeQuant = mother.AgeQuants, IsLookingForFemale = mother.IsFemale }; pc.Father = new RelationshipSearch() { IsLookingForAgeQuant = father.AgeQuants, IsLookingForFemale = father.IsFemale }; pc.Married = true; return(pc.KeyParents()); }
public DateTime?GetDateTimeFromModel(PersonWithMetadata nextPerson, string value) { if (!nextPerson.Person.DateOfBirth.HasValue) { return(null); } var diffPercent = !string.IsNullOrEmpty(value) ? DateDifference[value].Sample(nextPerson.Randy) : (DateDifference.ContainsKey(_novalue) ? DateDifference[_novalue].Sample(nextPerson.Randy) : DateDifference[string.Empty].Sample(nextPerson.Randy)); if (!diffPercent.HasValue) { return(null); } var recreatedDatestatus = (int)Math.Round((diffPercent.Value / 100.0) * CommonFunctions.GetAge(nextPerson.Person.DateOfBirth.Value) + nextPerson.Person.DateOfBirth.Value.Year); return(NinModel.GetBirthday(DateTime.Now.Year - recreatedDatestatus, nextPerson.Randy)); }
public PersonStatistics GetClosestStatisticByAgeQuant(PersonWithMetadata person, Func <PersonStatistics, bool> isValidForMe = null) { var ageQ = person.AgeQuants; if (ageQ <= 0) { return(StatisticsByAgeQuants.ContainsKey(1) ? StatisticsByAgeQuants[1] : this); } do { if (StatisticsByAgeQuants.ContainsKey(ageQ) && (isValidForMe == null || isValidForMe(StatisticsByAgeQuants[ageQ]))) { return(StatisticsByAgeQuants[ageQ]); } } while (ageQ-- > 0); return(this); }
private bool SetCouple(ParentRelationshipSearch next, PersonWithMetadata child, Func <ParentRelationshipSearch, PersonWithMetadata, Randomizer, Couple> getNewCouple, Randomizer randy) { var couple = GetFromCache(next.KeyParents()) ?? getNewCouple(next, child, randy); if (couple == null) { return(false); } SetNins(couple.FatherNin, couple.MotherNin, child); if (randy.Hit(NameModel.PHasSamesirnameAsParents(child))) { var takeFathers = couple.FatherSn != null && randy.Hit(50); child.Person.Sn = takeFathers ? couple.FatherSn : (couple.MotherSn ?? child.Person.Sn); } return(true); }
private Couple GetNewCouple(ParentRelationshipSearch next, PersonWithMetadata child, Randomizer randy) { var mother = next.Mother == null ? null : (GetParentNinFromCache(next.Mother) ?? GetNewParent(next.Mother, married: false)); var father = next.Father == null ? null : (GetParentNinFromCache(next.Father, mother) ?? GetNewParent(next.Father, married: false)); if (mother == null && father == null) { return(null); } var howManyChildrenTogether = GetNumberOfChildsTogether(mother?.RemainingNumberOfChildren, father?.RemainingNumberOfChildren, randy); int?beforeFather = father?.RemainingNumberOfChildren; int?beforeMother = mother?.RemainingNumberOfChildren; //usikker på om dette er mulig .. if (mother != null) { mother.RemainingNumberOfChildren = mother.RemainingNumberOfChildren - howManyChildrenTogether; } if (father != null) { father.RemainingNumberOfChildren = father.RemainingNumberOfChildren - howManyChildrenTogether; } var couple = new Couple { FatherNin = father?.Nin, MotherNin = mother?.Nin, FatherSn = father?.Sn, MotherSn = mother?.Sn, RemainingNumberOfChildren = howManyChildrenTogether - 1 }; AddToCoupleCache(couple, next.KeyParents()); return(couple); }
private void SetNins(string fatherNin, string motherNin, PersonWithMetadata child) { child.Person.FathersNIN = fatherNin; child.Person.MothersNIN = motherNin; }
public AddressPreg(Address address) { _address = address; CreatedDate = PersonWithMetadata.GetCreatedDate(address) ?? DateTime.Now.AddDays(-1); UpdatedDate = PersonWithMetadata.GetUpdatedDate(address) ?? DateTime.Now; }
public static string KeyMe(PersonWithMetadata person) { return(GetKey(person.IsFemale, person.AgeQuants)); }
public DateTime?GetDateTimeFromModel(PersonWithMetadata person, int?value) { return(GetDateTimeFromModel(person, value?.ToString())); }
private Couple GetNewMarriedCouple(ParentRelationshipSearch next, PersonWithMetadata child, Randomizer randu) { return(null); // all married couples are already in cache }