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

Commit

Permalink
Feature module filter (#50)
Browse files Browse the repository at this point in the history
* Filtering modules
* changes after feedback.
  • Loading branch information
NealGeilen authored Dec 7, 2022
1 parent 0e545d6 commit 97e2c0e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ namespace Epsilon.Canvas.Abstractions;

public interface ICanvasModuleCollectionFetcher
{
public IAsyncEnumerable<ModuleOutcomeResultCollection> GetAll(int courseId);
public IAsyncEnumerable<ModuleOutcomeResultCollection> GetAll(int courseId, String[] allowedModules);
}
21 changes: 12 additions & 9 deletions Epsilon.Canvas/CanvasModuleCollectionFetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,29 @@ IOutcomeHttpService outcomeService
_outcomeService = outcomeService;
}

public async IAsyncEnumerable<ModuleOutcomeResultCollection> GetAll(int courseId)
public async IAsyncEnumerable<ModuleOutcomeResultCollection> GetAll(int courseId, string[] allowedModules)
{
var response = await _outcomeService.GetResults(courseId, new[] { "outcomes", "alignments" });
var modules = await _moduleService.GetAll(courseId, new[] { "items" });

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");
if (allowedModules.Length == 0 || allowedModules.Contains(module.Name))
{
Debug.Assert(module.Items != null, "module.Items != null");

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

Debug.Assert(response.Links?.Alignments != null, "response.Links?.Alignments != null");
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)) }
));
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)) }
));
}
}
}
}
8 changes: 5 additions & 3 deletions Epsilon.Cli/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,17 @@ private async Task ExecuteAsync()
return;
}

_logger.LogInformation("Targeting Canvas course: {CourseId}, at {Url}", _canvasSettings.CourseId, _canvasSettings.ApiUrl);
var modules = _exportOptions.Modules.Split(",");
_logger.LogInformation("Targeting Canvas course: {CourseId}, at {Url}", _canvasSettings.CourseId,
_canvasSettings.ApiUrl);
_logger.LogInformation("Downloading results, this may take a few seconds...");
var items = _collectionFetcher.GetAll(_canvasSettings.CourseId);
var items = _collectionFetcher.GetAll(_canvasSettings.CourseId, modules);

var formats = _exportOptions.Formats.Split(",");
var exporters = _exporterCollection.DetermineExporters(formats).ToArray();

_logger.LogInformation("Attempting to use following formats: {Formats}", string.Join(", ", formats));

foreach (var (format, exporter) in exporters)
{
_logger.LogInformation("Exporting to {Format} using {Exporter}...", format, exporter.GetType().Name);
Expand Down
2 changes: 2 additions & 0 deletions Epsilon/Export/ExportOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ public class ExportOptions
public string OutputName { get; set; } = $"{Constants.ProjectName}-Export-{{DateTime}}";

public string Formats { get; set; } = "console";

public string Modules { get; set; } = "";

public string FormattedOutputName => OutputName
.Replace("{DateTime}", DateTime.Now.ToString("ddMMyyyyHHmmss"));
Expand Down

0 comments on commit 97e2c0e

Please sign in to comment.