private void btn_L7018_Click(object sender, EventArgs e) { String outFilename = Path.Combine(GlobalSettings.XMLOutputDir, "l7018.kml"); KmlHelper kmlWriter = MgrsGridElement.StartKmlWriting(); XmlNode kmlNode = kmlWriter.AddFolder(kmlWriter.DocumentNode, "L7018", false); RtsdMapIndex.CalcIndexList(); foreach (var entry in RtsdMapIndex.MapIndexL7018) { entry.WriteToKml(kmlWriter, kmlNode, entry.Name); } kmlWriter.SaveToFile(outFilename); String nonStandardSheetInfo = String.Empty; foreach (var index in RtsdMapIndex.NonStandardSheets) { var sheet = RtsdMapIndex.MapIndexL7018.FirstOrDefault(x => x.Index.Equals(index)); if (sheet != null) { nonStandardSheetInfo += sheet.Name + " " + sheet.NorthWestCorner.ToString("%D° %M' %S'' %H") + " - " + sheet.SouthEastCorner.ToString("%D° %M' %S'' %H") + Environment.NewLine; } } var stringDisplayForm = new StringDisplayForm("L7018 Non-Standard sheets", nonStandardSheetInfo); stringDisplayForm.Show(); }
private void ccaattPostProcessing(DopaGeocodeList data) { data.RemoveAllKnownGeocodes(); data.ExportToXML(Path.Combine(GlobalSettings.XMLOutputDir, "unknowngeocodes.xml")); var form = new StringDisplayForm("New Geocodes", data.ToString()); form.Show(); }
private void btnThesaban_Click(object sender, EventArgs e) { Int32 lGeocode = GetCurrentChangwat().Geocode; ConstituencyChecker lChecker = new ConstituencyChecker(lGeocode); String lResult = String.Empty; foreach (PopulationDataEntry lEntry in lChecker.ThesabanWithoutConstituencies()) { lResult = lResult + lEntry.Geocode.ToString() + " " + lEntry.English + Environment.NewLine; } var lForm = new StringDisplayForm("Thesaban without constituency announcement", lResult); lForm.Show(); }
private void btnMuban_Click(object sender, EventArgs e) { Int32 geocode = GetCurrentChangwat().Geocode; var mubanCsvReader = new MubanCSVReader(); var data = mubanCsvReader.Parse(geocode); if (data != null) { var form = new StringDisplayForm("Muban", mubanCsvReader.Information(data)); String outFilename = Path.Combine(GlobalSettings.XMLOutputDir, "Muban" + geocode.ToString() + ".kml"); data.ExportToKml(outFilename); form.Show(); } }
private void btnTambonFrequency_Click(Object sender, EventArgs e) { List <EntityType> types = new List <EntityType>() { EntityType.Tambon }; EntityCounter counter = new EntityCounter(types); var lChangwat = (PopulationDataEntry)cbx_changwat.SelectedItem; // lCounter.BaseGeocode = lChangwat.Geocode; counter.Calculate(); var form = new StringDisplayForm("Tambon", counter.CommonNames(20)); form.Show(); }
private void btnBoard_Click(object sender, EventArgs e) { String lFilename = Path.GetDirectoryName(Application.ExecutablePath) + "\\misc\\board.xml"; BoardMeetingList lBoardMeetingList = BoardMeetingList.Load(lFilename); if (lBoardMeetingList != null) { FrequencyCounter lCounter = lBoardMeetingList.EffectiveDateTillPublication(); lCounter = lBoardMeetingList.MeetingDateTillPublication(); String lResult = "Mean time " + lCounter.MeanValue.ToString("##0.0") + Environment.NewLine; lResult = lResult + "Max. time " + lCounter.MaxValue.ToString() + Environment.NewLine; lResult = lResult + "Min. time " + lCounter.MinValue.ToString() + Environment.NewLine; FrequencyCounter lCounterMissing = lBoardMeetingList.MissingConstituencyAnnouncements(); lResult = lResult + "No constituency: " + lCounterMissing.NumberOfValues.ToString() + Environment.NewLine + Environment.NewLine; var lSorted = new List <Int32>(); foreach (Int32 lKey in lCounter.Data.Keys) { lSorted.Add(lKey); } lSorted.Sort(delegate(Int32 p1, Int32 p2) { return(p2.CompareTo(p1)); }); foreach (int lEntry in lSorted) { String lLine = lEntry.ToString() + ": "; foreach (int lGeocode in lCounter.Data[lEntry]) { lLine = lLine + lGeocode.ToString() + ','; } lLine = lLine.Remove(lLine.Length - 1); lResult = lResult + lLine + Environment.NewLine; } var lForm = new StringDisplayForm("Board meeting to constituency", lResult); lForm.Show(); } }
private void btnBoard_Click(object sender, EventArgs e) { String lFilename = Path.GetDirectoryName(Application.ExecutablePath) + "\\misc\\board.xml"; BoardMeetingList lBoardMeetingList = BoardMeetingList.Load(lFilename); if ( lBoardMeetingList != null ) { FrequencyCounter lCounter = lBoardMeetingList.EffectiveDateTillPublication(); lCounter = lBoardMeetingList.MeetingDateTillPublication(); String lResult = "Mean time " + lCounter.MeanValue.ToString("##0.0") + Environment.NewLine; lResult = lResult + "Max. time " + lCounter.MaxValue.ToString() + Environment.NewLine; lResult = lResult + "Min. time " + lCounter.MinValue.ToString() + Environment.NewLine; FrequencyCounter lCounterMissing = lBoardMeetingList.MissingConstituencyAnnouncements(); lResult = lResult + "No constituency: " + lCounterMissing.NumberOfValues.ToString() + Environment.NewLine + Environment.NewLine; var lSorted = new List<Int32>(); foreach ( Int32 lKey in lCounter.Data.Keys ) { lSorted.Add(lKey); } lSorted.Sort(delegate(Int32 p1, Int32 p2) { return (p2.CompareTo(p1)); }); foreach ( int lEntry in lSorted ) { String lLine = lEntry.ToString() + ": "; foreach ( int lGeocode in lCounter.Data[lEntry] ) { lLine = lLine + lGeocode.ToString() + ','; } lLine = lLine.Remove(lLine.Length - 1); lResult = lResult + lLine + Environment.NewLine; } var lForm = new StringDisplayForm("Board meeting to constituency", lResult); lForm.Show(); } }
private void btnMubanNames_Click(object sender, EventArgs e) { List <EntityType> types = new List <EntityType>() { EntityType.Muban }; EntityCounter namesCounter = new EntityCounter(types); if (chkUseCsv.Checked) { var entityList = new List <PopulationDataEntry>(); var counter = new FrequencyCounter(); foreach (PopulationDataEntry entity in TambonHelper.ProvinceGeocodes) { if (entity.Geocode != 10) { var reader = new MubanCSVReader(); var data = reader.Parse(entity.Geocode); if (data != null) { MubanCSVReader.Statistics(data, counter); var flatData = data.FlatList(types); entityList.AddRange(flatData); } } } var formStatistics = new StringDisplayForm("Muban", MubanCSVReader.StatisticsText(counter)); formStatistics.Show(); namesCounter.Calculate(entityList); } else { namesCounter.Calculate(); } var formNames = new StringDisplayForm("Muban", namesCounter.CommonNames(20)); formNames.Show(); }
private void btnGovernor_Click(object sender, EventArgs e) { ProvinceGovernorParser lParser = new ProvinceGovernorParser(); lParser.ParseUrl("http://www.moi.go.th/portal/page?_pageid=33,76197,33_76230&_dad=portal&_schema=PORTAL"); // lParser.ParseFile("C:\\Users\\Andy\\Dropbox\\My Dropbox\\Misc\\governor list 2008.htm"); XmlDocument lXmlDocument = new XmlDocument(); lParser.ExportToXML(lXmlDocument); Directory.CreateDirectory(GlobalSettings.XMLOutputDir); lXmlDocument.Save(Path.Combine(GlobalSettings.XMLOutputDir, "governor.xml")); var lNewGovernors = lParser.NewGovernorsList(); lXmlDocument = new XmlDocument(); lParser.ExportToXML(lXmlDocument); lXmlDocument.Save(Path.Combine(GlobalSettings.XMLOutputDir, "newgovernor.xml")); var lForm = new StringDisplayForm("New governors", lParser.NewGovernorsText()); lForm.Show(); }
private void btnCheckNames_Click(object sender, EventArgs e) { var romanizationMissing = new List<RomanizationEntry>(); var country = new Entity(); foreach ( var province in GlobalData.Provinces ) { var provinceData = GlobalData.GetGeocodeList(province.geocode); country.entity.Add(provinceData); } var allEntities = country.FlatList(); Int32 numberOfEntities = allEntities.Count(); var romanizator = new Romanization(); romanizator.Initialize(allEntities); var romanizations = romanizator.Romanizations; var romanizationMistakes = romanizator.RomanizationMistakes; var romanizationSuggestions = romanizator.FindRomanizationSuggestions(out romanizationMissing, allEntities); UInt32 provinceFilter = 0; //if ( cbxCheckNamesFiltered.Checked ) //{ // provinceFilter = GetCurrentChangwat().Geocode; //} StringBuilder romanizationMistakesBuilder = new StringBuilder(); Int32 romanizationMistakeCount = 0; foreach ( var entry in romanizationMistakes ) { if ( GeocodeHelper.IsBaseGeocode(provinceFilter, entry.Key.Geocode) ) { romanizationMistakesBuilder.AppendLine(String.Format("{0} {1}: {2} vs. {3}", entry.Key.Geocode, entry.Key.Name, entry.Key.English, entry.Value)); romanizationMistakeCount++; } } if ( romanizationMistakeCount > 0 ) { var displayForm = new StringDisplayForm( String.Format("Romanization problems ({0})", romanizationMistakeCount), romanizationMistakesBuilder.ToString()); displayForm.Show(); } StringBuilder romanizationSuggestionBuilder = new StringBuilder(); Int32 romanizationSuggestionCount = 0; foreach ( var entry in romanizationSuggestions ) { if ( GeocodeHelper.IsBaseGeocode(provinceFilter, entry.Geocode) ) { var entity = allEntities.FirstOrDefault(x => x.geocode == entry.Geocode); var suggestedName = entry.English; romanizationSuggestionBuilder.AppendLine(String.Format("<entity type=\"{0}\" geocode=\"{1}\" name=\"{2}\" english=\"{3}\" />", entity.type, entity.geocode, entity.name, suggestedName)); romanizationSuggestionCount++; } } if ( romanizationSuggestionCount > 0 ) { var form = new StringDisplayForm( String.Format("Romanization suggestions ({0}", romanizationSuggestionCount), romanizationSuggestionBuilder.ToString()); form.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.Name); if ( found == null ) { counter.Add(Tuple.Create(entry.Name, entry.English, 1)); } else { counter.Remove(found); counter.Add(Tuple.Create(entry.Name, entry.English, 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 displayForm = new StringDisplayForm( String.Format("Romanization suggestions ({0} of {1})", suggestionCounter, romanizationSuggestionCount), sortedBuilder.ToString()); displayForm.Show(); } } // show missing romanizations 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.Name); if ( found == null ) { counter.Add(Tuple.Create(entry.Name, 1)); } else { counter.Remove(found); counter.Add(Tuple.Create(entry.Name, 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 displayForm = new StringDisplayForm( String.Format("Romanization missing ({0} of {1})", romanizationMissing.Count, numberOfEntities), sortedBuilder.ToString()); displayForm.Show(); } } }
private void btnCheckCensus_Click(object sender, EventArgs e) { Int16 year = Convert.ToInt16(cbxCensusYears.SelectedItem as String); var builder = new StringBuilder(); var baseEntity = GlobalData.CompleteGeocodeList(); var populationData = GlobalData.LoadPopulationDataUnprocessed(PopulationDataSourceType.Census, year); var allEntities = populationData.FlatList().Where(x => x.population.Any(y => y.source == PopulationDataSourceType.Census && y.Year == year)).ToList(); foreach ( var entity in allEntities ) { var population = entity.population.First(y => y.source == PopulationDataSourceType.Census && y.Year == year); Int32 diff = 0; foreach ( var data in population.data ) { if ( data.male != 0 && data.female != 0 ) { diff = Math.Abs(data.total - data.male - data.female); if ( diff > 1 ) { builder.AppendFormat("{0} ({1}): {2} differs male/female to total by {3}", entity.english, entity.geocode, data.type, diff); builder.AppendLine(); } } foreach ( var subData in data.data ) { if ( data.male != 0 && data.female != 0 ) { diff = Math.Abs(data.total - data.male - data.female); if ( diff > 1 ) { builder.AppendFormat("{0} ({1}): {2} of {3} differs male/female to total by {4}", entity.english, entity.geocode, subData.type, data.type, diff); builder.AppendLine(); } } } } diff = population.SumError(); if ( diff > 1 ) { builder.AppendFormat("{0} ({1}): Sum of parts differs by {2}", entity.english, entity.geocode, diff); builder.AppendLine(); } var sum = new PopulationData(); foreach ( var subEntity in entity.entity.Where(x => !x.IsObsolete && x.population.Any()) ) { var populationToAdd = subEntity.population.FirstOrDefault(y => y.source == PopulationDataSourceType.Census && y.Year == year); if ( populationToAdd != null ) { foreach ( var dataPoint in populationToAdd.data ) { sum.AddDataPoint(dataPoint); } } } if ( sum.data.Any() ) { diff = sum.TotalPopulation.MaxDeviation(entity.population.First(y => y.source == PopulationDataSourceType.Census && y.Year == year).TotalPopulation); if ( diff > 1 ) { builder.AppendFormat("{0} ({1}): Sum of subentities differs by {2}", entity.english, entity.geocode, diff); builder.AppendLine(); } } } var result = builder.ToString(); var formCensusProblems = new StringDisplayForm("Census data problems", result); formCensusProblems.Show(); }
private void btnTimeBetweenElection_Click(object sender, EventArgs e) { var counter = new FrequencyCounter(); foreach ( var changwat in GlobalData.Provinces ) { CalculateTimeBetweenLocalElection(changwat.geocode, counter); } var builder = new StringBuilder(); builder.AppendFormat(CultureInfo.CurrentUICulture, "Number of interregnums: {0}", counter.NumberOfValues); builder.AppendLine(); builder.AppendFormat(CultureInfo.CurrentUICulture, "Minimum days between elections: {0}", counter.MinValue); builder.AppendLine(); builder.AppendFormat(CultureInfo.CurrentUICulture, "Maximum days between elections: {0}", counter.MaxValue); builder.AppendLine(); builder.AppendFormat(CultureInfo.CurrentUICulture, "Mean number of days between elections: {0:#0.0}", counter.MeanValue); builder.AppendLine(); builder.AppendLine(); builder.AppendLine("Offices with longest interregnum:"); foreach ( var geocode in counter.Data[counter.MaxValue] ) { var entity = GlobalData.LookupGeocode(geocode); builder.AppendFormat(CultureInfo.CurrentUICulture, "{0} ({1}): {2} days", entity.english, geocode, counter.MaxValue); builder.AppendLine(); } builder.AppendLine(); builder.AppendLine("Offices with shortest interregnum:"); foreach ( var geocode in counter.Data[counter.MinValue] ) { var entity = GlobalData.LookupGeocode(geocode); builder.AppendFormat(CultureInfo.CurrentUICulture, "{0} ({1}): {2} days", entity.english, geocode, counter.MinValue); builder.AppendLine(); } var result = builder.ToString(); var formInterregnum = new StringDisplayForm("Time between elections", result); formInterregnum.Show(); }
private void btnTermEnds_Click(object sender, EventArgs e) { var itemsWithTermEnds = new List<EntityTermEnd>(); var geocode = (cbxChangwat.SelectedItem as Entity).geocode; if ( chkAllProvince.Checked ) { geocode = 0; } var itemWithCouncilTermEndsInChangwat = EntitiesWithCouncilTermEndInYear(geocode, DateTime.Now.Year); // var itemWithOfficialTermEndsInChangwat = EntitiesWithCouncilTermEndInYear(geocode, DateTime.Now.Year); itemsWithTermEnds.AddRange(itemWithCouncilTermEndsInChangwat); itemsWithTermEnds.Sort((x, y) => x.CouncilTerm.begin.CompareTo(y.CouncilTerm.begin)); var builder = new StringBuilder(); Int32 count = 0; foreach ( var item in itemsWithTermEnds ) { builder.AppendFormat(CultureInfo.CurrentUICulture, "{0} ({1}): {2:d}", item.Entity.english, item.Entity.geocode, item.CouncilTerm.begin.AddYears(4).AddDays(-1)); builder.AppendLine(); count++; } if ( count > 0 ) { var displayForm = new StringDisplayForm( String.Format("Term ends ({0})", count), builder.ToString()); displayForm.Show(); } }
private void btnTambonStatistics_Click(object sender, EventArgs e) { EntityCounter counter = new EntityCounter(new List<EntityType>() { EntityType.Tambon }); // var lChangwat = (PopulationDataEntry)cbx_changwat.SelectedItem; // lCounter.BaseGeocode = lChangwat.Geocode; counter.Calculate(); var form = new StringDisplayForm("Tambon", counter.CommonNames(20)); form.Show(); }
private void btnMubanNames_Click(object sender, EventArgs e) { List<EntityType> types = new List<EntityType>() { EntityType.Muban }; EntityCounter namesCounter = new EntityCounter(types); if ( chkUseCsv.Checked ) { var entityList = new List<PopulationDataEntry>(); var counter = new FrequencyCounter(); foreach ( PopulationDataEntry entity in TambonHelper.ProvinceGeocodes ) { if ( entity.Geocode != 10 ) { var reader = new MubanCSVReader(); var data = reader.Parse(entity.Geocode); if ( data != null ) { MubanCSVReader.Statistics(data, counter); var flatData = data.FlatList(types); entityList.AddRange(flatData); } } } var formStatistics = new StringDisplayForm("Muban", MubanCSVReader.StatisticsText(counter)); formStatistics.Show(); namesCounter.Calculate(entityList); } else { namesCounter.Calculate(); } var formNames = new StringDisplayForm("Muban", namesCounter.CommonNames(20)); formNames.Show(); }
private void btnMuban_Click(object sender, EventArgs e) { Int32 geocode = GetCurrentChangwat().Geocode; var mubanCsvReader = new MubanCSVReader(); var data = mubanCsvReader.Parse(geocode); if ( data != null ) { var form = new StringDisplayForm("Muban", mubanCsvReader.Information(data)); String outFilename = Path.Combine(GlobalSettings.XMLOutputDir, "Muban" + geocode.ToString() + ".kml"); data.ExportToKml(outFilename); form.Show(); } }
private void btnNayokResign_Click(object sender, EventArgs e) { UInt32 changwatGeocode = 0; if ( !chkAllProvince.Checked ) { changwatGeocode = (cbxChangwat.SelectedItem as Entity).geocode; } var allTermEnd = EntitiesWithCouncilTermEndInTimeSpan(changwatGeocode, new DateTime(2013, 9, 1), new DateTime(2013, 9, 30)); var allNextElectionNormal = allTermEnd.Where(x => x.Entity.office.First().council.CouncilTerms.Any(y => y.begin > x.CouncilTerm.end && (y.begin - x.CouncilTerm.end).Days < 60)).ToList(); List<EntityTermEnd> processedTermEnds = new List<EntityTermEnd>(); foreach ( var entry in allTermEnd ) { entry.Entity.office.First().officials.SortByDate(); processedTermEnds.Add(new EntityTermEnd( entry.Entity, entry.CouncilTerm, entry.Entity.office.First().officials.OfficialTerms.FirstOrDefault(y => y.begin == entry.CouncilTerm.begin))); } var nayokTermStartedSameDate = processedTermEnds.Where(x => x.OfficialTerm != null).ToList(); var nextElectionNormal = nayokTermStartedSameDate.Where(x => x.Entity.office.First().council.CouncilTerms.Any(y => y.begin > x.CouncilTerm.end && (y.begin - x.CouncilTerm.end).Days < 60)).ToList(); var nayokTermEndNormal = nextElectionNormal.Where(x => x.OfficialTerm.end == x.CouncilTerm.end).ToList(); var nayokTermEndUnknown = nextElectionNormal.Where(x => x.OfficialTerm.end != x.CouncilTerm.end).ToList(); List<EntityTermEnd> nextNayokElectionEarly = new List<EntityTermEnd>(); List<Entity> nayokElectedAgainEarly = new List<Entity>(); List<Entity> nayokElectionFailEarly = new List<Entity>(); List<Entity> nayokElectedAgainNormal = new List<Entity>(); List<Entity> nayokElectionFailNormal = new List<Entity>(); foreach ( var entry in nayokTermEndUnknown ) { var nextCouncilTerm = entry.Entity.office.First().council.CouncilTerms.First(y => y.begin > entry.CouncilTerm.end && (y.begin - entry.CouncilTerm.end).Days < 60); var nextNayokTerm = entry.Entity.office.First().officials.OfficialTerms.LastOrDefault(y => (y.begin < nextCouncilTerm.begin)); if ( (nextNayokTerm != null) && (nextNayokTerm.begin.Year == entry.CouncilTerm.end.Year) ) { nextNayokElectionEarly.Add(new EntityTermEnd(entry.Entity, nextCouncilTerm, nextNayokTerm)); var nextOfficial = nextNayokTerm as OfficialEntry; var previousOfficial = entry.OfficialTerm as OfficialEntry; if ( (nextOfficial != null) && (previousOfficial != null) ) { if ( nextOfficial.name == previousOfficial.name ) { nayokElectedAgainEarly.Add(entry.Entity); } else { nayokElectionFailEarly.Add(entry.Entity); } } } } foreach ( var entry in nayokTermEndNormal ) { var nextCouncilTerm = entry.Entity.office.First().council.CouncilTerms.First(y => y.begin > entry.CouncilTerm.end && (y.begin - entry.CouncilTerm.end).Days < 60); var nextOfficial = entry.Entity.office.First().officials.OfficialTerms.LastOrDefault(y => (y.begin == nextCouncilTerm.begin)) as OfficialEntry; var previousOfficial = entry.OfficialTerm as OfficialEntry; if ( (nextOfficial != null) && (previousOfficial != null) ) { if ( nextOfficial.name == previousOfficial.name ) { nayokElectedAgainNormal.Add(entry.Entity); } else { nayokElectionFailNormal.Add(entry.Entity); } } } var builder = new StringBuilder(); builder.AppendFormat(CultureInfo.CurrentUICulture, "Number of council term ends: {0}", allTermEnd.Count()); builder.AppendLine(); builder.AppendFormat(CultureInfo.CurrentUICulture, "Number of council term elections: {0}", allNextElectionNormal.Count()); builder.AppendLine(); builder.AppendFormat(CultureInfo.CurrentUICulture, "Number of term started together: {0}", nayokTermStartedSameDate.Count); builder.AppendLine(); builder.AppendFormat(CultureInfo.CurrentUICulture, "Number of term into consideration: {0}", nextElectionNormal.Count); builder.AppendLine(); builder.AppendFormat(CultureInfo.CurrentUICulture, "Number of Nayok till end of term: {0}", nayokTermEndNormal.Count); builder.AppendLine(); var success = Convert.ToDouble(nayokElectedAgainNormal.Count()); var fail = Convert.ToDouble(nayokElectionFailNormal.Count()); builder.AppendFormat(CultureInfo.CurrentUICulture, " {0} reelected, {1} changed; {2:P} success rate", success, fail, success / (success + fail)); builder.AppendLine(); builder.AppendFormat(CultureInfo.CurrentUICulture, "Number of Nayok early election: {0}", nextNayokElectionEarly.Count); builder.AppendLine(); success = Convert.ToDouble(nayokElectedAgainEarly.Count()); fail = Convert.ToDouble(nayokElectionFailEarly.Count()); builder.AppendFormat(CultureInfo.CurrentUICulture, " {0} reelected, {1} changed; {2:P} success rate", success, fail, success / (success + fail)); builder.AppendLine(); builder.AppendLine(); if ( chkAllProvince.Checked ) { foreach ( var changwat in GlobalData.Provinces ) { var nayokEndTermInChangwat = nayokTermEndNormal.Where(x => GeocodeHelper.ProvinceCode(x.Entity.geocode) == changwat.geocode).Count(); var nayokEarlyInChangwat = nextNayokElectionEarly.Where(x => GeocodeHelper.ProvinceCode(x.Entity.geocode) == changwat.geocode).Count(); var total = nayokEarlyInChangwat + nayokEndTermInChangwat; if ( total > 0 ) { builder.AppendFormat(CultureInfo.CurrentUICulture, "{0}: {1} of {2} normal, {3:P} early", changwat.english, nayokEndTermInChangwat, total, Convert.ToDouble(nayokEarlyInChangwat) / total); builder.AppendLine(); } } } var result = builder.ToString(); var formElectionDayOfWeek = new StringDisplayForm("Nayok info", result); formElectionDayOfWeek.Show(); }
private void btnElectionWeekday_Click(object sender, EventArgs e) { var counter = new FrequencyCounter(); foreach ( var changwat in GlobalData.Provinces ) { CountCouncilElectionWeekday(changwat.geocode, counter); } var builder = new StringBuilder(); builder.AppendFormat(CultureInfo.CurrentUICulture, "Number of elections: {0}", counter.NumberOfValues); builder.AppendLine(); DayOfWeek leastFrequentDay = DayOfWeek.Sunday; Int32 leastFrequentDayCount = Int32.MaxValue; foreach ( var dataEntry in counter.Data ) { var count = dataEntry.Value.Count(); var day = (DayOfWeek)(dataEntry.Key); builder.AppendFormat(CultureInfo.CurrentUICulture, "{0}: {1} ({2:#0.0%})", day, count, (Double)count / counter.NumberOfValues); if ( count < leastFrequentDayCount ) { leastFrequentDayCount = count; leastFrequentDay = day; } builder.AppendLine(); } builder.AppendFormat(CultureInfo.CurrentUICulture, "Elections on {0} at ", leastFrequentDay); foreach ( var value in counter.Data[(Int32)leastFrequentDay] ) { builder.AppendFormat(CultureInfo.CurrentUICulture, "{0},", value); } builder.AppendLine(); var result = builder.ToString(); var formElectionDayOfWeek = new StringDisplayForm("Election days", result); formElectionDayOfWeek.Show(); }
private void btnThesaban_Click(object sender, EventArgs e) { Int32 lGeocode = GetCurrentChangwat().Geocode; ConstituencyChecker lChecker = new ConstituencyChecker(lGeocode); String lResult = String.Empty; foreach ( PopulationDataEntry lEntry in lChecker.ThesabanWithoutConstituencies() ) { lResult = lResult + lEntry.Geocode.ToString() + " " + lEntry.English + Environment.NewLine; } var lForm = new StringDisplayForm("Thesaban without constituency announcement", lResult); lForm.Show(); }
private void btn_L7018_Click(object sender, EventArgs e) { String outFilename = Path.Combine(GlobalSettings.XMLOutputDir, "l7018.kml"); KmlHelper kmlWriter = MgrsGridElement.StartKmlWriting(); XmlNode kmlNode = kmlWriter.AddFolder(kmlWriter.DocumentNode, "L7018", false); RtsdMapIndex.CalcIndexList(); foreach ( var entry in RtsdMapIndex.MapIndexL7018 ) { entry.WriteToKml(kmlWriter, kmlNode, entry.Name); } kmlWriter.SaveToFile(outFilename); String nonStandardSheetInfo = String.Empty; foreach ( var index in RtsdMapIndex.NonStandardSheets ) { var sheet = RtsdMapIndex.MapIndexL7018.FirstOrDefault(x => x.Index.Equals(index)); if ( sheet != null ) { nonStandardSheetInfo += sheet.Name + " " + sheet.NorthWestCorner.ToString("%D° %M' %S'' %H") + " - " + sheet.SouthEastCorner.ToString("%D° %M' %S'' %H") + Environment.NewLine; } } var stringDisplayForm = new StringDisplayForm("L7018 Non-Standard sheets", nonStandardSheetInfo); stringDisplayForm.Show(); }
private void btnCheckTerms_Click(object sender, EventArgs e) { var itemsWithInvalidCouncilTerms = new List<Entity>(); var itemsWithInvalidOfficialTerms = new List<Entity>(); var itemsWithoutAnyCouncilTerms = new List<Entity>(); var itemsWithUnexplainedCouncilSizeChanges = new List<Entity>(); foreach ( var changwat in GlobalData.Provinces ) { var itemsWithInvalidCouncilTermsInChangwat = EntitiesWithInvalidCouncilTerms(changwat.geocode); var itemsWithoutAnyCouncilTermsInChangwat = EntitiesWithoutAnyCouncilTerms(changwat.geocode); var itemsWithInvalidOfficialTermsInChangwat = EntitiesWithInvalidElectedOfficialsTerms(changwat.geocode); itemsWithInvalidCouncilTerms.AddRange(itemsWithInvalidCouncilTermsInChangwat); itemsWithInvalidOfficialTerms.AddRange(itemsWithInvalidOfficialTermsInChangwat); itemsWithoutAnyCouncilTerms.AddRange(itemsWithoutAnyCouncilTermsInChangwat); itemsWithUnexplainedCouncilSizeChanges.AddRange(GlobalData.GetGeocodeList(changwat.geocode).FlatList().Where(entity => entity.office.Any(office => office.council.CouncilTerms.Any(term => term.sizechangereason == CouncilSizeChangeReason.Unknown)))); } var builder = new StringBuilder(); Int32 count = 0; if ( itemsWithInvalidCouncilTerms.Any() ) { builder.AppendLine("Council term problems:"); foreach ( var item in itemsWithInvalidCouncilTerms ) { builder.AppendFormat(CultureInfo.CurrentUICulture, "{0} ({1})", item.english, item.geocode); builder.AppendLine(); count++; } builder.AppendLine(); } if ( itemsWithInvalidOfficialTerms.Any() ) { builder.AppendLine("Official term problems:"); foreach ( var item in itemsWithInvalidOfficialTerms ) { builder.AppendFormat(CultureInfo.CurrentUICulture, "{0} ({1})", item.english, item.geocode); builder.AppendLine(); count++; } builder.AppendLine(); } if ( itemsWithoutAnyCouncilTerms.Any() ) { builder.AppendLine("No term at all:"); foreach ( var item in itemsWithoutAnyCouncilTerms ) { builder.AppendFormat(CultureInfo.CurrentUICulture, "{0} ({1})", item.english, item.geocode); builder.AppendLine(); count++; } builder.AppendLine(); } if ( itemsWithUnexplainedCouncilSizeChanges.Any() ) { builder.AppendLine("Unexplained council size changes:"); foreach ( var item in itemsWithUnexplainedCouncilSizeChanges ) { builder.AppendFormat(CultureInfo.CurrentUICulture, "{0} ({1})", item.english, item.geocode); builder.AppendLine(); count++; } builder.AppendLine(); } if ( count > 0 ) { var displayForm = new StringDisplayForm( String.Format("Invalid terms ({0})", count), builder.ToString()); displayForm.Show(); } }
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(); } } }
private void btnElectionDates_Click(object sender, EventArgs e) { var counter = new FrequencyCounter(); foreach ( var changwat in GlobalData.Provinces ) { CountCouncilElectionDate(changwat.geocode, counter); } var builder = new StringBuilder(); builder.AppendFormat(CultureInfo.CurrentUICulture, "Number of elections: {0}", counter.NumberOfValues); builder.AppendLine(); var zeroDate = new DateTime(2000, 1, 1); var ordered = counter.Data.OrderBy(x => x.Key); foreach ( var entry in ordered ) { var count = entry.Value.Count(); if ( count > 0 ) { builder.AppendFormat("{0:yyyy-MM-dd}: {1}", zeroDate.AddDays(entry.Key), entry.Value.Count()); builder.AppendLine(); } } builder.AppendLine(); var result = builder.ToString(); var formElectionDayOfWeek = new StringDisplayForm("Election dates", result); formElectionDayOfWeek.Show(); }
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(); } } }
private void btnMubanStatistics_Click(object sender, EventArgs e) { EntityCounter counter = new EntityCounter(new List<EntityType>() { EntityType.Muban }); counter.Calculate(); var formNames = new StringDisplayForm("Muban", counter.CommonNames(20)); formNames.Show(); }
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 void btnPendingElections_Click(object sender, EventArgs e) { var itemsWithCouncilElectionsPending = new List<EntityTermEnd>(); var itemsWithOfficialElectionsPending = new List<EntityTermEnd>(); var itemsWithOfficialElectionResultUnknown = new List<EntityTermEnd>(); Entity entity; if ( chkAllProvince.Checked ) { entity = GlobalData.CompleteGeocodeList(); } else { var changwatGeocode = (cbxChangwat.SelectedItem as Entity).geocode; entity = GlobalData.GetGeocodeList(changwatGeocode); } var itemsWithCouncilElectionPendingInChangwat = entity.EntitiesWithCouncilElectionPending(); itemsWithCouncilElectionsPending.AddRange(itemsWithCouncilElectionPendingInChangwat); itemsWithCouncilElectionsPending.Sort((x, y) => x.CouncilTerm.begin.CompareTo(y.CouncilTerm.begin)); var itemsWithOfficialElectionPendingInChangwat = entity.EntitiesWithOfficialElectionPending(); itemsWithOfficialElectionsPending.AddRange(itemsWithOfficialElectionPendingInChangwat); itemsWithOfficialElectionsPending.Sort((x, y) => x.OfficialTerm.begin.CompareTo(y.OfficialTerm.begin)); var itemsWithOfficialElectionResultUnknownInChangwat = entity.EntitiesWithLatestOfficialElectionResultUnknown(); itemsWithOfficialElectionResultUnknown.AddRange(itemsWithOfficialElectionResultUnknownInChangwat); itemsWithOfficialElectionResultUnknown.Sort((x, y) => x.OfficialTerm.begin.CompareTo(y.OfficialTerm.begin)); var councilBuilder = new StringBuilder(); Int32 councilCount = 0; foreach ( var item in itemsWithCouncilElectionsPending ) { DateTime end; if ( item.CouncilTerm.endSpecified ) { end = item.CouncilTerm.end; } else { end = item.CouncilTerm.begin.AddYears(4).AddDays(-1); } councilBuilder.AppendFormat(CultureInfo.CurrentUICulture, "{0} ({1}): {2:d}", item.Entity.english, item.Entity.geocode, end); councilBuilder.AppendLine(); councilCount++; } if ( councilCount > 0 ) { var displayForm = new StringDisplayForm( String.Format("{0} LAO council elections pending", councilCount), councilBuilder.ToString()); displayForm.Show(); } var officialBuilder = new StringBuilder(); Int32 officialCount = 0; foreach ( var item in itemsWithOfficialElectionsPending ) { String officialTermEnd = "unknown"; if ( (item.OfficialTerm.begin != null) && (item.OfficialTerm.begin.Year > 1900) ) { DateTime end; if ( item.OfficialTerm.endSpecified ) { end = item.OfficialTerm.end; } else { end = item.OfficialTerm.begin.AddYears(4).AddDays(-1); } officialTermEnd = String.Format(CultureInfo.CurrentUICulture, "{0:d}", end); } officialBuilder.AppendFormat(CultureInfo.CurrentUICulture, "{0} ({1}): {2}", item.Entity.english, item.Entity.geocode, officialTermEnd); officialBuilder.AppendLine(); officialCount++; } if ( officialCount > 0 ) { var displayForm = new StringDisplayForm( String.Format("{0} LAO official elections pending", officialCount), officialBuilder.ToString()); displayForm.Show(); } var officialUnknownBuilder = new StringBuilder(); Int32 officialUnknownCount = 0; foreach ( var item in itemsWithOfficialElectionResultUnknown ) { if ( (item.OfficialTerm.begin != null) && (item.OfficialTerm.begin.Year > 1900) ) // must be always true { officialUnknownBuilder.AppendFormat(CultureInfo.CurrentUICulture, "{0} ({1}): {2:d}", item.Entity.english, item.Entity.geocode, item.OfficialTerm.begin); officialUnknownBuilder.AppendLine(); officialUnknownCount++; } } if ( officialUnknownCount > 0 ) { var displayForm = new StringDisplayForm( String.Format("{0} LAO official elections result missing", officialUnknownCount), officialUnknownBuilder.ToString()); displayForm.Show(); } }
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(); }