Esempio n. 1
0
        private Address GetAdressObject(PersonWithMetadata person)
        {
            var hasPostalCode = MultivariateBinaryGenerator.Hit(PersonStatisticKeys.HasPostalCode, person.BooleanSamples, person.Randy.Hit(_model.Statistics.GetClosestStatisticByAgeQuant(person).HasPostalCode.TrueRatioPercent));

            string postalCode = null;

            while (postalCode == null)
            {
                postalCode = _model.Statistics.PostalCode.Sample(person.Randy);
            }

            if (!_adresses.ContainsKey(postalCode) || _adresses[postalCode].All(a => a.Claimed))
            {
                MakeAdresses(postalCode, 100, person);
            }

            var adress = _adresses[postalCode].First(x => !x.Claimed);

            if (adress.AdressElement != null)
            {
                ConvertFromAdressElement(adress, person);
            }

            adress.Claimed = true;

            if (!hasPostalCode)
            {
                adress.PostalCode = null;
            }

            return(adress);
        }
Esempio n. 2
0
        private static RelationshipSearch SetParent_ReturnLookingForParent(PersonWithMetadata person, bool hasThisParent, bool?hasValidThisParent, bool isFemale, bool setFathersNin, int age)
        {
            if (!hasThisParent)
            {
                return(null);
            }

            if (hasValidThisParent.HasValue && hasValidThisParent.Value)
            {
                return(new RelationshipSearch
                {
                    IsFemale = person.IsFemale,
                    AgeQuant = GetAgeQuant(person.GetAge()),
                    NinRef = person.Person.NIN,
                    IsLookingForFemale = isFemale,
                    IsLookingForAgeQuant = GetAgeQuant(age)
                });
            }
            else
            {
                if (setFathersNin)
                {
                    person.Person.FathersNIN = NinModel.GetBirthdayAndNin(age, isFemale, false, person.Randy).Item2;
                }
                else
                {
                    person.Person.MothersNIN = NinModel.GetBirthdayAndNin(age, isFemale, false, person.Randy).Item2;
                }
            }

            return(null);
        }
        public void SetProperties(PersonWithMetadata person)
        {
            var result = _getMaritialstatusAndDate(person);

            person.Person.MaritalStatus     = result.Item1;
            person.Person.DateMaritalStatus = result.Item2;
        }
Esempio n. 4
0
        private void RegisterParentSearch(PersonWithMetadata person, bool hasFather, bool hasMother, Randomizer randy)
        {
            bool?hasValidFather          = hasFather ? randy.Hit(_pParentNinExists_GivenHaveParentNin(person)) : (bool?)null;
            bool?hasValidMother          = hasMother ? randy.Hit(_pParentNinExists_GivenHaveParentNin(person)) : (bool?)null;
            var  motherAndFatherIsFemale = GetFatherAndMotherSex(person, hasValidFather, hasValidMother, randy);

            var married = hasValidFather.HasValue && hasValidFather.Value && hasValidMother.HasValue && hasValidMother.Value &&
                          randy.Hit(_pParentsAreMarried_GivenhaveMotherAndFather(person));

            var personAge = person.GetAge();
            var fatherAge = hasFather ? personAge + _getAgeDifferenceInYearsToParent(person) : 0;
            var motherAge = hasMother ? (hasFather && married ? fatherAge + _getSpouseAgeDifferential(new PersonWithMetadata {
                AgeQuants = GetAgeQuant(fatherAge), Randy = randy
            }) : personAge + _getAgeDifferenceInYearsToParent(person)) : 0;

            var fatherParentSearch = SetParent_ReturnLookingForParent(person, hasFather, hasValidFather, motherAndFatherIsFemale.Item1, true, fatherAge);
            var motherParentSearch = SetParent_ReturnLookingForParent(person, hasMother, hasValidMother, motherAndFatherIsFemale.Item2, false, motherAge);

            if (fatherParentSearch != null || motherParentSearch != null)
            {
                var next = new ParentRelationshipSearch
                {
                    ChildNin = person.Person.NIN,
                    Father   = fatherParentSearch,
                    Mother   = motherParentSearch,
                    Married  = married
                };

                ParentSearch.Push(next);
                _numberOfChildren.Update(next.KeyParents());
            }
        }
Esempio n. 5
0
        private void RegisterSpouseSearch(PersonWithMetadata person, bool hasSpouse, Randomizer randy)
        {
            if (!hasSpouse)
            {
                return;
            }

            person.Married = true;
            var spouseSameSex         = randy.Hit(_pSpouseSameSex_GivenHasValidSpouse(person));
            var spouseAgeDifferential = Try(_getSpouseAgeDifferential, person);
            var spouseAge             = person.GetAge() + spouseAgeDifferential;
            var spouseExists          = randy.Hit(_pSpouseExists_GivenHasSpouse(person));

            if (!spouseExists)
            {
                var spouseIsFemale = (person.IsFemale && spouseSameSex) || (!person.IsFemale && !spouseSameSex);

                person.Person.SpouseNIN = NinModel.GetBirthdayAndNin(spouseAge, spouseIsFemale, false, person.Randy).Item2;
                return;
            }

            var spouseDuplex = randy.Hit(_pSpouseDuplex_GivenHasValidSpouse(person));

            var spouseSearch = new RelationshipSearch()
            {
                NinRef   = person.Person.NIN,
                IsFemale = person.IsFemale,
                AgeQuant = GetAgeQuant(person.GetAge()),

                IsLookingForFemale   = (person.IsFemale && spouseSameSex) || (!person.IsFemale && !spouseSameSex),
                IsLookingForAgeQuant = GetAgeQuant(spouseAge)
            };

            AddSearchToDic(spouseSearch.KeyMe(), spouseSearch, spouseDuplex ? SpouseSearchDuplex : SpouseSearchNonDuplex);
        }
Esempio n. 6
0
        private Tuple <DateTime, string> GetNonTakenBirthdayAndNin(PersonWithMetadata person, bool isFemale, bool hasDnummer)
        {
            int howManyTries = 0;

            while (true)
            {
                if (howManyTries++ > 100)
                {
                    throw new ArgumentException($"Klarer ikke å lage nin for alder {person.Age}");
                }

                var bdayAndNin = NinModel.GetBirthdayAndNin(person.Age, isFemale, hasDnummer, person.Randy);

                if (_idControl.TakenContains(bdayAndNin.Item2))
                {
                    continue;
                }

                var successfulAdd = _idControl.TakenAdd(bdayAndNin.Item2);
                if (!successfulAdd)
                {
                    continue;
                }

                return(bdayAndNin);
            }
        }
Esempio n. 7
0
        private void MakeAdresses(string postalCode, int howmany, PersonWithMetadata person)
        {
            if (!_postalDictionary.ContainsKey(postalCode))
            {
                _postalDictionary.Add(postalCode, new Tuple <string, string>(GetRandomName(_randomPlacePostfixes, person), _municipalityDictionary.Keys.ElementAt(person.Randy.Next(_municipalityDictionary.Keys.Count))));
            }

            for (int i = 0; i < howmany; i++)
            {
                var adress = new ClaimableAddress();
                adress.Claimed = false;

                var streetname         = GetRandomName(_randomRoadPostfixes, person);
                var postalAdressLetter = _adressStatistics.HasHouseLetter.Sample(person.Randy) ? person.Randy.NextLetter().ToString().ToUpper() : null;
                int?postalAdressNumber = _adressStatistics.HasHouseNumber.Sample(person.Randy) ? person.Randy.Next(1000) : (int?)null;

                adress.PostalCode    = postalCode;
                adress.PostalPlace   = adress.PostalCode != null && _adressStatistics.HasPostalPlace.Sample(person.Randy) ? _postalDictionary[postalCode].Item1 : null;
                adress.PostalAddress = _adressStatistics.HasPostalAdress.Sample(person.Randy) ? streetname + " " + postalAdressNumber + postalAdressLetter : null;
                adress.St            = _adressStatistics.HasSt.Sample(person.Randy) ? _postalDictionary[postalCode].Item2 : null;
                adress.Municipality  = adress.St != null ? _municipalityDictionary[adress.St] : null;

                SetRestOfFields(adress, streetname, postalAdressLetter, postalAdressNumber, person);

                if (!_adresses.ContainsKey(postalCode))
                {
                    _adresses.Add(postalCode, new List <ClaimableAddress>());
                }

                _adresses[postalCode].Add(adress);
            }
        }
        public void SetProperties(PersonWithMetadata person)
        {
            var isSame = person.Randy.Hit(PIsSame);

            SetFornavn(person, isSame ? SameNameGenerator : NameGenerator);
            SetMellomnavn(person, isSame ? SameNameGenerator : NameGenerator);
            SetEtternavn(person, isSame ? SameNameGenerator : NameGenerator);
            SetMaidenName(person, isSame ? SameNameGenerator : NameGenerator);
        }
        private void SetMaidenName(PersonWithMetadata person, NameRandomzier nameRandomzier)
        {
            if (!_pHasMaidenName(person))
            {
                return;
            }

            person.Person.WithoutLegalCapacity = GetEtternavn(nameRandomzier, person); //"låner" WithoutLegalCapacity, siden det ikke brukes
        }
Esempio n. 10
0
        private string GetRandomName(string[] postfixes, PersonWithMetadata person)
        {
            var prefix = person.Randy.Hit(50) ? _nameModel.NameGenerator.NextSirname(false, person.Randy)
                : (person.Randy.Hit(50) ? _nameModel.NameGenerator.NextFemaleFirstname(person.Randy) : _nameModel.NameGenerator.NextMaleFirstname(person.Randy));

            var postfix = postfixes.ElementAt(person.Randy.Next(postfixes.Length));

            return(prefix + postfix);
        }
        private void SetEtternavn(PersonWithMetadata person, NameRandomzier nameGenerator)
        {
            if (!person.Randy.Hit(_pHasSirname(person)))
            {
                return;
            }

            person.Person.Sn = GetEtternavn(nameGenerator, person);
        }
Esempio n. 12
0
        public void SetProperties(PersonWithMetadata person)
        {
            var values = _hasFatherHasMotherHasSpouse(person);

            RegisterParentSearch(person, values.Item1, values.Item2, person.Randy);
            RegisterSpouseSearch(person, values.Item3, person.Randy);

            SetCustody(person, values.Item1 || values.Item2);
        }
Esempio n. 13
0
 public static int Try(Func <PersonWithMetadata, int> func, PersonWithMetadata person, int def = 0)
 {
     try
     {
         return(func(person));
     }
     catch (Exception)
     {
         return(def);
     }
 }
Esempio n. 14
0
        private Address MakeAdressForTheDead(PersonWithMetadata person)
        {
            var a = new Address
            {
                St = _postalDictionary[_postalDictionary.ElementAt(person.Randy.Next(_postalDictionary.Keys.Count)).Key]
                     .Item2,
            };

            SetAdressLines(a, person);

            return(a);
        }
        public void AddParentToCommonKid(PersonWithMetadata person)
        {
            if (PreviousParentWithCommonKids == null)
            {
                PreviousParentWithCommonKids = new List <PersonWithMetadata>();
            }

            if (PreviousParentWithCommonKids.All(p => p.Person.NIN != person.Person.NIN))
            {
                PreviousParentWithCommonKids.Add(person);
            }
        }
Esempio n. 16
0
        private Tuple <bool, bool> GetFatherAndMotherSex(PersonWithMetadata person, bool?hasValidFather, bool?hasValidMother, Randomizer randy)
        {
            var sameSex = randy.Hit(_pParentSameSex_GivenHaveValidParentNin(person));

            if (sameSex && hasValidFather.HasValue && hasValidFather.Value && hasValidMother.HasValue && hasValidMother.Value)
            {
                var isFemale = randy.Hit(50);
                return(new Tuple <bool, bool>(isFemale, isFemale));
            }

            return(new Tuple <bool, bool>(false, true));
        }
Esempio n. 17
0
        private void SetAdressLines(Address adress, PersonWithMetadata person)
        {
            var hasAddressLines = _adressStatistics.HasAdressLine12or3.Sample(person.Randy);

            if (hasAddressLines)
            {
                var adressLines = _adressLines.ElementAt(person.Randy.Next(_adressLines.Count));

                adress.AddressLine1 = _adressStatistics.HasAdressLine1_WhenHasAdressLine12or3.Sample(person.Randy) ? Max(adressLines.Item1, 30) : null;
                adress.AddressLine2 = _adressStatistics.HasAdressLine2_WhenHasAdressLine12or3.Sample(person.Randy) ? Max(adressLines.Item2, 30) : null;
                adress.AddressLine3 = _adressStatistics.HasAdressLine3_WhenHasAdressLine12or3.Sample(person.Randy) ? Max(adressLines.Item3, 30) : null;
            }
        }
Esempio n. 18
0
        public Tuple <bool, bool, bool> HasFatherHasMotherHasSpouse(PersonWithMetadata person)
        {
            var hasFatherStat = _model.Statistics.GetClosestStatisticByAgeQuant(person).HasFather;
            var hasMotherStat = _model.Statistics.GetClosestStatisticByAgeQuant(person).HasMother;
            var hasSpouseStat = _model.Statistics.GetClosestStatisticByAgeQuant(person).HasSpouse;

            var correlation = CommonFunctions.GetCorrelation(person, _model, "hasFather", "HasMother");

            var hasFatherHasMother = CommonFunctions.GetDependentStatistic(hasFatherStat, hasMotherStat, correlation, person.Randy);
            var hasSpouse          = person.Randy.HitPropabilityDecimal(hasSpouseStat.TrueRatio);

            return(new Tuple <bool, bool, bool>(hasFatherHasMother.Item1, hasFatherHasMother.Item2, hasSpouse));
        }
Esempio n. 19
0
        private void SetNewNin(PersonWithMetadata person, bool isFemale)
        {
            var hasNewNin = MultivariateBinaryGenerator.Hit(PersonStatisticKeys.HasNewNIN, person.BooleanSamples, person.Randy.Hit(_pHasNewNin(person)));

            if (!hasNewNin)
            {
                return;
            }

            var bdayAndNin = GetNonTakenBirthdayAndNin(person, isFemale, false);

            person.Person.NewNIN = bdayAndNin.Item2;
        }
        private void SetFornavn(PersonWithMetadata person, NameRandomzier nameGenerator)
        {
            if (!person.Randy.Hit(_pHasFirstname(person)))
            {
                return;
            }

            if (person.IsFemale)
            {
                person.Person.GivenName = GetName(_givenHasFirstNameHowManyNames(person), person.Randy, nameGenerator.NextFemaleFirstname);
            }
            else
            {
                person.Person.GivenName = GetName(_givenHasFirstNameHowManyNames(person), person.Randy, nameGenerator.NextMaleFirstname);
            }
        }
Esempio n. 21
0
        private void SetDufNo(PersonWithMetadata p)
        {
            var hasDufNo = MultivariateBinaryGenerator.Hit(PersonStatisticKeys.HasDufNo, p.BooleanSamples, p.Randy.Hit(_pDufNo(p)));

            if (!hasDufNo)
            {
                return;
            }

            var firstApplicationYear = DateTime.Now.Year - p.Randy.Next(p.Age);

            p.Person.DufNo = firstApplicationYear.ToString();
            for (int i = 0; i < 8; i++)
            {
                p.Person.DufNo += p.Randy.Next(10).ToString();
            }
        }
Esempio n. 22
0
        public void SetProperties(PersonWithMetadata person)
        {
            if (!string.IsNullOrEmpty(person.Person.NIN))
            {
                return;
            }

            person.HasDnummer = MultivariateBinaryGenerator.Hit(PersonStatisticKeys.HasDnummer, person.BooleanSamples, person.Randy.Hit(_pHasDnummer(person)));

            person.IsFemale = _getKjonnIsFemale(person);
            var bdayAndNin = GetNonTakenBirthdayAndNin(person, person.IsFemale, person.HasDnummer);

            person.Person.NIN         = bdayAndNin.Item2;
            person.Person.DateOfBirth = bdayAndNin.Item1;

            SetOldNin(person, person.IsFemale);
            //SetNewNin(person, person.IsFemale);
            SetDufNo(person);
        }
Esempio n. 23
0
        public void SetProperties(PersonWithMetadata person)
        {
            var howManyAdressObjects = _model.Statistics.AdressStatistics.NumberOfAdressObjects.Sample(person.Randy);

            if (!howManyAdressObjects.HasValue || howManyAdressObjects == 0)
            {
                return;
            }

            if (person.Person.Addresses == null)
            {
                person.Person.Addresses = new Address[howManyAdressObjects.Value];
            }

            for (int i = 0; i < howManyAdressObjects; i++)
            {
                var adressObject = GetAdressObject(person);
                if (i == 0)
                {
                    adressObject.CurrentAddress = true;
                }

                adressObject.PostalType     = _model.Statistics.AdressStatistics.PostalType.Sample(person.Randy);
                adressObject.DatePostalType = adressObject.PostalType.HasValue && _adressStatistics.HasDatePostalPlace.Sample(person.Randy) ? DateTime.Now.AddDays(person.Randy.Next(500)) : (DateTime?)null;

                if (_model.Statistics.AdressStatistics.HasDateAdrFrom.Sample(person.Randy))
                {
                    adressObject.DateAdrFrom = NinModel.GetBirthday(person.Randy.Next(person.GetAge()), person.Randy);
                }

                if (person.HasDnummer)
                {
                    adressObject.St = GetRekvirentKode(person.Randy);
                }

                adressObject.NIN           = person.Person.NIN;
                person.Person.Addresses[i] = adressObject;
            }

            ReplacePostalcodeForSammenslaatteKommuner(person.Person);
        }
        private string GetEtternavn(NameRandomzier nameGenerator, PersonWithMetadata person)
        {
            var howMany = _givenHasHasSirnameHowManyNames(person);

            var name = "";
            var lastWasBindestrek = false;

            for (int i = 0; i < howMany; i++)
            {
                var addThis = nameGenerator.NextSirname(person.Randy);
                if ((name + addThis).Length > MaxLength)
                {
                    break;
                }

                name += addThis;

                if (i != howMany - 1)
                {
                    var useBindestrek = !lastWasBindestrek && person.Randy.Hit(_givenHasMultipleSirnameUseBindestrek(person));
                    if (useBindestrek)
                    {
                        name += "-";
                        lastWasBindestrek = true;
                    }
                    else
                    {
                        name += " ";
                        lastWasBindestrek = false;
                    }
                }
            }

            if (name.EndsWith("-"))
            {
                name = name.Substring(0, name.LastIndexOf("-", StringComparison.Ordinal) - 1);
            }

            return(name);
        }
Esempio n. 25
0
        private void SetCustody(PersonWithMetadata person, bool hasParentNin)
        {
            bool?hasCustody = person.BooleanSamples.ContainsKey(PersonStatisticKeys.HasCustody) ? person.BooleanSamples[PersonStatisticKeys.HasCustody] : (bool?)null;

            if (hasCustody.HasValue && !hasCustody.Value)
            {
                return;
            }

            if (hasCustody.HasValue)
            {
                person.Person.Custody = hasParentNin?
                                        _model.Statistics.GetClosestStatisticByAgeQuant(person).RelationshipStatistics.Custody_HaveParentNin.NonNullSample(person.Randy) :
                                        _model.Statistics.GetClosestStatisticByAgeQuant(person).RelationshipStatistics.Custody_HaveNotParentNin.NonNullSample(person.Randy);
            }
            else
            {
                person.Person.Custody = hasParentNin ?
                                        _model.Statistics.GetClosestStatisticByAgeQuant(person).RelationshipStatistics.Custody_HaveParentNin.Sample(person.Randy) :
                                        _model.Statistics.GetClosestStatisticByAgeQuant(person).RelationshipStatistics.Custody_HaveNotParentNin.Sample(person.Randy);
            }
        }
        public void SetProperties(PersonWithMetadata person)
        {
            bool?isDead = person.BooleanSamples.ContainsKey(PersonStatisticKeys.IsDead)
                ? MultivariateBinaryGenerator.Hit(PersonStatisticKeys.IsDead, person.BooleanSamples, false)
                : (bool?)null;

            var stat = _model.Statistics.GetClosestStatisticByAgeQuant(person).RegStatus;

            if (!isDead.HasValue)
            {
                person.Person.RegStatus = stat?.Sample(person.Randy);
            }
            else
            {
                if (isDead.Value)
                {
                    person.Person.RegStatus = 5;
                }
                else
                {
                    int count = 1000;
                    while (count-- > 0)
                    {
                        var sample = stat.Sample(person.Randy);
                        if (sample.HasValue && sample.Value == 5)
                        {
                            continue;
                        }

                        person.Person.RegStatus = sample;
                        break;
                    }
                }
            }

            person.Person.DateStatus = _model.Statistics.GetClosestStatisticByAgeQuant(person).RegstatusStatistics.DateDifference.GetDateTimeFromModel(person, person.Person.RegStatus);
        }
Esempio n. 27
0
 private string GetAppartmentNumber(PersonWithMetadata person)
 {
     return("H0" + person.Randy.Next(10) + "0" + person.Randy.Next(10));
 }
Esempio n. 28
0
        private string GetFourSiffers(bool startsWithZero, string endsWithSameAsThis, PersonWithMetadata person)
        {
            var s = "";

            s += startsWithZero ? "0" : person.Randy.Next(10).ToString();
            s += person.Randy.Next(10);
            s += person.Randy.Next(10);
            s += endsWithSameAsThis?.ElementAt(endsWithSameAsThis.Length - 1).ToString() ?? person.Randy.Next(10).ToString();

            return(s);
        }
Esempio n. 29
0
        private void SetParentsSameAdress(Dictionary <string, PersonWithMetadata> persons, PersonWithMetadata child, Randomizer randy)
        {
            var ninMaster = randy.Hit(50) ? child.Person.FathersNIN : child.Person.MothersNIN;
            var ninSlave  = ninMaster == child.Person.MothersNIN ? child.Person.FathersNIN : child.Person.MothersNIN;

            if (!persons.ContainsKey(ninMaster) || !persons.ContainsKey(ninSlave) || persons[ninMaster].Person?.Addresses?.Any(x => x.CurrentAddress) == null)
            {
                return;
            }

            var adress = AdressModel.Clone(persons[ninMaster].Person.Addresses.First(x => x.CurrentAddress));

            adress.NIN = ninSlave;
            var indexOfCurrentAdress = AdressModel.IndexOfCurrentAdress(persons[ninSlave].Person.Addresses);

            if (indexOfCurrentAdress == null)
            {
                persons[ninSlave].Person.Addresses = new[] { adress }
            }
            ;
            else
            {
                persons[ninSlave].Person.Addresses[indexOfCurrentAdress.Value] = adress;
            }
        }
Esempio n. 30
0
        private void SetChildAdressToParents(Dictionary <string, PersonWithMetadata> persons, PersonWithMetadata child, Randomizer randy)
        {
            var takeFathers = child.Person.FathersNIN != null && randy.Hit(50);
            var ninToTake   = takeFathers ? child.Person.FathersNIN : child.Person.MothersNIN;

            if (ninToTake != null && persons.ContainsKey(ninToTake) && persons[ninToTake].Person?.Addresses?.Any(x => x.CurrentAddress) != null)
            {
                var adress = AdressModel.Clone(persons[ninToTake].Person.Addresses.First(x => x.CurrentAddress));
                adress.NIN = child.Person.NIN;

                var indexOfCurrentAdress = AdressModel.IndexOfCurrentAdress(child.Person.Addresses);
                if (indexOfCurrentAdress == null)
                {
                    child.Person.Addresses = new[] { adress }
                }
                ;
                else
                {
                    child.Person.Addresses[indexOfCurrentAdress.Value] = adress;
                }
            }
        }