public static Dictionary <PopulationDataEntry, Int32> Calculate(Int32 parentGeocode, Int32 year, Int32 numberOfSeats) { Dictionary <PopulationDataEntry, Int32> retval = null; PopulationData downloader = new PopulationData(year, parentGeocode); downloader.Process(); retval = Calculate(downloader.Data, year, numberOfSeats); return(retval); }
private PopulationDataEntry GetPopulationData(Int32 year) { PopulationDataEntry data = GetPopulationDataFromCache(year); if (data == null) { PopulationData downloader = new PopulationData(year, 0); downloader.Process(); data = downloader.Data; StorePopulationDataToCache(data, year); } return(data); }
private void ProcessAllProvinces() { PopulationDataEntry data = new PopulationDataEntry(); foreach (PopulationDataEntry entry in TambonHelper.ProvinceGeocodes) { PopulationData tempCalculator = new PopulationData(Year, entry.Geocode); tempCalculator.Process(); data.SubEntities.Add(tempCalculator.Data); } data.CalculateNumbersFromSubEntities(); _changwat = data; }
public static PopulationDataEntry GetCountryPopulationData(Int32 year) { PopulationDataEntry country = null; if (TambonHelper.PopulationDataByYear.Keys.Contains(year)) { country = TambonHelper.PopulationDataByYear[year]; } else { PopulationData downloader = new PopulationData(year, 0); downloader.Process(); downloader.ReOrderThesaban(); country = downloader.Data; TambonHelper.PopulationDataByYear[year] = country; } return(country); }
private void btnCalc_Click(Object sender, EventArgs e) { Int32 year = Convert.ToInt32(edtYear.Value); Int32 numberOfConstituencies = Convert.ToInt32(edtNumberOfConstituencies.Value); Int32 geocode = 0; PopulationDataEntry data = null; if ( rbxNational.Checked ) { data = GetPopulationData(year); } if ( rbxProvince.Checked ) { var province = (PopulationDataEntry)cbxProvince.SelectedItem; geocode = province.Geocode; PopulationData downloader = new PopulationData(year, geocode); downloader.Process(); data = downloader.Data; } if ( rbxNational.Checked && chkBuengKan.Checked ) { ModifyPopulationDataForBuengKan(data); } data.SortSubEntitiesByEnglishName(); Dictionary<PopulationDataEntry, Int32> result = ConstituencyCalculator.Calculate(data, year, numberOfConstituencies); if ( chkRegions.Checked ) { List<PopulationDataEntry> regions = TambonHelper.GetRegionBySchemeName(cbxRegion.Text); Dictionary<PopulationDataEntry, Int32> regionResult = new Dictionary<PopulationDataEntry, Int32>(); foreach ( PopulationDataEntry region in regions ) { Int32 constituencies = 0; List<PopulationDataEntry> subList = new List<PopulationDataEntry>(); foreach ( PopulationDataEntry province in region.SubEntities ) { PopulationDataEntry foundEntry = data.FindByCode(province.Geocode); if ( foundEntry != null ) { constituencies = constituencies + result[foundEntry]; subList.Add(foundEntry); } } region.SubEntities.Clear(); region.SubEntities.AddRange(subList); region.CalculateNumbersFromSubEntities(); regionResult.Add(region, constituencies); } result = regionResult; } String displayResult = String.Empty; foreach ( KeyValuePair<PopulationDataEntry, Int32> entry in result ) { Int32 votersPerSeat = 0; if ( entry.Value != 0 ) { votersPerSeat = entry.Key.Total / entry.Value; } displayResult = displayResult + String.Format("{0} {1} ({2} per seat)", entry.Key.English, entry.Value, votersPerSeat) + Environment.NewLine; } txtData.Text = displayResult; _lastCalculation = result; btnSaveCsv.Enabled = true; }
private PopulationDataEntry GetPopulationData(Int32 year) { PopulationDataEntry data = GetPopulationDataFromCache(year); if ( data == null ) { PopulationData downloader = new PopulationData(year, 0); downloader.Process(); data = downloader.Data; StorePopulationDataToCache(data, year); } return data; }
private void btnCalc_Click(Object sender, EventArgs e) { Int32 year = Convert.ToInt32(edtYear.Value); Int32 numberOfConstituencies = Convert.ToInt32(edtNumberOfConstituencies.Value); Int32 geocode = 0; PopulationDataEntry data = null; if (rbxNational.Checked) { data = GetPopulationData(year); } if (rbxProvince.Checked) { var province = (PopulationDataEntry)cbxProvince.SelectedItem; geocode = province.Geocode; PopulationData downloader = new PopulationData(year, geocode); downloader.Process(); data = downloader.Data; } if (rbxNational.Checked && chkBuengKan.Checked) { ModifyPopulationDataForBuengKan(data); } data.SortSubEntitiesByEnglishName(); Dictionary <PopulationDataEntry, Int32> result = ConstituencyCalculator.Calculate(data, year, numberOfConstituencies); if (chkRegions.Checked) { List <PopulationDataEntry> regions = TambonHelper.GetRegionBySchemeName(cbxRegion.Text); Dictionary <PopulationDataEntry, Int32> regionResult = new Dictionary <PopulationDataEntry, Int32>(); foreach (PopulationDataEntry region in regions) { Int32 constituencies = 0; List <PopulationDataEntry> subList = new List <PopulationDataEntry>(); foreach (PopulationDataEntry province in region.SubEntities) { PopulationDataEntry foundEntry = data.FindByCode(province.Geocode); if (foundEntry != null) { constituencies = constituencies + result[foundEntry]; subList.Add(foundEntry); } } region.SubEntities.Clear(); region.SubEntities.AddRange(subList); region.CalculateNumbersFromSubEntities(); regionResult.Add(region, constituencies); } result = regionResult; } String displayResult = String.Empty; foreach (KeyValuePair <PopulationDataEntry, Int32> entry in result) { Int32 votersPerSeat = 0; if (entry.Value != 0) { votersPerSeat = entry.Key.Total / entry.Value; } displayResult = displayResult + String.Format("{0} {1} ({2} per seat)", entry.Key.English, entry.Value, votersPerSeat) + Environment.NewLine; } txtData.Text = displayResult; _lastCalculation = result; btnSaveCsv.Enabled = true; }
public static PopulationDataEntry GetCountryPopulationData(Int32 year) { PopulationDataEntry country = null; if ( TambonHelper.PopulationDataByYear.Keys.Contains(year) ) { country = TambonHelper.PopulationDataByYear[year]; } else { PopulationData downloader = new PopulationData(year, 0); downloader.Process(); downloader.ReOrderThesaban(); country = downloader.Data; TambonHelper.PopulationDataByYear[year] = country; } return country; }