-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #126 from Clean-CaDET/development
[July 2024] Learning use case enhancement pack
- Loading branch information
Showing
104 changed files
with
1,595 additions
and
369 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/BuildingBlocks/Tutor.BuildingBlocks.Core/Domain/EventSourcing/IEventQueryable.cs
This file contains 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 @@ | ||
using System.Linq.Expressions; | ||
using System.Text.Json; | ||
using Tutor.BuildingBlocks.Core.EventSourcing; | ||
|
||
namespace Tutor.BuildingBlocks.Core.Domain.EventSourcing; | ||
|
||
public interface IEventQueryable<TEvent> where TEvent : DomainEvent | ||
{ | ||
IEventQueryable<TEvent> After(DateTime moment); | ||
IEventQueryable<TEvent> Before(DateTime moment); | ||
IEventQueryable<TEvent> Where(Expression<Func<JsonDocument, bool>> condition); | ||
List<TEvent> ToList(); | ||
List<T> ToList<T>() where T : TEvent; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/BuildingBlocks/Tutor.BuildingBlocks.Core/Domain/EventSourcing/IEventSerializer.cs
This file contains 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,10 @@ | ||
using System.Text.Json; | ||
using Tutor.BuildingBlocks.Core.EventSourcing; | ||
|
||
namespace Tutor.BuildingBlocks.Core.Domain.EventSourcing; | ||
|
||
public interface IEventSerializer<TEvent> where TEvent : DomainEvent | ||
{ | ||
JsonDocument Serialize(TEvent @event); | ||
TEvent Deserialize(JsonDocument @event); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/BuildingBlocks/Tutor.BuildingBlocks.Core/Domain/EventSourcing/IEventStore.cs
This file contains 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,11 @@ | ||
using Tutor.BuildingBlocks.Core.EventSourcing; | ||
using Tutor.BuildingBlocks.Core.UseCases; | ||
|
||
namespace Tutor.BuildingBlocks.Core.Domain.EventSourcing; | ||
|
||
public interface IEventStore<TEvent> where TEvent : DomainEvent | ||
{ | ||
void Save(EventSourcedAggregateRoot aggregate); | ||
IEventQueryable<TEvent> Events { get; } | ||
Task<PagedResult<TEvent>> GetEventsAsync(int page, int pageSize); | ||
} |
13 changes: 0 additions & 13 deletions
13
src/BuildingBlocks/Tutor.BuildingBlocks.Core/EventSourcing/IEventQueryable.cs
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
src/BuildingBlocks/Tutor.BuildingBlocks.Core/EventSourcing/IEventSerializer.cs
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
src/BuildingBlocks/Tutor.BuildingBlocks.Core/EventSourcing/IEventStore.cs
This file was deleted.
Oops, something went wrong.
This file contains 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 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
29 changes: 15 additions & 14 deletions
29
...tStore/Postgres/PostgresEventQueryable.cs → ...tStore/Postgres/PostgresEventQueryable.cs
This file contains 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
4 changes: 2 additions & 2 deletions
4
.../EventStore/Postgres/StoredDomainEvent.cs → .../EventStore/Postgres/StoredDomainEvent.cs
This file contains 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 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
7 changes: 7 additions & 0 deletions
7
src/Modules/Courses/Tutor.Courses.API/Dtos/UnitFeedbackRequestDto.cs
This file contains 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,7 @@ | ||
namespace Tutor.Courses.API.Dtos; | ||
|
||
public class UnitFeedbackRequestDto | ||
{ | ||
public bool RequestKcFeedback { get; set; } | ||
public bool RequestTaskFeedback { get; set; } | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Modules/Courses/Tutor.Courses.API/Dtos/UnitProgressRatingDto.cs
This file contains 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,12 @@ | ||
namespace Tutor.Courses.API.Dtos; | ||
|
||
public class UnitProgressRatingDto | ||
{ | ||
public int? LearnerId { get; set; } | ||
public int KnowledgeUnitId { get; set; } | ||
public int[] CompletedKcIds { get; set; } = Array.Empty<int>(); | ||
public int[] CompletedTaskIds { get; set; } = Array.Empty<int>(); | ||
public DateTime Created { get; set; } | ||
public string Feedback { get; set; } = ""; | ||
public bool IsLearnerInitiated { get; set; } | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Modules/Courses/Tutor.Courses.API/Public/Analysis/IUnitProgressRatingService.cs
This file contains 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,10 @@ | ||
using FluentResults; | ||
using Tutor.Courses.API.Dtos; | ||
|
||
namespace Tutor.Courses.API.Public.Analysis; | ||
|
||
public interface IUnitProgressRatingService | ||
{ | ||
Result<UnitFeedbackRequestDto> ShouldRequestFeedback(int unitId, int learnerId); | ||
Result<UnitProgressRatingDto> Create(UnitProgressRatingDto rating, int learnerId); | ||
} |
This file contains 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
7 changes: 7 additions & 0 deletions
7
...s/Courses/Tutor.Courses.Core/Domain/RepositoryInterfaces/IUnitProgressRatingRepository.cs
This file contains 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,7 @@ | ||
namespace Tutor.Courses.Core.Domain.RepositoryInterfaces; | ||
|
||
public interface IUnitProgressRatingRepository | ||
{ | ||
List<UnitProgressRating> GetByUnitAndLearner(int unitId, int learnerId); | ||
UnitProgressRating Create(UnitProgressRating rating); | ||
} |
This file contains 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
21 changes: 21 additions & 0 deletions
21
src/Modules/Courses/Tutor.Courses.Core/Domain/UnitFeedbackRequest.cs
This file contains 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,21 @@ | ||
using Tutor.BuildingBlocks.Core.Domain; | ||
|
||
namespace Tutor.Courses.Core.Domain; | ||
|
||
public class UnitFeedbackRequest : ValueObject | ||
{ | ||
public bool RequestKcFeedback { get; } | ||
public bool RequestTaskFeedback { get; } | ||
|
||
public UnitFeedbackRequest(bool requestKcFeedback, bool requestTaskFeedback) | ||
{ | ||
RequestKcFeedback = requestKcFeedback; | ||
RequestTaskFeedback = requestTaskFeedback; | ||
} | ||
|
||
protected override IEnumerable<object> GetEqualityComponents() | ||
{ | ||
yield return RequestKcFeedback; | ||
yield return RequestTaskFeedback; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/Modules/Courses/Tutor.Courses.Core/Domain/UnitFeedbackRequestor.cs
This file contains 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,39 @@ | ||
using FluentResults; | ||
|
||
namespace Tutor.Courses.Core.Domain; | ||
|
||
public static class UnitFeedbackRequestor | ||
{ | ||
public static Result<UnitFeedbackRequest> ShouldRequestFeedback(Tuple<int, int> kcMasteryCount, Tuple<int, int> taskProgressCount, List<UnitProgressRating> ratings) | ||
{ | ||
var totalItemsCount = kcMasteryCount.Item1 + taskProgressCount.Item1; | ||
var completedItemsCount = kcMasteryCount.Item2 + taskProgressCount.Item2; | ||
|
||
var lastRatingTime = ratings.Where(r => !r.IsLearnerInitiated).MaxBy(r => r.Created)?.Created ?? DateTime.UtcNow; | ||
var ratedKcsCount = ratings.SelectMany(r => r.CompletedKcIds).Distinct().Count(); | ||
var ratedTasksCount = ratings.SelectMany(r => r.CompletedTaskIds).Distinct().Count(); | ||
var ratedItemsCount = ratedKcsCount + ratedTasksCount; | ||
|
||
if (ratedItemsCount >= completedItemsCount) | ||
return new UnitFeedbackRequest(false, false); | ||
if (HasSufficientlyProgressed(completedItemsCount, totalItemsCount, ratedItemsCount, lastRatingTime)) | ||
return new UnitFeedbackRequest( | ||
kcMasteryCount.Item2 > ratedKcsCount, | ||
taskProgressCount.Item2 > ratedTasksCount | ||
); | ||
return new UnitFeedbackRequest(false, false); | ||
} | ||
|
||
private static bool HasSufficientlyProgressed(int completedItemsCount, int totalItemsCount, int ratedItemsCount, DateTime lastRatingTime) | ||
{ | ||
return completedItemsCount == totalItemsCount || | ||
completedItemsCount >= ratedItemsCount + 3 || | ||
(completedItemsCount == ratedItemsCount + 1 && HoursHavePassed(lastRatingTime, 1.5)) || | ||
(completedItemsCount == ratedItemsCount + 2 && HoursHavePassed(lastRatingTime, 1)); | ||
} | ||
|
||
private static bool HoursHavePassed(DateTime lastRatingTime, double hours) | ||
{ | ||
return DateTime.UtcNow - lastRatingTime > TimeSpan.FromHours(hours); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/Modules/Courses/Tutor.Courses.Core/Domain/UnitProgressRating.cs
This file contains 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,24 @@ | ||
using Tutor.BuildingBlocks.Core.Domain; | ||
|
||
namespace Tutor.Courses.Core.Domain; | ||
|
||
public class UnitProgressRating : Entity | ||
{ | ||
public int LearnerId { get; private set; } | ||
public int KnowledgeUnitId { get; private set; } | ||
public DateTime Created { get; private set; } = DateTime.UtcNow; | ||
public int[] CompletedKcIds { get; private set; } = Array.Empty<int>(); | ||
public int[] CompletedTaskIds { get; private set; } = Array.Empty<int>(); | ||
public string Feedback { get; private set; } = ""; | ||
public bool IsLearnerInitiated { get; private set; } | ||
|
||
private UnitProgressRating() {} | ||
|
||
public UnitProgressRating(int[] completedKcIds, int[] completedTaskIds, DateTime created, bool isLearnerInitiated) | ||
{ | ||
CompletedKcIds = completedKcIds; | ||
CompletedTaskIds = completedTaskIds; | ||
Created = created; | ||
IsLearnerInitiated = isLearnerInitiated; | ||
} | ||
} |
This file contains 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.