Exemplo n.º 1
0
        public Dictionary <PopulationDataEntry, PopulationDataEntry> DifferentMubanNames(PopulationDataEntry changwat)
        {
            var RetVal = new Dictionary <PopulationDataEntry, PopulationDataEntry>();

            PopulationData      geocodes        = TambonHelper.GetGeocodeList(changwat.Geocode);
            PopulationDataEntry currentChangwat = geocodes.Data;

            foreach (PopulationDataEntry currentAmphoe in currentChangwat.SubEntities)
            {
                foreach (PopulationDataEntry currentTambon in currentAmphoe.SubEntities)
                {
                    foreach (PopulationDataEntry currentMuban in currentTambon.SubEntities)
                    {
                        if (currentMuban.Type == EntityType.Muban)
                        {
                            PopulationDataEntry mubanDopa = changwat.FindByCode(currentMuban.Geocode);
                            if (mubanDopa != null)
                            {
                                if (!TambonHelper.IsSameMubanName(mubanDopa.Name, currentMuban.Name))
                                {
                                    RetVal.Add(currentMuban, mubanDopa);
                                }
                            }
                        }
                    }
                }
            }
            return(RetVal);
        }
Exemplo n.º 2
0
        public List <PopulationDataEntry> ThesabanWithoutConstituencies()
        {
            List <PopulationDataEntry> lResult = new List <PopulationDataEntry>();

            PopulationData lGeocodes = TambonHelper.GetGeocodeList(mGeocode);

            lGeocodes.ReOrderThesaban();
            foreach (PopulationDataEntry lEntry in lGeocodes.Thesaban)
            {
                if (EntityTypeHelper.Thesaban.Contains(lEntry.Type) & (!lEntry.Obsolete))
                {
                    Boolean lSuccess = HasConstituencyAnnouncement(lEntry.Geocode, lEntry.Type);

                    if ((!lSuccess) & (lEntry.GeocodeOfCorrespondingTambon != 0))
                    {
                        lSuccess = HasConstituencyAnnouncement(lEntry.GeocodeOfCorrespondingTambon, lEntry.Type);
                    }
                    if (!lSuccess)
                    {
                        lResult.Add(lEntry);
                    }
                }
            }
            return(lResult);
        }
Exemplo n.º 3
0
        public Dictionary <String, EntityLeader> NewGovernorsList()
        {
            Dictionary <String, EntityLeader> RetVal        = new Dictionary <String, EntityLeader>();
            List <PopulationDataEntry>        lFoundEntries = new List <PopulationDataEntry>();

            foreach (PopulationDataEntry lEntry in mData)
            {
                lEntry.Geocode = TambonHelper.GetGeocode(lEntry.Name);
                PopulationData lData = TambonHelper.GetGeocodeList(lEntry.Geocode);
                lEntry.English = lData.Data.English;
                foreach (EntityOffice lOffice in lEntry.Offices)
                {
                    foreach (EntityLeader lLeader in lOffice.OfficialsList)
                    {
                        if (lLeader.Position == EntityLeaderType.Governor)
                        {
                            if (lData.Data.LeaderAlreadyInList(lLeader))
                            {
                                lFoundEntries.Add(lEntry);
                            }
                            else
                            {
                                RetVal.Add(lEntry.English, lLeader);
                            }
                        }
                    }
                }
            }
            foreach (PopulationDataEntry lEntry in lFoundEntries)
            {
                mData.Remove(lEntry);
            }
            return(RetVal);
        }
Exemplo n.º 4
0
 public void RemoveAllKnownGeocodes()
 {
     foreach (var lEntry in TambonHelper.ProvinceGeocodes)
     {
         PopulationData lCurrentList = TambonHelper.GetGeocodeList(lEntry.Geocode);
         RemoveKnownGeocodes(lCurrentList.Data);
     }
 }
Exemplo n.º 5
0
 protected void GetGeocodes()
 {
     if (_changwat != null)
     {
         PopulationData geocodes = TambonHelper.GetGeocodeList(_changwat.Geocode);
         _invalidGeocodes = geocodes.Data.InvalidGeocodeEntries();
         Data.GetCodes(geocodes.Data);
     }
 }
Exemplo n.º 6
0
        private List <PopulationDataEntry> LoadGeocodeLists()
        {
            var lList = new List <PopulationDataEntry>();

            foreach (PopulationDataEntry lEntry in TambonHelper.ProvinceGeocodes)
            {
                if (TambonHelper.IsBaseGeocode(BaseGeocode, lEntry.Geocode))
                {
                    PopulationData lEntities = TambonHelper.GetGeocodeList(lEntry.Geocode);
                    lList.AddRange(lEntities.Data.FlatList(mEntityTypes));
                }
            }
            return(lList);
        }
Exemplo n.º 7
0
        private void btnCheckNames_Click(object sender, EventArgs e)
        {
            PopulationDataEntry         masterDataEntry = new PopulationDataEntry();
            Dictionary <String, String> romanizations   = new Dictionary <String, String>();
            var romanizationMistakes    = new List <Tuple <Int32, String, String, String> >();
            var romanizationSuggestions = new List <Tuple <Int32, String, String> >();
            var romanizationMissing     = new List <Tuple <Int32, String> >();

            var provinceList = new List <PopulationDataEntry>();

            foreach (PopulationDataEntry province in TambonHelper.ProvinceGeocodes)
            {
                PopulationData entities = TambonHelper.GetGeocodeList(province.Geocode);
                provinceList.Add(entities.Data);
            }
            masterDataEntry.SubEntities.AddRange(provinceList);
            foreach (var entityToCheck in masterDataEntry.FlatList(EntityTypeHelper.AllEntityTypes))
            {
                if (!String.IsNullOrEmpty(entityToCheck.English))
                {
                    String name    = entityToCheck.Name;
                    String english = entityToCheck.English;
                    if ((entityToCheck.Type == EntityType.Muban) | (entityToCheck.Type == EntityType.Chumchon))
                    {
                        name = TambonHelper.StripBanOrChumchon(name);

                        if (english.StartsWith("Ban "))
                        {
                            english = english.Remove(0, "Ban ".Length).Trim();
                        }
                        if (english.StartsWith("Chumchon "))
                        {
                            english = english.Remove(0, "Chumchon ".Length).Trim();
                        }

                        if (entityToCheck.Type == EntityType.Chumchon)
                        {
                            // Chumchon may have the name "Chumchon Ban ..."
                            name = TambonHelper.StripBanOrChumchon(name);

                            if (english.StartsWith("Ban "))
                            {
                                english = english.Remove(0, "Ban ".Length).Trim();
                            }
                        }
                    }
                    if (romanizations.Keys.Contains(name))
                    {
                        if (romanizations[name] != english)
                        {
                            romanizationMistakes.Add(Tuple.Create(entityToCheck.Geocode, name, english, romanizations[name]));
                        }
                    }
                    else
                    {
                        romanizations[name] = english;
                    }
                }
            }

            foreach (var entityToCheck in masterDataEntry.FlatList(EntityTypeHelper.AllEntityTypes))
            {
                if (String.IsNullOrEmpty(entityToCheck.English))
                {
                    String foundEnglishName = String.Empty;
                    if (romanizations.Keys.Contains(entityToCheck.Name))
                    {
                        foundEnglishName = entityToCheck.Name;
                    }
                    else
                    {
                        var searchName = TambonHelper.StripBanOrChumchon(entityToCheck.Name);

                        if (romanizations.Keys.Contains(searchName))
                        {
                            foundEnglishName = searchName;
                        }
                        else
                        {
                            // Chumchon may have the name "Chumchon Ban ..."
                            searchName = TambonHelper.StripBanOrChumchon(searchName);
                            if (romanizations.Keys.Contains(searchName))
                            {
                                foundEnglishName = searchName;
                            }
                        }
                    }

                    if (!String.IsNullOrEmpty(foundEnglishName))
                    {
                        romanizationSuggestions.Add(Tuple.Create(entityToCheck.Geocode, entityToCheck.Name, romanizations[foundEnglishName]));
                    }
                    else
                    {
                        Boolean found = false;
                        String  name  = TambonHelper.StripBanOrChumchon(entityToCheck.Name);
                        name = TambonHelper.ReplaceThaiNumerals(name);
                        List <Char> numerals = new List <Char>()
                        {
                            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
                        };
                        foreach (Char c in numerals)
                        {
                            name = name.Replace(c, ' ');
                        }
                        name = name.Trim();
                        foreach (var keyValuePair in TambonHelper.NameSuffixRomanizations)
                        {
                            if (entityToCheck.Name.EndsWith(keyValuePair.Key))
                            {
                                String searchString = TambonHelper.StripBanOrChumchon(name.Substring(0, name.Length - keyValuePair.Key.Length));
                                if (String.IsNullOrEmpty(searchString))
                                {
                                    romanizationSuggestions.Add(Tuple.Create(entityToCheck.Geocode, entityToCheck.Name, keyValuePair.Value));
                                    found = true;
                                }
                                else if (romanizations.Keys.Contains(searchString))
                                {
                                    romanizationSuggestions.Add(Tuple.Create(entityToCheck.Geocode, entityToCheck.Name, romanizations[searchString] + " " + keyValuePair.Value));
                                    found = true;
                                }
                            }
                        }
                        if (!found)
                        {
                            var prefixes = TambonHelper.NamePrefixRomanizations.Union(TambonHelper.NameSuffixRomanizations);
                            foreach (var keyValuePair in prefixes)
                            {
                                if (name.StartsWith(keyValuePair.Key))
                                {
                                    String searchString = name.Substring(keyValuePair.Key.Length);
                                    if (String.IsNullOrEmpty(searchString))
                                    {
                                        romanizationSuggestions.Add(Tuple.Create(entityToCheck.Geocode, entityToCheck.Name, keyValuePair.Value));
                                        found = true;
                                    }
                                    else if (romanizations.Keys.Contains(searchString))
                                    {
                                        romanizationSuggestions.Add(Tuple.Create(entityToCheck.Geocode, entityToCheck.Name, keyValuePair.Value + " " + romanizations[searchString]));
                                        found = true;
                                    }
                                }
                            }
                        }
                        if (!found)
                        {
                            romanizationMissing.Add(Tuple.Create(entityToCheck.Geocode, entityToCheck.Name));
                        }
                    }
                }
            }

            Int32 provinceFilter = 0;

            if (cbxCheckNamesFiltered.Checked)
            {
                provinceFilter = GetCurrentChangwat().Geocode;
            }

            StringBuilder romanizationMistakesBuilder = new StringBuilder();
            Int32         romanizationMistakeCount    = 0;

            foreach (var entry in romanizationMistakes)
            {
                if (TambonHelper.IsBaseGeocode(provinceFilter, entry.Item1))
                {
                    romanizationMistakesBuilder.AppendLine(String.Format("{0} {1}: {2} vs. {3}", entry.Item1, entry.Item2, entry.Item3, entry.Item4));
                    romanizationMistakeCount++;
                }
            }

            if (romanizationMistakeCount > 0)
            {
                var lForm = new StringDisplayForm("Romanization problems (" + romanizationMistakeCount.ToString() + ")", romanizationMistakesBuilder.ToString());
                lForm.Show();
            }

            StringBuilder romanizationSuggestionBuilder = new StringBuilder();
            Int32         romanizationSuggestionCount   = 0;

            foreach (var entry in romanizationSuggestions)
            {
                if (TambonHelper.IsBaseGeocode(provinceFilter, entry.Item1))
                {
                    romanizationSuggestionBuilder.AppendLine(String.Format("{0} {1}: {2}", entry.Item1, entry.Item2, entry.Item3));
                    romanizationSuggestionCount++;
                }
            }
            if (romanizationSuggestionCount > 0)
            {
                var lForm = new StringDisplayForm("Romanization suggestions (" + romanizationSuggestionCount.ToString() + ")", romanizationSuggestionBuilder.ToString());
                lForm.Show();

                List <Tuple <String, String, Int32> > counter = new List <Tuple <String, String, Int32> >();
                foreach (var entry in romanizationSuggestions)
                {
                    var found = counter.FirstOrDefault(x => x.Item1 == entry.Item2);
                    if (found == null)
                    {
                        counter.Add(Tuple.Create(entry.Item2, entry.Item3, 1));
                    }
                    else
                    {
                        counter.Remove(found);
                        counter.Add(Tuple.Create(entry.Item2, entry.Item3, found.Item3 + 1));
                    }
                }
                counter.RemoveAll(x => x.Item3 < 2);
                if (counter.Any())
                {
                    counter.Sort(delegate(Tuple <String, String, Int32> p1, Tuple <String, String, Int32> p2)
                    {
                        return(p2.Item3.CompareTo(p1.Item3));
                    });

                    Int32         suggestionCounter = 0;
                    StringBuilder sortedBuilder     = new StringBuilder();
                    foreach (var entry in counter)
                    {
                        sortedBuilder.AppendLine(String.Format("{0}: {1} ({2})", entry.Item1, entry.Item2, entry.Item3));
                        suggestionCounter += entry.Item3;
                    }
                    var lForm2 = new StringDisplayForm(
                        String.Format("Romanization suggestions ({0} of {1})", suggestionCounter, romanizationSuggestionCount),
                        sortedBuilder.ToString());
                    lForm2.Show();
                }
            }

            if (romanizationMissing.Any())
            {
                List <Tuple <String, Int32> > counter = new List <Tuple <String, Int32> >();
                foreach (var entry in romanizationMissing)
                {
                    var found = counter.FirstOrDefault(x => x.Item1 == entry.Item2);
                    if (found == null)
                    {
                        counter.Add(Tuple.Create(entry.Item2, 1));
                    }
                    else
                    {
                        counter.Remove(found);
                        counter.Add(Tuple.Create(entry.Item2, found.Item2 + 1));
                    }
                }
                // counter.RemoveAll(x => x.Item2 < 2);
                if (counter.Any())
                {
                    counter.Sort(delegate(Tuple <String, Int32> p1, Tuple <String, Int32> p2)
                    {
                        var result = p2.Item2.CompareTo(p1.Item2);
                        if (result == 0)
                        {
                            result = p2.Item1.CompareTo(p1.Item1);
                        }
                        return(result);
                    });

                    Int32         missingCounter = 0;
                    StringBuilder sortedBuilder  = new StringBuilder();
                    foreach (var entry in counter)
                    {
                        sortedBuilder.AppendLine(String.Format("{0}: {1}", entry.Item1, entry.Item2));
                        missingCounter += entry.Item2;
                    }
                    var lForm2 = new StringDisplayForm(
                        String.Format("Romanization missing ({0} of {1})", missingCounter, romanizationMissing.Count),
                        sortedBuilder.ToString());
                    lForm2.Show();
                }
            }
        }
Exemplo n.º 8
0
        private void btnCreateKml_Click(object sender, EventArgs e)
        {
            var allEntities = new List <PopulationDataEntry>();

            foreach (PopulationDataEntry provinceGeocode in TambonHelper.ProvinceGeocodes)
            {
                PopulationData provinceEntities = TambonHelper.GetGeocodeList(provinceGeocode.Geocode);
                allEntities.Add(provinceEntities.Data);
            }
            PopulationDataEntry master = new PopulationDataEntry();

            master.SubEntities.AddRange(allEntities);
            String outFilename = Path.Combine(GlobalSettings.XMLOutputDir, "offices.kml");

            master.ExportToKml(outFilename);

            var geotaggedOffices = new Dictionary <OfficeType, Int32>();
            var anyOffices       = new Dictionary <OfficeType, Int32>();
            var flatList         = master.FlatList(EntityTypeHelper.AllEntityTypes);

            foreach (var entity in flatList)
            {
                foreach (var office in entity.Offices)
                {
                    if (office.Location != null)
                    {
                        if (!geotaggedOffices.ContainsKey(office.Type))
                        {
                            geotaggedOffices.Add(office.Type, 0);
                        }
                        geotaggedOffices[office.Type]++;
                    }
                    if (!anyOffices.ContainsKey(office.Type))
                    {
                        anyOffices.Add(office.Type, 0);
                    }
                    anyOffices[office.Type]++;
                }
            }
            String officeTypeInfo = String.Empty;

            foreach (OfficeType officeType in System.Enum.GetValues(typeof(OfficeType)))
            {
                if (geotaggedOffices.ContainsKey(officeType))
                {
                    officeTypeInfo =
                        officeTypeInfo +
                        String.Format("{0} {1} (of {2})", officeType, geotaggedOffices[officeType], anyOffices[officeType])
                        + Environment.NewLine;
                }
            }

            var    provincesWithoutPAOLocation     = flatList.FindAll(x => x.Offices.Any(y => (y.Type == OfficeType.PAOOffice) && (y.Location == null)));
            String provincesWithoutPAOLocationInfo = String.Format("No PAO location ({0}): ", provincesWithoutPAOLocation.Count());

            foreach (var entity in provincesWithoutPAOLocation)
            {
                provincesWithoutPAOLocationInfo = provincesWithoutPAOLocationInfo + String.Format("{0} ({1}),", entity.English, entity.Geocode);
            }
            var    districtsWithoutOffice     = flatList.FindAll(x => x.Offices.Any(y => (y.Type == OfficeType.DistrictOffice) && (y.Location == null)));
            String districtsWithoutOfficeInfo = String.Format("No district office location ({0}): ", districtsWithoutOffice.Count());

            foreach (var entity in districtsWithoutOffice)
            {
                districtsWithoutOfficeInfo = districtsWithoutOfficeInfo + String.Format("{0} ({1}),", entity.English, entity.Geocode);
            }

            var info = officeTypeInfo + Environment.NewLine + provincesWithoutPAOLocationInfo + Environment.NewLine + districtsWithoutOfficeInfo;

            var form = new StringDisplayForm("Office types", info);

            form.Show();
        }