Example #1
0
        public async Task <bool> BuildCorrelationMatrix(SynteticModel model, string sessionId)
        {
            SessionId = sessionId;

            model.Statistics.Correlations = new CorrelationMatrix(model.Statistics.CorrelationFactory.CorrelationFactoryElements.Count, model.Statistics.CorrelationFactory.CorrelationFactoryElements.Values.Select(x => x.Key).ToArray());

            int c = 0;

            Console.WriteLine("Staring import");
            while (_dataProvider.HasMore())
            {
                var p = await _dataProvider.GetNextPerson();

                if (p == null)
                {
                    continue;
                }

                bool birthdayWasFoundFromNin;
                var  ageQuant = PersonStatistics.CalculateAgeQuant(p, _ageQuants, out birthdayWasFoundFromNin);
                if (ageQuant == PersonStatistics.InvalidQuant)
                {
                    continue;
                }

                model.Statistics.Correlations.Update(p, ageQuant, model.Statistics.Statistics);

                if (c++ % 10000 == 0)
                {
                    Console.WriteLine("Done calculating correlations for " + c);
                }
            }

            model.Statistics.Correlations.Closure(model.Statistics.CorrelationFactory);

            return(true);
        }
        public async Task <int> ImportStaticData(HashSet <string> staticNinList, IPregDataProvider staticdataSource, IPushPregData targetPusher)
        {
            var person = await staticdataSource.GetNextPerson();

            while (staticdataSource.HasMore())
            {
                if (staticNinList.Contains(person.NIN))
                {
                    if (person.NewNIN == "")
                    {
                        person.NewNIN = null;
                    }

                    if (person.OldNIN == "")
                    {
                        person.OldNIN = null;
                    }

                    targetPusher.AddToSaveQueue(new List <Person> {
                        person
                    });
                    var wasAdded = IdControl.TakenAdd(person.NIN);
                    if (!wasAdded)
                    {
                        throw new Exception("TakenAdd feilet. dette skal ikke skje siden input liste er kun unike. Sjekk at database var tom initielt");
                    }

                    staticNinList.Remove(person.NIN);
                }

                person = await staticdataSource.GetNextPerson();
            }

            Outputter.WriteLine("Done importing static data. Number of object not found in source was " + staticNinList.Count + ". Items are put on save queue. Length:" + targetPusher.QueueLength());

            return(staticNinList.Count);
        }