fix getCategory function

pull/1490/head
ggurdin 12 months ago
parent 661a64f68b
commit c2ca1b24f5
No known key found for this signature in database
GPG Key ID: A01CB41737CBB478

@ -77,10 +77,10 @@ class GetAnalyticsController {
...(_getConstructsLocal() ?? []),
..._locallyCachedConstructs,
]);
_updateAnalyticsStream();
} catch (err, s) {
ErrorHandler.logError(e: err, s: s);
} finally {
_updateAnalyticsStream();
if (!initCompleter.isCompleted) initCompleter.complete();
}
}
@ -124,8 +124,13 @@ class GetAnalyticsController {
Map<String, List<dynamic>>.from(locallySaved);
final Map<String, List<OneConstructUse>> formattedCache = {};
for (final entry in cache.entries) {
formattedCache[entry.key] =
entry.value.map((e) => OneConstructUse.fromJson(e)).toList();
try {
formattedCache[entry.key] =
entry.value.map((e) => OneConstructUse.fromJson(e)).toList();
} catch (err, s) {
ErrorHandler.logError(e: err, s: s);
continue;
}
}
return formattedCache;
} catch (err) {

@ -29,7 +29,12 @@ class ConstructAnalyticsModel {
if (["grammar", "g"].contains(useJson['constructType'])) {
continue;
} else {
uses.add(OneConstructUse.fromJson(useJson));
try {
uses.add(OneConstructUse.fromJson(useJson));
} catch (err, s) {
ErrorHandler.logError(e: err, s: s);
continue;
}
}
}
} else {
@ -94,7 +99,7 @@ class OneConstructUse {
useType: ConstructUseTypeUtil.fromString(json['useType']),
lemma: json['lemma'],
form: json['form'],
category: getCategory(json),
category: getCategory(json, constructType),
constructType: constructType,
id: json['id'],
metadata: ConstructUseMetaData(
@ -117,9 +122,21 @@ class OneConstructUse {
'id': id,
};
static String getCategory(Map<String, dynamic> json) {
static String getCategory(
Map<String, dynamic> json,
ConstructTypeEnum constructType,
) {
final categoryEntry = json['cat'] ?? json['categories'];
if (constructType == ConstructTypeEnum.vocab) {
final String? category = categoryEntry is String
? categoryEntry
: categoryEntry is List && categoryEntry.isNotEmpty
? categoryEntry.first
: null;
return category ?? "Other";
}
if (categoryEntry == null) {
return _guessGrammarCategory(json["lemma"]);
}

@ -39,8 +39,7 @@ class LearningProgressIndicatorsState
// if getAnalytics has already finished initializing,
// the data is loaded and should be displayed.
if (MatrixState.pangeaController.getAnalytics.initCompleter?.isCompleted ??
false) {
if (MatrixState.pangeaController.getAnalytics.initCompleter.isCompleted) {
updateData(null);
}
_analyticsSubscription = MatrixState

Loading…
Cancel
Save