Skip to content

Commit

Permalink
Show missing and existed resources
Browse files Browse the repository at this point in the history
  • Loading branch information
anhappdev committed Nov 15, 2024
1 parent d56a530 commit 56ab757
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 20 deletions.
1 change: 1 addition & 0 deletions flutter/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"resourceDownload": "Download",
"resourceClear": "Clear",
"resourceChecking": "Checking download status",
"resourceDownloading": "Downloading",
"resourceErrorMessage": "Some resources failed to load.\nIf you didn't change config from default you can try clearing the cache.\nIf you use a custom configuration file ensure that it has correct structure or switch back to default config.",
"resourceErrorSelectTaskFile": "Update task configuration",
"resourceErrorCurrentConfig": "Current task config file: ",
Expand Down
17 changes: 13 additions & 4 deletions flutter/lib/resources/resource_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,30 @@ class ResourceManager {
resultManager = await ResultManager.create(applicationDirectory);
}

Future<List<String>> validateResourcesExist(List<Resource> resources) async {
// Returns a map of { true: [existedResources], false: [missingResources] }
Future<Map<bool, List<String>>> validateResourcesExist(
List<Resource> resources) async {
final missingResources = <String>[];
final existedResources = <String>[];
for (var r in resources) {
final resolvedPath = get(r.path);
if (resolvedPath.isEmpty) {
missingResources.add(r.path);
} else {
final isResourceExist = await File(resolvedPath).exists() ||
await Directory(resolvedPath).exists();
if (!isResourceExist) {
missingResources.add(resolvedPath);
if (isResourceExist) {
existedResources.add(r.path);
} else {
missingResources.add(r.path);
}
}
}
return missingResources;
final result = {
false: missingResources,
true: existedResources,
};
return result;
}

Future<List<Resource>> validateResourcesChecksum(
Expand Down
9 changes: 5 additions & 4 deletions flutter/lib/resources/validation_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class ValidationHelper {
modes: selectedRunModes,
benchmarks: activeBenchmarks,
);
final missing = await resourceManager.validateResourcesExist(resources);
final result = await resourceManager.validateResourcesExist(resources);
final missing = result[false] ?? [];
if (missing.isEmpty) return '';

return errorDescription +
Expand All @@ -55,13 +56,13 @@ class ValidationHelper {
.join();
}

Future<bool> validateResourcesExist(
Future<Map<bool, List<String>>> validateResourcesExist(
Benchmark benchmark, BenchmarkRunMode mode) async {
final resources = benchmarkStore.listResources(
modes: [mode],
benchmarks: [benchmark],
);
final missing = await resourceManager.validateResourcesExist(resources);
return missing.isEmpty;
final result = await resourceManager.validateResourcesExist(resources);
return result;
}
}
2 changes: 1 addition & 1 deletion flutter/lib/ui/home/app_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import 'package:mlperfbench/ui/app_styles.dart';
import 'package:mlperfbench/ui/history/history_list_screen.dart';
import 'package:mlperfbench/ui/home/user_profile.dart';
import 'package:mlperfbench/ui/settings/about_screen.dart';
import 'package:mlperfbench/ui/settings/settings_screen.dart';
import 'package:mlperfbench/ui/settings/resources_screen.dart';
import 'package:mlperfbench/ui/settings/settings_screen.dart';

class AppDrawer extends StatelessWidget {
const AppDrawer({super.key});
Expand Down
118 changes: 107 additions & 11 deletions flutter/lib/ui/settings/resources_screen.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:mlperfbench/benchmark/benchmark.dart';

import 'package:bot_toast/bot_toast.dart';
import 'package:provider/provider.dart';

import 'package:mlperfbench/benchmark/benchmark.dart';
import 'package:mlperfbench/benchmark/run_mode.dart';
import 'package:mlperfbench/benchmark/state.dart';
import 'package:mlperfbench/localizations/app_localizations.dart';
Expand Down Expand Up @@ -84,18 +84,43 @@ class _ResourcesScreen extends State<ResourcesScreen> {
}

Widget _downloadStatus(Benchmark benchmark, BenchmarkRunMode mode) {
return FutureBuilder<bool>(
return FutureBuilder<Map<bool, List<String>>>(
future: state.validator.validateResourcesExist(benchmark, mode),
builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
builder: (BuildContext context,
AsyncSnapshot<Map<bool, List<String>>> snapshot) {
if (snapshot.hasData && snapshot.data != null) {
final downloaded = snapshot.data!;
const double size = 18;
const downloadedIcon =
Icon(Icons.check_circle, size: 16, color: Colors.green);
Icon(Icons.check_circle, size: size, color: Colors.green);
const notDownloadedIcon =
Icon(Icons.check_circle_outline, size: 16, color: Colors.grey);
Icon(Icons.check_circle_outline, size: size, color: Colors.grey);
final result = snapshot.data!;
final missing = result[false] ?? [];
final existed = result[true] ?? [];
final downloaded = missing.isEmpty;
return Row(
children: [
downloaded ? downloadedIcon : notDownloadedIcon,
SizedBox(
height: size,
width: size,
child: IconButton(
padding: const EdgeInsets.all(0),
icon: downloaded ? downloadedIcon : notDownloadedIcon,
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return _ResourcesTable(
taskName: benchmark.info.taskName,
modeName: mode.readable,
missing: missing,
existed: existed,
);
},
);
},
),
),
const SizedBox(width: 10),
Text(mode.readable),
],
Expand All @@ -117,13 +142,16 @@ class _ResourcesScreen extends State<ResourcesScreen> {
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
l10n.resourceDownloading,
maxLines: 1,
style: const TextStyle(fontSize: 12),
),
Text(
state.loadingPath,
maxLines: 5,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 12.0,
),
style: const TextStyle(fontSize: 12),
),
const SizedBox(height: 8),
LinearProgressIndicator(
Expand Down Expand Up @@ -184,3 +212,71 @@ class _ResourcesScreen extends State<ResourcesScreen> {
);
}
}

class _ResourcesTable extends StatelessWidget {
final String taskName;
final String modeName;
final List<String> missing;
final List<String> existed;

const _ResourcesTable({
required this.taskName,
required this.modeName,
required this.missing,
required this.existed,
});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Column(
children: [
Text(taskName),
Text(modeName),
],
),
),
body: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
children: [
const SizedBox(height: 20),
Table(
columnWidths: const {
0: FixedColumnWidth(40),
1: FlexColumnWidth(),
},
border: TableBorder.all(color: Colors.grey),
defaultVerticalAlignment: TableCellVerticalAlignment.top,
children: [
for (var path in missing) _row(path, false),
for (var path in existed) _row(path, true),
],
),
],
),
),
);
}

TableRow _row(String path, bool existed) {
return TableRow(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(
existed ? Icons.check_circle : Icons.check_circle_outline,
color: existed
? Colors.green
: Colors.grey, // Grey check mark for missing
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(path),
),
],
);
}
}

0 comments on commit 56ab757

Please sign in to comment.