selectInterleavingTopics static method
Select 2-3 topics suitable for interleaving with the current topic.
Criteria: same domain, similar mastery level, recently studied.
masteryMap maps topicId → mastery level.
recentTopicIds is ordered most-recent-first.
Implementation
static List<String> selectInterleavingTopics({
required String currentTopicId,
required String currentDomainId,
required Map<String, String> masteryMap,
required Map<String, String> topicDomainMap, // topicId → domainId
required List<String> recentTopicIds,
int maxTopics = 3,
}) {
final currentMastery = masteryMap[currentTopicId] ?? 'unstarted';
final currentIdx = _masteryIndex(currentMastery);
// Candidates: same domain, different topic, similar mastery (±1 level).
final candidates = <String>[];
for (final topicId in recentTopicIds) {
if (topicId == currentTopicId) continue;
if (topicDomainMap[topicId] != currentDomainId) continue;
final mastery = masteryMap[topicId] ?? 'unstarted';
final idx = _masteryIndex(mastery);
if ((idx - currentIdx).abs() <= 1 && idx > 0) {
candidates.add(topicId);
}
if (candidates.length >= maxTopics) break;
}
return candidates;
}