fix: base propotion on shouldDoActivity so messages don't end up locked (#1434)
This commit is contained in:
parent
bc3cda6dda
commit
496a789030
3 changed files with 33 additions and 30 deletions
|
|
@ -569,20 +569,21 @@ class PangeaMessageEvent {
|
|||
}
|
||||
|
||||
final eligibleTokens = messageDisplayRepresentation!.tokens!.where(
|
||||
(token) =>
|
||||
token.isActivityBasicallyEligible(ActivityTypeEnum.wordMeaning),
|
||||
(token) => token.shouldDoActivity(
|
||||
a: ActivityTypeEnum.wordMeaning,
|
||||
feature: null,
|
||||
tag: null,
|
||||
),
|
||||
);
|
||||
|
||||
final int total = eligibleTokens.length;
|
||||
if (total == 0) return 1;
|
||||
|
||||
final int toDo = eligibleTokens
|
||||
.where(
|
||||
(token) =>
|
||||
token.didActivitySuccessfully(ActivityTypeEnum.wordMeaning),
|
||||
)
|
||||
.length;
|
||||
final didActivity = eligibleTokens.where(
|
||||
(token) => token.didActivitySuccessfully(ActivityTypeEnum.wordMeaning),
|
||||
);
|
||||
|
||||
final double proportion = 1 - ((total - toDo) / total);
|
||||
final double proportion = 1 - ((total - didActivity.length) / total);
|
||||
|
||||
if (proportion < 0) {
|
||||
debugger(when: kDebugMode);
|
||||
|
|
@ -591,7 +592,7 @@ class PangeaMessageEvent {
|
|||
data: {
|
||||
"proportion": proportion,
|
||||
"total": total,
|
||||
"toDo": toDo,
|
||||
"toDo": didActivity,
|
||||
"tokens": messageDisplayRepresentation!.tokens,
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -211,20 +211,34 @@ class PangeaToken {
|
|||
);
|
||||
}
|
||||
|
||||
bool isActivityBasicallyEligible(ActivityTypeEnum a) {
|
||||
bool _isActivityBasicallyEligible(
|
||||
ActivityTypeEnum a, [
|
||||
String? morphFeature,
|
||||
String? morphTag,
|
||||
]) {
|
||||
if (!lemma.saveVocab) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool canGenerate = false;
|
||||
if (a != ActivityTypeEnum.lemmaId) {
|
||||
canGenerate = _canGenerateDistractors(
|
||||
a,
|
||||
morphFeature: morphFeature,
|
||||
morphTag: morphTag,
|
||||
);
|
||||
}
|
||||
|
||||
switch (a) {
|
||||
case ActivityTypeEnum.wordMeaning:
|
||||
return canBeDefined;
|
||||
return canBeDefined && canGenerate;
|
||||
case ActivityTypeEnum.lemmaId:
|
||||
return lemma.saveVocab &&
|
||||
text.content.toLowerCase() != lemma.text.toLowerCase();
|
||||
case ActivityTypeEnum.emoji:
|
||||
return true;
|
||||
case ActivityTypeEnum.morphId:
|
||||
return morph.isNotEmpty;
|
||||
return morph.isNotEmpty && canGenerate;
|
||||
case ActivityTypeEnum.wordFocusListening:
|
||||
case ActivityTypeEnum.hiddenWordListening:
|
||||
return canBeHeard;
|
||||
|
|
@ -366,7 +380,7 @@ class PangeaToken {
|
|||
/// Syncronously determine if a distractor can be generated for a given activity type.
|
||||
/// WARNING - do not use this function to determine if lemma activities can be generated.
|
||||
/// Use [canGenerateLemmaDistractors] instead.
|
||||
bool canGenerateDistractors(
|
||||
bool _canGenerateDistractors(
|
||||
ActivityTypeEnum type, {
|
||||
String? morphFeature,
|
||||
String? morphTag,
|
||||
|
|
@ -406,7 +420,7 @@ class PangeaToken {
|
|||
required String? feature,
|
||||
required String? tag,
|
||||
}) {
|
||||
return isActivityBasicallyEligible(a) &&
|
||||
return _isActivityBasicallyEligible(a, feature, tag) &&
|
||||
_isActivityProbablyLevelAppropriate(a, feature, tag);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -179,21 +179,9 @@ class WordZoomWidgetState extends State<WordZoomWidget> {
|
|||
);
|
||||
if (!shouldDo) return false;
|
||||
|
||||
switch (selection) {
|
||||
case WordZoomSelection.lemma:
|
||||
return _canGenerateLemmaActivity;
|
||||
case WordZoomSelection.meaning:
|
||||
case WordZoomSelection.morph:
|
||||
return widget.token.canGenerateDistractors(
|
||||
selection.activityType,
|
||||
morphFeature: _selectedMorphFeature,
|
||||
morphTag: _selectedMorphFeature == null
|
||||
? null
|
||||
: widget.token.morph[_selectedMorphFeature],
|
||||
);
|
||||
case WordZoomSelection.emoji:
|
||||
return true;
|
||||
}
|
||||
return selection == WordZoomSelection.lemma
|
||||
? _canGenerateLemmaActivity
|
||||
: true;
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue