effectiveMastery static method
Compute effective mastery for a parent topic from its children's mastery
values. Returns 'in_progress' when children have mixed mastery levels.
childMasteries should already be the effective mastery of each child
(i.e. recursively computed for nested parents).
ownMastery is the topic's own DB mastery (fallback for empty children).
Implementation
static String effectiveMastery(
List<String> childMasteries, [
String? ownMastery,
]) {
final filtered = childMasteries.where((m) => m != 'in_progress').toList();
if (filtered.isEmpty) return ownMastery ?? 'unstarted';
final allSame = filtered.every((m) => m == filtered.first);
if (allSame) return filtered.first;
final anyStarted = filtered.any((m) => m != 'unstarted');
return anyStarted ? 'in_progress' : 'unstarted';
}