Beispiel #1
0
 public void Reset()
 {
     _numberOfChildren     = new DiscreteStringStatistics(100000, "NumberOfChildren", null);
     SpouseSearchNonDuplex = new Dictionary <string, List <RelationshipSearch> >();
     SpouseSearchDuplex    = new Dictionary <string, List <RelationshipSearch> >();
     ParentSearch          = new Stack <ParentRelationshipSearch>();
 }
        public static string Sample(string key, Dictionary <string, bool> values, DiscreteStringStatistics stats, Randomizer randy)
        {
            if (!values.ContainsKey(key))
            {
                return(stats.Sample(randy));
            }

            var hasValue = values[key];

            if (!hasValue)
            {
                return(null);
            }

            return(stats.NonNullSample(randy));
        }
        public void RegisterNumberofChildrenToMarried(DiscreteStringStatistics childrenCount)
        {
            foreach (var parentKey in childrenCount.Stats.Keys)
            {
                var numberOfChildrenToDistribute = childrenCount.Stats[parentKey].Count;
                var couplesInThisGroup           = CoupleCache.ContainsKey(parentKey) ? CoupleCache[parentKey] : null;
                if (couplesInThisGroup == null || numberOfChildrenToDistribute == 0)
                {
                    continue;
                }

                var buckets = DistributeToBuckets(couplesInThisGroup.Count, numberOfChildrenToDistribute);

                var index = 0;
                foreach (var couple in couplesInThisGroup)
                {
                    var value = buckets[index++];
                    couple.RemainingNumberOfChildren = value >= 0 ? value : 0;
                }
            }
        }
        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);
        }