/// <summary>
        /// Handles the change of the year with which the data shall be compared.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event arguments.</param>
        private void edtCompareYear_ValueChanged(Object sender, EventArgs e)
        {
            Int16 newYear = Convert.ToInt16(edtCompareYear.Value);

            if (chkCompare.Checked)
            {
                if (!_country.population.Any(x => x.source == PopulationDataSource && x.Year == newYear))
                {
                    GlobalData.LoadPopulationData(PopulationDataSource, newYear);
                    // GlobalData.CompleteGeocodeList creates a clone, thus need to use the new instances to get the new population data

                    _country = GlobalData.CompleteGeocodeList();
                    _country.PropagateObsoleteToSubEntities();
                    _allEntities = _country.FlatList().Where(x => !x.IsObsolete).Where(x => x.type != EntityType.Muban && x.type != EntityType.Chumchon).ToList();

                    // re-calculate the local government populations
                    var allTambon = _allEntities.Where(x => x.type == EntityType.Tambon).ToList();
                    Entity.CalculateLocalGovernmentPopulation(_localGovernments, allTambon, PopulationDataSource, Convert.ToInt16(edtCompareYear.Value));

                    UpdateBaseEntity();  // need to get _baseEntity
                }
                UpdateList();
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Fills <see cref="OldGeocodes"/> for this entity and all its subentities.
 /// </summary>
 public void CalcOldGeocodesRecursive()
 {
     CalcOldGeocodesRecursive(GlobalData.CompleteGeocodeList().FlatList().Where(x => x.newgeocode.Any()).ToList());
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the description ready to be set to WikiData.
        /// </summary>
        /// <param name="language">Language.</param>
        /// <returns>Description of the entity.</returns>
        public String GetWikiDataDescription(Language language)
        {
            if (language == Language.German)
            {
                // the hierachical expansion does not sound good in German
                return(GetGermanWikiDataDescription());
            }

            var allEntities      = GlobalData.CompleteGeocodeList().FlatList();
            var typeValue        = this.type.Translate(language);
            var expanded         = String.Empty; // 0 = type, 1 = hierarchy
            var expandedTopLevel = String.Empty; // 0 = type
            var hierarchy        = String.Empty;
            var hierarchyExpand  = String.Empty; // 0 = name, 1 = type

            switch (language)
            {
            case Language.English:
                expanded         = "{0} in {1}Thailand";
                expandedTopLevel = "{0} of Thailand";
                hierarchyExpand  = "{0} {1}, ";
                break;

            case Language.German:
                expanded         = "{0} in {1}Thailand";
                expandedTopLevel = "{0} in Thailand";
                hierarchyExpand  = "{1} {0}, ";
                break;

            case Language.Thai:
                expanded         = "{0}ใน{1}ประเทศไทย";
                expandedTopLevel = "{0}ในประเทศไทย";
                hierarchyExpand  = "{1}{0} ";
                break;
            }
            var currentGeocode = geocode;

            if (this.parent.Any())
            {
                currentGeocode = this.parent.First() * 100;
            }
            while (currentGeocode / 100 != 0)
            {
                currentGeocode = currentGeocode / 100;
                var parentEntity = allEntities.First(x => x.geocode == currentGeocode);
                var parentType   = parentEntity.type.Translate(language);
                if (language == Language.Thai)
                {
                    hierarchy += String.Format(hierarchyExpand, parentEntity.name, parentType);
                }
                else if (parentEntity.type == EntityType.Bangkok)
                {
                    hierarchy += String.Format(hierarchyExpand, String.Empty, "Bangkok").TrimStart();
                }
                else
                {
                    hierarchy += String.Format(hierarchyExpand, parentEntity.english, parentType);
                }
            }
            return(String.Format(expanded, typeValue, hierarchy));
        }
Ejemplo n.º 4
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();
                    }
                }
            }
        }
Ejemplo n.º 5
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();
                    }
                }
            }
        }