/// <summary>
        /// Calculate current group statistics
        /// </summary>
        public void CalculateGroupStatistics()
        {
            List <int> mathData    = new List <int>();
            List <int> physicsData = new List <int>();
            List <int> englishData = new List <int>();

            foreach (Student item in Students)
            {
                mathData.Add(item.Math);
                physicsData.Add(item.Physics);
                englishData.Add(item.English);
            }

            Statistics.Add("Math", new Statistic(StatisticHelper.Mode(mathData), StatisticHelper.Median(mathData), StatisticHelper.SimpleAverage(mathData)));
            Statistics.Add("Physics", new Statistic(StatisticHelper.Mode(physicsData), StatisticHelper.Median(physicsData), StatisticHelper.SimpleAverage(physicsData)));
            Statistics.Add("English", new Statistic(StatisticHelper.Mode(englishData), StatisticHelper.Median(englishData), StatisticHelper.SimpleAverage(englishData)));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///  Calculate statistics for all data, using StatisticHelper class for mode,median and average calculations
        /// </summary>
        public void CalculateDataStatistics()
        {
            List <int> mData = new List <int>();
            List <int> pData = new List <int>();
            List <int> eData = new List <int>();

            foreach (Group item in Groups.Values)
            {
                for (int i = 0; i < item.GetStudentsCount; i++)
                {
                    mData.Add(item.GetStudent(i).Math);
                    pData.Add(item.GetStudent(i).Physics);
                    eData.Add(item.GetStudent(i).English);
                }
            }


            Statistics.Add("Math", new Statistic(StatisticHelper.Mode(mData), StatisticHelper.Median(mData), StatisticHelper.SimpleAverage(mData)));
            Statistics.Add("Physics", new Statistic(StatisticHelper.Mode(pData), StatisticHelper.Median(pData), StatisticHelper.SimpleAverage(pData)));
            Statistics.Add("English", new Statistic(StatisticHelper.Mode(eData), StatisticHelper.Median(eData), StatisticHelper.SimpleAverage(eData)));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Method that gets data from file and process it
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public bool ProcessExaminationData(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                Console.WriteLine("\r\nThere is no path");
                return(false);
            }

            if (!File.Exists(filePath))
            {
                Console.WriteLine("\r\nFile with data does not exist, please put 'examination.txt' into the Desktop folder");
                return(false);
            }

            string[] lines = File.ReadAllLines(filePath);

            if (lines.Length == 0)
            {
                return(false);
            }

            int GroupCount = 0;

            foreach (string item in lines)
            {
                string[] line = item.Split(';');

                if (line.Length == 1)
                {
                    if (line[0].ToLower().Contains("group"))
                    {
                        GroupCount++;
                        ExaminationData.InsertGroup(GroupPrefix + GroupCount, new Group());
                    }

                    continue;
                }

                int math    = Int16.Parse(Regex.Match(line[1], @"\d+").Value);
                int physics = Int16.Parse(Regex.Match(line[2], @"\d+").Value);
                int english = Int16.Parse(Regex.Match(line[3], @"\d+").Value);

                ExaminationData.InserStudentToGroup(GroupPrefix + GroupCount, new Student(line[0], math, physics, english, StatisticHelper.CalculateWeightedAverage(math, physics, english)));
            }

            CalculateGroupSubjectsStatistics();
            CalculateWholeDataStatistics();

            return(true);
        }