/// <summary> /// Checks the difference between this and <paramref name="compare"/>. /// </summary> /// <param name="compare">Data to compare with.</param> /// <returns>Maximum deviation between the two data points.</returns> /// <exception cref="ArgumentNullException"><paramref name="compare"/> is <c>null</c>.</exception> public Int32 MaxDeviation(PopulationDataPoint compare) { if (compare == null) { throw new ArgumentNullException("compare"); } Int32 maleError = Math.Abs(this.male - compare.male); if ((this.male == 0) || (compare.male == 0)) { maleError = 0; } Int32 femaleError = Math.Abs(this.female - compare.female); if ((this.female == 0) || (compare.female == 0)) { femaleError = 0; } Int32 totalError = Math.Abs(this.total - compare.total); if ((this.total == 0) || (compare.total == 0)) { totalError = 0; } return(Math.Max(Math.Max(maleError, femaleError), totalError)); }
private Boolean IsEqual(PopulationDataPoint data) { return ((this.female == data.female) && (this.male == data.male) && (this.total == data.total)); }
private void FillListView(IEnumerable <Entity> entityList, IEnumerable <Tuple <UInt32, Int32, Double> > compare) { lvData.BeginUpdate(); lvData.Items.Clear(); if (entityList.Any()) { foreach (var entity in entityList) { ListViewItem listViewItem = lvData.Items.Add(entity.english); listViewItem.SubItems.Add(entity.name); listViewItem.SubItems.Add(entity.geocode.ToString(CultureInfo.CurrentUICulture)); PopulationDataPoint populationDataPoint = entity.GetPopulationDataPoint(PopulationDataSource, PopulationReferenceYear); listViewItem.SubItems.Add(populationDataPoint.total.ToString(CultureInfo.CurrentUICulture)); if (compare != null) { var compareEntry = compare.FirstOrDefault(x => x.Item1 == entity.geocode); if (compareEntry != null) { listViewItem.SubItems.Add(compareEntry.Item2.ToString(CultureInfo.CurrentUICulture)); listViewItem.SubItems.Add(compareEntry.Item3.ToString("##0.00", CultureInfo.CurrentUICulture)); } } } } lvData.EndUpdate(); }
/// <summary> /// Adds the values from <paramref name="data"/> to self. /// </summary> /// <param name="data">Data to add.</param> public void Add(PopulationDataPoint data) { if (data == null) { throw new ArgumentNullException("data"); } this.female += data.female; this.male += data.male; this.total += data.total; }
/// <summary> /// Calculates the maximum deviation of the sum of the partial data point. /// </summary> /// <returns>Maximum deviation, <c>0</c> if all parts sum up correctly.</returns> public Int32 SumError() { Int32 maxError = 0; var validData = data.Where(x => x.valid); // DOPA data can contain more than one municipal entry with different geocodes PopulationDataPoint municipal = null; var municipalData = validData.Where(x => x.type == PopulationDataType.municipal); if (municipalData.Any()) { municipal = new PopulationDataPoint(); foreach (var dataPoint in municipalData) { municipal.Add(dataPoint); } } var rural = validData.FirstOrDefault(x => x.type == PopulationDataType.nonmunicipal); if ((municipal != null) && (rural != null)) { maxError = Math.Max(maxError, TotalPopulation.SumError(municipal, rural)); } var collectivehouseholds = validData.FirstOrDefault(x => x.type == PopulationDataType.collectivehouseholds); var privatehouseholds = validData.FirstOrDefault(x => x.type == PopulationDataType.privatehouseholds); if ((collectivehouseholds != null) && (privatehouseholds != null)) { maxError = Math.Max(maxError, TotalPopulation.SumError(collectivehouseholds, privatehouseholds)); } var agricultural = validData.FirstOrDefault(x => x.type == PopulationDataType.agricultural); var nonagricultural = validData.FirstOrDefault(x => x.type == PopulationDataType.nonagricultural); if ((agricultural != null) && (nonagricultural != null)) { maxError = Math.Max(maxError, TotalPopulation.SumError(agricultural, nonagricultural)); } var sanitary = validData.FirstOrDefault(x => x.type == PopulationDataType.sanitary); var urbanSanitary = validData.FirstOrDefault(x => x.type == PopulationDataType.urbansanitary); var ruralSanitary = validData.FirstOrDefault(x => x.type == PopulationDataType.ruralsanitary); if ((urbanSanitary != null) && (ruralSanitary != null) && (sanitary != null)) { maxError = Math.Max(maxError, sanitary.SumError(urbanSanitary, ruralSanitary)); } var thai = validData.FirstOrDefault(x => x.type == PopulationDataType.thai); var foreigner = validData.FirstOrDefault(x => x.type == PopulationDataType.foreigner); if ((thai != null) && (foreigner != null)) { maxError = Math.Max(maxError, TotalPopulation.SumError(thai, foreigner)); } return(maxError); }
/// <summary> /// Creates a new instance of HouseholdDataPoint. /// </summary> public HouseholdDataPoint() { this.geocodeField = new List <uint>(); this.movingField = new PopulationDataPoint(); this.houseregisterField = new PopulationDataPoint(); this.foreignerField = new PopulationDataPoint(); this.agetableField = new AgeTable(); this.dataField = new List <HouseholdDataPoint>(); this.typeField = PopulationDataType.undefined; this.householdsField = 0; }
/// <summary> /// Checks whether the two population data added together are equal with this. /// </summary> /// <param name="data1">First datapoint.</param> /// <param name="data2">Second datapoint.</param> /// <returns>Maximum deviation in one of the sum, <c>0</c> if equal.</returns> public Int32 SumError(PopulationDataPoint data1, PopulationDataPoint data2) { var sum = new PopulationDataPoint(); if (data1 != null) { sum.Add(data1); } if (data2 != null) { sum.Add(data2); } return(this.MaxDeviation(sum)); }
/// <summary> /// Checks the difference between this and <paramref name="compare"/>. /// </summary> /// <param name="compare">Data to compare with.</param> /// <returns>Maximum deviation between the two data points.</returns> /// <exception cref="ArgumentNullException"><paramref name="compare"/> is <c>null</c>.</exception> public Int32 MaxDeviation(PopulationDataPoint compare) { if (compare == null) { throw new ArgumentNullException("compare"); } return(Math.Max( Math.Abs(this.total - compare.total), Math.Max( Math.Abs(this.male - compare.male), Math.Abs(this.female - compare.female)) )); }
public Boolean IsEqual(PopulationDataPoint data) { if (data == null) { throw new ArgumentNullException("data"); } var diffFemale = this.female - data.female; var diffMale = this.male - data.male; var diffTotal = this.total - data.total; return ((this.female == data.female) && (this.male == data.male) && (this.total == data.total)); }
/// <summary> /// Checks whether the <see cref="agetable"/> fits to self. /// </summary> /// <returns><c>true</c> if age table if valid, <c>false</c> otherwise.</returns> /// <remarks>Also returns <c>true</c> if there is no age table.</remarks> public Boolean AgeTableValid() { var result = true; if (agetable != null && agetable.age.Any()) { var ageSum = new PopulationDataPoint(); foreach (var ageEntry in agetable.age) { ageSum.Add(ageEntry); } ageSum.Add(agetable.unknown); result &= ageSum.IsEqual(this); } return(result); }
private Boolean IsEqual(PopulationDataPoint data) { return (this.female == data.female) && (this.male == data.male) && (this.total == data.total); }
private void Add(PopulationDataPoint data) { this.female += data.female; this.male += data.male; this.total += data.total; }
/// <summary> /// Checks whether the two population data added together are equal with this. /// </summary> /// <param name="data1">First datapoint.</param> /// <param name="data2">Second datapoint.</param> /// <returns><c>true</c> if equal, <c>false</c> otherwise.</returns> public Boolean VerifySum(PopulationDataPoint data1, PopulationDataPoint data2) { return this.SumError(data1, data2) == 0; }
/// <summary> /// Checks whether the two population data added together are equal with this. /// </summary> /// <param name="data1">First datapoint.</param> /// <param name="data2">Second datapoint.</param> /// <returns>Maximum deviation in one of the sum, <c>0</c> if equal.</returns> public Int32 SumError(PopulationDataPoint data1, PopulationDataPoint data2) { var sum = new PopulationDataPoint(); if ( data1 != null ) { sum.Add(data1); } if ( data2 != null ) { sum.Add(data2); } return this.MaxDeviation(sum); }
/// <summary> /// Checks the difference between this and <paramref name="compare"/>. /// </summary> /// <param name="compare">Data to compare with.</param> /// <returns>Maximum deviation between the two data points.</returns> /// <exception cref="ArgumentNullException"><paramref name="compare"/> is <c>null</c>.</exception> public Int32 MaxDeviation(PopulationDataPoint compare) { if ( compare == null ) { throw new ArgumentNullException("compare"); } return Math.Max( Math.Abs(this.total - compare.total), Math.Max( Math.Abs(this.male - compare.male), Math.Abs(this.female - compare.female)) ); }
/// <summary> /// Creates a new instance of AgeTable. /// </summary> public AgeTable() { this.unknownField = new PopulationDataPoint(); this.ageField = new List<AgeTableEntry>(); }
/// <summary> /// Creates a new instance of AgeTable. /// </summary> public AgeTable() { this.unknownField = new PopulationDataPoint(); this.ageField = new List <AgeTableEntry>(); }
/// <summary> /// Checks whether the two population data added together are equal with this. /// </summary> /// <param name="data1">First datapoint.</param> /// <param name="data2">Second datapoint.</param> /// <returns><c>true</c> if equal, <c>false</c> otherwise.</returns> public Boolean VerifySum(PopulationDataPoint data1, PopulationDataPoint data2) { return(this.SumError(data1, data2) == 0); }
/// <summary> /// Checks whether data has less or equal data. /// </summary> /// <param name="data">Data point.</param> /// <returns><c>true</c> if less or equal, <c>false</c> otherwise.</returns> public Boolean VerifyLessOrEqual(PopulationDataPoint data) { return(this.total <= data.total && this.male <= data.male && this.female <= data.female); }