Example #1
0
        public WeightStatistics ComputeStatistics()
        {
            WeightStatistics stats = new WeightStatistics();
            float            start = weights.FirstOrDefault();
            int   weightsCount     = weights.Count() - 1;
            float last             = weights.LastOrDefault();

            foreach (float weight in weights)
            {
                stats.HighestWeight = Math.Max(weight, stats.HighestWeight);
                stats.LowestWeight  = Math.Min(weight, stats.LowestWeight);
            }

            stats.LostWeight    = start - last;
            stats.AverageWeight = stats.LostWeight / weightsCount;
            stats.Startweight   = start;
            stats.Startdate     = dates.FirstOrDefault();
            stats.LatestWeight  = last;

            return(stats);
        }
Example #2
0
        private static bool ShowStatistics()
        {
            Console.Clear();
            Console.WriteLine();
            Console.WriteLine("  Weight Plan Statistics: ");
            Console.WriteLine();

            Console.Write("  Enter your name: ");
            string bookName = Console.ReadLine();

            //Read info from "WeightBook(bookName).txt" file.
            try
            {
                WeightBook book        = new WeightBook();
                float      startWeight = book.ReadStartWeight(bookName);
                string     startDate   = book.ReadStartDate(bookName);
                string     latestDate  = book.dates.LastOrDefault();
                int        count       = (book.dates.Count() - 1);

                WeightStatistics stats = book.ComputeStatistics();

                /*Console.WriteLine("  Stored Data: ");     //Tabel
                 *
                 * DataTable storedData = new DataTable();
                 * storedData.Columns.Add(" Dates ");
                 * storedData.Columns.Add(" Weights ");
                 * string passDate = " ";
                 * foreach (string date in book.dates)
                 * {
                 *
                 *  for (int i = 0; i < (book.dates.Count() - 1); i++)
                 *  {
                 *      passDate = book.dates[i];
                 *  }
                 *  storedData.Rows.Add(passDate);
                 * }
                 *
                 * Console.WriteLine("  " + storedData);*/
                Console.WriteLine();
                Console.Write("  Start Weight   :   {0:f2}", startWeight);
                Console.WriteLine(" at " + startDate);
                Console.Write("  Latest weight  :   {0:f2}", stats.LatestWeight);
                Console.WriteLine(" at " + latestDate);
                Console.WriteLine();
                Console.WriteLine("  Highest weight :   {0:f2}", stats.HighestWeight);
                Console.WriteLine("  Lowest weight  :   {0:f2}", stats.LowestWeight);
                Console.Write("  Lost weight    :   {0:f2}", stats.LostWeight);
                Console.WriteLine(" lost over {0} weeks ", count);
                Console.Write("  Average        :   {0:f2}", stats.AverageWeight);
                Console.WriteLine(" a week ");
                Console.WriteLine();

                Console.WriteLine();

                return(Back());
            }
            catch (Exception)
            {
                Console.WriteLine("  A WeightBook with this name could not be found. ");
                return(Back());
            }
        }