[mob][photos] Clustering sort to cluster new files first

This commit is contained in:
laurenspriem 2024-05-24 10:57:27 +05:30
parent edf9f743f4
commit f1d1a4a9e1
2 changed files with 22 additions and 38 deletions

View file

@ -498,19 +498,8 @@ class FaceClusteringService {
} }
} }
// Sort the faceInfos based on fileCreationTime, in ascending order, so oldest faces are first
if (fileIDToCreationTime != null) { if (fileIDToCreationTime != null) {
faceInfos.sort((a, b) { _sortFaceInfosOnCreationTime(faceInfos);
if (a.fileCreationTime == null && b.fileCreationTime == null) {
return 0;
} else if (a.fileCreationTime == null) {
return 1;
} else if (b.fileCreationTime == null) {
return -1;
} else {
return a.fileCreationTime!.compareTo(b.fileCreationTime!);
}
});
} }
// Sort the faceInfos such that the ones with null clusterId are at the end // Sort the faceInfos such that the ones with null clusterId are at the end
@ -796,19 +785,8 @@ class FaceClusteringService {
); );
} }
// Sort the faceInfos based on fileCreationTime, in ascending order, so oldest faces are first
if (fileIDToCreationTime != null) { if (fileIDToCreationTime != null) {
faceInfos.sort((a, b) { _sortFaceInfosOnCreationTime(faceInfos);
if (a.fileCreationTime == null && b.fileCreationTime == null) {
return 0;
} else if (a.fileCreationTime == null) {
return 1;
} else if (b.fileCreationTime == null) {
return -1;
} else {
return a.fileCreationTime!.compareTo(b.fileCreationTime!);
}
});
} }
if (faceInfos.isEmpty) { if (faceInfos.isEmpty) {
@ -996,19 +974,8 @@ class FaceClusteringService {
); );
} }
// Sort the faceInfos based on fileCreationTime, in ascending order, so oldest faces are first
if (fileIDToCreationTime != null) { if (fileIDToCreationTime != null) {
faceInfos.sort((a, b) { _sortFaceInfosOnCreationTime(faceInfos);
if (a.fileCreationTime == null && b.fileCreationTime == null) {
return 0;
} else if (a.fileCreationTime == null) {
return 1;
} else if (b.fileCreationTime == null) {
return -1;
} else {
return a.fileCreationTime!.compareTo(b.fileCreationTime!);
}
});
} }
// Get the embeddings // Get the embeddings
@ -1027,3 +994,20 @@ class FaceClusteringService {
return clusteredFaceIDs; return clusteredFaceIDs;
} }
} }
/// Sort the faceInfos based on fileCreationTime, in descending order, so newest faces are first
void _sortFaceInfosOnCreationTime(
List<FaceInfo> faceInfos,
) {
faceInfos.sort((b, a) {
if (a.fileCreationTime == null && b.fileCreationTime == null) {
return 0;
} else if (a.fileCreationTime == null) {
return 1;
} else if (b.fileCreationTime == null) {
return -1;
} else {
return a.fileCreationTime!.compareTo(b.fileCreationTime!);
}
});
}

View file

@ -590,8 +590,8 @@ class FaceMlService {
allFaceInfoForClustering.add(faceInfo); allFaceInfoForClustering.add(faceInfo);
} }
} }
// sort the embeddings based on file creation time, oldest first // sort the embeddings based on file creation time, newest first
allFaceInfoForClustering.sort((a, b) { allFaceInfoForClustering.sort((b, a) {
return fileIDToCreationTime[a.fileID]! return fileIDToCreationTime[a.fileID]!
.compareTo(fileIDToCreationTime[b.fileID]!); .compareTo(fileIDToCreationTime[b.fileID]!);
}); });