Skip to content
Open
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,10 @@ $RECYCLE.BIN/
/.trae
/TEMP

# Local diagnostic tools and crash dumps
.tools/
*.dmp

# omo
.sisyphus
/.mimocode
Expand Down
30 changes: 24 additions & 6 deletions SecRandom/Services/SecAgent/SecAgentHttpHostedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,24 +188,41 @@ private async Task<JsonObject> DrawStudentsAsync(JsonObject arguments, Cancellat

var requestedCount = Math.Clamp(arguments["count"]?.GetValue<int>() ?? 1, 1, 100);
if (mode == "flash") requestedCount = 1;
var gender = StringArgument(arguments, "gender");
var includeTags = StringArray(arguments, "include_tags");
var excludeTags = StringArray(arguments, "exclude_tags");
var includeIds = StringArray(arguments, "include_ids");
var includeNames = StringArray(arguments, "include_names");
var listName = profileService.CurrentStudentList?.Name ?? string.Empty;
var temporaryCounts = temporaryRecordService.GetStudentCounts(listName, string.Empty, string.Empty);
var temporaryCounts = temporaryRecordService.GetStudentCounts(listName, gender, string.Empty);
var hasMatchingStudents = (profileService.CurrentStudentList?.Students ?? [])
.Any(student => student.IsCandidate && Matches(student, gender, includeTags, excludeTags, includeIds, includeNames));
var mayResetExhaustedRound = configHandler.Data.QuickDrawSettings.DrawMode != DrawMode.Repeat
&& hasMatchingStudents;

var result = await InvokeAuthorizedAsync(SecurityOperation.QuickDrawStart, () =>
{
var draw = drawEngine.DrawStudent(requestedCount, student => Matches(student, includeTags, excludeTags, includeIds, includeNames)
&& !HasReachedTemporaryLimit(student, temporaryCounts), DrawSettingsType.QuickDraw, linkageDrawCoordinator.GetCourseName());
DrawResult<Student> DrawFromRemainingStudents()
=> drawEngine.DrawStudent(requestedCount,
student => Matches(student, gender, includeTags, excludeTags, includeIds, includeNames)
&& !HasReachedTemporaryLimit(student, temporaryCounts),
DrawSettingsType.QuickDraw, linkageDrawCoordinator.GetCourseName());

var draw = DrawFromRemainingStudents();
if (!draw.IsSuccess && mayResetExhaustedRound && draw.Status == DrawStatus.RepeatLimitExhausted)
{
temporaryRecordService.ResetStudentList(listName);
temporaryCounts = temporaryRecordService.GetStudentCounts(listName, gender, string.Empty);
draw = DrawFromRemainingStudents();
}

if (!draw.IsSuccess || draw.Result.Count == 0)
return Task.FromResult(draw);

profileService.RecordStudentHistory(draw.Result, DateTime.Now, requestedCount,
drawMethod: (int)configHandler.Data.QuickDrawSettings.DrawType,
courseName: linkageDrawCoordinator.GetCourseName());
temporaryRecordService.RecordStudents(listName, string.Empty, string.Empty, draw.Result);
temporaryRecordService.RecordStudents(listName, gender, string.Empty, draw.Result);
if (mode == "flash")
notificationService.QueueStudents(NotificationSettingsType.QuickDraw, linkageDrawCoordinator.GetCourseName(), draw.Result);
return Task.FromResult(draw);
Expand Down Expand Up @@ -242,11 +259,12 @@ private bool HasReachedTemporaryLimit(Student student, IReadOnlyDictionary<strin
return threshold > 0 && temporaryCounts.GetValueOrDefault(ProfileRecordIdentity.EnsureRecordId(student)) >= threshold;
}

private static bool Matches(Student student, IReadOnlyCollection<string> includeTags, IReadOnlyCollection<string> excludeTags,
private static bool Matches(Student student, string gender, IReadOnlyCollection<string> includeTags, IReadOnlyCollection<string> excludeTags,
IReadOnlyCollection<string> includeIds, IReadOnlyCollection<string> includeNames)
{
var tags = student.Tags.Split([',', ';', ' '], StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
return includeTags.All(tag => tags.Contains(tag, StringComparer.OrdinalIgnoreCase))
return (string.IsNullOrWhiteSpace(gender) || string.Equals(student.Gender, gender, StringComparison.OrdinalIgnoreCase))
&& includeTags.All(tag => tags.Contains(tag, StringComparer.OrdinalIgnoreCase))
&& excludeTags.All(tag => !tags.Contains(tag, StringComparer.OrdinalIgnoreCase))
&& (includeIds.Count == 0 || includeIds.Contains(student.Id, StringComparer.OrdinalIgnoreCase))
&& (includeNames.Count == 0 || includeNames.Contains(student.Name, StringComparer.OrdinalIgnoreCase));
Expand Down
Loading