getUniqueColumns function

List<String> getUniqueColumns(
  1. WidgetRef ref
)

Implementation

List<String> getUniqueColumns(WidgetRef ref) {
  // 20260118 gjw I considered replacing the console scanning implementation
  // using `unique_colums()` (whose definition we will now remove from the R
  // code setup) with accessing the data from the meta data provider.  But I do
  // not currently have the number of rows captured in a provider. Once that is
  // captured we can use the meta data to determine the columns with unique
  // values. This may be quicker than scanning the console for the output of
  // `unique_columns()`

  String stdout = ref.watch(stdoutProvider);

  String uniqueColumns = rExtract(stdout, 'unique_columns(ds)');

  uniqueColumns = uniqueColumns.replaceAll(RegExp(r'^ *\[[^\]]\] '), '');

  // Extract the ids from the output of unique_columns().

  RegExp regExp = RegExp(r'"(.*?)"');
  Iterable<Match> matches = regExp.allMatches(uniqueColumns);
  List<String> ids = matches.map((match) => match.group(1)!).toList();

  // Map metaData = ref.read(metaDataProvider);

  // List<String> ids = [];

  // final nRows = 365;

  // for (var entry in metaData.entries) {
  //   // Ensure the value is a Map and check the 'unique' key.

  //   if (entry.value is Map<String, dynamic>) {
  //     var uniqueList = (entry.value as Map<String, dynamic>)['unique'];

  //     // Check if 'unique' is a List and if the first element is the same as the
  //     // number of rows in the dataset.

  //     if (uniqueList is List &&
  //         uniqueList.isNotEmpty &&
  //         uniqueList[0] == nRows) {
  //       ids.add(entry.key);
  //     }
  //   }
  // }

  return ids;
}