Skip to content

armgit / ente

Public Imported from GitHub
0

💚 End-to-end encrypted cloud for everything.

Exclude first four years of person

laurenspriemab94d1640dba
diff --git a/mobile/apps/photos/.docs/face_timeline_spec.md b/mobile/apps/photos/.docs/face_timeline_spec.md
index 2b07ca820f..da5b573621 100644
--- a/mobile/apps/photos/.docs/face_timeline_spec.md
+++ b/mobile/apps/photos/.docs/face_timeline_spec.md
@@ -6,6 +6,7 @@ Deliver an on-device, auto-playing “faces timeline” for eligible named peopl
### Eligibility & Precomputation
- Run background precomputation per person after ML syncs or people data changes.
- Skip people marked ignored/hidden or lacking ≥5 distinct calendar years that each contribute ≥4 faces (based on file `creationTime`); a year only counts toward eligibility if it independently meets that four-face threshold.
+- When a birthdate is known, ignore faces captured before the person's fifth birthday so ages 0–4 neither count toward eligibility nor appear in playback.
- Group faces by year, sort chronologically, and select four samples spread across the year (prefer quarterly spacing; gracefully accept uneven distributions).
- Store the resulting ordered face list with metadata (faceID, fileID, creationTime, optional crop bytes) in a local cache keyed by personID.
- Persist the ordered timeline metadata for all people in a single JSON cache (e.g., `faces_timeline/cache.json`) that maps each eligible `personID` to the face ordering, timestamps, and auxiliary playback data; continue to rely on the existing face thumbnail cache for the actual crop bytes.
diff --git a/mobile/apps/photos/lib/services/faces_timeline/faces_timeline_service.dart b/mobile/apps/photos/lib/services/faces_timeline/faces_timeline_service.dart
index 02b4b0e256..9120ef393b 100644
--- a/mobile/apps/photos/lib/services/faces_timeline/faces_timeline_service.dart
+++ b/mobile/apps/photos/lib/services/faces_timeline/faces_timeline_service.dart
@@ -31,6 +31,7 @@ class FacesTimelineService {
static const _minimumYears = 5;
static const _minimumFacesPerYear = 4;
+ static const _minimumEligibleAgeYears = 5;
static const _recomputeCooldown = Duration(hours: 24);
final Logger _logger = Logger("FacesTimelineService");
@@ -254,6 +255,8 @@ class FacesTimelineService {
int nowMicros,
) async {
final personId = person.remoteID;
+ final minCreationTimeMicros =
+ minimumEligibleCreationTimeMicros(person.data.birthDate);
final faceIds = await _mlDataDB.getFaceIDsForPerson(personId);
if (faceIds.isEmpty) {
_logger.fine(
@@ -312,9 +315,16 @@ class FacesTimelineService {
);
}
+ if (minCreationTimeMicros != null) {
+ faces.removeWhere(
+ (face) => face.creationTimeMicros < minCreationTimeMicros,
+ );
+ }
+
if (faces.isEmpty) {
_logger.fine(
- "Faces timeline: person $personId has no usable faces after filtering, marking ineligible",
+ "Faces timeline: person $personId has no usable faces after filtering,"
+ " marking ineligible",
);
final timeline = FacesTimelinePersonTimeline(
personId: personId,
@@ -331,6 +341,8 @@ class FacesTimelineService {
"faces": faces.map((face) => face.toJson()).toList(),
"minYears": _minimumYears,
"minFaces": _minimumFacesPerYear,
+ if (minCreationTimeMicros != null)
+ "minCreationTime": minCreationTimeMicros,
},
taskName: "faces_timeline_select_${person.remoteID}",
);
@@ -432,6 +444,28 @@ class FacesTimelineService {
.toSet();
readyPersonIds.value = current;
}
+
+ @visibleForTesting
+ static int? minimumEligibleCreationTimeMicros(String? birthDateString) {
+ if (birthDateString == null || birthDateString.isEmpty) {
+ return null;
+ }
+ final birthDate = DateTime.tryParse(birthDateString);
+ if (birthDate == null) {
+ return null;
+ }
+ final targetYear = birthDate.year + _minimumEligibleAgeYears;
+ final targetMonth = birthDate.month;
+ final daysInTargetMonth = DateTime(targetYear, targetMonth + 1, 0).day;
+ final targetDay =
+ birthDate.day > daysInTargetMonth ? daysInTargetMonth : birthDate.day;
+ final cutoff = DateTime(
+ targetYear,
+ targetMonth,
+ targetDay,
+ );
+ return cutoff.microsecondsSinceEpoch;
+ }
}
class _TimelineFaceData {
@@ -479,9 +513,16 @@ Map<String, dynamic> selectTimelineEntriesTask(Map<String, dynamic> param) {
(param["faces"] as List<dynamic>).cast<Map<String, dynamic>>();
final minYears = param["minYears"] as int;
final minFacesPerYear = param["minFaces"] as int;
+ final minCreationTimeMicros = param["minCreationTime"] as int?;
final faces = facesJson.map(_TimelineFaceData.fromJson).toList();
+ if (minCreationTimeMicros != null) {
+ faces.removeWhere(
+ (face) => face.creationTimeMicros < minCreationTimeMicros,
+ );
+ }
+
if (faces.isEmpty) {
return {"status": "ineligible", "eligibleYearCount": 0};
}
diff --git a/mobile/apps/photos/test/services/faces_timeline/timeline_selector_test.dart b/mobile/apps/photos/test/services/faces_timeline/timeline_selector_test.dart
index 6248a8127c..eb8764e133 100644
--- a/mobile/apps/photos/test/services/faces_timeline/timeline_selector_test.dart
+++ b/mobile/apps/photos/test/services/faces_timeline/timeline_selector_test.dart
@@ -4,8 +4,7 @@ import "package:photos/services/faces_timeline/faces_timeline_service.dart";
Map<String, dynamic> _buildFace(
String faceId,
int fileId,
- DateTime creationDate,
- {
+ DateTime creationDate, {
double score = 0.9,
double blur = 50.0,
}) {
@@ -133,10 +132,12 @@ void main() {
final entries =
(result["entries"] as List<dynamic>).cast<Map<String, dynamic>>();
final faceIds = entries.map((entry) => entry["faceId"]).toList();
- expect(faceIds, containsAll(<String>[
- "sharp-and-high-score",
- "high-resolution",
- ]));
+ expect(
+ faceIds,
+ containsAll(<String>[
+ "sharp-and-high-score",
+ "high-resolution",
+ ]));
expect(faceIds.length, equals(4));
expect(faceIds, isNot(contains("low-score")));
});
@@ -229,5 +230,101 @@ void main() {
expect(dayCounts.keys.length, equals(3));
expect(dayCounts.values.any((count) => count > 1), isTrue);
});
+
+ test("excludes faces captured before minimum creation time", () {
+ final faces = <Map<String, dynamic>>[];
+ for (int year = 2008; year < 2017; year++) {
+ for (int index = 0; index < 4; index++) {
+ faces.add(
+ _buildFace(
+ "face-$year-$index",
+ year * 1000 + index,
+ DateTime(year, index + 1, 1),
+ ),
+ );
+ }
+ }
+
+ final cutoff = DateTime(2010, 1, 1).microsecondsSinceEpoch;
+ final result = selectTimelineEntriesTask({
+ "faces": faces,
+ "minYears": 5,
+ "minFaces": 4,
+ "minCreationTime": cutoff,
+ });
+
+ expect(result["status"], equals("ready"));
+ final years = (result["years"] as List<dynamic>).cast<int>();
+ expect(years.first, equals(2010));
+ expect(years.length, equals(7));
+ expect(years, isNot(contains(2008)));
+ expect(years, isNot(contains(2009)));
+ });
+
+ test("minimum creation time affects eligibility counts", () {
+ final faces = <Map<String, dynamic>>[];
+ for (int year = 2012; year < 2018; year++) {
+ for (int index = 0; index < 4; index++) {
+ faces.add(
+ _buildFace(
+ "face-$year-$index",
+ year * 10 + index,
+ DateTime(year, 6, 1).add(Duration(days: index * 30)),
+ ),
+ );
+ }
+ }
+
+ final cutoff = DateTime(2014, 1, 1).microsecondsSinceEpoch;
+ final result = selectTimelineEntriesTask({
+ "faces": faces,
+ "minYears": 5,
+ "minFaces": 4,
+ "minCreationTime": cutoff,
+ });
+
+ expect(result["status"], equals("ineligible"));
+ expect(result["eligibleYearCount"], equals(4));
+ expect(result["entries"], isNull);
+ });
+ });
+
+ group("minimum eligible creation time", () {
+ test("returns null when birthdate missing", () {
+ expect(
+ FacesTimelineService.minimumEligibleCreationTimeMicros(null),
+ isNull,
+ );
+ expect(
+ FacesTimelineService.minimumEligibleCreationTimeMicros(""),
+ isNull,
+ );
+ });
+
+ test("returns null for invalid birthdate string", () {
+ expect(
+ FacesTimelineService.minimumEligibleCreationTimeMicros("invalid"),
+ isNull,
+ );
+ });
+
+ test("computes fifth birthday cutoff", () {
+ final birthDate = DateTime(2010, 6, 15);
+ final cutoff = FacesTimelineService.minimumEligibleCreationTimeMicros(
+ "2010-06-15",
+ );
+ final expected =
+ DateTime(birthDate.year + 5, birthDate.month, birthDate.day)
+ .microsecondsSinceEpoch;
+ expect(cutoff, equals(expected));
+ });
+
+ test("clamps day for leap birthdays", () {
+ final cutoff = FacesTimelineService.minimumEligibleCreationTimeMicros(
+ "2012-02-29",
+ );
+ final expected = DateTime(2017, 2, 28).microsecondsSinceEpoch;
+ expect(cutoff, equals(expected));
+ });
});
}