Ejemplo n.º 1
0
 private static void CentroidTest(DataTable tableOutput, CentroidDistanceGenerator generator)
 {
     var average = generator.AverageDistance(tableOutput, new EastingNorthingColumnIndexer(0, 1));
     Console.WriteLine(string.Format("Average distance from centroid: {0}", average));
     Console.WriteLine("Press any key to exit");
     Console.ReadKey();
 }
        /// <summary>
        /// For each date in the specified period calculate and return the average distance from the group centroid
        /// </summary>
        /// <returns>List of average distances by day</returns>
        public List<double> GetAverageDistances()
        {
            var performance = new List<double>();

            var generator = new CentroidDistanceGenerator(new PythagoreanCalculator());

            foreach (DateTime day in EachDay(period))
            {
                performance.Add(DailyAverage(generator, day));
            }

            return performance;
        }
        /// <summary>
        /// Calculate the average distance from the group centroid on the particular day.
        /// </summary>
        /// <param name="generator">Object that generates the distance from the centroid</param>
        /// <param name="day">Date for calculation</param>
        /// <returns>Average distance from the group centroid for specified day</returns>
        private double DailyAverage(CentroidDistanceGenerator generator, DateTime day)
        {
            DataTable data;
            data = GetData(day);
            var average = generator.AverageDistance(data, new EastingNorthingColumnIndexer(0, 1));

            Console.WriteLine(string.Format("average dist: {0}", average));

            data.Clear();
            data.Dispose();
            data = null;
            return average;
        }