Example #1
0
        private String GetGermanWikiDataDescription()
        {
            String expandText = String.Empty;

            switch (this.type)
            {
            case EntityType.Changwat:
                return("Provinz in Thailand");

            case EntityType.Khet:
                return("Bezirk von Bangkok, Thailand");

            case EntityType.Khwaeng:
                expandText = "Unterbezirk von {0}, Bangkok, Thailand";
                break;

            case EntityType.Amphoe:
            case EntityType.KingAmphoe:
                expandText = "Landkreis in der Provinz {0}, Thailand";
                break;

            case EntityType.Tambon:
                expandText = "Kommune im Landkreis {0}, Provinz {1}, Thailand";
                break;

            case EntityType.Muban:
                expandText = "Dorf in Kommune {0}, Landkreis {1}, Provinz {2}, Thailand";
                break;

            case EntityType.TAO:
            case EntityType.Thesaban:
            case EntityType.ThesabanTambon:
            case EntityType.ThesabanMueang:
            case EntityType.ThesabanNakhon:
                expandText = this.type.Translate(Language.German) + " im Landkreis {0}, Provinz {1}, Thailand";
                break;
            }
            var allEntities    = GlobalData.CompleteGeocodeList().FlatList();
            var parents        = new String[3];
            var currentGeocode = geocode;

            if (this.parent.Any())
            {
                currentGeocode = this.parent.First() * 100;
            }
            var index = 0;

            while (currentGeocode / 100 != 0)
            {
                currentGeocode = currentGeocode / 100;
                var parentEntity = allEntities.First(x => x.geocode == currentGeocode);
                parents[index] = parentEntity.english;
                index++;
            }
            for (Int32 i = index; i < 3; i++)
            {
                parents[i] = String.Empty;
            }
            return(String.Format(expandText, parents));
        }
        /// <summary>
        /// Initializes the data for the view.
        /// </summary>
        private void InitializeData()
        {
            _country = GlobalData.CompleteGeocodeList();
            _country.PropagateObsoleteToSubEntities();
            _allEntities      = _country.FlatList().Where(x => !x.IsObsolete).Where(x => x.type != EntityType.Muban && x.type != EntityType.Chumchon).ToList();
            _localGovernments = new List <Entity>();
            var allLocalGovernmentParents = _allEntities.Where(x => x.type == EntityType.Tambon || x.type == EntityType.Changwat).ToList();

            _localGovernments.AddRange(_allEntities.Where(x => x.type.IsLocalGovernment()));

            foreach (var tambon in allLocalGovernmentParents)
            {
                var localGovernmentEntity = tambon.CreateLocalGovernmentDummyEntity();
                if (localGovernmentEntity != null && !localGovernmentEntity.IsObsolete)
                {
                    _localGovernments.Add(localGovernmentEntity);
                    _allEntities.Add(localGovernmentEntity);
                }
            }

            var allTambon = _allEntities.Where(x => x.type == EntityType.Tambon).ToList();

            GlobalData.LoadPopulationData(PopulationDataSource, PopulationReferenceYear);
            Entity.CalculateLocalGovernmentPopulation(_localGovernments, allTambon, PopulationDataSource, PopulationReferenceYear);
        }
Example #3
0
 private void SetShareBorderWith(IEnumerable <Entity> entities, StringBuilder collisionInfo, Boolean overrideData)
 {
     if (entities == null)
     {
         throw new ArgumentNullException("entities");
     }
     ClearRunInfo();
     foreach (var entity in entities.Where(x => !x.IsObsolete && x.area.bounding.Any()))
     {
         var item = _helper.GetWikiDataItemForEntity(entity);
         if (item == null)
         {
             _runInfo[WikiDataState.ItemNotFound]++;
             collisionInfo.AppendFormat("{0}: {1} was deleted!", entity.wiki.wikidata, entity.english);
         }
         else
         {
             var allEntities = GlobalData.CompleteGeocodeList().FlatList();
             foreach (var bounding in entity.area.bounding.Where(x => x.type == BoundaryType.land))
             {
                 var boundingEntity = allEntities.FirstOrDefault(x => x.geocode == bounding.geocode);
                 if ((boundingEntity != null) && (!String.IsNullOrEmpty(boundingEntity.wiki.wikidata)))
                 {
                     var state = _helper.BoundingEntityCorrect(item, entity, boundingEntity);
                     _runInfo[state]++;
                     if (state == WikiDataState.Incomplete)
                     {
                         var statement = _helper.SetBoundingEntity(item, entity, boundingEntity);
                         if (statement != null)
                         {
                             statement.save(_helper.GetClaimSaveEditSummary(statement));
                         }
                     }
                 }
             }
         }
     }
 }
        /// <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();
            }
        }
Example #5
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());
 }
Example #6
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));
        }
Example #7
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();
                    }
                }
            }
        }
Example #8
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();
                    }
                }
            }
        }