Beispiel #1
0
        /// <summary>
        /// Calculates the maximum deviation of the sum of the partial datapoint.
        /// </summary>
        /// <returns>Maximum deviation, <c>0</c> if all sum up correctly.</returns>
        public Int32 SumError()
        {
            Int32 maxError  = 0;
            var   municipal = data.FirstOrDefault(x => x.type == PopulationDataType.municipal);
            var   rural     = data.FirstOrDefault(x => x.type == PopulationDataType.nonmunicipal);

            if ((municipal != null) && (rural != null))
            {
                maxError = Math.Max(maxError, TotalPopulation.SumError(municipal, rural));
            }
            var collectivehouseholds = data.FirstOrDefault(x => x.type == PopulationDataType.collectivehouseholds);
            var privatehouseholds    = data.FirstOrDefault(x => x.type == PopulationDataType.privatehouseholds);

            if ((collectivehouseholds != null) && (privatehouseholds != null))
            {
                maxError = Math.Max(maxError, TotalPopulation.SumError(collectivehouseholds, privatehouseholds));
            }
            var agricultural    = data.FirstOrDefault(x => x.type == PopulationDataType.agricultural);
            var nonagricultural = data.FirstOrDefault(x => x.type == PopulationDataType.nonagricultural);

            if ((agricultural != null) && (nonagricultural != null))
            {
                maxError = Math.Max(maxError, TotalPopulation.SumError(agricultural, nonagricultural));
            }
            return(maxError);
        }
Beispiel #2
0
        /// <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);
        }