Merge pull request #1017 from pangeachat/xp-fix

manage getting construct uses with category 'other'
This commit is contained in:
ggurdin 2024-11-15 12:59:36 -05:00 committed by GitHub
commit 653ee5f75f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 51 additions and 27 deletions

View file

@ -23,7 +23,7 @@ void main() async {
// #Pangea
try {
await dotenv.load(fileName: ".env.local_choreo");
await dotenv.load(fileName: ".env");
} catch (e) {
Logs().e('Failed to load .env file', e);
}

View file

@ -1,5 +1,6 @@
import 'dart:math';
import 'package:collection/collection.dart';
import 'package:fluffychat/pangea/enum/construct_type_enum.dart';
import 'package:fluffychat/pangea/models/analytics/construct_use_model.dart';
import 'package:fluffychat/pangea/models/analytics/constructs_model.dart';
@ -127,7 +128,28 @@ class ConstructListModel {
}
ConstructUses? getConstructUses(ConstructIdentifier identifier) {
return _constructMap[identifier.string];
final partialKey = "${identifier.lemma}-${identifier.type.string}";
if (_constructMap.containsKey(identifier.string)) {
// try to get construct use entry with full ID key
return _constructMap[identifier.string];
} else if (identifier.category.toLowerCase() == "other") {
// if the category passed to this function is "other", return the first
// construct use entry that starts with the partial key
return _constructMap.entries
.firstWhereOrNull((entry) => entry.key.startsWith(partialKey))
?.value;
} else {
// if the category passed to this function is not "other", return the first
// construct use entry that starts with the partial key and ends with "other"
return _constructMap.entries
.firstWhereOrNull(
(entry) =>
entry.key.startsWith(partialKey) &&
entry.key.toLowerCase().endsWith("other"),
)
?.value;
}
}
List<ConstructUses> constructList({ConstructTypeEnum? type}) => _constructList

View file

@ -94,9 +94,7 @@ class OneConstructUse {
useType: ConstructUseTypeUtil.fromString(json['useType']),
lemma: json['lemma'],
form: json['form'],
category: constructType == ConstructTypeEnum.morph
? getCategory(json)
: "Other",
category: getCategory(json),
constructType: constructType,
id: json['id'],
metadata: ConstructUseMetaData(

View file

@ -324,16 +324,11 @@ class PangeaToken {
List<ConstructUses> get constructs => _constructIDs
.map(
(id) =>
MatrixState.pangeaController.getAnalytics.constructListModel
.getConstructUses(id) ??
ConstructUses(
lemma: id.lemma,
constructType: id.type,
category: id.category,
uses: [],
),
(id) => MatrixState.pangeaController.getAnalytics.constructListModel
.getConstructUses(id),
)
.where((construct) => construct != null)
.cast<ConstructUses>()
.toList();
Map<String, dynamic> toServerChoiceTokenWithXP() {

View file

@ -61,7 +61,10 @@ class ConstructIdentifier {
return other is ConstructIdentifier &&
other.lemma == lemma &&
other.type == type;
other.type == type &&
(category == other.category ||
category.toLowerCase() == "other" ||
other.category.toLowerCase() == "other");
}
@override

View file

@ -33,7 +33,7 @@ class MessageSelectionOverlay extends StatefulWidget {
final Event? _nextEvent;
final Event? _prevEvent;
final PangeaMessageEvent _pangeaMessageEvent;
final PangeaToken? _selectedTokenOnInitialization;
final PangeaToken? _initialSelectedToken;
const MessageSelectionOverlay({
required this.chatController,
@ -43,7 +43,7 @@ class MessageSelectionOverlay extends StatefulWidget {
required Event? nextEvent,
required Event? prevEvent,
super.key,
}) : _selectedTokenOnInitialization = selectedTokenOnInitialization,
}) : _initialSelectedToken = selectedTokenOnInitialization,
_pangeaMessageEvent = pangeaMessageEvent,
_nextEvent = nextEvent,
_prevEvent = prevEvent,
@ -78,16 +78,22 @@ class MessageOverlayController extends State<MessageSelectionOverlay>
bool get showToolbarButtons => !widget._pangeaMessageEvent.isAudioMessage;
PangeaToken? get selectedTargetTokenForWordMeaning =>
widget._selectedTokenOnInitialization != null &&
!(messageAnalyticsEntry?.isTokenInHiddenWordActivity(
widget._selectedTokenOnInitialization!,
) ??
false) &&
widget._selectedTokenOnInitialization!
.shouldDoActivity(ActivityTypeEnum.wordMeaning)
? widget._selectedTokenOnInitialization
: null;
PangeaToken? get selectedTargetTokenForWordMeaning {
if (widget._initialSelectedToken == null || messageAnalyticsEntry == null) {
return null;
}
final isInActivity = messageAnalyticsEntry!.isTokenInHiddenWordActivity(
widget._initialSelectedToken!,
);
final shouldDoActivity = widget._initialSelectedToken!
.shouldDoActivity(ActivityTypeEnum.wordMeaning);
return isInActivity && shouldDoActivity
? widget._initialSelectedToken
: null;
}
List<PangeaToken>? tokens;