[mob] Show clustered percentage in UI

This commit is contained in:
laurenspriem 2024-04-13 15:11:12 +05:30
parent 5cf10c9c9b
commit 8801dc1a7a
3 changed files with 24 additions and 10 deletions

View File

@ -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 {

View File

@ -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);
}

View File

@ -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();