runRadRequest method
Implementation
Future<Map<String, dynamic>> runRadRequest(RADRequest radRequest,
{bool printDebug = false}) async {
int boxWidth = 37;
if (printDebug) {
print('╔════════════════════════════════════════════╗');
print('║ Witnet data request local execution report ║');
print('╚═╤══════════════════════════════════════════╝');
print(' │');
}
List<RetrieveReport> reports = [];
// retrieve
Stopwatch stopwatch = new Stopwatch()..start();
await retrievalStage(radRequest, reports);
var timeElapsed =
(stopwatch.elapsedMicroseconds * 0.001).toStringAsPrecision(3);
if (printDebug) {
print('╔════════════════════════════════════════════╗');
print('║ Witnet data request local execution report ║');
print('╚═╤══════════════════════════════════════════╝');
print(' │');
print(' │ ┌──────────────────────────────────────┐');
print(' ├──┤ ${padStr('Retrieval Stage', ' ', boxWidth)}│');
print(' │ ├──────────────────────────────────────┤');
print(
' │ │ ${padStr('Number of retrieved data sources: ${reports.length}', ' ', boxWidth)}│');
print(' │ └──────────────────────────────────────┘');
print(' │ ');
for (int i = 0; i < reports.length; i++) {
print(' │ [ Source #$i ]');
var report = reports[i];
report.printDebug();
}
}
stopwatch = new Stopwatch()..start();
RADAggregate aggregate = radRequest.aggregate;
stopwatch = new Stopwatch()..start();
var ag = aggregateStage(reports, aggregate);
timeElapsed =
(stopwatch.elapsedMicroseconds * 0.001).toStringAsPrecision(3);
if (printDebug) {
print(' │ ┌──────────────────────────────────────┐');
print(' ├──┤ ${padStr('Aggregation Stage', ' ', boxWidth)}│');
print(' │ ├──────────────────────────────────────┤');
print(
' │ │ ${padStr('Execution time: $timeElapsed ms', ' ', boxWidth)}│');
print(
' │ │ ${padStr('Result is ${typeConversion(ag)}: $ag', ' ', boxWidth)}│');
print(' │ └──────────────────────────────────────┘');
print(' │');
stopwatch = new Stopwatch()..start();
print(' │ ┌──────────────────────────────────────┐');
print(' └──┤ ${padStr('Tally Stage', ' ', boxWidth)}│');
print(' ├──────────────────────────────────────┤');
print(
' │ ${padStr('Execution time: ${(stopwatch.elapsedMicroseconds * 0.001).toStringAsPrecision(3)} ms', ' ', boxWidth)}│');
print(
' │ ${padStr('Result is ${typeConversion(ag)}: $ag', ' ', boxWidth)}│');
print(' └──────────────────────────────────────┘');
}
return {'retrieval': reports, 'aggregate': ag, 'tally': ag};
}