public FrequencyCounter EffectiveDateTillPublication() { FrequencyCounter lCounter = new FrequencyCounter(); foreach (BoardMeetingEntry lEntry in this) { foreach (BoardMeetingTopic lTopic in lEntry.Contents) { if ((lTopic.Gazette != null) && (lTopic.Effective.Year > 2000)) { TimeSpan lDiff = lTopic.TimeTillPublish(); { Int32 lGeocode = lTopic.Topic.Geocode; if (lGeocode == 0) { lGeocode = lTopic.Topic.TambonGeocode; } lCounter.IncrementForCount(lDiff.Days, lGeocode); if ((lDiff.Days < 0) & (!mStrangeEntries.Contains(lTopic))) { mStrangeEntries.Add(lTopic); } } } } } return(lCounter); }
protected override void ProcessAnnouncement(GazetteEntry entry) { Int32 count = 0; UInt32 provinceGeocode = 0; foreach (var content in entry.Items) { var contentBase = content as GazetteOperationBase; if (ContentFitting(contentBase)) { count++; ProcessContent(content as GazetteCreate); provinceGeocode = contentBase.geocode; while (provinceGeocode / 100 != 0) { provinceGeocode = provinceGeocode / 100; } } } if (count > 0) { NumberOfAnnouncements++; _creationsPerAnnouncement.IncrementForCount(count, provinceGeocode); if (entry.effective.Year > 1) { DateTime dummy = new DateTime(2004, entry.effective.Month, entry.effective.Day); Int32 index = dummy.DayOfYear; if (!_effectiveDayOfYear.ContainsKey(index)) { _effectiveDayOfYear[index] = 0; } _effectiveDayOfYear[index]++; } } }
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 ProcessAnnouncement(RoyalGazette iEntry) { Int32 lCount = 0; Int32 lProvinceGeocode = 0; foreach (RoyalGazetteContent lContent in iEntry.Content) { if (ContentFitting(lContent)) { lCount++; ProcessContent(lContent); lProvinceGeocode = lContent.Geocode; while (lProvinceGeocode / 100 != 0) { lProvinceGeocode = lProvinceGeocode / 100; } } } if (lCount > 0) { NumberOfAnnouncements++; mCreationsPerAnnouncement.IncrementForCount(lCount, lProvinceGeocode); if (iEntry.Effective.Year > 1) { DateTime lDummy = new DateTime(2004, iEntry.Effective.Month, iEntry.Effective.Day); Int32 lIndex = lDummy.DayOfYear; if (!mEffectiveDayOfYear.ContainsKey(lIndex)) { mEffectiveDayOfYear[lIndex] = 0; } mEffectiveDayOfYear[lIndex]++; } } }
public FrequencyCounter MissingConstituencyAnnouncements() { FrequencyCounter lCounter = new FrequencyCounter(); foreach (BoardMeetingEntry lEntry in this) { foreach (BoardMeetingTopic lTopic in lEntry.Contents) { if ((lTopic.Gazette == null) & (lTopic.Topic.GetType() == typeof(RoyalGazetteContentStatus))) { TimeSpan lDiff = DateTime.Now - lEntry.Date; { Int32 lGeocode = lTopic.Topic.Geocode; if (lGeocode == 0) { lGeocode = lTopic.Topic.TambonGeocode; } lCounter.IncrementForCount(lDiff.Days, lGeocode); } } } } return(lCounter); }
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; }
static public 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); } } }
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); } } }
protected override void ProcessContent(GazetteCreate content) { base.ProcessContent(content); UInt32 mubanNumber = content.geocode % 100; if (mubanNumber != content.geocode) { _highestMubanNumber.IncrementForCount(Convert.ToInt32(mubanNumber), content.geocode); } ProcessContentForName(content); }
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(); }
protected override void ProcessContent(RoyalGazetteContent iContent) { base.ProcessContent(iContent); RoyalGazetteContentCreate lCreate = (RoyalGazetteContentCreate)iContent; Int32 lMubanNumber = lCreate.Geocode % 100; if (lMubanNumber != lCreate.Geocode) { mHighestMubanNumber.IncrementForCount(lMubanNumber, lCreate.Geocode); } ProcessContentForName(lCreate); }
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); } } } }
protected override void ProcessContent(GazetteCreate content) { base.ProcessContent(content); var create = content as GazetteCreate; UInt32 parentGeocode = create.geocode / 100; if (!_creationsPerParent.ContainsKey(parentGeocode)) { _creationsPerParent.Add(parentGeocode, 0); } _creationsPerParent[parentGeocode]++; Int32 maxSubEntityIndex = 0; List <UInt32> parentEntities = new List <UInt32>(); foreach (GazetteOperationBase subEntry in create.Items) { var createSubEntry = subEntry as GazetteCreate; if (createSubEntry != null) { maxSubEntityIndex++; } var reassignSubEntry = subEntry as GazetteReassign; if (reassignSubEntry != null) { maxSubEntityIndex++; UInt32 parentEntityCode = reassignSubEntry.oldgeocode / 100; if (!parentEntities.Contains(parentEntityCode)) { parentEntities.Add(parentEntityCode); } } } _numberOfSubEntities.IncrementForCount(maxSubEntityIndex, create.geocode); if (parentEntities.Any()) { _numberOfParentEntities.IncrementForCount(parentEntities.Count, create.geocode); } }
protected override void ProcessContent(RoyalGazetteContent iContent) { base.ProcessContent(iContent); RoyalGazetteContentCreate lCreate = (RoyalGazetteContentCreate)iContent; Int32 lParentGeocode = lCreate.Geocode / 100; if (!mCreationsPerParent.ContainsKey(lParentGeocode)) { mCreationsPerParent.Add(lParentGeocode, 0); } mCreationsPerParent[lParentGeocode]++; Int32 lMaxSubEntityIndex = 0; List <Int32> lParentEntities = new List <Int32>(); foreach (RoyalGazetteContent lSubEntry in lCreate.SubEntries) { if (lSubEntry is RoyalGazetteContentCreate) { lMaxSubEntityIndex++; } if (lSubEntry is RoyalGazetteContentReassign) { lMaxSubEntityIndex++; RoyalGazetteContentReassign lReassign = (RoyalGazetteContentReassign)lSubEntry; Int32 lParentEntityCode = lReassign.OldGeocode / 100; if (!lParentEntities.Contains(lParentEntityCode)) { lParentEntities.Add(lParentEntityCode); } } } mNumberOfSubEntities.IncrementForCount(lMaxSubEntityIndex, lCreate.Geocode); if (lParentEntities.Any()) { mNumberOfParentEntities.IncrementForCount(lParentEntities.Count, lCreate.Geocode); } }
protected override void ProcessAnnouncement(GazetteEntry entry) { Int32 warningOffsetDays = 345; Boolean processed = false; if (entry.publication.Year > 1) { if (entry.effective.Year > 1) { processed = true; TimeSpan timeBetweenPublicationAndEffective = entry.publication.Subtract(entry.effective); _daysBetweenPublicationAndEffective.IncrementForCount(timeBetweenPublicationAndEffective.Days, 0); if (Math.Abs(timeBetweenPublicationAndEffective.Days) > warningOffsetDays) { _strangeAnnouncements.Add(entry); } } if (entry.sign.Year > 1) { processed = true; TimeSpan timeBetweenSignAndPublication = entry.publication.Subtract(entry.sign); _daysBetweenSignAndPublication.IncrementForCount(timeBetweenSignAndPublication.Days, 0); if ((timeBetweenSignAndPublication.Days < 0) | (timeBetweenSignAndPublication.Days > warningOffsetDays)) { if (!StrangeAnnouncements.Contains(entry)) { _strangeAnnouncements.Add(entry); } } } if (processed) { NumberOfAnnouncements++; } } }
protected override void ProcessAnnouncement(RoyalGazette iEntry) { Int32 lWarningOffsetDays = 345; Boolean lProcessed = false; if (iEntry.Publication.Year > 1) { if (iEntry.Effective.Year > 1) { lProcessed = true; TimeSpan iTime = iEntry.Publication.Subtract(iEntry.Effective); mDaysBetweenPublicationAndEffective.IncrementForCount(iTime.Days, 0); if (Math.Abs(iTime.Days) > lWarningOffsetDays) { StrangeAnnouncements.Add(iEntry); } } if (iEntry.Sign.Year > 1) { lProcessed = true; TimeSpan iTime = iEntry.Publication.Subtract(iEntry.Sign); mDaysBetweenSignAndPublication.IncrementForCount(iTime.Days, 0); if ((iTime.Days < 0) | (iTime.Days > lWarningOffsetDays)) { if (!StrangeAnnouncements.Contains(iEntry)) { StrangeAnnouncements.Add(iEntry); } } } if (lProcessed) { NumberOfAnnouncements++; } } }
/// <summary> /// Updates the calculated data. /// </summary> private void UpdateList() { IEnumerable <Entity> list = CalculateList(); IEnumerable <Tuple <UInt32, Int32, Double> > populationChanges = null; if (chkCompare.Checked) { populationChanges = CalcPopulationChanges(list, Convert.ToInt16(edtCompareYear.Value)); } FillListView(list, populationChanges); FrequencyCounter counter = new FrequencyCounter(); foreach (var entity in list) { var populationData = entity.GetPopulationDataPoint(PopulationDataSource, PopulationReferenceYear); counter.IncrementForCount(populationData.total, entity.geocode); } StringBuilder builder = new StringBuilder(); builder.AppendFormat(CultureInfo.CurrentUICulture, "Total population: {0:##,###,##0}", counter.SumValue); builder.AppendLine(); builder.AppendFormat(CultureInfo.CurrentUICulture, "Number of entities: {0}", counter.NumberOfValues); builder.AppendLine(); builder.AppendFormat(CultureInfo.CurrentUICulture, "Mean population: {0:##,###,##0.0}", counter.MedianValue); builder.AppendLine(); builder.AppendFormat(CultureInfo.CurrentUICulture, "Standard deviation: {0:##,###,##0.0}", counter.StandardDeviation); builder.AppendLine(); if (list.Any()) { var maxEntity = list.Last(); builder.AppendFormat(CultureInfo.CurrentUICulture, "Maximum population: {0:##,###,##0} ({1} - {2})", counter.MaxValue, maxEntity.geocode, maxEntity.english); builder.AppendLine(); var minEntity = list.First(); builder.AppendFormat(CultureInfo.CurrentUICulture, "Minimum population: {0:##,###,##0} ({1} - {2})", counter.MinValue, minEntity.geocode, minEntity.english); builder.AppendLine(); } if ((populationChanges != null) && (populationChanges.Any(x => x.Item2 != 0))) { builder.AppendLine(); var ordered = populationChanges.OrderBy(x => x.Item2); var winner = ordered.Last(); var winnerEntry = list.First(x => x.geocode == winner.Item1); var looser = ordered.First(); var looserEntry = list.First(x => x.geocode == looser.Item1); builder.AppendFormat(CultureInfo.CurrentUICulture, "Biggest winner: {0:##,###,##0} by {1} ({2})", winner.Item2, winnerEntry.english, winner.Item1); builder.AppendLine(); builder.AppendFormat(CultureInfo.CurrentUICulture, "Biggest looser: {0:##,###,##0} by {1} ({2})", looser.Item2, looserEntry.english, looser.Item1); builder.AppendLine(); } if ((populationChanges != null) && (populationChanges.Any(x => x.Item2 != 0))) { builder.AppendLine(); var ordered = populationChanges.OrderBy(x => x.Item3); var winner = ordered.Last(); var winnerEntry = list.First(x => x.geocode == winner.Item1); var looser = ordered.First(); var looserEntry = list.First(x => x.geocode == looser.Item1); builder.AppendFormat(CultureInfo.CurrentUICulture, "Biggest winner: {0:##0.00}% by {1} ({2})", winner.Item3, winnerEntry.english, winner.Item1); builder.AppendLine(); builder.AppendFormat(CultureInfo.CurrentUICulture, "Biggest looser: {0:##0.00}% by {1} ({2})", looser.Item3, looserEntry.english, looser.Item1); builder.AppendLine(); } txtStatistics.Text = builder.ToString(); }
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 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 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); }