Skip to content

Commit

Permalink
Add option --all-reviewers to list-review-statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
jheinzel committed Oct 13, 2023
1 parent bfe65f4 commit 9fa6481
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ TutorBot offers the following range of commands:
[--classroom <classroom>]
[--order-by (reviewer|comment-length[-desc]|review-date[-desc])]
[--group <nr>]
[--all-reviewers]
```
+ `--order-by` specifies how the statistics data is ordered:
+ `reviewer`: Order by reviewer name.
Expand All @@ -101,7 +102,9 @@ TutorBot offers the following range of commands:
+ `review-date`: Order by last review date (ascending).
+ `review-date-desc`: Order by last review date (descending).
+ `--group`: Filter by group. The group number is specified as a positive
integer. If omitted, all groups are considered.
integer. If omitted, all groups are considered
+ `--all-reviewers`: Show statistics from all reviewers: students, leturers,
and tutors. If omitted, only students are considered.
* Perform a plagiarism check: Uses JPlag to cross-verify all assignment
submissions for plagiarism. Before using this command, download the JPlag JAR
Expand Down
32 changes: 21 additions & 11 deletions src/TutorBot.Cli/Commands/ListReviewStatisticsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using TutorBot.Domain.Exceptions;
using TutorBot.Infrastructure;
using TutorBot.Infrastructure.OctokitExtensions;
using TutorBot.Infrastructure.TextWriterExtensions;
using TutorBot.Utility;

namespace TutorBot.Commands;
Expand All @@ -17,8 +18,9 @@ internal class ListReviewStatisticsCommand : Command
private readonly Option<string> classroomOption = new("--classroom", "classroom name");
private readonly Option<string> orderOption = new("--order-by", "order criteria");
private readonly Option<int?> groupOption = new("--group", "filter group");
private readonly Option<bool> allReviewersOption = new("--all-reviewers", "include review statistics from non-students");

private async Task HandleAsync(string assignmentName, string classroomName, string order, int? group)
private async Task HandleAsync(string assignmentName, string classroomName, string order, int? group, bool showAllReviewers)
{
var printer = new TablePrinter();
printer.AddRow("REVIEWER", "GR.", "OWNER", "#REVIEWS", "#COMMENTS", "#WORDS", "LASTREVIEWDATE");
Expand Down Expand Up @@ -50,21 +52,25 @@ private async Task HandleAsync(string assignmentName, string classroomName, stri

foreach (var ((ownerName, reviewerName), stats) in orderedReviewStats)
{
if (! studentList.TryGetValue(ownerName, out var owner))
if (!studentList.TryGetValue(ownerName, out var owner))
{
throw new DomainException($"Unknown student \"{ownerName}\".");
Console.Out.WriteRedLine($"Ignoring repository from unknown student \"{ownerName}\".");
continue;
}

if (!studentList.TryGetValue(reviewerName, out var reviewer))
if (!studentList.TryGetValue(reviewerName, out var reviewer) && !showAllReviewers)
{
throw new DomainException($"Unknown student \"{reviewerName}\".");
continue; // ignore reviews from non-students when --all-reviewers is not specified
}

if (group is null || reviewer.GroupNr == group.Value)
if (reviewer is null || group is null || reviewer.GroupNr == group.Value)
{
var lastReviewDate = stats.LastReviewDate?.ToString("yyyy-MM-dd HH:mm") ?? "-";
printer.AddRow(reviewer.FullName,
reviewer.GroupNr.ToString().PadLeft(3),
var reviewerDisplayName = reviewer is null ? reviewerName : reviewer.FullName;
var reviewerGroup = reviewer is null ? "-" : reviewer.GroupNr.ToString();

printer.AddRow(reviewerDisplayName,
reviewerGroup.PadLeft(3),
owner.FullName,
stats.NumReviews.ToString().PadLeft(8),
stats.NumComments.ToString().PadLeft(9),
Expand All @@ -81,7 +87,7 @@ private async Task HandleAsync(string assignmentName, string classroomName, stri
}
}

public ListReviewStatisticsCommand(IGitHubClassroomClient client, ConfigurationHelper configuration) :
public ListReviewStatisticsCommand(IGitHubClassroomClient client, ConfigurationHelper configuration) :
base("list-review-statistics", "Display summary of reviewers' activity")
{
this.client = client;
Expand All @@ -93,7 +99,7 @@ public ListReviewStatisticsCommand(IGitHubClassroomClient client, ConfigurationH
classroomOption.SetDefaultValue(configuration.DefaultClassroom);
AddOption(classroomOption);

orderOption.AddAlias("-s");
orderOption.AddAlias("-o");
orderOption.FromAmong("reviewer", "comment-length", "comment-length-desc", "review-date", "review-date-desc")
.SetDefaultValue("review-date-desc");
AddOption(orderOption);
Expand All @@ -102,9 +108,13 @@ public ListReviewStatisticsCommand(IGitHubClassroomClient client, ConfigurationH
groupOption.SetDefaultValue(null);
AddOption(groupOption);

allReviewersOption.AddAlias("-a");
allReviewersOption.SetDefaultValue(false);
AddOption(allReviewersOption);

AddAlias("lr");

this.SetHandler(HandleAsync, assignmentArgument, classroomOption, orderOption, groupOption);
this.SetHandler(HandleAsync, assignmentArgument, classroomOption, orderOption, groupOption, allReviewersOption);
}
}

2 changes: 1 addition & 1 deletion src/TutorBot.Cli/Domain/Assignment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public async Task<ReviewStatistics> GetReviewStatistics(IStudentList students, I

foreach (var submission in Submissions)
{
await submission.AddReviewStatistics(students, reviewStats);
await submission.AddReviewStatistics(reviewStats);
progress?.Increment();
}

Expand Down
6 changes: 3 additions & 3 deletions src/TutorBot.Cli/Domain/Submission.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public Submission(IGitHubClassroomClient client, Repository repository, Student
this.Reviewers = reviewers.ToList();
}

public async Task AddReviewStatistics(IStudentList students, ReviewStatistics reviewStats)
public async Task AddReviewStatistics(ReviewStatistics reviewStats)
{
var reviews = await client.Repository.PullRequest.Review.GetAll(RepositoryId, Constants.FEEDBACK_PULLREQUEST_ID);
foreach (var review in reviews.Where(r => students.Contains(r.User.Login)))
foreach (var review in reviews)
{
if (!reviewStats.TryGetValue((Owner.GitHubUsername, review.User.Login), out Domain.ReviewStatisticsItem? stats))
{
Expand All @@ -51,7 +51,7 @@ public async Task AddReviewStatistics(IStudentList students, ReviewStatistics re
}

var comments = await client.Repository.PullRequest.ReviewComment.GetAll(RepositoryId, Constants.FEEDBACK_PULLREQUEST_ID);
foreach (var comment in comments.Where(r => students.Contains(r.User.Login)))
foreach (var comment in comments)
{
if (!reviewStats.TryGetValue((Owner.GitHubUsername, comment.User.Login), out Domain.ReviewStatisticsItem? stats))
{
Expand Down

0 comments on commit 9fa6481

Please sign in to comment.