diff --git a/mobile/lib/face/db.dart b/mobile/lib/face/db.dart index c72b197b46..626a25114d 100644 --- a/mobile/lib/face/db.dart +++ b/mobile/lib/face/db.dart @@ -13,6 +13,8 @@ import "package:photos/face/model/face.dart"; import "package:photos/models/file/file.dart"; import "package:photos/services/machine_learning/face_ml/face_clustering/face_info_for_clustering.dart"; import 'package:photos/services/machine_learning/face_ml/face_filtering/face_filtering_constants.dart'; +import "package:photos/services/machine_learning/face_ml/face_ml_result.dart"; +import "package:photos/utils/ml_util.dart"; import 'package:sqlite_async/sqlite_async.dart'; /// Stores all data for the FacesML-related features. The database can be accessed by `FaceMLDataDB.instance.database`. @@ -401,8 +403,10 @@ class FaceMLDataDB { final personID = map[personIdColumn] as String; final clusterID = map[fcClusterID] as int; final faceID = map[fcFaceId] as String; - result.putIfAbsent(personID, () => {}).putIfAbsent(clusterID, () => {}) - .add(faceID); + result + .putIfAbsent(personID, () => {}) + .putIfAbsent(clusterID, () => {}) + .add(faceID); } return result; } @@ -673,11 +677,24 @@ class FaceMLDataDB { return maps.first['count'] as int; } - Future getClusteredToTotalFacesRatio() async { - final int totalFaces = await getTotalFaceCount(); - final int clusteredFaces = await getClusteredFaceCount(); + Future getClusteredFileCount() async { + final db = await instance.asyncDB; + final List> maps = await db.getAll( + 'SELECT COUNT(DISTINCT $fcFaceId) as count FROM $faceClustersTable', + ); + final Set fileIDs = {}; + for (final map in maps) { + final int fileID = getFileIdFromFaceId(map[fcFaceId] as String); + fileIDs.add(fileID); + } + return fileIDs.length; + } - return clusteredFaces / totalFaces; + Future getClusteredToIndexableFilesRatio() async { + final int indexableFiles = (await getIndexableFileIDs()).length; + final int clusteredFiles = await getClusteredFileCount(); + + return clusteredFiles / indexableFiles; } Future getBlurryFaceCount([ diff --git a/mobile/lib/ui/settings/debug/face_debug_section_widget.dart b/mobile/lib/ui/settings/debug/face_debug_section_widget.dart index 726a9f2ceb..376793769f 100644 --- a/mobile/lib/ui/settings/debug/face_debug_section_widget.dart +++ b/mobile/lib/ui/settings/debug/face_debug_section_widget.dart @@ -177,7 +177,7 @@ class _FaceDebugSectionWidgetState extends State { sectionOptionSpacing, MenuItemWidget( captionedTextWidget: FutureBuilder( - future: FaceMLDataDB.instance.getClusteredToTotalFacesRatio(), + future: FaceMLDataDB.instance.getClusteredToIndexableFilesRatio(), builder: (context, snapshot) { if (snapshot.hasData) { return CaptionedTextWidget( diff --git a/mobile/lib/ui/settings/machine_learning_settings_page.dart b/mobile/lib/ui/settings/machine_learning_settings_page.dart index cf546015ce..4e9178a57d 100644 --- a/mobile/lib/ui/settings/machine_learning_settings_page.dart +++ b/mobile/lib/ui/settings/machine_learning_settings_page.dart @@ -439,19 +439,16 @@ class FaceRecognitionStatusWidgetState }); } - Future<(int, int, int, double)> getIndexStatus() async { + Future<(int, int, double)> getIndexStatus() async { try { final indexedFiles = await FaceMLDataDB.instance .getIndexedFileCount(minimumMlVersion: faceMlVersion); final indexableFiles = (await getIndexableFileIDs()).length; final showIndexedFiles = min(indexedFiles, indexableFiles); final pendingFiles = max(indexableFiles - indexedFiles, 0); - final foundFaces = await FaceMLDataDB.instance.getTotalFaceCount(); - final clusteredFaces = - await FaceMLDataDB.instance.getClusteredFaceCount(); - final clusteringDoneRatio = clusteredFaces / foundFaces; + final clusteringDoneRatio = await FaceMLDataDB.instance.getClusteredToIndexableFilesRatio(); - return (showIndexedFiles, pendingFiles, foundFaces, clusteringDoneRatio); + return (showIndexedFiles, pendingFiles, clusteringDoneRatio); } catch (e, s) { _logger.severe('Error getting face recognition status', e, s); rethrow; @@ -480,7 +477,7 @@ class FaceRecognitionStatusWidgetState if (snapshot.hasData) { final int indexedFiles = snapshot.data!.$1; final int pendingFiles = snapshot.data!.$2; - final double clusteringDoneRatio = snapshot.data!.$4; + final double clusteringDoneRatio = snapshot.data!.$3; final double clusteringPercentage = (clusteringDoneRatio * 100).clamp(0, 100);