/// <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);
        }
Beispiel #2
0
        private void SetPopulationData(IEnumerable <Entity> entities, StringBuilder collisionInfo, Boolean overrideData, PopulationDataSourceType dataSource, Int16 year)
        {
            if (entities == null)
            {
                throw new ArgumentNullException("entities");
            }
            ClearRunInfo();
            GlobalData.LoadPopulationData(dataSource, year);
            foreach (var entity in entities.Where(x => x.population.Any(y => y.source == dataSource && y.Year == year)))
            {
                var item = _helper.GetWikiDataItemForEntity(entity);
                if (item == null)
                {
                    _runInfo[WikiDataState.ItemNotFound]++;
                    collisionInfo.AppendFormat("{0}: {1} was deleted!", entity.wiki.wikidata, entity.english);
                }
                else
                {
                    var data = entity.population.First(y => y.source == dataSource && y.Year == year);

                    var state = _helper.PopulationDataCorrect(item, data);
                    _runInfo[state]++;
                    if (state != WikiDataState.Valid)
                    {
                        var statement = _helper.SetPopulationData(item, data, overrideData);
                        if (statement != null)
                        {
                            statement.save(_helper.GetClaimSaveEditSummary(statement));
                            _helper.AddPopulationDataReferences(statement, data, entity);
                            foreach (var reference in statement.References)
                            {
                                reference.Save(_helper.GetReferenceSaveEditSummary(reference));
                            }

                            _helper.AddPopulationDataQualifiers(statement, data);
                            foreach (var qualifier in statement.Qualifiers)
                            {
                                qualifier.Save(_helper.GetQualifierSaveEditSummary(qualifier));
                            }
                        }
                    }
                }
            }
        }
        /// <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();
            }
        }