-
Notifications
You must be signed in to change notification settings - Fork 1
HEEDLS-470 - Implemented Top Courses page #463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
DanBloxham-sw
merged 5 commits into
master
from
HEEDLS-470-TrackingSystemCentreTopCoursesPage
Jul 6, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
344c619
HEEDLS-470 - Implemented Top Courses page
DanBloxham-sw ac513e1
HEEDLS-470 - review markups
DanBloxham-sw 55aa954
HEEDLS-470 - change private field capitalisation to match other files.
DanBloxham-sw 71343ad
HEEDLS-470 - Minor review markups
DanBloxham-sw ca2ca26
HEEDLS-470 - remove depreciated field from query
DanBloxham-sw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
DigitalLearningSolutions.Data.Tests/Models/CourseStatisticTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| namespace DigitalLearningSolutions.Data.Tests.Models | ||
| { | ||
| using DigitalLearningSolutions.Data.Models.Courses; | ||
| using FluentAssertions; | ||
| using NUnit.Framework; | ||
|
|
||
| public class CourseStatisticTests | ||
| { | ||
| [Test] | ||
| 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); | ||
| } | ||
|
|
||
| [Test] | ||
| 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); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Course_name_should_be_application_name_if_customisation_name_is_null() | ||
| { | ||
| // When | ||
| var courseStatistics = new CourseStatistics | ||
| { | ||
| ApplicationName = "Test application", | ||
| CustomisationName = null, | ||
| }; | ||
|
|
||
| // Then | ||
| courseStatistics.CourseName.Should().BeEquivalentTo("Test application"); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Course_name_should_include_customisation_name_if_it_is_not_null() | ||
| { | ||
| // When | ||
| var courseStatistics = new CourseStatistics | ||
| { | ||
| ApplicationName = "Test application", | ||
| CustomisationName = "customisation", | ||
| }; | ||
|
|
||
| // Then | ||
| courseStatistics.CourseName.Should().BeEquivalentTo("Test application - customisation"); | ||
| } | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
DigitalLearningSolutions.Data/Models/Courses/CourseStatistics.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| namespace DigitalLearningSolutions.Data.Models.Courses | ||
| { | ||
| using System; | ||
|
|
||
| public class CourseStatistics | ||
| { | ||
| public int CustomisationId { get; set; } | ||
| public int CentreId { get; set; } | ||
| public bool Active { get; set; } | ||
| public bool AllCentres { get; set; } | ||
| public DateTime? ArchivedDate { get; set; } | ||
| public string ApplicationName { get; set; } | ||
| public string? CustomisationName { get; set; } | ||
| public int DelegateCount { get; set; } | ||
| public int CompletedCount { get; set; } | ||
| public int InProgressCount => DelegateCount - CompletedCount; | ||
| public int AllAttempts { get; set; } | ||
| public int AttemptsPassed { get; set; } | ||
|
|
||
| public string CourseName => string.IsNullOrWhiteSpace(CustomisationName) | ||
| ? ApplicationName | ||
| : ApplicationName + " - " + CustomisationName; | ||
| public double PassRate => AllAttempts == 0 ? 0 : Math.Round(100 * AttemptsPassed / (double)AllAttempts); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| namespace DigitalLearningSolutions.Data.Services | ||
| { | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using DigitalLearningSolutions.Data.DataServices; | ||
| using DigitalLearningSolutions.Data.Models.Courses; | ||
|
|
||
| public interface ICourseService | ||
| { | ||
| IEnumerable<CourseStatistics> GetTopCourseStatistics(int centreId, int categoryId); | ||
| } | ||
|
|
||
| public class CourseService : ICourseService | ||
| { | ||
| private readonly ICourseDataService courseDataService; | ||
|
|
||
| public CourseService(ICourseDataService courseDataService) | ||
| { | ||
| this.courseDataService = courseDataService; | ||
| } | ||
|
|
||
| public IEnumerable<CourseStatistics> GetTopCourseStatistics(int centreId, int categoryId) | ||
| { | ||
| var allCourses = courseDataService.GetCourseStatisticsAtCentreForCategoryId(centreId, categoryId); | ||
| return allCourses.Where(c => c.Active).OrderByDescending(c => c.InProgressCount); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...LearningSolutions.Web/Controllers/TrackingSystem/Centre/Dashboard/TopCoursesController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| namespace DigitalLearningSolutions.Web.Controllers.TrackingSystem.Centre.Dashboard | ||
| { | ||
| using System.Linq; | ||
| using DigitalLearningSolutions.Data.Services; | ||
| using DigitalLearningSolutions.Web.Helpers; | ||
| using DigitalLearningSolutions.Web.ViewModels.TrackingSystem.Centre.TopCourses; | ||
| using Microsoft.AspNetCore.Authorization; | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| [Authorize(Policy = CustomPolicies.UserCentreAdmin)] | ||
| [Route("/TrackingSystem/Centre/TopCourses")] | ||
| public class TopCoursesController : Controller | ||
| { | ||
| private readonly ICourseService courseService; | ||
| private const int NumberOfTopCourses = 10; | ||
|
|
||
| public TopCoursesController(ICourseService courseService) | ||
| { | ||
| this.courseService = courseService; | ||
| } | ||
|
|
||
| public IActionResult Index() | ||
| { | ||
| var centreId = User.GetCentreId(); | ||
| var adminCategoryId = User.GetAdminCategoryId()!; | ||
|
|
||
| var topCourses = | ||
| courseService.GetTopCourseStatistics(centreId, adminCategoryId.Value).Take(NumberOfTopCourses); | ||
|
|
||
| var model = new TopCoursesViewModel(topCourses); | ||
|
|
||
| return View(model); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...lLearningSolutions.Web/ViewModels/TrackingSystem/Centre/TopCourses/TopCoursesViewModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| namespace DigitalLearningSolutions.Web.ViewModels.TrackingSystem.Centre.TopCourses | ||
| { | ||
| using System.Collections.Generic; | ||
| using DigitalLearningSolutions.Data.Models.Courses; | ||
|
|
||
| public class TopCoursesViewModel | ||
| { | ||
| public TopCoursesViewModel(IEnumerable<CourseStatistics> topCourses) | ||
| { | ||
| TopCourses = topCourses; | ||
| } | ||
| public IEnumerable<CourseStatistics> TopCourses { get; set; } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.