private void FilterAndTake(Dictionary <string, List <int> > wantedData, Predicate <double> givenFilter, int studentsToTake)
        {
            int counterForPrinted = 0;

            foreach (var userName_Points in wantedData)
            {
                if (counterForPrinted == studentsToTake)
                {
                    break;
                }

                double averageScore            = userName_Points.Value.Average();
                double percentageOfFullfilment = averageScore / 100;
                double mark = percentageOfFullfilment * 4 + 2;

                if (givenFilter(mark))
                {
                    OutputWriter.PrintStudent(userName_Points);
                    counterForPrinted++;
                }
            }
        }
Beispiel #2
0
        private void PrintOutput(string[] mismatches, bool hasMismatch, string mismatchesPath)
        {
            if (hasMismatch)
            {
                foreach (var line in mismatches)
                {
                    OutputWriter.WriteMessageOnNewLine(line);
                }

                try
                {
                    File.WriteAllLines(mismatchesPath, mismatches);
                }
                catch (DirectoryNotFoundException)
                {
                    OutputWriter.DisplayException(ExceptionMessages.InvalidPath);
                }

                return;
            }

            OutputWriter.WriteMessageOnNewLine("Files are identical. There are no mismatches.");
        }
Beispiel #3
0
        public void CompareContent(string userOutputPath, string expectedOutputPath)
        {
            OutputWriter.WriteMessageOnNewLine("Reading files...");

            try
            {
                string mismatchPath = GetMismatchPath(expectedOutputPath);

                string[] actualOutputLines   = File.ReadAllLines(userOutputPath);
                string[] expectedOutputLines = File.ReadAllLines(expectedOutputPath);

                bool     hasMismatch;
                string[] mismatches = GetLinesWithPossibleMismatches(
                    actualOutputLines, expectedOutputLines, out hasMismatch);

                PrintOutput(mismatches, hasMismatch, mismatchPath);
                OutputWriter.WriteMessageOnNewLine("Files read!");
            }
            catch (IOException ex)
            {
                OutputWriter.DisplayException(ex.Message);
            }
        }
Beispiel #4
0
 public void ChangeCurrentDirectoryRelative(string relativePath)
 {
     if (relativePath == "..")
     {
         try
         {
             string currentPath      = SessionData.currentPath;
             int    indexOfLastSlash = currentPath.LastIndexOf("\\");
             string newPath          = currentPath.Substring(0, indexOfLastSlash);
             SessionData.currentPath = newPath;
         }
         catch (ArgumentOutOfRangeException)
         {
             OutputWriter.DisplayException(ExceptionMessages.InvalidDestination);
         }
     }
     else
     {
         string currentPath = SessionData.currentPath;
         currentPath += "\\" + relativePath;
         ChangeCurrentDirectoryAbsolute(currentPath);
     }
 }
        private void ReadData(string fileName)
        {
            string path = SessionData.currentPath + "\\" + fileName;

            if (File.Exists(path))
            {
                OutputWriter.WriteMessageOnNewLine("Reading data...");

                string   pattern       = @"([A-Z][a-zA-Z#\++]*_[A-Z][a-z]{2}_\d{4})\s+([A-Za-z]+\d{2}_\d{2,4})\s([\s0-9]+)";
                Regex    rgx           = new Regex(pattern);
                string[] allInputLines = File.ReadAllLines(path);

                for (int line = 0; line < allInputLines.Length; line++)
                {
                    if (!string.IsNullOrEmpty(allInputLines[line]) && rgx.IsMatch(allInputLines[line]))
                    {
                        Match  currentMatch = rgx.Match(allInputLines[line]);
                        string courseName   = currentMatch.Groups[1].Value;
                        string username     = currentMatch.Groups[2].Value;
                        string scoresStr    = currentMatch.Groups[3].Value;
                        try
                        {
                            int[] scores = scoresStr.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                                           .Select(int.Parse)
                                           .ToArray();

                            if (scores.Any(x => x > 100 || x < 0))
                            {
                                OutputWriter.DisplayException(ExceptionMessages.InvalidScore);
                            }
                            if (scores.Length > Course.NumberOfTasksOnExam)
                            {
                                OutputWriter.DisplayException(ExceptionMessages.InvalidNumberOfScores);
                                continue;
                            }
                            if (!this.students.ContainsKey(username))
                            {
                                this.students.Add(username, new Student(username));
                            }
                            if (!this.courses.ContainsKey(courseName))
                            {
                                this.courses.Add(courseName, new Course(courseName));
                            }
                            Course  course  = this.courses[courseName];
                            Student student = this.students[username];

                            student.EnrollInCourse(course);
                            student.SetMarkOnCourse(courseName, scores);

                            course.EnrollStudent(student);
                        }
                        catch (FormatException fex)
                        {
                            OutputWriter.DisplayException(fex.Message + $"at line: {line}");
                        }

                        //int studentScoreOnTask;
                        //bool hasParsedScore = int.TryParse(currentMatch.Groups[3].Value, out studentScoreOnTask);

                        //if (hasParsedScore && studentScoreOnTask >= 0 && studentScoreOnTask <= 100)
                        //{
                        //    if (!studentsByCourse.ContainsKey(courseName))
                        //    {
                        //        studentsByCourse.Add(courseName, new Dictionary<string, List<int>>());
                        //    }

                        //    if (!studentsByCourse[courseName].ContainsKey(username))
                        //    {
                        //        studentsByCourse[courseName].Add(username, new List<int>());
                        //    }

                        //    studentsByCourse[courseName][username].Add(studentScoreOnTask);
                        //}
                    }
                }
                isDataInitialized = true;
                OutputWriter.WriteMessageOnNewLine("Data read!");
            }
            else
            {
                OutputWriter.DisplayException(ExceptionMessages.InvalidPath);
            }
        }
Beispiel #6
0
 public static void PrintStudent(KeyValuePair <string, double> student)
 {
     OutputWriter.WriteMessageOnNewLine($"{student.Key} - {student.Value}");
 }
Beispiel #7
0
 public void DisplayInvalidCommandMessage(string input)
 {
     OutputWriter.DisplayException($"The command '{input}' is invalid");
 }
 public void PrintStudent(KeyValuePair <string, List <int> > student)
 {
     OutputWriter.WriteMessageOnNewLine(string.Format($"{student.Key} - {string.Join(", ", student.Value)}"));
 }