Browse Source

[mob] Minimum size argument for getting all cluster summaries

laurenspriem 1 year ago
parent
commit
a0502886b6

+ 7 - 3
mobile/lib/face/db.dart

@@ -829,10 +829,14 @@ class FaceMLDataDB {
   }
 
   /// Returns a map of clusterID to (avg embedding, count)
-  Future<Map<int, (Uint8List, int)>> clusterSummaryAll() async {
-    final db = await instance.database;
+  Future<Map<int, (Uint8List, int)>> getAllClusterSummary([
+    int? minClusterSize,
+  ]) async {
+    final db = await instance.sqliteAsyncDB;
     final Map<int, (Uint8List, int)> result = {};
-    final rows = await db.rawQuery('SELECT * from $clusterSummaryTable');
+    final rows = await db.getAll(
+      'SELECT * FROM $clusterSummaryTable${minClusterSize != null ? ' WHERE $countColumn >= $minClusterSize' : ''}',
+    );
     for (final r in rows) {
       final id = r[clusterIDColumn] as int;
       final avg = r[avgColumn] as Uint8List;

+ 2 - 2
mobile/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dart

@@ -661,7 +661,7 @@ class ClusterFeedbackService {
     );
 
     final Map<int, (Uint8List, int)> clusterToSummary =
-        await faceMlDb.clusterSummaryAll();
+        await faceMlDb.getAllClusterSummary();
     final Map<int, (Uint8List, int)> updatesForClusterSummary = {};
 
     final Map<int, List<double>> clusterAvg = {};
@@ -852,7 +852,7 @@ class ClusterFeedbackService {
 
     // Get the cluster averages for the person's clusters and the suggestions' clusters
     final Map<int, (Uint8List, int)> clusterToSummary =
-        await faceMlDb.clusterSummaryAll();
+        await faceMlDb.getAllClusterSummary();
 
     // Calculate the avg embedding of the person
     final personClusters = await faceMlDb.getPersonClusterIDs(person.remoteID);