Skip to content

Commit 7d8ff61

Browse files
authored
feat: support gender filtering for SecAgent draws
1 parent 64320b9 commit 7d8ff61

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

‎SecRandom/Services/SecAgent/SecAgentHttpHostedService.cs‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,24 +188,25 @@ private async Task<JsonObject> DrawStudentsAsync(JsonObject arguments, Cancellat
188188

189189
var requestedCount = Math.Clamp(arguments["count"]?.GetValue<int>() ?? 1, 1, 100);
190190
if (mode == "flash") requestedCount = 1;
191+
var gender = StringArgument(arguments, "gender");
191192
var includeTags = StringArray(arguments, "include_tags");
192193
var excludeTags = StringArray(arguments, "exclude_tags");
193194
var includeIds = StringArray(arguments, "include_ids");
194195
var includeNames = StringArray(arguments, "include_names");
195196
var listName = profileService.CurrentStudentList?.Name ?? string.Empty;
196-
var temporaryCounts = temporaryRecordService.GetStudentCounts(listName, string.Empty, string.Empty);
197+
var temporaryCounts = temporaryRecordService.GetStudentCounts(listName, gender, string.Empty);
197198

198199
var result = await InvokeAuthorizedAsync(SecurityOperation.QuickDrawStart, () =>
199200
{
200-
var draw = drawEngine.DrawStudent(requestedCount, student => Matches(student, includeTags, excludeTags, includeIds, includeNames)
201+
var draw = drawEngine.DrawStudent(requestedCount, student => Matches(student, gender, includeTags, excludeTags, includeIds, includeNames)
201202
&& !HasReachedTemporaryLimit(student, temporaryCounts), DrawSettingsType.QuickDraw, linkageDrawCoordinator.GetCourseName());
202203
if (!draw.IsSuccess || draw.Result.Count == 0)
203204
return Task.FromResult(draw);
204205

205206
profileService.RecordStudentHistory(draw.Result, DateTime.Now, requestedCount,
206207
drawMethod: (int)configHandler.Data.QuickDrawSettings.DrawType,
207208
courseName: linkageDrawCoordinator.GetCourseName());
208-
temporaryRecordService.RecordStudents(listName, string.Empty, string.Empty, draw.Result);
209+
temporaryRecordService.RecordStudents(listName, gender, string.Empty, draw.Result);
209210
if (mode == "flash")
210211
notificationService.QueueStudents(NotificationSettingsType.QuickDraw, linkageDrawCoordinator.GetCourseName(), draw.Result);
211212
return Task.FromResult(draw);
@@ -242,11 +243,12 @@ private bool HasReachedTemporaryLimit(Student student, IReadOnlyDictionary<strin
242243
return threshold > 0 && temporaryCounts.GetValueOrDefault(ProfileRecordIdentity.EnsureRecordId(student)) >= threshold;
243244
}
244245

245-
private static bool Matches(Student student, IReadOnlyCollection<string> includeTags, IReadOnlyCollection<string> excludeTags,
246+
private static bool Matches(Student student, string gender, IReadOnlyCollection<string> includeTags, IReadOnlyCollection<string> excludeTags,
246247
IReadOnlyCollection<string> includeIds, IReadOnlyCollection<string> includeNames)
247248
{
248249
var tags = student.Tags.Split([',', ';', ' '], StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
249-
return includeTags.All(tag => tags.Contains(tag, StringComparer.OrdinalIgnoreCase))
250+
return (string.IsNullOrWhiteSpace(gender) || string.Equals(student.Gender, gender, StringComparison.OrdinalIgnoreCase))
251+
&& includeTags.All(tag => tags.Contains(tag, StringComparer.OrdinalIgnoreCase))
250252
&& excludeTags.All(tag => !tags.Contains(tag, StringComparer.OrdinalIgnoreCase))
251253
&& (includeIds.Count == 0 || includeIds.Contains(student.Id, StringComparer.OrdinalIgnoreCase))
252254
&& (includeNames.Count == 0 || includeNames.Contains(student.Name, StringComparer.OrdinalIgnoreCase));

0 commit comments

Comments
 (0)