diff --git a/lib/pangea/models/analytics/construct_list_model.dart b/lib/pangea/models/analytics/construct_list_model.dart index b82ca6cb2..bcf676db3 100644 --- a/lib/pangea/models/analytics/construct_list_model.dart +++ b/lib/pangea/models/analytics/construct_list_model.dart @@ -63,49 +63,14 @@ class ConstructListModel { /// key = lemmma + constructType.string, value = ConstructUses void _updateConstructMap(final List newUses) { for (final use in newUses) { - ConstructUses? currentUses; - if (use.category.toLowerCase() == "other") { - final specificKey = _constructMap.keys.firstWhereOrNull( - (key) => key.startsWith(use.identifier.partialString), - ); - - if (specificKey != null) { - currentUses = _constructMap[specificKey]; - use.category = currentUses!.category; - } else if (_constructMap.containsKey(use.identifier.string)) { - currentUses = _constructMap[use.identifier.string]; - } else { - currentUses = ConstructUses( + final currentUses = _constructMap[use.identifier.string] ?? + ConstructUses( uses: [], constructType: use.constructType, lemma: use.lemma, category: use.category, ); - } - } else { - final broadKey = _constructMap.keys.firstWhereOrNull( - (key) => - key.startsWith(use.identifier.partialString) && - key.toLowerCase().endsWith("other"), - ); - - if (broadKey != null) { - currentUses = _constructMap[broadKey]; - for (final broadUse in currentUses!.uses) { - broadUse.category = use.category; - } - _constructMap.remove(broadKey); - } else { - currentUses = _constructMap[use.identifier.string] ?? - ConstructUses( - uses: [], - constructType: use.constructType, - lemma: use.lemma, - category: use.category, - ); - } - } - currentUses!.uses.add(use); + currentUses.uses.add(use); currentUses.setLastUsed(use.timeStamp); _constructMap[use.identifier.string] = currentUses; } @@ -162,38 +127,28 @@ class ConstructListModel { } } - ConstructUses? _getPartialSpecificMatch(ConstructIdentifier identifier) { - return _constructMap.entries - .firstWhereOrNull( - (entry) => - entry.key.startsWith(identifier.partialString) && - !entry.key.toLowerCase().endsWith("other"), - ) - ?.value; - } - - ConstructUses? _getPartialBroadMatch(ConstructIdentifier identifier) { - return _constructMap.entries - .firstWhereOrNull( - (entry) => - entry.key.startsWith(identifier.partialString) && - entry.key.toLowerCase().endsWith("other"), - ) - ?.value; - } - ConstructUses? getConstructUses(ConstructIdentifier identifier) { + 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.isOther) { + } 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 _getPartialSpecificMatch(identifier); + 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 _getPartialBroadMatch(identifier); + return _constructMap.entries + .firstWhereOrNull( + (entry) => + entry.key.startsWith(partialKey) && + entry.key.toLowerCase().endsWith("other"), + ) + ?.value; } } diff --git a/lib/pangea/models/analytics/construct_use_model.dart b/lib/pangea/models/analytics/construct_use_model.dart index ce9a1658d..09195ecba 100644 --- a/lib/pangea/models/analytics/construct_use_model.dart +++ b/lib/pangea/models/analytics/construct_use_model.dart @@ -39,7 +39,7 @@ class ConstructUses { _lastUsed = time; } - String get category => _category ?? "other"; + String get category => _category ?? "Other"; ConstructIdentifier get id => ConstructIdentifier( lemma: lemma, diff --git a/lib/pangea/models/analytics/constructs_model.dart b/lib/pangea/models/analytics/constructs_model.dart index 16c6d62df..1a9118838 100644 --- a/lib/pangea/models/analytics/constructs_model.dart +++ b/lib/pangea/models/analytics/constructs_model.dart @@ -134,7 +134,7 @@ class OneConstructUse { : categoryEntry is List && categoryEntry.isNotEmpty ? categoryEntry.first : null; - return category ?? "other"; + return category ?? "Other"; } if (categoryEntry == null) { @@ -168,7 +168,7 @@ class OneConstructUse { ErrorHandler.logError( m: "Morph construct lemma $morphLemma not found in morph categories and labels", ); - return "other"; + return "Other"; } Room? getRoom(Client client) { diff --git a/lib/pangea/models/practice_activities.dart/practice_activity_model.dart b/lib/pangea/models/practice_activities.dart/practice_activity_model.dart index 1502a7066..d871e0836 100644 --- a/lib/pangea/models/practice_activities.dart/practice_activity_model.dart +++ b/lib/pangea/models/practice_activities.dart/practice_activity_model.dart @@ -62,7 +62,9 @@ class ConstructIdentifier { return other is ConstructIdentifier && other.lemma == lemma && other.type == type && - (category == other.category || isOther || other.isOther); + (category == other.category || + category.toLowerCase() == "other" || + other.category.toLowerCase() == "other"); } @override @@ -71,11 +73,7 @@ class ConstructIdentifier { } String get string => - "$partialString${category != "" ? "-$category" : "-other"}".toLowerCase(); - - String get partialString => "$lemma:${type.string}".toLowerCase(); - - bool get isOther => category.toLowerCase() == "other"; + "$lemma-${type.string}${category != "" ? "-$category" : "-other"}"; } class CandidateMessage { diff --git a/lib/pangea/utils/grammar/get_grammar_copy.dart b/lib/pangea/utils/grammar/get_grammar_copy.dart index af13fa065..b8e406faf 100644 --- a/lib/pangea/utils/grammar/get_grammar_copy.dart +++ b/lib/pangea/utils/grammar/get_grammar_copy.dart @@ -15,7 +15,7 @@ String? getGrammarCopy({ required String lemma, required BuildContext context, }) { - if (category.toLowerCase() == "other") { + if (category.toLowerCase() == 'other') { return null; } diff --git a/lib/pangea/widgets/chat_list/analytics_summary/analytics_popup/analytics_popup.dart b/lib/pangea/widgets/chat_list/analytics_summary/analytics_popup/analytics_popup.dart index cebfd18ea..4fae8c71c 100644 --- a/lib/pangea/widgets/chat_list/analytics_summary/analytics_popup/analytics_popup.dart +++ b/lib/pangea/widgets/chat_list/analytics_summary/analytics_popup/analytics_popup.dart @@ -34,8 +34,8 @@ class AnalyticsPopupState extends State { // Sort the list with custom logic entries.sort((a, b) { // Check if one of the keys is 'Other' - if (a.key.toLowerCase() == "other") return 1; - if (b.key.toLowerCase() == "other") return -1; + if (a.key == 'Other') return 1; + if (b.key == 'Other') return -1; // Sort by the length of the list in descending order final aTotalPoints = a.value.fold( @@ -73,7 +73,7 @@ class AnalyticsPopupState extends State { final bool hasNoData = _constructsModel.constructList(type: widget.type).isEmpty; final bool hasNoCategories = _categoriesToUses.length == 1 && - _categoriesToUses.entries.first.key.toLowerCase() == "other"; + _categoriesToUses.entries.first.key == "Other"; if (selectedCategory != null) { dialogContent = Column(