intelligently choosing tokens and passing all their info

pull/1384/head
William Jordan-Cooley 1 year ago
parent 8bffe17455
commit f9ad45d203

@ -22,7 +22,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);
}

@ -121,11 +121,12 @@ class PracticeGenerationController {
// if the server points to an existing event, return that event
if (res.existingActivityEventId != null) {
debugPrint(
'Existing activity event found: ${res.existingActivityEventId}',
);
final Event? existingEvent =
await event.room.getEventById(res.existingActivityEventId!);
debugPrint(
'Existing activity event found: ${existingEvent?.content}',
);
if (existingEvent != null) {
return PracticeActivityEvent(
event: existingEvent,

@ -21,7 +21,7 @@ class ConstructListModel {
}) : _uses = uses;
List<OneConstructUse> get uses =>
_uses.where((use) => use.constructType == type).toList();
_uses.where((use) => use.constructType == type || type == null).toList();
/// All unique lemmas used in the construct events
List<String> get lemmas => constructList.map((e) => e.lemma).toSet().toList();
@ -38,7 +38,7 @@ class ConstructListModel {
_constructMap = lemmaToUses.map(
(key, value) => MapEntry(
key + value.first.constructType.string,
key,
ConstructUses(
uses: value,
constructType: value.first.constructType,

@ -27,11 +27,12 @@ class ConstructWithXP {
}
Map<String, dynamic> toJson() {
return {
final json = {
'construct_id': id.toJson(),
'xp': xp,
'last_used': lastUsed?.toIso8601String(),
};
return json;
}
}

@ -253,6 +253,21 @@ class PracticeActivityModel {
this.freeResponse,
});
String get question {
switch (activityType) {
case ActivityTypeEnum.multipleChoice:
return multipleChoice!.question;
case ActivityTypeEnum.listening:
return listening!.text;
case ActivityTypeEnum.speaking:
return speaking!.text;
case ActivityTypeEnum.freeResponse:
return freeResponse!.question;
default:
return '';
}
}
factory PracticeActivityModel.fromJson(Map<String, dynamic> json) {
return PracticeActivityModel(
tgtConstructs: (json['tgt_constructs'] as List)

@ -1,6 +1,5 @@
import 'package:collection/collection.dart';
import 'package:fluffychat/pangea/choreographer/widgets/choice_array.dart';
import 'package:fluffychat/pangea/enum/construct_use_type_enum.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';
@ -28,21 +27,22 @@ class MultipleChoiceActivityState extends State<MultipleChoiceActivity> {
PracticeActivityRecordModel? get currentRecordModel =>
widget.practiceCardController.currentCompletionRecord;
bool get isSubmitted =>
widget.currentActivity?.latestUserRecord?.record.latestResponse != null;
// bool get isSubmitted =>
// widget.currentActivity?.latestUserRecord?.record.latestResponse != null;
@override
void initState() {
super.initState();
setCompletionRecord();
// setCompletionRecord();
}
@override
void didUpdateWidget(covariant MultipleChoiceActivity oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.currentActivity?.event.eventId !=
widget.currentActivity?.event.eventId) {
setCompletionRecord();
if (widget.practiceCardController.currentCompletionRecord?.responses
.isEmpty ??
false) {
selectedChoiceIndex = null;
}
}
@ -52,21 +52,21 @@ class MultipleChoiceActivityState extends State<MultipleChoiceActivity> {
/// Otherwise, it sets the current model to the user record's record and
/// determines the selected choice index.
void setCompletionRecord() {
if (widget.currentActivity?.latestUserRecord?.record == null) {
widget.practiceCardController.setCompletionRecord(
PracticeActivityRecordModel(
question:
widget.currentActivity?.practiceActivity.multipleChoice!.question,
),
);
selectedChoiceIndex = null;
} else {
widget.practiceCardController.setCompletionRecord(
widget.currentActivity!.latestUserRecord!.record);
selectedChoiceIndex = widget
.currentActivity?.practiceActivity.multipleChoice!
.choiceIndex(currentRecordModel!.latestResponse!.text!);
}
// if (widget.currentActivity?.latestUserRecord?.record == null) {
widget.practiceCardController.setCompletionRecord(
PracticeActivityRecordModel(
question:
widget.currentActivity?.practiceActivity.multipleChoice!.question,
),
);
selectedChoiceIndex = null;
// } else {
// widget.practiceCardController.setCompletionRecord(
// widget.currentActivity!.latestUserRecord!.record);
// selectedChoiceIndex = widget
// .currentActivity?.practiceActivity.multipleChoice!
// .choiceIndex(currentRecordModel!.latestResponse!.text!);
// }
setState(() {});
}
@ -79,8 +79,8 @@ class MultipleChoiceActivityState extends State<MultipleChoiceActivity> {
.currentActivity!.practiceActivity.multipleChoice!
.isCorrect(value, index);
final ConstructUseTypeEnum useType =
isCorrect ? ConstructUseTypeEnum.corPA : ConstructUseTypeEnum.incPA;
// final ConstructUseTypeEnum useType =
// isCorrect ? ConstructUseTypeEnum.corPA : ConstructUseTypeEnum.incPA;
currentRecordModel?.addResponse(
text: value,
@ -146,7 +146,7 @@ class MultipleChoiceActivityState extends State<MultipleChoiceActivity> {
),
)
.toList(),
isActive: !isSubmitted,
isActive: true,
),
],
),

@ -73,17 +73,27 @@ class MessagePracticeActivityCardState extends State<PracticeActivityCard> {
setState(() => fetchingActivity = value);
}
/// Set target tokens.
void _setPracticeActivity(PracticeActivityEvent? activity) {
if (activity == null) {
widget.overlayController.exitPracticeFlow();
return;
}
currentActivity = activity;
currentCompletionRecord = PracticeActivityRecordModel(
question: activity.practiceActivity.question,
);
widget.overlayController.setSelectedSpan(currentActivity!.practiceActivity);
}
/// Get an existing activity if there is one.
/// If not, get a new activity from the server.
Future<void> initialize() async {
currentActivity =
_fetchExistingIncompleteActivity() ?? await _fetchNewActivity();
currentActivity == null
? widget.overlayController.exitPracticeFlow()
: widget.overlayController
.setSelectedSpan(currentActivity!.practiceActivity);
_setPracticeActivity(
_fetchExistingIncompleteActivity() ?? await _fetchNewActivity(),
);
}
// if the user did the activity before but awhile ago and we don't have any
@ -178,77 +188,73 @@ class MessagePracticeActivityCardState extends State<PracticeActivityCard> {
/// Fetches a new activity if there are any left to complete.
/// Exits the practice flow if there are no more activities.
void onActivityFinish() async {
try {
if (currentCompletionRecord == null || currentActivity == null) {
debugger(when: kDebugMode);
return;
}
// start joy timer
_savorTheJoy();
final uses = currentCompletionRecord!.uses(
currentActivity!.practiceActivity,
ConstructUseMetaData(
roomId: widget.pangeaMessageEvent.room.id,
timeStamp: DateTime.now(),
),
);
// try {
if (currentCompletionRecord == null || currentActivity == null) {
debugger(when: kDebugMode);
return;
}
// update the target tokens with the new construct uses
targetTokensController.updateTokensWithConstructs(
uses,
context,
widget.pangeaMessageEvent,
);
// start joy timer
_savorTheJoy();
MatrixState.pangeaController.myAnalytics.setState(
AnalyticsStream(
// note - this maybe should be the activity event id
eventId: widget.pangeaMessageEvent.eventId,
roomId: widget.pangeaMessageEvent.room.id,
constructs: uses,
),
);
final uses = currentCompletionRecord!.uses(
currentActivity!.practiceActivity,
ConstructUseMetaData(
roomId: widget.pangeaMessageEvent.room.id,
timeStamp: DateTime.now(),
),
);
// save the record without awaiting to avoid blocking the UI
// send a copy of the activity record to make sure its not overwritten by
// the new activity
MatrixState.pangeaController.activityRecordController
.send(currentCompletionRecord!, currentActivity!)
.catchError(
(e, s) => ErrorHandler.logError(
e: e,
s: s,
m: 'Failed to save record',
data: {
'record': currentCompletionRecord?.toJson(),
'activity': currentActivity?.practiceActivity.toJson(),
},
),
);
// update the target tokens with the new construct uses
await targetTokensController.updateTokensWithConstructs(
uses,
context,
widget.pangeaMessageEvent,
);
widget.overlayController.onActivityFinish();
MatrixState.pangeaController.myAnalytics.setState(
AnalyticsStream(
// note - this maybe should be the activity event id
eventId: widget.pangeaMessageEvent.eventId,
roomId: widget.pangeaMessageEvent.room.id,
constructs: uses,
),
);
currentActivity = await _fetchNewActivity();
// save the record without awaiting to avoid blocking the UI
// send a copy of the activity record to make sure its not overwritten by
// the new activity
MatrixState.pangeaController.activityRecordController
.send(currentCompletionRecord!, currentActivity!)
.catchError(
(e, s) => ErrorHandler.logError(
e: e,
s: s,
m: 'Failed to save record',
data: {
'record': currentCompletionRecord?.toJson(),
'activity': currentActivity?.practiceActivity.toJson(),
},
),
);
currentActivity == null
? widget.overlayController.exitPracticeFlow()
: widget.overlayController
.setSelectedSpan(currentActivity!.practiceActivity);
} catch (e, s) {
debugger(when: kDebugMode);
ErrorHandler.logError(
e: e,
s: s,
m: 'Failed to get new activity',
data: {
'activity': currentActivity,
'record': currentCompletionRecord,
},
);
widget.overlayController.exitPracticeFlow();
}
widget.overlayController.onActivityFinish();
_setPracticeActivity(await _fetchNewActivity());
// } catch (e, s) {
// debugger(when: kDebugMode);
// ErrorHandler.logError(
// e: e,
// s: s,
// m: 'Failed to get new activity',
// data: {
// 'activity': currentActivity,
// 'record': currentCompletionRecord,
// },
// );
// widget.overlayController.exitPracticeFlow();
// }
}
RepresentationEvent? get representation =>

Loading…
Cancel
Save