Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1949-changing-it-feedback #2088

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
100 changes: 54 additions & 46 deletions lib/pangea/choreographer/controllers/alternative_translator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,32 @@ class AlternativeTranslator {
similarityResponse = null;
}

// Calculate the percentage of correct choices
double get _percentCorrectChoices {
// Get the core counts from ITController
final correctChoices = choreographer.itController.correctChoices;
final incorrectChoices = choreographer.itController.incorrectChoices;
final wildcardChoices = choreographer.itController.wildcardChoices;
final customChoices = choreographer.itController.customChoices;

debugPrint(
"PERCENT DEBUG: Correct: $correctChoices, Incorrect: $incorrectChoices, Wildcard: $wildcardChoices, Custom: $customChoices");

// Total number of choices made (both correct and incorrect)
final totalChoices =
correctChoices + incorrectChoices + wildcardChoices + customChoices;

if (totalChoices == 0) {
return 0;
}

// Calculate percentage based on correct choices as a portion of total choices
final percentage = (correctChoices / totalChoices) * 100;
debugPrint("PERCENT DEBUG: Final percentage: $percentage%");

return percentage;
}

Future<void> setTranslationFeedback() async {
try {
choreographer.startLoading();
Expand All @@ -40,9 +66,17 @@ class AlternativeTranslator {

userTranslation = choreographer.currentText;

if (choreographer.itController.allCorrect) {
// Calculate percentage based on correct/total choices ratio
final double percentCorrect = _percentCorrectChoices;
debugPrint("FEEDBACK: Calculated percentage correct: $percentCorrect%");

// Set feedback based on percentage
if (percentCorrect == 100) {
translationFeedbackKey = FeedbackKey.allCorrect;
return;
} else if (percentCorrect > 90) {
translationFeedbackKey = FeedbackKey.newWayAllGood;
} else {
translationFeedbackKey = FeedbackKey.othersAreBetter;
}

final String? goldRouteTranslation =
Expand All @@ -59,43 +93,24 @@ class AlternativeTranslator {
deepL: goldRouteTranslation == null,
),
);

translations = results.translations;
if (results.deepL != null || goldRouteTranslation != null) {
translations.insert(0, (results.deepL ?? goldRouteTranslation)!);
}
// final List<String> altAndUser = [...results.translations];
// if (results.deepL != null) {
// altAndUser.add(results.deepL!);
// }
// altAndUser.add(userTranslation);

if (userTranslation?.toLowerCase() ==
if (userTranslation?.toLowerCase() !=
results.bestTranslation.toLowerCase()) {
translationFeedbackKey = FeedbackKey.allCorrect;
return;
}

similarityResponse = await SimilarityRepo.get(
accessToken: choreographer.accessToken,
request: SimilarityRequestModel(
benchmark: results.bestTranslation,
toCompare: [userTranslation!],
),
);
similarityResponse = await SimilarityRepo.get(
accessToken: choreographer.accessToken,
request: SimilarityRequestModel(
benchmark: results.bestTranslation,
toCompare: [userTranslation!],
),
);

// if (similarityResponse!
// .userTranslationIsSameAsBotTranslation(userTranslation!)) {
// translationFeedbackKey = FeedbackKey.allCorrect;
// return;
// }

// if (similarityResponse!
// .userTranslationIsDifferentButBetter(userTranslation!)) {
// translationFeedbackKey = FeedbackKey.newWayAllGood;
// return;
// }
showAlternativeTranslations = true;
translationFeedbackKey = FeedbackKey.othersAreBetter;
showAlternativeTranslations = true;
}
} catch (err, stack) {
if (err is! http.Response) {
ErrorHandler.logError(
Expand All @@ -120,29 +135,22 @@ class AlternativeTranslator {
}

String translationFeedback(BuildContext context) {
final String displayScore = _percentCorrectChoices.toStringAsFixed(0);

// Use original feedback messages
switch (translationFeedbackKey) {
case FeedbackKey.allCorrect:
return "Match: 100%\n${L10n.of(context).allCorrect}";
return "Match: $displayScore%\n${L10n.of(context).allCorrect}";
case FeedbackKey.newWayAllGood:
return "Match: 100%\n${L10n.of(context).newWayAllGood}";
return "Match: $displayScore%\n${L10n.of(context).newWayAllGood}";
case FeedbackKey.othersAreBetter:
final num userScore =
(similarityResponse!.userScore(userTranslation!) * 100).round();
final String displayScore = userScore.toString();
if (userScore > 90) {
if (_percentCorrectChoices > 90) {
return "Match: $displayScore%\n${L10n.of(context).almostPerfect}";
}
if (userScore > 80) {
if (_percentCorrectChoices > 80) {
return "Match: $displayScore%\n${L10n.of(context).prettyGood}";
}
return "Match: $displayScore%\n${L10n.of(context).othersAreBetter}";
// case FeedbackKey.commonalityFeedback:
// final int count = controller.completedITSteps
// .where((element) => element.isCorrect)
// .toList()
// .length;
// final int total = controller.completedITSteps.length;
// return L10n.of(context).commonalityFeedback(count,total);
case FeedbackKey.loadingPleaseWait:
return L10n.of(context).letMeThink;
case FeedbackKey.allDone:
Expand Down
12 changes: 7 additions & 5 deletions lib/pangea/choreographer/controllers/choreographer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,14 @@ class Choreographer {
}
}

final List<bool> answerChoices = [];

void onITChoiceSelect(ITStep step) {
if (step.chosen != null) {
answerChoices.add(step.continuances[step.chosen!].wasClicked);
debugPrint('ANSWER CHOICES: $answerChoices');
}

choreoRecord.addRecord(_textController.text, step: step);
_textController.setSystemText(
_textController.text + step.continuances[step.chosen!].text,
Expand Down Expand Up @@ -516,9 +523,6 @@ class Choreographer {
}

void onSelectAlternativeTranslation(String translation) {
// PTODO - add some kind of record of this
// choreoRecord.addRecord(_textController.text, match);

_textController.setSystemText(
translation,
EditType.alternativeTranslation,
Expand Down Expand Up @@ -550,8 +554,6 @@ class Choreographer {
choreoRecord = ChoreoRecord.newRecord;
itController.clear();
igc.dispose();
//@ggurdin - why is this commented out?
// errorService.clear();
_resetDebounceTimer();
}

Expand Down
2 changes: 2 additions & 0 deletions lib/pangea/choreographer/controllers/it_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,11 @@ class ITController {
//maybe we store IT data in the same format? make a specific kind of match?
void selectTranslation(int chosenIndex) {
if (currentITStep == null) return;

final itStep = ITStep(currentITStep!.continuances, chosen: chosenIndex);

completedITSteps.add(itStep);
debugPrint('TEST: $itStep');

showChoiceFeedback = true;

Expand Down