public List <CourseStatistics> GetCourseStatisticsByDepartmentId(int?departmentId)
        {
            string query = "SELECT * FROM CourseStatisticsView WHERE DepartmentId = '" + departmentId + "' ORDER BY Code ASC";

            Command = new SqlCommand(query, Connection);
            Connection.Open();
            List <CourseStatistics> courseStatisticses = new List <CourseStatistics>();

            Reader = Command.ExecuteReader();
            while (Reader.Read())
            {
                CourseStatistics courseStatistics = new CourseStatistics();
                courseStatistics.Code        = Reader["Code"].ToString();
                courseStatistics.CourseTitle = Reader["CourseTitle"].ToString();
                courseStatistics.Semester    = Reader["Semester"].ToString();
                courseStatistics.TeacherName = Reader["TeacherName"].ToString();
                courseStatistics.Action      = Reader["Action"].ToString();
                if (courseStatistics.Action != "Not Assigned Yet")
                {
                    courseStatisticses.Add(courseStatistics);
                }
            }
            Reader.Close();
            Connection.Close();
            return(courseStatisticses);
        }
Example #2
0
        public async Task Update_CourseStatistics_Test()
        {
            CourseStatisticsRepository courseStatisticsRepository = new CourseStatisticsRepository(context, logger);
            var courseLoggerMock = new Mock <ILogger <CourseRepository> >();
            CourseRepository courseRepository = new CourseRepository(context, courseLoggerMock.Object);
            var courses = await courseRepository.GetAllAsync();

            bool allPersisted = true;

            foreach (var course in courses)
            {
                var courseStatistics = new CourseStatistics {
                    CourseId = course.Id, Name = course.Name
                };
                var persisted = await courseStatisticsRepository.UpdateAsync(courseStatistics);

                if (!persisted)
                {
                    allPersisted = false;
                    break;
                }
            }

            Assert.True(allPersisted);
        }
Example #3
0
        public void GetNonArchivedCourseStatisticsAtCentreFilteredByCategory_should_return_course_statistics_correctly()
        {
            // Given
            const int centreId   = 101;
            int?      categoryId = null;

            // When
            var result = courseDataService.GetNonArchivedCourseStatisticsAtCentreFilteredByCategory(centreId, categoryId).ToList();

            // Then
            var expectedFirstCourse = new CourseStatistics
            {
                CustomisationId     = 100,
                CentreId            = 101,
                Active              = false,
                AllCentres          = false,
                ApplicationId       = 1,
                ApplicationName     = "Entry Level - Win XP, Office 2003/07 OLD",
                CustomisationName   = "Standard",
                DelegateCount       = 25,
                AllAttempts         = 49,
                AttemptsPassed      = 34,
                CompletedCount      = 5,
                HideInLearnerPortal = false,
                CategoryName        = "Office 2007",
                CourseTopic         = "Microsoft Office",
                LearningMinutes     = "N/A",
            };

            result.Should().HaveCount(256);
            result.First().Should().BeEquivalentTo(expectedFirstCourse);
        }
Example #4
0
        public static IEnumerable <SearchableTagViewModel> GetCurrentTagsForCourseStatistics(
            CourseStatistics courseStatistics
            )
        {
            var tags = new List <SearchableTagViewModel>();

            if (courseStatistics.Active)
            {
                tags.Add(new SearchableTagViewModel(CourseStatusFilterOptions.IsActive));
            }
            else
            {
                tags.Add(new SearchableTagViewModel(CourseStatusFilterOptions.IsInactive));
            }

            if (courseStatistics.HideInLearnerPortal)
            {
                tags.Add(new SearchableTagViewModel(CourseVisibilityFilterOptions.IsHiddenInLearningPortal));
            }
            else
            {
                tags.Add(new SearchableTagViewModel(CourseVisibilityFilterOptions.IsNotHiddenInLearningPortal));
            }

            return(tags);
        }
Example #5
0
        public List <CourseStatistics> GetAllCourseStatisticesByDeptId(int deptId)
        {
            Query   = "Select * From CourseStatisticsView Where DeptId = '" + deptId + "'";
            Command = new SqlCommand(Query, Connection);
            Connection.Open();
            Reader = Command.ExecuteReader();
            List <CourseStatistics> statisticses = new List <CourseStatistics>();

            while (Reader.Read())
            {
                CourseStatistics aStatistics = new CourseStatistics();
                aStatistics.CourseCode = Reader["Code"].ToString();
                aStatistics.CourseName = Reader["Title"].ToString();
                aStatistics.Semester   = (int)Reader["Semester"];
                statisticses.RemoveAll(x => x.CourseCode == aStatistics.CourseCode);
                if (Reader["Valid"].ToString() == "true")
                {
                    aStatistics.TeacherName = Reader["AssignedTo"].ToString();
                }
                else
                {
                    aStatistics.TeacherName = "Not Assigned Yet";
                }
                statisticses.Add(aStatistics);
            }
            Reader.Close();
            Connection.Close();
            return(statisticses);
        }
        public List <CourseStatistics> GetAllCourseStatistics()
        {
            SqlConnection           connection = new SqlConnection(connectionString);
            string                  query      = "SELECT * FROM course_statics";
            SqlCommand              command    = new SqlCommand(query, connection);
            List <CourseStatistics> aList      = new List <CourseStatistics>();

            connection.Open();
            SqlDataReader reader = command.ExecuteReader();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    CourseStatistics aCourseStatics = new CourseStatistics();
                    aCourseStatics.CourseCode   = reader["CourseCode"].ToString();
                    aCourseStatics.CourseName   = reader["CourseName"].ToString();
                    aCourseStatics.Credit       = Convert.ToDouble(reader["Credit"].ToString());
                    aCourseStatics.SemesterName = reader["SemesterName"].ToString();
                    aCourseStatics.DepartmentId = Convert.ToInt32(reader["DepartmentId"].ToString());
                    aCourseStatics.TeacherName  = reader["Name"].ToString();
                    aList.Add(aCourseStatics);
                }
                reader.Close();
            }
            connection.Close();
            return(aList);
        }
        public async Task <CourseStatistics> CreateStatistics(int courseId, IQueryable <Course> courses, CancellationToken token = default)
        {
            CourseStatistics stats = null;

            await CreateStatisticsImpl(courses, s => { stats = s; return(Task.CompletedTask); }, courseId, token);

            return(stats);
        }
Example #8
0
        public async Task <ActionResult <CourseStatistics> > GetCourseStatistics(Guid courseId, int timeStamps)
        {
            double averageMark;

            try
            {
                averageMark = await m_analyzer.GetCourseAverageMark(courseId);
            }
            catch (InvalidDataException)
            {
                averageMark = 0;
            }

            List <DateMark> averageMarks;

            try
            {
                averageMarks = await m_analyzer.GetCourseAverageMarks(courseId, timeStamps);
            }
            catch (InvalidDataException)
            {
                averageMarks = new List <DateMark>();
            }

            double levelOfDifficulty;

            try
            {
                levelOfDifficulty = await m_analyzer.GetCourseAverageLevelOfDifficulty(courseId);
            }
            catch (InvalidDataException)
            {
                levelOfDifficulty = 0;
            }

            double wouldTakeAgainRatio;

            try
            {
                wouldTakeAgainRatio = await m_analyzer.GetCourseWouldTakeTeacherAgainRatio(courseId);
            }
            catch (InvalidDataException)
            {
                wouldTakeAgainRatio = 0;
            }

            var courseStatistic = new CourseStatistics
            {
                Id                       = Guid.NewGuid(),
                CourseId                 = courseId,
                AverageMark              = averageMark,
                AverageMarks             = averageMarks,
                AverageLevelOfDifficulty = levelOfDifficulty,
                WouldTakeAgainRatio      = wouldTakeAgainRatio
            };

            return(courseStatistic);
        }
        public ActionResult CourseStatistics(CourseStatistics aCourseStatics)
        {
            DepartmentManager       aDepartmentManager   = new DepartmentManager();
            CourseStatisticsManager aCourseStaticManager = new CourseStatisticsManager();

            ViewBag.departments      = aDepartmentManager.GetAllDepartmentInfo();
            ViewBag.Coursestatistics = aCourseStaticManager.GetAllCourseStatistics();
            return(View());
        }
        public CourseStatisticsResponseDTO Get_Course_Statistics_Course_Uuid(string courseUuid)
        {
            CourseStatistics stat = this._queryExecutor.Execute <CourseStatistics>(DatabaseConsts.USER_SCHEMA, this._sqlCommands.GET_COURSE_STATISTICS_COURSE_UUID(courseUuid), this._modelMapper.MapToCourseStatistics);

            if (stat == null)
            {
                throw new EntityNotFoundException($"No data for course with uuid: " + courseUuid, GeneralConsts.MICROSERVICE_NAME);
            }
            return(this._autoMapper.Map <CourseStatisticsResponseDTO>(stat));
        }
        public CourseStatisticsResponseDTO Get_Course_Statistics_Year(int year)
        {
            CourseStatistics stat = this._queryExecutor.Execute <CourseStatistics>(DatabaseConsts.USER_SCHEMA, this._sqlCommands.GET_COURSE_STATISTCS_YEAR(year), this._modelMapper.MapToCourseStatistics);

            if (stat == null)
            {
                throw new EntityNotFoundException($"No data for year: " + year, GeneralConsts.MICROSERVICE_NAME);
            }
            return(this._autoMapper.Map <CourseStatisticsResponseDTO>(stat));
        }
        public async Task <UpdateCourseStatisticsCommandResponse> Handle(UpdateCourseStatisticsCommand command)
        {
            var courseStatistics = await _courseStatisticsRepository.GetByCourseIdAsync(command.Course.Id);

            var student          = command.Student;
            var course           = command.Course;
            var numberOfStudents = course.NumberOfStudents > 0 ? course.NumberOfStudents : 1;

            if (courseStatistics != null)
            {
                courseStatistics.SumAges += student.Age;

                if (courseStatistics.MinimumAge > student.Age)
                {
                    courseStatistics.MinimumAge = student.Age;
                }

                if (courseStatistics.MaximumAge < student.Age)
                {
                    courseStatistics.MaximumAge = student.Age;
                }

                courseStatistics.AverageAge = (decimal)courseStatistics.SumAges / numberOfStudents;
            }
            else
            {
                courseStatistics = new CourseStatistics
                {
                    CourseId   = course.Id,
                    Name       = course.Name,
                    MinimumAge = student.Age,
                    MaximumAge = student.Age,
                    SumAges    = student.Age,
                    AverageAge = (decimal)student.Age / numberOfStudents
                };
            }

            var success = await _courseStatisticsRepository.UpdateAsync(courseStatistics);

            var response = new UpdateCourseStatisticsCommandResponse(courseStatistics);

            if (success)
            {
                response.Message = "OK";
            }
            else
            {
                response.Message = "Sorry, Something went wrong updating course statistics.";
                var msgError = $"Course Statistics Name '{courseStatistics.Name}', Sum Ages {courseStatistics.SumAges}, Average Age {courseStatistics.AverageAge}, Student '{student.Email}'.";
                response.AddError(msgError);
                _logger.LogError(msgError);
            }

            return(response);
        }
Example #13
0
 public SearchableCourseStatisticsViewModel(CourseStatistics courseStatistics)
 {
     CustomisationId = courseStatistics.CustomisationId;
     DelegateCount   = courseStatistics.DelegateCount;
     InProgressCount = courseStatistics.InProgressCount;
     CourseName      = courseStatistics.CourseName;
     CategoryName    = courseStatistics.CategoryName;
     CourseTopic     = courseStatistics.CourseTopic;
     LearningMinutes = courseStatistics.LearningMinutes;
     Tags            = FilterableTagHelper.GetCurrentTagsForCourseStatistics(courseStatistics);
 }
Example #14
0
 public static IEnumerable <SearchableTagViewModel> GetCurrentTagsForDelegateCourses(
     CourseStatistics courseStatistics
     )
 {
     return(new List <SearchableTagViewModel>
     {
         courseStatistics.Active
             ? new SearchableTagViewModel(CourseStatusFilterOptions.IsActive)
             : new SearchableTagViewModel(CourseStatusFilterOptions.IsInactive),
     });
 }
        public void InProgressCount_should_be_calculated_from_total_delegates_and_total_completed()
        {
            // When
            var courseStatistics = new CourseStatistics
            {
                DelegateCount  = 90,
                CompletedCount = 48
            };

            // Then
            courseStatistics.InProgressCount.Should().Be(42);
        }
        public void Pass_rate_should_be_calculated_from_attempts_and_rounded()
        {
            // When
            var courseStatistics = new CourseStatistics
            {
                AllAttempts    = 1000,
                AttemptsPassed = 514
            };

            // Then
            courseStatistics.PassRate.Should().Be(51);
        }
Example #17
0
        public async Task AggregateStatistics(Course course, ImmutableArray <Student> newStudents, DateTime now)
        {
            if (newStudents.IsEmpty)
            {
                return;
            }
            var maxAge = newStudents.Max(student => CalculateAge(student));

            var minAge = newStudents.Min(student => CalculateAge(student));

            var avgAge = newStudents.Sum(student => CalculateAge(student)) / (decimal)newStudents.Length;

            var statistics = new CourseStatistics(course, maxAge, minAge, avgAge);

            await _statisticsRepo.SaveStatisticsSlice(statistics, newStudents.Length, now);
        }
        public async Task <bool> UpdateAsync(CourseStatistics courseStatistics)
        {
            var foundEntity = await _context.CourseStatistics.FindAsync(courseStatistics.CourseId);

            if (foundEntity == null)
            {
                _context.CourseStatistics.Add(courseStatistics);
            }
            else
            {
                _context.CourseStatistics.Attach(courseStatistics);
                _context.Entry <CourseStatistics>(courseStatistics).State = EntityState.Modified;
            }

            var rowsAffected = await _context.SaveChangesAsync();

            return(rowsAffected > 0);
        }
        public CourseStatisticsResponseDTO Get_Course_Satistics_Student_Uuid(string studentUuid)
        {
            try
            {
                StudentResponseDTO student = this._httpClientService.SendRequest <StudentResponseDTO>(HttpMethod.Get, "http://localhost:40001/api/users/students/" + studentUuid, new UserPrincipal(_httpContextAccessor.HttpContext).token).Result;
            }
            catch
            {
                throw new EntityNotFoundException("Student with uuid " + studentUuid + " doesn't exist", GeneralConsts.MICROSERVICE_NAME);
            }
            CourseStatistics stat = this._queryExecutor.Execute <CourseStatistics>(DatabaseConsts.USER_SCHEMA, this._sqlCommands.GET_COURSE_STATISTICS_STUDENT_UUID(studentUuid), this._modelMapper.MapToCourseStatistics);

            if (stat == null)
            {
                throw new EntityNotFoundException($"No data for student with uuid: " + studentUuid, GeneralConsts.MICROSERVICE_NAME);
            }
            return(this._autoMapper.Map <CourseStatisticsResponseDTO>(stat));
        }
Example #20
0
        public JsonResult GetCourseStatistics(int?departmentId)
        {
            var courses    = courseManager.GetAllCourseStatistics();
            var courseList = courses.Where(a => a.DepartmentId == departmentId).ToList();
            List <CourseStatistics> coursesList = new List <CourseStatistics>();

            foreach (var item in courseList)
            {
                CourseStatistics coursesStatistics = new CourseStatistics
                {
                    Code         = item.Code,
                    Name         = item.Name,
                    SemesterName = item.SemesterName,
                    TeacherName  = item.TeacherName,
                };
                coursesList.Add(coursesStatistics);
            }
            return(Json(coursesList, JsonRequestBehavior.AllowGet));
        }
Example #21
0
        public async Task Update_Course_Statistics_Average_Age_Test(string dateOfBirth, int sumAges, int numberOfStudents, string courseName)
        {
            var courseSt = new CourseStatistics
            {
                CourseId = Guid.NewGuid(),
                Name     = courseName,
                SumAges  = sumAges
            };

            var mock = new Mock <ICourseStatisticsRepository>();

            mock.Setup(r => r.GetByCourseIdAsync(It.IsAny <Guid>()))
            .Returns(Task.FromResult(courseSt));

            mock.Setup(r => r.UpdateAsync(It.IsAny <CourseStatistics>()))
            .Returns(Task.FromResult(true));

            var signUpCommandHandler = new UpdateCourseStatisticsCommandHandler(mock.Object, logger);

            var updCourseStatisticsCommander = new UpdateCourseStatisticsCommand
            {
                Course = new Course {
                    Id = courseSt.CourseId, Name = courseSt.Name, NumberOfStudents = numberOfStudents
                },
                Student = new Student {
                    DateOfBirth = DateTime.Parse(dateOfBirth)
                }
            };

            var commandResponse = await signUpCommandHandler.Handle(updCourseStatisticsCommander);

            var age        = new DateTime(DateTime.Now.Subtract(DateTime.Parse(dateOfBirth)).Ticks).Year - 1;
            var averageAge = (decimal)(sumAges + age) / numberOfStudents;

            output.WriteLine("Course statistics: {0}, Average Age: {1}", commandResponse.CourseStatistics.Name, commandResponse.CourseStatistics.AverageAge);
            Assert.Equal(age, updCourseStatisticsCommander.Student.Age);
            Assert.Equal(averageAge, commandResponse.CourseStatistics.AverageAge);
        }
 public UpdateCourseStatisticsCommandResponse(CourseStatistics courseStatistics)
 {
     this.CourseStatistics = courseStatistics;
 }