private void FixupWronglyPlacedAmphoe() { var invalidTambon = new List <Entity>(); foreach (var amphoe in Data.entity.Where(x => x.type.IsCompatibleEntityType(EntityType.Amphoe))) { foreach (var tambon in amphoe.entity.Where(x => !GeocodeHelper.IsBaseGeocode(amphoe.geocode, x.geocode)).ToList()) { invalidTambon.Add(tambon); amphoe.entity.Remove(tambon); } } foreach (var tambon in invalidTambon) { var mainTambon = Data.FlatList().FirstOrDefault(x => GeocodeHelper.IsSameGeocode(x.geocode, tambon.geocode, false)); if (mainTambon != null) { foreach (var dataPoint in tambon.population.First().data) { mainTambon.population.First().AddDataPoint(dataPoint); } } } var emptyAmphoe = Data.entity.Where(x => x.type.IsCompatibleEntityType(EntityType.Amphoe) && !x.entity.Any()).ToList(); foreach (var toRemove in emptyAmphoe) { Data.entity.Remove(toRemove); } }
/// <summary> /// Checks if this instance is about the entity identified by the <paramref name="geocode"/>. /// If <paramref name="includeSubEntities"/> is <c>true</c>, /// </summary> /// <param name="geocode">Geocode to check.</param> /// <param name="includeSubEntities">Toggles whether codes under <paramref name="geocode"/> are considered fitting as well.</param> /// <returns><c>true</c> if instance is about the code, <c>false</c> otherwise.</returns> public Boolean IsAboutGeocode(UInt32 geocode, Boolean includeSubEntities) { Boolean result = false; if (geocodeSpecified) { result = result | GeocodeHelper.IsSameGeocode(geocode, this.geocode, includeSubEntities); } if (ownerFieldSpecified) { result = result | GeocodeHelper.IsSameGeocode(geocode, this.owner, includeSubEntities); } if (tambonFieldSpecified) { result = result | GeocodeHelper.IsSameGeocode(geocode, this.tambon, includeSubEntities); } foreach (var entry in Items) { var toTest = entry as IGeocode; if (toTest != null) { result = result | toTest.IsAboutGeocode(geocode, includeSubEntities); } } return(result); }
internal void AddTambonInThesabanToAmphoe(Entity tambon, Entity thesaban) { var allSubEntities = entity.SelectMany(x => x.entity).ToList(); var mainTambon = allSubEntities.SingleOrDefault(x => (GeocodeHelper.IsSameGeocode(x.geocode, tambon.geocode, false)) & (x.type == tambon.type)); var mainAmphoe = entity.FirstOrDefault(x => (x.geocode == tambon.geocode / 100)); if (mainTambon == null) { if (mainAmphoe != null) { mainTambon = XmlManager.MakeClone <Entity>(tambon); mainAmphoe.entity.Add(mainTambon); } } else { if (mainTambon.population.Any()) { mainTambon.population.First().data.AddRange(tambon.population.First().data); } else { mainTambon.population.Add(tambon.population.First()); } } if (mainAmphoe != null) { var population = tambon.population.First(); foreach (var dataPoint in population.data) { var amphoePopulation = mainAmphoe.population.FirstOrDefault(); if (amphoePopulation == null) { amphoePopulation = new PopulationData(); amphoePopulation.referencedate = population.referencedate; amphoePopulation.referencedateSpecified = population.referencedateSpecified; amphoePopulation.source = population.source; amphoePopulation.year = population.year; mainAmphoe.population.Add(amphoePopulation); } amphoePopulation.AddDataPoint(dataPoint); } } }
/// <summary> /// Synchronizes the calculated data with the global geocode list. /// </summary> private void GetGeocodes() { if (Data != null) { var geocodes = GlobalData.GetGeocodeList(Data.geocode); // _invalidGeocodes = geocodes.InvalidGeocodeEntries(); foreach (var amphoe in geocodes.entity.Where(x => x.type.IsCompatibleEntityType(EntityType.Amphoe))) { if (!Data.entity.Any(x => GeocodeHelper.IsSameGeocode(x.geocode, amphoe.geocode, false))) { // make sure all Amphoe will be in the result list, in case of a Amphoe which has only Thesaban it will be missing in the DOPA data var newAmphoe = new Entity(); newAmphoe.population.Add(CreateEmptyPopulationEntry()); newAmphoe.CopyBasicDataFrom(amphoe); Data.entity.Add(newAmphoe); } } Data.SynchronizeGeocodes(geocodes); } }
internal void SynchronizeGeocodes(Entity geocodeSource) { var missedEntities = new List <Entity>(); if (geocodeSource != null) { var sourceFlat = geocodeSource.FlatList(); foreach (var entity in this.FlatList()) { var source = sourceFlat.FirstOrDefault(x => GeocodeHelper.IsSameGeocode(x.geocode, entity.geocode, false)); if (source == null) { missedEntities.Add(entity); } else { entity.CopyBasicDataFrom(source); } } } }