Exemple #1
0
        public static void LoadPopulationData(PopulationDataSourceType source, Int16 year)
        {
            var populationData = LoadPopulationDataUnprocessed(source, year);

            if (populationData != null)
            {
                MergePopulationData(populationData);
            }

            var geocodeToRecalculate = new List <UInt32>();
            var allEntities          = GlobalData.CompleteGeocodeList().FlatList();

            foreach (var item in allEntities.Where(x =>
                                                   x.newgeocode.Any() &&
                                                   x.population.Any(y => y.Year == year && y.source == source)).ToList())
            {
                foreach (var newGeocode in item.newgeocode)
                {
                    var newItem = allEntities.FirstOrDefault(x => x.geocode == newGeocode);
                    if (newItem != null)
                    {
                        if (!newItem.IsObsolete)
                        {
                            newItem.population.Add(item.population.First(y => y.Year == year && y.source == source));
                            geocodeToRecalculate.AddRange(GeocodeHelper.ParentGeocodes(newItem.geocode));
                        }
                    }
                }
                geocodeToRecalculate.AddRange(GeocodeHelper.ParentGeocodes(item.geocode));
            }
            if (source == PopulationDataSourceType.Census)
            {
                // For DOPA need to be done with CalculateLocalGovernmentPopulation
                Entity.FillExplicitLocalGovernmentPopulation(allEntities.Where(x => x.type.IsLocalGovernment()).ToList(), allEntities, source, year);
            }

            foreach (var recalculate in geocodeToRecalculate.Distinct())
            {
                var entityToRecalculate = allEntities.FirstOrDefault(x => x.geocode == recalculate);
                if (entityToRecalculate != null)
                {
                    var data = entityToRecalculate.population.FirstOrDefault(y => y.Year == year && y.source == source);
                    if (data != null)
                    {
                        data.data.Clear();
                        foreach (var subentity in entityToRecalculate.entity.Where(x => !x.IsObsolete))
                        {
                            var subData = subentity.population.FirstOrDefault(y => y.Year == year && y.source == source);
                            if (subData != null)
                            {
                                foreach (var subDataPoint in subData.data)
                                {
                                    data.AddDataPoint(subDataPoint);
                                }
                            }
                        }
                        data.CalculateTotal();
                    }
                }
            }
        }
Exemple #2
0
        public static void LoadPopulationData(PopulationDataSourceType source, Int16 year)
        {
            if (!GlobalData.CountryEntity.population.Any(x => x.Year == year && x.source == source))
            {
                String filename = String.Empty;
                switch (source)
                {
                case PopulationDataSourceType.Census:
                    filename = BaseXMLDirectory + "\\population\\census{0}.xml";
                    break;

                case PopulationDataSourceType.DOPA:
                    filename = BaseXMLDirectory + "\\population\\DOPA{0}.xml";
                    break;
                }
                filename = String.Format(CultureInfo.InvariantCulture, filename, year);
                if (!string.IsNullOrWhiteSpace(filename))
                {
                    LoadPopulationData(filename);
                }
            }

            var geocodeToRecalculate = new List <UInt32>();
            var allEntities          = GlobalData.CompleteGeocodeList().FlatList();

            foreach (var item in allEntities.Where(x =>
                                                   x.newgeocode.Any() &&
                                                   x.population.Any(y => y.Year == year && y.source == source)).ToList())
            {
                foreach (var newGeocode in item.newgeocode)
                {
                    var newItem = allEntities.FirstOrDefault(x => x.geocode == newGeocode);
                    if (newItem != null)
                    {
                        if (!newItem.IsObsolete)
                        {
                            newItem.population.Add(item.population.First(y => y.Year == year && y.source == source));
                            geocodeToRecalculate.AddRange(GeocodeHelper.ParentGeocodes(newItem.geocode));
                        }
                    }
                }
                geocodeToRecalculate.AddRange(GeocodeHelper.ParentGeocodes(item.geocode));
            }
            foreach (var recalculate in geocodeToRecalculate.Distinct())
            {
                var entityToRecalculate = allEntities.FirstOrDefault(x => x.geocode == recalculate);
                if (entityToRecalculate != null)
                {
                    var data = entityToRecalculate.population.FirstOrDefault(y => y.Year == year && y.source == source);
                    if (data != null)
                    {
                        data.data.Clear();
                        foreach (var subentity in entityToRecalculate.entity.Where(x => !x.IsObsolete))
                        {
                            var subData = subentity.population.FirstOrDefault(y => y.Year == year && y.source == source);
                            if (subData != null)
                            {
                                foreach (var subDataPoint in subData.data)
                                {
                                    data.AddDataPoint(subDataPoint);
                                }
                            }
                        }
                        data.CalculateTotal();
                    }
                }
            }
        }