Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob] Show clustered percentage in UI

laurenspriem8801dc1a7a34
diff --git a/mobile/lib/face/db.dart b/mobile/lib/face/db.dart
index 23e6a5935c..f192607ec9 100644
--- a/mobile/lib/face/db.dart
+++ b/mobile/lib/face/db.dart
@@ -513,6 +513,22 @@ class FaceMLDataDB {
return maps.first['count'] as int;
}
+ Future<double> getClusteredToTotalFacesRatio() async {
+ final db = await instance.sqliteAsyncDB;
+
+ final List<Map<String, dynamic>> totalFacesMaps = await db.getAll(
+ 'SELECT COUNT(*) as count FROM $facesTable WHERE $faceScore > $kMinHighQualityFaceScore AND $faceBlur > $kLaplacianThreshold',
+ );
+ final int totalFaces = totalFacesMaps.first['count'] as int;
+
+ final List<Map<String, dynamic>> clusteredFacesMaps = await db.getAll(
+ 'SELECT COUNT(DISTINCT $fcFaceId) as count FROM $faceClustersTable',
+ );
+ final int clusteredFaces = clusteredFacesMaps.first['count'] as int;
+
+ return clusteredFaces / totalFaces;
+ }
+
Future<int> getBlurryFaceCount([
int blurThreshold = kLaplacianThreshold,
]) async {
diff --git a/mobile/lib/services/machine_learning/face_ml/face_ml_service.dart b/mobile/lib/services/machine_learning/face_ml/face_ml_service.dart
index b882519c86..52d415cb9f 100644
--- a/mobile/lib/services/machine_learning/face_ml/face_ml_service.dart
+++ b/mobile/lib/services/machine_learning/face_ml/face_ml_service.dart
@@ -367,11 +367,10 @@ class FaceMlService {
_logger.info("`clusterAllImages()` called");
try {
+ // Get a sense of the total number of faces in the database
+ final int totalFaces = await FaceMLDataDB.instance
+ .getTotalFaceCount(minFaceScore: minFaceScore);
if (clusterInBuckets) {
- // Get a sense of the total number of faces in the database
- final int totalFaces = await FaceMLDataDB.instance
- .getTotalFaceCount(minFaceScore: minFaceScore);
-
// read the creation times from Files DB, in a map from fileID to creation time
final fileIDToCreationTime =
await FilesDB.instance.getFileIDToCreationTime();
@@ -419,9 +418,6 @@ class FaceMlService {
bucket++;
}
} else {
- final int totalFaces = await FaceMLDataDB.instance
- .getTotalFaceCount(minFaceScore: minFaceScore);
-
// Read all the embeddings from the database, in a map from faceID to embedding
final clusterStartTime = DateTime.now();
final faceIdToEmbedding =
@@ -463,6 +459,7 @@ class FaceMlService {
_logger.info('Done updating FaceIDs with clusterIDs in the DB, in '
'${DateTime.now().difference(clusterDoneTime).inSeconds} seconds');
}
+ _logger.info('clusterAllImages() finished');
} catch (e, s) {
_logger.severe("`clusterAllImages` failed", e, s);
}
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 a3bad274df..85aa992a31 100644
--- a/mobile/lib/ui/settings/debug/face_debug_section_widget.dart
+++ b/mobile/lib/ui/settings/debug/face_debug_section_widget.dart
@@ -179,12 +179,13 @@ class _FaceDebugSectionWidgetState extends State<FaceDebugSectionWidget> {
// },
// ),
MenuItemWidget(
- captionedTextWidget: FutureBuilder<int>(
- future: FaceMLDataDB.instance.getTotalFaceCount(),
+ captionedTextWidget: FutureBuilder<double>(
+ future: FaceMLDataDB.instance.getClusteredToTotalFacesRatio(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return CaptionedTextWidget(
- title: "Run clustering (${snapshot.data!} faces)",
+ title:
+ "Run clustering (${(100 * snapshot.data!).toStringAsFixed(0)}% done)",
);
}
return const SizedBox.shrink();