fix: base propotion on shouldDoActivity so messages don't end up locked (#1434)

pull/1593/head
ggurdin 10 months ago committed by GitHub
parent bc3cda6dda
commit 496a789030
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -569,20 +569,21 @@ class PangeaMessageEvent {
} }
final eligibleTokens = messageDisplayRepresentation!.tokens!.where( final eligibleTokens = messageDisplayRepresentation!.tokens!.where(
(token) => (token) => token.shouldDoActivity(
token.isActivityBasicallyEligible(ActivityTypeEnum.wordMeaning), a: ActivityTypeEnum.wordMeaning,
feature: null,
tag: null,
),
); );
final int total = eligibleTokens.length; final int total = eligibleTokens.length;
if (total == 0) return 1;
final int toDo = eligibleTokens final didActivity = eligibleTokens.where(
.where( (token) => token.didActivitySuccessfully(ActivityTypeEnum.wordMeaning),
(token) => );
token.didActivitySuccessfully(ActivityTypeEnum.wordMeaning),
)
.length;
final double proportion = 1 - ((total - toDo) / total); final double proportion = 1 - ((total - didActivity.length) / total);
if (proportion < 0) { if (proportion < 0) {
debugger(when: kDebugMode); debugger(when: kDebugMode);
@ -591,7 +592,7 @@ class PangeaMessageEvent {
data: { data: {
"proportion": proportion, "proportion": proportion,
"total": total, "total": total,
"toDo": toDo, "toDo": didActivity,
"tokens": messageDisplayRepresentation!.tokens, "tokens": messageDisplayRepresentation!.tokens,
}, },
); );

@ -211,20 +211,34 @@ class PangeaToken {
); );
} }
bool isActivityBasicallyEligible(ActivityTypeEnum a) { bool _isActivityBasicallyEligible(
ActivityTypeEnum a, [
String? morphFeature,
String? morphTag,
]) {
if (!lemma.saveVocab) { if (!lemma.saveVocab) {
return false; return false;
} }
bool canGenerate = false;
if (a != ActivityTypeEnum.lemmaId) {
canGenerate = _canGenerateDistractors(
a,
morphFeature: morphFeature,
morphTag: morphTag,
);
}
switch (a) { switch (a) {
case ActivityTypeEnum.wordMeaning: case ActivityTypeEnum.wordMeaning:
return canBeDefined; return canBeDefined && canGenerate;
case ActivityTypeEnum.lemmaId: case ActivityTypeEnum.lemmaId:
return lemma.saveVocab && return lemma.saveVocab &&
text.content.toLowerCase() != lemma.text.toLowerCase(); text.content.toLowerCase() != lemma.text.toLowerCase();
case ActivityTypeEnum.emoji: case ActivityTypeEnum.emoji:
return true; return true;
case ActivityTypeEnum.morphId: case ActivityTypeEnum.morphId:
return morph.isNotEmpty; return morph.isNotEmpty && canGenerate;
case ActivityTypeEnum.wordFocusListening: case ActivityTypeEnum.wordFocusListening:
case ActivityTypeEnum.hiddenWordListening: case ActivityTypeEnum.hiddenWordListening:
return canBeHeard; return canBeHeard;
@ -366,7 +380,7 @@ class PangeaToken {
/// Syncronously determine if a distractor can be generated for a given activity type. /// 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. /// WARNING - do not use this function to determine if lemma activities can be generated.
/// Use [canGenerateLemmaDistractors] instead. /// Use [canGenerateLemmaDistractors] instead.
bool canGenerateDistractors( bool _canGenerateDistractors(
ActivityTypeEnum type, { ActivityTypeEnum type, {
String? morphFeature, String? morphFeature,
String? morphTag, String? morphTag,
@ -406,7 +420,7 @@ class PangeaToken {
required String? feature, required String? feature,
required String? tag, required String? tag,
}) { }) {
return isActivityBasicallyEligible(a) && return _isActivityBasicallyEligible(a, feature, tag) &&
_isActivityProbablyLevelAppropriate(a, feature, tag); _isActivityProbablyLevelAppropriate(a, feature, tag);
} }

@ -179,21 +179,9 @@ class WordZoomWidgetState extends State<WordZoomWidget> {
); );
if (!shouldDo) return false; if (!shouldDo) return false;
switch (selection) { return selection == WordZoomSelection.lemma
case WordZoomSelection.lemma: ? _canGenerateLemmaActivity
return _canGenerateLemmaActivity; : true;
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;
}
} }
@override @override

Loading…
Cancel
Save