Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        private Func <int> GetAgeGenerator()
        {
            var randy = base._databuilder.GetRandomizer();

            _ageStatistic = new DiscreteStatistic(1, "Age");
            foreach (var ageQuant in _model.Statistics.StatisticsByAgeQuants)
            {
                _ageStatistic._stats.Add(ageQuant.Key, ageQuant.Value.NumberOfPersons);
            }

            return(() => NinModel.GetRandomAge(_ageStatistic.Sample(randy).Value, _model.AgeQuantLevel, randy));
        }
Ejemplo n.º 5
0
        private string GetParent(string parentNin)
        {
            if (string.IsNullOrEmpty(parentNin) || !NinModel.IsValidNin(parentNin))
            {
                return(null);
            }

            if (!_persons.ContainsKey(parentNin))
            {
                _persons.Add(parentNin, new PregNode());
            }

            return(parentNin);
        }
Ejemplo n.º 6
0
        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));
        }
Ejemplo n.º 7
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);
        }
        public PersonStatistics(string sessionId, int numberOfSamplesToTake, int ageQuants, int?ageQuantLevel) : base(sessionId, numberOfSamplesToTake, ageQuants, ageQuantLevel)
        {
            RelationshipStatistics  = new RelationshipStatistics(numberOfSamplesToTake);
            SivilstatusStatistics   = new SivilstatusStatistics(numberOfSamplesToTake);
            NameStatistics          = ageQuantLevel.HasValue ? null : new NameStatistics(numberOfSamplesToTake);
            RegstatusStatistics     = new RegstatusStatistics(numberOfSamplesToTake);
            AdressStatistics        = ageQuantLevel.HasValue ? null : new AdressStatistics(numberOfSamplesToTake);
            RegStatus_Vs_PostalType = new DependentDiscreteStatistic(numberOfSamplesToTake, "RegStatus_Vs_PostalType", (p, a) => new Tuple <double?, double?>(p.RegStatus, AdressStatistics.GetCurrent(p.Addresses)?.PostalType));

            CustomModels.Add("RelationshipStatistics", RelationshipStatistics);
            CustomModels.Add("SivilstatusStatistics", SivilstatusStatistics);
            CustomModels.Add("NameStatistics", NameStatistics);
            CustomModels.Add("RegstatusStatistics", RegstatusStatistics);
            CustomModels.Add("AdressStatistics", AdressStatistics);
            CustomModels.Add("RegStatus_Vs_PostalType", RegStatus_Vs_PostalType);

            Kjonn = new DiscreteStatistic(numberOfSamplesToTake, "Kjonn", CorrelationFactory, (p, a) =>
            {
                if (NinModel.IsValidNin(p.NIN) && !CommonFunctions.HasDnummer(p.NIN))
                {
                    return(CommonFunctions.GetKjonn(p.NIN).Value);
                }

                return(Statistic.DontUpdateWhenThisValue);
            });

            HasDnummer_Kjonn = new DiscreteStatistic(numberOfSamplesToTake, "HasDnummer_Kjonn", CorrelationFactory,
                                                     (p, a) =>
            {
                if (NinModel.IsValidNin(p.NIN) && CommonFunctions.HasDnummer(p.NIN))
                {
                    return(CommonFunctions.GetKjonn(p.NIN).Value);
                }

                return(Statistic.DontUpdateWhenThisValue);
            });

            HasDnummer = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.HasDnummer, CorrelationFactory, (p, a) =>
            {
                if (NinModel.IsValidNin(p.NIN))
                {
                    return(CommonFunctions.HasDnummer(p.NIN) ? 1 : 0);
                }

                return(Statistic.DontUpdateWhenThisValue);
            });

            Age = new Statistic(numberOfSamplesToTake, PersonStatisticKeys.Age, CorrelationFactory, (p, a) => p.DateOfBirth.HasValue? CommonFunctions.GetAge(p.DateOfBirth.Value).GetValue() : null);

            IsDead                = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.IsDead, CorrelationFactory, (p, a) => IsPersonDead(p));
            IsUkjent              = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.IsUkjent, CorrelationFactory, (p, a) => HasUkjentRegCode(p));           //-1000
            IsBosatt              = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.IsBosatt, CorrelationFactory, (p, a) => HasRegcode(p, 1));              //1
            IsUtflyttet           = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.IsUtflyttet, CorrelationFactory, (p, a) => HasRegcode(p, 2));           //2
            IsUtvandret           = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.IsUtvandret, CorrelationFactory, (p, a) => HasRegcode(p, 3));           //3
            IsForsvunnet          = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.IsForsvunnet, CorrelationFactory, (p, a) => HasRegcode(p, 4));          //4
            IsUtgaatFodselsnummer = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.IsUtgaatFodselsnummer, CorrelationFactory, (p, a) => HasRegcode(p, 6)); //6
            IsFodselsregistrert   = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.IsFodselsregistrert, CorrelationFactory, (p, a) => HasRegcode(p, 7));   //7
            IsAnnullertTilgang    = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.IsAnnullertTilgang, CorrelationFactory, (p, a) => HasRegcode(p, 8));    //8
            IsUregistrertTilgang  = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.IsUregistrertTilgang, CorrelationFactory, (p, a) => HasRegcode(p, 9));  //9

            HasFirstname = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.HasFirstname, CorrelationFactory, (p, a) => string.IsNullOrEmpty(p.GivenName) || string.IsNullOrWhiteSpace(p.GivenName) ? 0 : 1);
            HasLastname  = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.HasLastname, CorrelationFactory, (p, a) => string.IsNullOrEmpty(p.Sn) || string.IsNullOrWhiteSpace(p.Sn) ? 0 : 1);

            HasFather = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.HasFather, CorrelationFactory, (p, a) => String.IsNullOrEmpty(p.FathersNIN) ? 0 : 1);
            HasMother = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.HasMother, CorrelationFactory, (p, a) => String.IsNullOrEmpty(p.MothersNIN) ? 0 : 1);
            HasSpouse = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.HasSpouse, CorrelationFactory, (p, a) => String.IsNullOrEmpty(p.SpouseNIN) ? 0 : 1);
            Citizenship_And_CitizenshipCode = new DiscreteStringStatistics(numberOfSamplesToTake, ageQuantLevel, PersonStatisticKeys.Citizenship_And_CitizenshipCode, CorrelationFactory, (p, a) => (string.IsNullOrEmpty(p.Citizenship) ? "null" : p.Citizenship) + "_" + (string.IsNullOrEmpty(p.CitizenshipCode) ? "null" : p.CitizenshipCode));
            HasCitizenship          = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.HasCitizenship, CorrelationFactory, (p, a) => string.IsNullOrEmpty(p.Citizenship) ? 0 : 1);
            Custody                 = new DiscreteStringStatistics(numberOfSamplesToTake, ageQuantLevel, PersonStatisticKeys.Custody, CorrelationFactory, (p, a) => p.Custody);
            HasCustody              = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.HasCustody, CorrelationFactory, (p, a) => string.IsNullOrEmpty(p.Custody) ? 0 : 1);
            WithoutLegalCapacity    = new DiscreteStringStatistics(numberOfSamplesToTake, ageQuantLevel, PersonStatisticKeys.WithoutLegalCapacity, CorrelationFactory, (p, a) => p.WithoutLegalCapacity);
            HasWithoutLegalCapacity = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.HasWithoutLegalCapacity, CorrelationFactory, (p, a) => string.IsNullOrEmpty(p.WithoutLegalCapacity) ? 0 : 1);
            HasValidNin             = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.HasValidNin, CorrelationFactory, (p, a) => NinModel.IsValidNin(p.NIN) ? 1 : 0);
            HasDufNo                = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.HasDufNo, CorrelationFactory, (p, a) => string.IsNullOrEmpty(p.DufNo) ? 0 : 1);
            MaritalStatus           = new DiscreteStatistic(numberOfSamplesToTake, PersonStatisticKeys.MaritalStatus, CorrelationFactory, (p, a) => p.MaritalStatus.GetValue());
            HasOldNIN               = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.HasOldNIN, CorrelationFactory, (p, a) => string.IsNullOrEmpty(p.OldNIN) ? 0 : 1);
            HasNewNIN               = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.HasNewNIN, CorrelationFactory, (p, a) => string.IsNullOrEmpty(p.NewNIN) ? 0 : 1);
            ParentalResponsibility  = new DiscreteStatistic(numberOfSamplesToTake, PersonStatisticKeys.ParentalResponsibility, CorrelationFactory, (p, a) => p.ParentalResponsibility.GetValue());
            RegStatus               = new DiscreteStatistic(numberOfSamplesToTake, PersonStatisticKeys.RegStatus, CorrelationFactory, (p, a) => p.RegStatus.GetValue());
            StatusCountryCode       = new DiscreteStatistic(numberOfSamplesToTake, PersonStatisticKeys.StatusCountryCode, CorrelationFactory, (p, a) => p.StatusCountryCode);
            HasStatusCountryCode    = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.HasStatusCountryCode, CorrelationFactory, (p, a) => p.StatusCountryCode.HasValue ? 1 : 0);
            WorkPermit              = new DiscreteStringStatistics(numberOfSamplesToTake, ageQuantLevel, PersonStatisticKeys.WorkPermit, CorrelationFactory, (p, a) => p.WorkPermit);
            HasWorkPermit           = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.HasWorkPermit, CorrelationFactory, (p, a) => string.IsNullOrEmpty(p.WorkPermit) ? 0 : 1);
            PostalCode              = new DiscreteStringStatistics(numberOfSamplesToTake, ageQuantLevel, PersonStatisticKeys.PostalCode, CorrelationFactory, (p, a) => p.Addresses != null && p.Addresses.Any() ? p.Addresses.First().PostalCode : null);
            HasPostalCode           = new BooleanStatistic(numberOfSamplesToTake, PersonStatisticKeys.HasPostalCode, CorrelationFactory, (p, aa) => p.Addresses != null && p.Addresses.Any(a => a.CurrentAddress && !string.IsNullOrEmpty(a.PostalCode)) ? 1 : 0);

            DateWorkPermit             = new DateStatistics(numberOfSamplesToTake, PersonStatisticKeys.DateWorkPermit, CorrelationFactory, (p, a) => new Tuple <string, DateTime?, DateTime?>(p.WorkPermit, p.DateWorkPermit, p.DateOfBirth));
            DateParentalResponsibility = new DateStatistics(numberOfSamplesToTake, PersonStatisticKeys.DateParentalResponsibility, CorrelationFactory, (p, a) => new Tuple <string, DateTime?, DateTime?>(p.ParentalResponsibility?.ToString(), p.DateParentalResponsibility, p.DateOfBirth));
            DateWithoutLegalCapacity   = new DateStatistics(numberOfSamplesToTake, PersonStatisticKeys.DateWithoutLegalCapacity, CorrelationFactory, (p, a) => new Tuple <string, DateTime?, DateTime?>(p.WithoutLegalCapacity, p.DateWithoutLegalCapacity, p.DateOfBirth));
            DateCustody     = new DateStatistics(numberOfSamplesToTake, PersonStatisticKeys.DateCustody, CorrelationFactory, (p, a) => new Tuple <string, DateTime?, DateTime?>(p.Custody, p.DateCustody, p.DateOfBirth));
            DateCitizenship = new DateStatistics(numberOfSamplesToTake, PersonStatisticKeys.DateCitizenship, CorrelationFactory, (p, a) => new Tuple <string, DateTime?, DateTime?>(p.Citizenship, p.DateCitizenship, p.DateOfBirth));

            AddEntitiesToBaseDictionary <BooleanStatistic>();
            AddEntitiesToBaseDictionary <DiscreteStringStatistics>();
            AddEntitiesToBaseDictionary <DiscreteStatistic>();
            AddEntitiesToBaseDictionary <DateStatistics>();

            Statistics.Add(Age.Name, Age);
        }