executeEvaluation function

Future<void> executeEvaluation({
  1. required bool executed,
  2. required List parameters,
  3. required String datasetSplitType,
  4. required BuildContext context,
  5. required dynamic ref,
})

Executes model evaluation based on the given parameters and conditions.

executed - Boolean indicating if the model evaluation should proceed. parameters - List of parameters specific to the model. datasetSplitType - String indicating the dataset split type ('Training', 'Tuning', etc.). context - Build context for the operation. ref - Reference used in the evaluation (e.g., for dependency injection).

Implementation

Future<void> executeEvaluation({
  required bool executed,
  required List parameters,
  required String datasetSplitType,
  required BuildContext context,
  required dynamic ref,
}) async {
  // 20250805 gjw On removing `hand` from the list of scripts to run, due to
  // `hmeasure` being removed from CRAN, [hd] below has become the empty
  // string, for convenience, expecting the `hmeasure` package to resurface in
  // CRAN, and so keeping [hd] in all the places where it needs to be. So
  // check here and remove any empty strings in the list [parameters].

  parameters.removeWhere((s) => s.isEmpty);

  // 20241220 gjw One of the following templates then needs to be
  // run to convert the appropriate predictions and probabilities
  // to the variables that are non-specific to a dataset
  // partition.

  final templateMap = {
    'Training': 'evaluate_template_tr',
    'Tuning': 'evaluate_template_tu',
    'Validation': 'evaluate_template_tu',
    'Testing': 'evaluate_template_te',
    'Complete': 'evaluate_template_tc',
  };

  if (executed) {
    final template = templateMap[datasetSplitType] ??
        (throw Exception('Invalid datasetSplitType: $datasetSplitType'));

    // Insert 'template' as the second item in the parameters list.

    final selectedParameters = [
      parameters.first,
      template,
      ...parameters.skip(1),
    ];

    await rSource(context, ref, selectedParameters.cast<String>());

    // Add a delay to avoid overrunning the CONSOLE which reuslts in scripts
    // being truncated withthe current R CONSOLE implementation. This works
    // for me on my kadesh Ubuntu laptop. It may be less of a problem on
    // slower machines. (gjw 20250316)

    await Future.delayed(const Duration(milliseconds: 500));
  }
}