Skip to content
This repository has been archived by the owner on Sep 4, 2023. It is now read-only.

Module filtering #47

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name-template: 'v$RESOLVED_VERSION'
tag-template: 'v$RESOLVED_VERSION'
categories:
- title: '🚀 Features'
labels:
- 'feature'
- 'enhancement'
- title: '🐛 Bug Fixes'
labels:
- 'fix'
- 'bugfix'
- 'bug'
- title: '🧰 Maintenance'
label: 'chore'
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
version-resolver:
major:
labels:
- 'major'
minor:
labels:
- 'minor'
patch:
labels:
- 'patch'
default: patch
template: |
## Changes

$CHANGES
23 changes: 16 additions & 7 deletions .github/workflows/continuous-deployment.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
name: Continuous deployment
on:
release:
on:
push:
#Testing only
branches: [ master ]
pull_request:
branches: [ master ]
types: [closed]
types: [ closed ]

jobs:
publish:
permissions:
contents: write
pull-requests: write
name: Publish
runs-on: ubuntu-20.04
strategy:
matrix:
RID: [ 'linux-x64', 'win-x64', 'osx-x64' ]
env:
env:
release-directory: ./Epsilon.Cli/bin/Release/net6.0/
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:
- name: Create release draft
uses: release-drafter/release-drafter@v5
id: create_release
- uses: actions/checkout@v2
- uses: actions/setup-dotnet@v1.7.2
with:
Expand All @@ -24,11 +33,11 @@ jobs:
run: dotnet publish Epsilon.Cli --runtime ${{ matrix.RID }} --configuration Release -p:PublishSingleFile=true -p:PublishTrimmed=true --self-contained true
- name: Copy appsettings.json
run: cp ./Epsilon.Cli/appsettings.example.json ${{env.release-directory}}${{ matrix.RID }}/publish/appsettings.json
- name: Removing unnecessary files
- name: Removing unnecessary files
run: rm ${{env.release-directory}}${{ matrix.RID }}/publish/*.pdb

- name: Create artifact ${{ matrix.RID }}
uses: actions/upload-artifact@v2
with:
name: Epsilon.Cli - ${{ matrix.RID }}
path: ${{env.release-directory}}${{ matrix.RID }}/publish
path: ${{env.release-directory}}${{ matrix.RID }}/publish
upload_url: ${{ steps.create_release.outputs.upload_url }}
2 changes: 1 addition & 1 deletion Epsilon.Abstractions/Export/ICanvasModuleExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Epsilon.Abstractions.Export;

public interface ICanvasModuleExporter : IExporter<IEnumerable<Module>>
public interface ICanvasModuleExporter : IExporter<IAsyncEnumerable<ModuleOutcomeResultCollection>>
{

}
2 changes: 1 addition & 1 deletion Epsilon.Abstractions/Export/IExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ public interface IExporter<in T>
{
public IEnumerable<string> Formats { get; }

void Export(T data, string format);
Task Export(T data, string format);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Epsilon.Http.Abstractions;
namespace Epsilon.Abstractions.Http;

public abstract class HttpService
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Epsilon.Http.Abstractions.Json;
namespace Epsilon.Abstractions.Http.Json;

public static class HttpClientJsonExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json;

namespace Epsilon.Http.Abstractions.Json;
namespace Epsilon.Abstractions.Http.Json;

public static class HttpResponseMessageJsonExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ namespace Epsilon.Canvas.Abstractions;

public interface ICanvasModuleCollectionFetcher
{
public Task<IEnumerable<Module>> GetAll(int courseId);
public IAsyncEnumerable<ModuleOutcomeResultCollection> GetAll(int courseId);
}
7 changes: 1 addition & 6 deletions Epsilon.Canvas.Abstractions/Model/Module.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Text.Json.Serialization;
using Epsilon.Canvas.Abstractions.Response;

namespace Epsilon.Canvas.Abstractions.Model;

Expand All @@ -8,8 +7,4 @@ public record Module(
[property: JsonPropertyName("name")] string Name,
[property: JsonPropertyName("items_count")] int Count,
[property: JsonPropertyName("items")] IEnumerable<ModuleItem>? Items
)
{
[JsonIgnore]
public OutcomeResultCollection Collection { get; set; }
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace Epsilon.Canvas.Abstractions.Model;

public record ModuleOutcomeResultCollection(Module Module, OutcomeResultCollection Collection);
22 changes: 21 additions & 1 deletion Epsilon.Canvas.Abstractions/Model/Outcome.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;

namespace Epsilon.Canvas.Abstractions.Model;

public record Outcome(
[property: JsonPropertyName("id")] int Id,
[property: JsonPropertyName("title")] string Title,
[property: JsonPropertyName("description")] string Description
);
)
{
public string ShortDescription()
{
string description = RemoveHtml();
//Function gives only the short English description back of the outcome.
var startPos = description.IndexOf(" EN ", StringComparison.Ordinal) + " EN ".Length;
var endPos = description.IndexOf(" NL ", StringComparison.Ordinal);

return description.Substring(startPos, endPos - startPos);
}

private string RemoveHtml()
{
var raw = Regex.Replace(Description, "<.*?>", " ");
var trimmed = Regex.Replace(raw, @"\s\s+", " ");

return trimmed;
}
};
18 changes: 16 additions & 2 deletions Epsilon.Canvas.Abstractions/Model/OutcomeResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@
namespace Epsilon.Canvas.Abstractions.Model;

public record OutcomeResult(
[property: JsonPropertyName("mastery")] bool? Mastery,
[property: JsonPropertyName("mastery")]
bool? Mastery,
[property: JsonPropertyName("score")] double? Score,
[property: JsonPropertyName("links")] OutcomeResultLink Link
);
)
{
public string? Grade()
{
return Score switch
{
<= 2 => "Unsatisfactory",
3 => "Satisfactory",
4 => "Good",
5 => "Outstanding",
_ => null,
};
}
}
3 changes: 1 addition & 2 deletions Epsilon.Canvas.Abstractions/Model/OutcomeResultCollection.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Text.Json.Serialization;
using Epsilon.Canvas.Abstractions.Model;

namespace Epsilon.Canvas.Abstractions.Response;
namespace Epsilon.Canvas.Abstractions.Model;

public record OutcomeResultCollection(
[property: JsonPropertyName("outcome_results")] IEnumerable<OutcomeResult> OutcomeResults,
Expand Down
10 changes: 4 additions & 6 deletions Epsilon.Canvas.Abstractions/Model/OutcomeResultCollectionLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
namespace Epsilon.Canvas.Abstractions.Model;

public record OutcomeResultCollectionLink(
[property: JsonPropertyName("outcomes")] IEnumerable<Outcome>? Outcomes,
[property: JsonPropertyName("alignments")] IEnumerable<Alignment>? Alignments
[property: JsonPropertyName("outcomes")] IEnumerable<Outcome> Outcomes,
[property: JsonPropertyName("alignments")] IEnumerable<Alignment> Alignments
)
{
public IDictionary<string, Outcome> OutcomesDictionary => Outcomes
.DistinctBy(static o => o.Id)
public IDictionary<string, Outcome> OutcomesDictionary => Outcomes.DistinctBy(static o => o.Id)
.ToDictionary(static o => o.Id.ToString(), static o => o);

public IDictionary<string, Alignment> AlignmentsDictionary => Alignments
.DistinctBy(static a => a.Id)
public IDictionary<string, Alignment> AlignmentsDictionary => Alignments.DistinctBy(static a => a.Id)
.ToDictionary(static a => a.Id, static a => a);
}
12 changes: 0 additions & 12 deletions Epsilon.Canvas.Abstractions/Model/User.cs

This file was deleted.

1 change: 0 additions & 1 deletion Epsilon.Canvas.Abstractions/Service/IOutcomeHttpService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Epsilon.Canvas.Abstractions.Model;
using Epsilon.Canvas.Abstractions.Response;

namespace Epsilon.Canvas.Abstractions.Service;

Expand Down
35 changes: 14 additions & 21 deletions Epsilon.Canvas/CanvasModuleCollectionFetcher.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using Epsilon.Canvas.Abstractions;
using System.Diagnostics;
using Epsilon.Canvas.Abstractions;
using Epsilon.Canvas.Abstractions.Model;
using Epsilon.Canvas.Abstractions.Response;
using Epsilon.Canvas.Abstractions.Service;
using Microsoft.Extensions.Logging;

namespace Epsilon.Canvas;

public class CanvasModuleCollectionFetcher : ICanvasModuleCollectionFetcher
{
private readonly ILogger<CanvasModuleCollectionFetcher> _logger;
private readonly IModuleHttpService _moduleService;
private readonly IOutcomeHttpService _outcomeService;

Expand All @@ -18,36 +17,30 @@ public CanvasModuleCollectionFetcher(
IOutcomeHttpService outcomeService
)
{
_logger = logger;
_moduleService = moduleService;
_outcomeService = outcomeService;
}

public async Task<IEnumerable<Module>> GetAll(int courseId)
public async IAsyncEnumerable<ModuleOutcomeResultCollection> GetAll(int courseId)
{
_logger.LogInformation("Downloading results...");

var response = await _outcomeService.GetResults(courseId, new[] { "outcomes", "alignments" });

var alignments = response.Links.Alignments
.DistinctBy(static a => a.Id)
.ToDictionary(static a => a.Id, static a => a);

var outcomes = response.Links.Outcomes
.DistinctBy(static o => o.Id)
.ToDictionary(static o => o.Id.ToString(), static o => o);

var modules = await _moduleService.GetAll(courseId, new[] { "items" });
foreach (var module in modules)

Debug.Assert(response != null, nameof(response) + " != null");
Debug.Assert(modules != null, nameof(modules) + " != null");

foreach (var module in modules.ToArray())
{
Debug.Assert(module.Items != null, "module.Items != null");

var ids = module.Items.Select(static i => $"assignment_{i.ContentId}");

module.Collection = new OutcomeResultCollection(
Debug.Assert(response.Links?.Alignments != null, "response.Links?.Alignments != null");

yield return new ModuleOutcomeResultCollection(module, new OutcomeResultCollection(
response.OutcomeResults.Where(r => ids.Contains(r.Link.Alignment)),
response.Links with { Alignments = response.Links.Alignments.Where(a => ids.Contains(a.Id)) }
);
));
}

return modules;
}
}
1 change: 1 addition & 0 deletions Epsilon.Canvas/CanvasServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static class CanvasServiceCollectionExtensions
{
private const string CanvasHttpClient = "CanvasHttpClient";

// ReSharper disable once UnusedMethodReturnValue.Global
public static IServiceCollection AddCanvas(this IServiceCollection services, IConfiguration config)
{
services.Configure<CanvasSettings>(config);
Expand Down
2 changes: 1 addition & 1 deletion Epsilon.Canvas/Converter/LinkHeaderConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public LinkHeader ConvertFrom(HttpResponseMessage response)
{
if (!response.Headers.Contains("Link"))
{
throw new ArgumentNullException(nameof(response.Headers), "Header does not contain link key");
throw new KeyNotFoundException("Header does not contain link key");
}

return ConvertFrom(response.Headers.GetValues("Link").First());
Expand Down
2 changes: 1 addition & 1 deletion Epsilon.Canvas/Epsilon.Canvas.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Epsilon.Abstractions\Epsilon.Abstractions.csproj" />
<ProjectReference Include="..\Epsilon.Canvas.Abstractions\Epsilon.Canvas.Abstractions.csproj" />
<ProjectReference Include="..\Epsilon.Http.Abstractions\Epsilon.Http.Abstractions.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions Epsilon.Canvas/Service/AssignmentHttpService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Epsilon.Canvas.Abstractions.Model;
using Epsilon.Abstractions.Http;
using Epsilon.Abstractions.Http.Json;
using Epsilon.Canvas.Abstractions.Model;
using Epsilon.Canvas.Abstractions.Service;
using Epsilon.Http.Abstractions;
using Epsilon.Http.Abstractions.Json;

namespace Epsilon.Canvas.Service;

Expand Down
4 changes: 2 additions & 2 deletions Epsilon.Canvas/Service/ModuleHttpService.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Text;
using Epsilon.Abstractions.Http;
using Epsilon.Abstractions.Http.Json;
using Epsilon.Canvas.Abstractions.Model;
using Epsilon.Canvas.Abstractions.Service;
using Epsilon.Http.Abstractions;
using Epsilon.Http.Abstractions.Json;

namespace Epsilon.Canvas.Service;

Expand Down
Loading