/// <summary>
 /// Inspects the members of the data Table, focusing on the named field.  It calculates
 /// the median of the values in the named field.
 /// </summary>
 /// <param name="self"></param>
 /// <param name="fieldName"></param>
 /// <returns></returns>
 public static BoxStatistics GetBoxStatistics(this DataTable self, string fieldName)
 {
     DataColumn dc = self.Columns[fieldName];
     ArrayList lst = new ArrayList();
     foreach (DataRow row in self.Rows)
     {
         lst.Add(row[fieldName]);
     }
     lst.Sort();
     BoxStatistics result = new BoxStatistics();
     if (lst.Count % 2 == 0)
     {
         if (dc.DataType == typeof(string))
         {
         }
         // For an even number of items, the mean is the average of the middle two values (after sorting)
         double high = Convert.ToDouble(lst.Count / 2);
         double low = Convert.ToDouble(lst.Count / 2 - 1);
         result.Median = (high + low) / 2;
     }
     else
     {
         result.Median = lst[(int)Math.Floor(lst.Count / (double)2)];
     }
     return result;
 }
示例#2
0
        /// <summary>
        /// Inspects the members of the data Table, focusing on the named field.  It calculates
        /// the median of the values in the named field.
        /// </summary>
        /// <param name="self"></param>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        public static BoxStatistics GetBoxStatistics(this DataTable self, string fieldName)
        {
            DataColumn dc  = self.Columns[fieldName];
            ArrayList  lst = new ArrayList();

            foreach (DataRow row in self.Rows)
            {
                lst.Add(row[fieldName]);
            }
            lst.Sort();
            BoxStatistics result = new BoxStatistics();

            if (lst.Count % 2 == 0)
            {
                if (dc.DataType == typeof(string))
                {
                }
                // For an even number of items, the mean is the average of the middle two values (after sorting)
                double high = Convert.ToDouble(lst.Count / 2);
                double low  = Convert.ToDouble(lst.Count / 2 - 1);
                result.Median = (high + low) / 2;
            }
            else
            {
                result.Median = lst[(int)Math.Floor(lst.Count / (double)2)];
            }
            return(result);
        }