toJson method

Map<String, dynamic> toJson()

Returns a JSON representation of the profile that will be sent to the server.

Implementation

Map<String, dynamic> toJson() {
  final List<String> scoreKeys = <String>[];
  final Map<String, dynamic> json = <String, dynamic>{
    'name': name,
    'scoreKeys': scoreKeys,
  };

  for (final String key in scoreData.keys) {
    final Timeseries timeseries = scoreData[key]!;

    if (timeseries.isReported) {
      scoreKeys.add('$key.average');
      // Report `outlierRatio` rather than `outlierAverage`, because
      // the absolute value of outliers is less interesting than the
      // ratio.
      scoreKeys.add('$key.outlierRatio');
    }

    final TimeseriesStats stats = timeseries.computeStats();
    json['$key.average'] = stats.average;
    json['$key.outlierAverage'] = stats.outlierAverage;
    json['$key.outlierRatio'] = stats.outlierRatio;
    json['$key.noise'] = stats.noise;
  }

  json.addAll(extraData);

  return json;
}