private String CalculateData(Int32 iGeocode)
        {
            String lResult             = String.Empty;
            PopulationDataEntry lEntry = null;

            if (iGeocode == 0)
            {
                lEntry = mData;
            }
            else
            {
                lEntry = mData.FindByCode(iGeocode);
            }
            if (lEntry != null)
            {
                List <PopulationDataEntry> lList = lEntry.FlatList(new List <EntityType>()
                {
                    EntityType.Bangkok, EntityType.Changwat, EntityType.Amphoe, EntityType.KingAmphoe, EntityType.Khet
                });
                lList.Add(lEntry);
                FrequencyCounter lCounter = new FrequencyCounter();
                Int32            lSeats   = 0;
                foreach (PopulationDataEntry lSubEntry in lList)
                {
                    foreach (ConstituencyEntry lConstituency in lSubEntry.ConstituencyList)
                    {
                        lCounter.IncrementForCount(lConstituency.Population() / lConstituency.NumberOfSeats, lSubEntry.Geocode * 100 + lConstituency.Index);
                        lSeats += lConstituency.NumberOfSeats;
                    }
                }
                StringBuilder lBuilder = new StringBuilder();
                lBuilder.AppendLine("Number of constituencies: " + lCounter.NumberOfValues.ToString());
                lBuilder.AppendLine("Number of seats: " + lSeats.ToString());
                if (lCounter.NumberOfValues > 0)
                {
                    lBuilder.AppendLine("Mean population per seat: " + Math.Round(lCounter.MeanValue).ToString());
                    lBuilder.AppendLine("Standard deviation: " + Math.Round(lCounter.StandardDeviation).ToString());
                    lBuilder.AppendLine("Maximum population per seat: " + lCounter.MaxValue.ToString());
                    foreach (var lSubEntry in lCounter.Data[lCounter.MaxValue])
                    {
                        lBuilder.AppendLine(" " + GetEntityConstituencyName(lSubEntry));
                    }
                    lBuilder.AppendLine("Minimum population per seat: " + lCounter.MinValue.ToString());
                    foreach (var lSubEntry in lCounter.Data[lCounter.MinValue])
                    {
                        lBuilder.AppendLine(" " + GetEntityConstituencyName(lSubEntry));
                    }
                }
                lBuilder.AppendLine();
                foreach (PopulationDataEntry lSubEntry in lList)
                {
                    foreach (ConstituencyEntry lConstituency in lSubEntry.ConstituencyList)
                    {
                        lBuilder.AppendLine(
                            GetEntityConstituencyName(lSubEntry.Geocode * 100 + lConstituency.Index)
                            + ": " +
                            lConstituency.Population() / lConstituency.NumberOfSeats);
                    }
                }
                lResult = lBuilder.ToString();
            }
            return(lResult);
        }
Beispiel #2
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();
                }
            }
        }
Beispiel #3
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();
        }
Beispiel #4
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();
                }
            }
        }
Beispiel #5
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();
        }
        private IEnumerable <PopulationDataEntry> CalculateList()
        {
            List <PopulationDataEntry> list     = new List <PopulationDataEntry>();
            List <EntityType>          entities = new List <EntityType>();

            if (rbx_Changwat.Checked)
            {
                entities.Add(EntityType.Changwat);
                entities.Add(EntityType.Bangkok);
                list.AddRange(BaseEntry.FlatList(entities));
                if (entities.Contains(BaseEntry.Type))
                {
                    list.Add(BaseEntry);
                }
            }
            else if (rbxAmphoeKhet.Checked)
            {
                if (chkAmphoe.Checked)
                {
                    entities.Add(EntityType.Amphoe);
                }
                if (chkKhet.Checked)
                {
                    entities.Add(EntityType.Khet);
                }
                list.AddRange(_baseEntry.FlatList(entities));
            }
            else if (rbxTambonKhwaeng.Checked)
            {
                if (chkTambon.Checked)
                {
                    entities.Add(EntityType.Tambon);
                }
                if (chkKhwaeng.Checked)
                {
                    entities.Add(EntityType.Khwaeng);
                }
                list.AddRange(_baseEntry.FlatList(entities));
            }
            else if (rbxThesaban.Checked)
            {
                if (chkThesabanTambon.Checked)
                {
                    entities.Add(EntityType.ThesabanTambon);
                }
                if (chkThesabanMueang.Checked)
                {
                    entities.Add(EntityType.ThesabanMueang);
                }
                if (chkThesabanNakhon.Checked)
                {
                    entities.Add(EntityType.ThesabanNakhon);
                }

                foreach (PopulationDataEntry entity in _baseEntry.ThesabanList())
                {
                    if (entities.Contains(entity.Type))
                    {
                        list.Add(entity);
                    }
                }
            }

            list.Sort(delegate(PopulationDataEntry p1, PopulationDataEntry p2)
            {
                return(p2.Total.CompareTo(p1.Total));
            });
            return(list);
        }