Beispiel #1
0
        public StudentAggregate CalculateStudentsStatistics(IEnumerable <Student> students)
        {
            var     attendanceDictionary    = new Dictionary <int, int>();
            var     annualGpaDictionary     = new Dictionary <int, IList <float> >();
            var     bestStudents            = new SortedDictionary <float, IList <Student> >(new GpaComparer());
            Student mostInconsistentStudent = null;
            float   maxInconsistency        = -1;

            foreach (var student in students)
            {
                AttendanceHelper.AddStudentAttendance(student, attendanceDictionary);
                GpaHelper.AddStudentToBestStudents(student, bestStudents);
                GpaHelper.AddStudentGradesToAnnualGpa(student, annualGpaDictionary);
                float inconsistency = student.CalculateGradesInconsistency();
                if (maxInconsistency < inconsistency)
                {
                    maxInconsistency        = inconsistency;
                    mostInconsistentStudent = student;
                }
            }

            var statistics = new StudentAggregate();

            statistics.YearWithHighestAttendance     = AttendanceHelper.FindMostAttendedYear(attendanceDictionary);
            statistics.StudentIdMostInconsistent     = (mostInconsistentStudent?.Id).GetValueOrDefault();
            statistics.YearWithHighestOverallGpa     = GpaHelper.GetHighestsAnnualGpaYear(annualGpaDictionary);
            statistics.Top10StudentIdsWithHighestGpa = GpaHelper.GetBestStudents(bestStudents, Constants.TopStudentsToSubmit).Select(x => x.Id).ToArray();

            return(statistics);
        }
 public void PrintResult(StudentAggregate studentAggregate)
 {
     Console.WriteLine($"YourName: {studentAggregate.YourName}");
     Console.WriteLine($"YourEmail: {studentAggregate.YourEmail}");
     Console.WriteLine($"YearWithHighestAttendance: {studentAggregate.YearWithHighestAttendance}");
     Console.WriteLine($"YearWithHighestOverallGpa: {studentAggregate.YearWithHighestOverallGpa}");
     Console.WriteLine($"Top10StudentIdsWithHighestGpa: {string.Join(",", studentAggregate.Top10StudentIdsWithHighestGpa)}");
     Console.WriteLine($"StudentIdMostInconsistent: {studentAggregate.StudentIdMostInconsistent}");
 }
Beispiel #3
0
 public async Task SubmitResult(StudentAggregate aggregate)
 {
     using (var client = _clientFactory.CreateClient("ApiTestClient"))
     {
         using (var stringContent = new StringContent(JsonConvert.SerializeObject(aggregate)))
         {
             stringContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
             using (var response = await client.PutAsync("StudentAggregate", stringContent))
             {
                 response.EnsureSuccessStatusCode();
             }
         }
     }
 }