private static void CalculateTimeBetweenLocalElection(UInt32 geocode, FrequencyCounter counter) { var fullChangwat = GlobalData.GetGeocodeList(geocode); foreach ( var item in fullChangwat.FlatList() ) { foreach ( var office in item.office ) { office.council.SortByDate(); CouncilTerm lastTerm = null; foreach ( var term in office.council.CouncilTerms ) { if ( lastTerm != null ) { if ( lastTerm.endSpecified ) { var interregnum = term.begin - lastTerm.end; counter.IncrementForCount(interregnum.Days, item.geocode); } } lastTerm = term; } } } }
protected override void Clear() { base.Clear(); _daysBetweenPublicationAndEffective = new FrequencyCounter(); _daysBetweenSignAndPublication = new FrequencyCounter(); _strangeAnnouncements.Clear(); }
public static String StatisticsText(FrequencyCounter counter) { StringBuilder builder = new StringBuilder(); Int32 lCount = counter.NumberOfValues; builder.AppendLine(lCount.ToString() + " Tambon"); builder.AppendLine(Math.Round(counter.MeanValue * lCount).ToString() + " Muban"); builder.AppendLine(); builder.AppendLine(counter.MeanValue.ToString("F2", CultureInfo.InvariantCulture) + " Muban per Tambon"); builder.AppendLine(counter.MaxValue.ToString() + " Muban per Tambon max."); String tambonCodes = String.Empty; if ( counter.MaxValue != 0 ) { foreach ( var lEntry in counter.Data[counter.MaxValue] ) { tambonCodes = tambonCodes + lEntry.ToString() + ", "; } } if ( tambonCodes.Length > 0 ) { builder.AppendLine(tambonCodes.Substring(0, tambonCodes.Length - 2)); } String result = builder.ToString(); return result; }
protected override void Clear() { base.Clear(); mCreationsPerAnnouncement = new FrequencyCounter(); mNumberOfCreationsPerChangwat = new Int32[100]; mNumberOfCreations = 0; }
protected override void Clear() { base.Clear(); mDaysBetweenPublicationAndEffective = new FrequencyCounter(); mDaysBetweenSignAndPublication = new FrequencyCounter(); StrangeAnnouncements = new RoyalGazetteList(); }
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; }
protected override void Clear() { base.Clear(); _newNameSuffix = new Dictionary<string, Int32>(); _newNamePrefix = new Dictionary<string, Int32>(); _highestMubanNumber = new FrequencyCounter(); _creationsWithoutParentName = 0; }
public static void Statistics(PopulationDataEntry changwat, FrequencyCounter counter) { foreach ( PopulationDataEntry amphoe in changwat.SubEntities ) { foreach ( PopulationDataEntry tambon in amphoe.SubEntities ) { Int32 lNumberOfMuban = tambon.SubEntities.Count; counter.IncrementForCount(lNumberOfMuban, tambon.Geocode); } } }
private static void CountCouncilElectionWeekday(UInt32 geocode, FrequencyCounter counter) { var fullChangwat = GlobalData.GetGeocodeList(geocode); foreach ( var item in fullChangwat.FlatList() ) { foreach ( var office in item.office ) { foreach ( var term in office.council.CouncilTerms ) { counter.IncrementForCount((Int32)term.begin.DayOfWeek, item.geocode); } } } }
private static void CountCouncilElectionDate(UInt32 geocode, FrequencyCounter counter) { var zeroDate = new DateTime(2000, 1, 1); var fullChangwat = GlobalData.GetGeocodeList(geocode); foreach ( var item in fullChangwat.FlatList() ) { foreach ( var office in item.office ) { foreach ( var term in office.council.CouncilTerms ) { var span = term.begin - zeroDate; counter.IncrementForCount(span.Days, item.geocode); } } } }
private static void CountNayokElectionDate(UInt32 geocode, FrequencyCounter counter) { var zeroDate = new DateTime(2000, 1, 1); var fullChangwat = GlobalData.GetGeocodeList(geocode); foreach ( var item in fullChangwat.FlatList() ) { foreach ( var office in item.office ) { if ( office.officials != null ) { foreach ( var officialTerm in office.officials.OfficialTerms ) { if ( officialTerm.beginreason == OfficialBeginType.ElectedDirectly ) { var span = officialTerm.begin - zeroDate; counter.IncrementForCount(span.Days, item.geocode); } } } } } }
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 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 UpdateList() { IEnumerable<PopulationDataEntry> list = CalculateList(); PopulationDataEntry compare = FindCompare(); List<Tuple<Int32, Int32, Double>> populationChanges = null; if ( compare != null ) { populationChanges = CalcPopulationChanges(list, compare).ToList(); } FillListView(list, populationChanges); FrequencyCounter counter = new FrequencyCounter(); foreach ( var entry in list ) { counter.IncrementForCount(entry.Total, entry.Geocode); } StringBuilder builder = new StringBuilder(); builder.AppendLine("Total population: " + counter.SumValue.ToString("##,###,##0")); builder.AppendLine("Number of entities: " + counter.NumberOfValues.ToString()); builder.AppendLine("Mean population: " + counter.MeanValue.ToString("##,###,##0.0")); builder.AppendLine("Maximum population: " + counter.MaxValue.ToString("##,###,##0")); builder.AppendLine("Minimum population: " + counter.MinValue.ToString("##,###,##0")); if ( (populationChanges != null) && (populationChanges.Any(x => x.Item2 != 0)) ) { builder.AppendLine(); populationChanges.Sort((x, y) => y.Item2.CompareTo(x.Item2)); var winner = populationChanges.First(); var winnerEntry = list.First(x => x.Geocode == winner.Item1); var looser = populationChanges.Last(); var looserEntry = list.First(x => x.Geocode == looser.Item1); builder.AppendLine("Biggest winner: " + winner.Item2.ToString("##,###,##0") + " by " + winnerEntry.English + " (" + winner.Item1 + ")"); builder.AppendLine("Biggest looser: " + looser.Item2.ToString("##,###,##0") + " by " + looserEntry.English + " (" + looser.Item1 + ")"); } if ( (populationChanges != null) && (populationChanges.Any(x => x.Item2 != 0)) ) { builder.AppendLine(); populationChanges.Sort((x, y) => y.Item3.CompareTo(x.Item3)); var winner = populationChanges.First(); var winnerEntry = list.First(x => x.Geocode == winner.Item1); var looser = populationChanges.Last(); var looserEntry = list.First(x => x.Geocode == looser.Item1); builder.AppendLine("Biggest winner: " + winner.Item3.ToString("##0.00") + "% by " + winnerEntry.English + " (" + winner.Item1 + ")"); builder.AppendLine("Biggest looser: " + looser.Item3.ToString("##0.00") + "% by " + looserEntry.English + " (" + looser.Item1 + ")"); } txtStatistics.Text = builder.ToString(); }
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 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(); }
protected override void Clear() { base.Clear(); _numberOfSubEntities = new FrequencyCounter(); _numberOfParentEntities = new FrequencyCounter(); _creationsPerParent = new Dictionary<UInt32, Int32>(); }
public static FrequencyCounter Statistics(PopulationDataEntry changwat) { FrequencyCounter counter = new FrequencyCounter(); Statistics(changwat, counter); return counter; }