successfully received/completed bot-generated practice activity
This commit is contained in:
parent
5d5b35b4eb
commit
d6a56cbd43
7 changed files with 83 additions and 47 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:fluffychat/pangea/constants/pangea_event_types.dart';
|
||||
import 'package:fluffychat/pangea/enum/activity_type_enum.dart';
|
||||
import 'package:fluffychat/pangea/enum/construct_type_enum.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/matrix_event_wrappers/pangea_message_event.dart';
|
||||
|
|
@ -89,13 +90,13 @@ class PracticeGenerationController {
|
|||
tgtConstructs: [
|
||||
ConstructIdentifier(lemma: "be", type: ConstructType.vocab),
|
||||
],
|
||||
activityType: ActivityType.multipleChoice,
|
||||
activityType: ActivityTypeEnum.multipleChoice,
|
||||
langCode: event.messageDisplayLangCode,
|
||||
msgId: event.eventId,
|
||||
multipleChoice: MultipleChoice(
|
||||
question: "What is a synonym for 'happy'?",
|
||||
choices: ["sad", "angry", "joyful", "tired"],
|
||||
correctAnswer: "joyful",
|
||||
answer: "joyful",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
16
lib/pangea/enum/activity_type_enum.dart
Normal file
16
lib/pangea/enum/activity_type_enum.dart
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
enum ActivityTypeEnum { multipleChoice, freeResponse, listening, speaking }
|
||||
|
||||
extension ActivityTypeExtension on ActivityTypeEnum {
|
||||
String get string {
|
||||
switch (this) {
|
||||
case ActivityTypeEnum.multipleChoice:
|
||||
return 'multiple_choice';
|
||||
case ActivityTypeEnum.freeResponse:
|
||||
return 'free_response';
|
||||
case ActivityTypeEnum.listening:
|
||||
return 'listening';
|
||||
case ActivityTypeEnum.speaking:
|
||||
return 'speaking';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:fluffychat/pangea/constants/model_keys.dart';
|
||||
|
|
@ -15,6 +16,7 @@ import 'package:fluffychat/pangea/models/speech_to_text_models.dart';
|
|||
import 'package:fluffychat/pangea/models/tokens_event_content_model.dart';
|
||||
import 'package:fluffychat/pangea/utils/bot_name.dart';
|
||||
import 'package:fluffychat/pangea/widgets/chat/message_audio_card.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
|
@ -653,9 +655,15 @@ class PangeaMessageEvent {
|
|||
}
|
||||
|
||||
List<PracticeActivityEvent> practiceActivities(String langCode) {
|
||||
return _practiceActivityEvents
|
||||
.where((ev) => ev.practiceActivity.langCode == langCode)
|
||||
.toList();
|
||||
try {
|
||||
return _practiceActivityEvents
|
||||
.where((ev) => ev.practiceActivity.langCode == langCode)
|
||||
.toList();
|
||||
} catch (e, s) {
|
||||
debugger(when: kDebugMode);
|
||||
ErrorHandler.logError(e: e, s: s, data: event.toJson());
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// List<SpanData> get activities =>
|
||||
|
|
|
|||
|
|
@ -4,19 +4,19 @@ import 'package:flutter/material.dart';
|
|||
class MultipleChoice {
|
||||
final String question;
|
||||
final List<String> choices;
|
||||
final String correctAnswer;
|
||||
final String answer;
|
||||
|
||||
MultipleChoice({
|
||||
required this.question,
|
||||
required this.choices,
|
||||
required this.correctAnswer,
|
||||
required this.answer,
|
||||
});
|
||||
|
||||
bool isCorrect(int index) => index == correctAnswerIndex;
|
||||
|
||||
bool get isValidQuestion => choices.contains(correctAnswer);
|
||||
bool get isValidQuestion => choices.contains(answer);
|
||||
|
||||
int get correctAnswerIndex => choices.indexOf(correctAnswer);
|
||||
int get correctAnswerIndex => choices.indexOf(answer);
|
||||
|
||||
Color choiceColor(int index) =>
|
||||
index == correctAnswerIndex ? AppConfig.success : AppConfig.warning;
|
||||
|
|
@ -25,7 +25,7 @@ class MultipleChoice {
|
|||
return MultipleChoice(
|
||||
question: json['question'] as String,
|
||||
choices: (json['choices'] as List).map((e) => e as String).toList(),
|
||||
correctAnswer: json['correct_answer'] as String,
|
||||
answer: json['answer'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ class MultipleChoice {
|
|||
return {
|
||||
'question': question,
|
||||
'choices': choices,
|
||||
'correct_answer': correctAnswer,
|
||||
'answer': answer,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:fluffychat/pangea/enum/activity_type_enum.dart';
|
||||
import 'package:fluffychat/pangea/enum/construct_type_enum.dart';
|
||||
import 'package:fluffychat/pangea/models/practice_activities.dart/multiple_choice_activity_model.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
class ConstructIdentifier {
|
||||
final String lemma;
|
||||
|
|
@ -8,12 +13,18 @@ class ConstructIdentifier {
|
|||
ConstructIdentifier({required this.lemma, required this.type});
|
||||
|
||||
factory ConstructIdentifier.fromJson(Map<String, dynamic> json) {
|
||||
return ConstructIdentifier(
|
||||
lemma: json['lemma'] as String,
|
||||
type: ConstructType.values.firstWhere(
|
||||
(e) => e.string == json['type'],
|
||||
),
|
||||
);
|
||||
try {
|
||||
return ConstructIdentifier(
|
||||
lemma: json['lemma'] as String,
|
||||
type: ConstructType.values.firstWhere(
|
||||
(e) => e.string == json['type'],
|
||||
),
|
||||
);
|
||||
} catch (e, s) {
|
||||
debugger(when: kDebugMode);
|
||||
ErrorHandler.logError(e: e, s: s, data: json);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
|
|
@ -24,8 +35,6 @@ class ConstructIdentifier {
|
|||
}
|
||||
}
|
||||
|
||||
enum ActivityType { multipleChoice, freeResponse, listening, speaking }
|
||||
|
||||
class CandidateMessage {
|
||||
final String msgId;
|
||||
final String roomId;
|
||||
|
|
@ -72,7 +81,7 @@ class PracticeActivityRequest {
|
|||
final List<ConstructIdentifier>? targetConstructs;
|
||||
final List<CandidateMessage>? candidateMessages;
|
||||
final List<String>? userIds;
|
||||
final ActivityType? activityType;
|
||||
final ActivityTypeEnum? activityType;
|
||||
final int? numActivities;
|
||||
|
||||
PracticeActivityRequest({
|
||||
|
|
@ -96,7 +105,7 @@ class PracticeActivityRequest {
|
|||
.map((e) => CandidateMessage.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
userIds: (json['user_ids'] as List?)?.map((e) => e as String).toList(),
|
||||
activityType: ActivityType.values.firstWhere(
|
||||
activityType: ActivityTypeEnum.values.firstWhere(
|
||||
(e) => e.toString().split('.').last == json['activity_type'],
|
||||
),
|
||||
numActivities: json['num_activities'] as int,
|
||||
|
|
@ -210,7 +219,7 @@ class PracticeActivityModel {
|
|||
final List<ConstructIdentifier> tgtConstructs;
|
||||
final String langCode;
|
||||
final String msgId;
|
||||
final ActivityType activityType;
|
||||
final ActivityTypeEnum activityType;
|
||||
final MultipleChoice? multipleChoice;
|
||||
final Listening? listening;
|
||||
final Speaking? speaking;
|
||||
|
|
@ -234,8 +243,8 @@ class PracticeActivityModel {
|
|||
.toList(),
|
||||
langCode: json['lang_code'] as String,
|
||||
msgId: json['msg_id'] as String,
|
||||
activityType: ActivityType.values.firstWhere(
|
||||
(e) => e.toString().split('.').last == json['activity_type'],
|
||||
activityType: ActivityTypeEnum.values.firstWhere(
|
||||
(e) => e.string == json['activity_type'],
|
||||
),
|
||||
multipleChoice: json['multiple_choice'] != null
|
||||
? MultipleChoice.fromJson(
|
||||
|
|
@ -249,7 +258,9 @@ class PracticeActivityModel {
|
|||
? Speaking.fromJson(json['speaking'] as Map<String, dynamic>)
|
||||
: null,
|
||||
freeResponse: json['free_response'] != null
|
||||
? FreeResponse.fromJson(json['free_response'] as Map<String, dynamic>)
|
||||
? FreeResponse.fromJson(
|
||||
json['free_response'] as Map<String, dynamic>,
|
||||
)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import 'package:collection/collection.dart';
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pangea/enum/activity_type_enum.dart';
|
||||
import 'package:fluffychat/pangea/matrix_event_wrappers/pangea_message_event.dart';
|
||||
import 'package:fluffychat/pangea/matrix_event_wrappers/practice_acitivity_record_event.dart';
|
||||
import 'package:fluffychat/pangea/matrix_event_wrappers/practice_activity_event.dart';
|
||||
import 'package:fluffychat/pangea/models/practice_activities.dart/practice_activity_model.dart';
|
||||
import 'package:fluffychat/pangea/models/practice_activities.dart/practice_activity_record_model.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
import 'package:fluffychat/pangea/widgets/practice_activity_card/multiple_choice_activity.dart';
|
||||
|
|
@ -64,7 +64,7 @@ class MessagePracticeActivityContentState
|
|||
|
||||
Widget get activityWidget {
|
||||
switch (widget.practiceEvent.practiceActivity.activityType) {
|
||||
case ActivityType.multipleChoice:
|
||||
case ActivityTypeEnum.multipleChoice:
|
||||
return MultipleChoiceActivity(
|
||||
card: this,
|
||||
updateChoice: updateChoice,
|
||||
|
|
|
|||
40
pubspec.lock
40
pubspec.lock
|
|
@ -1184,10 +1184,10 @@ packages:
|
|||
dependency: "direct main"
|
||||
description:
|
||||
name: intl
|
||||
sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d"
|
||||
sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.18.1"
|
||||
version: "0.19.0"
|
||||
io:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -1200,10 +1200,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: jiffy
|
||||
sha256: cc1d4b75016a9156c29b5d61f0c9176c3e0fb0580cc5a0e0422b5d2cab3fbfff
|
||||
sha256: "3497caaa36d36a29033e66803c9739ce6bccbc7e241ca46070f76ee9e6f6eb0c"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.2.1"
|
||||
version: "6.3.1"
|
||||
js:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -1281,26 +1281,26 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: leak_tracker
|
||||
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
|
||||
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "10.0.0"
|
||||
version: "10.0.4"
|
||||
leak_tracker_flutter_testing:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: leak_tracker_flutter_testing
|
||||
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
|
||||
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
version: "3.0.3"
|
||||
leak_tracker_testing:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: leak_tracker_testing
|
||||
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
|
||||
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
version: "3.0.1"
|
||||
license_checker:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
|
|
@ -1425,10 +1425,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: meta
|
||||
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
|
||||
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.11.0"
|
||||
version: "1.12.0"
|
||||
mgrs_dart:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -2254,26 +2254,26 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: test
|
||||
sha256: a1f7595805820fcc05e5c52e3a231aedd0b72972cb333e8c738a8b1239448b6f
|
||||
sha256: "7ee446762c2c50b3bd4ea96fe13ffac69919352bd3b4b17bac3f3465edc58073"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.24.9"
|
||||
version: "1.25.2"
|
||||
test_api:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_api
|
||||
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
|
||||
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.6.1"
|
||||
version: "0.7.0"
|
||||
test_core:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_core
|
||||
sha256: a757b14fc47507060a162cc2530d9a4a2f92f5100a952c7443b5cad5ef5b106a
|
||||
sha256: "2bc4b4ecddd75309300d8096f781c0e3280ca1ef85beda558d33fcbedc2eead4"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.5.9"
|
||||
version: "0.6.0"
|
||||
timezone:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -2566,10 +2566,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: vm_service
|
||||
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
|
||||
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "13.0.0"
|
||||
version: "14.2.1"
|
||||
wakelock_plus:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue