Add server-side ELO ratings

This commit is contained in:
hz
2026-07-11 02:05:43 -05:00
parent bdd32c9dac
commit c716b16c53
21 changed files with 688 additions and 47 deletions
@@ -26,7 +26,7 @@ public class QuestionAttemptStore
_col.Indexes.CreateOne(new CreateIndexModel<QuestionAttempt>(questionIndex));
}
public async Task RecordFirstAttemptAsync(string questionExternalId, string userId, string choiceId, bool isCorrect)
public async Task<bool> RecordFirstAttemptAsync(string questionExternalId, string userId, string choiceId, bool isCorrect, bool isSkip = false)
{
var attempt = new QuestionAttempt
{
@@ -34,15 +34,18 @@ public class QuestionAttemptStore
UserId = userId,
ChoiceId = choiceId,
IsCorrect = isCorrect,
IsSkip = isSkip,
CreatedUtc = DateTime.UtcNow
};
try
{
await _col.InsertOneAsync(attempt);
return true;
}
catch (MongoWriteException ex) when (ex.WriteError.Category == ServerErrorCategory.DuplicateKey)
{
return false;
}
}
@@ -58,7 +61,7 @@ public class QuestionAttemptStore
if (ids.Count == 0)
return [];
var attempts = await _col.Find(a => ids.Contains(a.QuestionExternalId)).ToListAsync();
var attempts = await _col.Find(a => ids.Contains(a.QuestionExternalId) && !a.IsSkip).ToListAsync();
var output = new Dictionary<string, Dictionary<string, int>>();
foreach (var group in attempts.GroupBy(a => a.QuestionExternalId))