π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add people chapter for Wrapped 2025
laurenspriem0d9fcb930ff5
diff --git a/mobile/apps/photos/lib/services/wrapped/builders/people_candidate_builder.dart b/mobile/apps/photos/lib/services/wrapped/builders/people_candidate_builder.dartindex 97891c0cf1..395cff305b 100644--- a/mobile/apps/photos/lib/services/wrapped/builders/people_candidate_builder.dart+++ b/mobile/apps/photos/lib/services/wrapped/builders/people_candidate_builder.dart@@ -3,11 +3,571 @@ part of 'package:photos/services/wrapped/candidate_builders.dart';class PeopleCandidateBuilder extends WrappedCandidateBuilder {const PeopleCandidateBuilder();+ static const int _kMinFacesForTopPerson = 6;+ static const int _kMinFacesPerNewPerson = 4;+ static const int _kMinClusterFacesForNewPerson = 10;+@overrideString get debugLabel => "people";@overrideFuture<List<WrappedCard>> build(WrappedEngineContext context) async {- return <WrappedCard>[];+ final WrappedPeopleContext peopleContext = context.people;+ final _PeopleDataset dataset =+ _PeopleDataset.fromContext(peopleContext, context.year);+ if (!dataset.hasAnyContent) {+ return const <WrappedCard>[];+ }++ final List<WrappedCard> cards = <WrappedCard>[];++ final WrappedCard? topPersonCard = _buildTopPersonCard(dataset);+ if (topPersonCard != null) {+ cards.add(topPersonCard);+ }++ final WrappedCard? topThreeCard = _buildTopThreePeopleCard(dataset);+ if (topThreeCard != null) {+ cards.add(topThreeCard);+ }++ final WrappedCard? groupVsSoloCard = _buildGroupVsSoloCard(dataset);+ if (groupVsSoloCard != null) {+ cards.add(groupVsSoloCard);+ }++ final WrappedCard? newFacesCard = _buildNewFacesCard(dataset);+ if (newFacesCard != null) {+ cards.add(newFacesCard);+ }++ return cards;+ }++ WrappedCard? _buildTopPersonCard(_PeopleDataset dataset) {+ final _PersonStats? topPerson = dataset.topNamedPerson;+ if (topPerson == null || topPerson.faceCount < _kMinFacesForTopPerson) {+ return null;+ }++ final NumberFormat numberFormat = NumberFormat.decimalPattern();+ final int uniqueMoments = topPerson.uniqueMoments;+ final double share =+ dataset.totalNamedFaceCount == 0 || topPerson.faceCount == 0+ ? 0+ : topPerson.faceCount / dataset.totalNamedFaceCount;+ final int sharePercent = _percentOf(share);+ final List<String> chips = _cleanChips(<String>[+ "${numberFormat.format(topPerson.faceCount)} close-ups",+ if (sharePercent > 0) "$sharePercent% of your people shots",+ if (topPerson.firstSeenYear != null &&+ topPerson.firstSeenYear == dataset.year)+ "New in ${dataset.year}",+ ]);++ final String mention = topPerson.mentionForSentence;+ final String subtitle = uniqueMoments > 1+ ? "${numberFormat.format(uniqueMoments)} moments with $mention."+ : "One unforgettable moment with $mention.";++ final List<MediaRef> media =+ topPerson.topMediaFileIDs(3).map(MediaRef.new).toList(growable: false);++ final Map<String, Object?> meta = <String, Object?>{+ "personId": topPerson.personEntry.personID,+ "displayName": topPerson.displayNameForTitle,+ "appearanceCount": topPerson.faceCount,+ "uniqueMoments": uniqueMoments,+ "sharePercent": sharePercent,+ "detailChips": chips,+ "displayDurationMillis": 7500,+ };++ return WrappedCard(+ type: WrappedCardType.topPerson,+ title: "${topPerson.displayNameForTitle} starred in your ${dataset.year}",+ subtitle: subtitle,+ media: media,+ meta: meta,+ );+ }++ WrappedCard? _buildTopThreePeopleCard(_PeopleDataset dataset) {+ if (dataset.topNamedPeople.length < 3) {+ return null;+ }+ final List<_PersonStats> topThree =+ dataset.topNamedPeople.take(3).toList(growable: false);+ final NumberFormat numberFormat = NumberFormat.decimalPattern();++ final List<String> names = topThree+ .map((_PersonStats stats) => stats.displayNameForTitle)+ .toList(growable: false);+ final List<String> chips = _cleanChips(+ <String>[+ for (final _PersonStats stats in topThree)+ "${stats.displayNameForTitle}: ${numberFormat.format(stats.faceCount)} shots",+ ],+ );++ final List<MediaRef> media = topThree+ .map((_PersonStats stats) => stats.topMediaFileIDs(1))+ .expand((List<int> ids) => ids)+ .where((int id) => id > 0)+ .map(MediaRef.new)+ .toList(growable: false);++ final Map<String, Object?> meta = <String, Object?>{+ "personIds": topThree+ .map((_PersonStats stats) => stats.personEntry.personID)+ .toList(growable: false),+ "detailChips": chips,+ "displayDurationMillis": 7000,+ };++ return WrappedCard(+ type: WrappedCardType.topThreePeople,+ title: "Your top crew",+ subtitle: "${_formatNameList(names)} lit up your ${dataset.year}.",+ media: media.take(3).toList(growable: false),+ meta: meta,+ );+ }++ WrappedCard? _buildGroupVsSoloCard(_PeopleDataset dataset) {+ if (!dataset.hasFaceMoments) {+ return null;+ }+ final int totalMoments = dataset.totalFaceMoments;+ if (totalMoments <= 0) {+ return null;+ }+ final NumberFormat numberFormat = NumberFormat.decimalPattern();+ final int groupPercent =+ _percentOf(dataset.groupMoments / totalMoments.toDouble());+ final int soloPercent =+ _percentOf(dataset.soloMoments / totalMoments.toDouble());+ final int duoPercent =+ _percentOf(dataset.duoMoments / totalMoments.toDouble());++ final List<String> subtitleParts = <String>[];+ if (groupPercent > 0) {+ subtitleParts.add("$groupPercent% with the crew");+ }+ if (soloPercent > 0) {+ subtitleParts.add("$soloPercent% one-on-one");+ }+ if (subtitleParts.isEmpty && duoPercent > 0) {+ subtitleParts.add("$duoPercent% with a plus-one");+ }++ final List<String> chips = _cleanChips(<String>[+ if (dataset.groupMoments > 0)+ "${numberFormat.format(dataset.groupMoments)} group moments",+ if (dataset.duoMoments > 0)+ "${numberFormat.format(dataset.duoMoments)} duo shots",+ if (dataset.soloMoments > 0)+ "${numberFormat.format(dataset.soloMoments)} solo portraits",+ ]);++ final List<MediaRef> media = <int>[+ ...dataset.groupSampleFileIDs(2),+ ...dataset.soloSampleFileIDs(1),+ ].where((int id) => id > 0).map(MediaRef.new).toList(growable: false);++ final Map<String, Object?> meta = <String, Object?>{+ "groupShots": dataset.groupMoments,+ "soloShots": dataset.soloMoments,+ "duoShots": dataset.duoMoments,+ "totalFaceMoments": totalMoments,+ "groupSharePercent": groupPercent,+ "soloSharePercent": soloPercent,+ "duoSharePercent": duoPercent,+ "detailChips": chips,+ "displayDurationMillis": 6500,+ };++ return WrappedCard(+ type: WrappedCardType.groupVsSolo,+ title: "Memories shared",+ subtitle: subtitleParts.isEmpty+ ? "You balanced time with friends and quiet moments."+ : subtitleParts.join(" Β· "),+ media: media,+ meta: meta,+ );+ }++ WrappedCard? _buildNewFacesCard(_PeopleDataset dataset) {+ final List<_PersonStats> newPeople = dataset.topPeople.where(+ (_PersonStats stats) {+ final int? firstSeenYear = stats.firstSeenYear;+ if (firstSeenYear == null || firstSeenYear != dataset.year) {+ return false;+ }+ if (stats.faceCount < _kMinFacesPerNewPerson) {+ return false;+ }+ if (stats.personEntry.totalClusterFaceCount <+ _kMinClusterFacesForNewPerson) {+ return false;+ }+ return true;+ },+ ).toList(growable: false);++ if (newPeople.isEmpty) {+ return null;+ }++ final NumberFormat numberFormat = NumberFormat.decimalPattern();+ final int count = newPeople.length;+ final List<_PersonStats> highlights =+ newPeople.take(3).toList(growable: false);+ final List<String> highlightNames = highlights+ .map((_PersonStats stats) => stats.displayNameForTitle)+ .toList(growable: false);+ final String subtitleNames = highlightNames.isEmpty+ ? ""+ : "${_formatNameList(highlightNames)} joined your story.";++ final List<String> chips = _cleanChips(<String>[+ "${numberFormat.format(count)} new faces",+ if (highlightNames.isNotEmpty)+ "Spotlight: ${_formatNameList(highlightNames)}",+ ]);++ final List<MediaRef> media = highlights+ .map((_PersonStats stats) => stats.topMediaFileIDs(1))+ .expand((List<int> ids) => ids)+ .where((int id) => id > 0)+ .map(MediaRef.new)+ .toList(growable: false);++ final Map<String, Object?> meta = <String, Object?>{+ "newPersonCount": count,+ "highlightNames": highlightNames,+ "detailChips": chips,+ "displayDurationMillis": 6500,+ };++ return WrappedCard(+ type: WrappedCardType.newFaces,+ title: "${numberFormat.format(count)} new faces met",+ subtitle: subtitleNames.isEmpty+ ? "Fresh connections defined your ${dataset.year}."+ : subtitleNames,+ media: media,+ meta: meta,+ );+ }+}++class _PeopleDataset {+ _PeopleDataset._({+ required this.year,+ required List<_PersonStats> topPeople,+ required List<_PersonStats> topNamedPeople,+ required this.totalNamedFaceCount,+ required this.totalFaceMoments,+ required this.groupMoments,+ required this.soloMoments,+ required this.duoMoments,+ required List<_FileSample> groupSamples,+ required List<_FileSample> soloSamples,+ }) : _topPeople = List<_PersonStats>.unmodifiable(topPeople),+ _topNamedPeople = List<_PersonStats>.unmodifiable(topNamedPeople),+ _groupSamples = List<_FileSample>.unmodifiable(groupSamples),+ _soloSamples = List<_FileSample>.unmodifiable(soloSamples);++ final int year;+ final List<_PersonStats> _topPeople;+ final List<_PersonStats> _topNamedPeople;+ final int totalNamedFaceCount;+ final int totalFaceMoments;+ final int groupMoments;+ final int soloMoments;+ final int duoMoments;+ final List<_FileSample> _groupSamples;+ final List<_FileSample> _soloSamples;++ bool get hasAnyContent =>+ hasFaceMoments || _topPeople.isNotEmpty || _topNamedPeople.isNotEmpty;++ bool get hasFaceMoments => totalFaceMoments > 0;++ List<_PersonStats> get topPeople => _topPeople;++ List<_PersonStats> get topNamedPeople => _topNamedPeople;++ _PersonStats? get topNamedPerson =>+ _topNamedPeople.isEmpty ? null : _topNamedPeople.first;++ List<int> groupSampleFileIDs(int count) {+ return _groupSamples+ .map((_FileSample sample) => sample.fileID)+ .where((int id) => id > 0)+ .take(count)+ .toList(growable: false);+ }++ List<int> soloSampleFileIDs(int count) {+ return _soloSamples+ .map((_FileSample sample) => sample.fileID)+ .where((int id) => id > 0)+ .take(count)+ .toList(growable: false);+ }++ static _PeopleDataset fromContext(+ WrappedPeopleContext context,+ int year,+ ) {+ if (context.files.isEmpty) {+ return _PeopleDataset._empty(year);+ }++ final Map<String, _PersonStats> personStats = <String, _PersonStats>{};+ final Map<String, int> firstSeenYear = <String, int>{+ for (final MapEntry<String, int> entry+ in context.personFirstCaptureMicros.entries)+ entry.key: DateTime.fromMicrosecondsSinceEpoch(entry.value).year,+ };++ int totalNamedFaceCount = 0;+ int totalFaceMoments = 0;+ int groupMoments = 0;+ int soloMoments = 0;+ int duoMoments = 0;+ final List<_FileSample> groupSamples = <_FileSample>[];+ final List<_FileSample> soloSamples = <_FileSample>[];+ final Set<int> seenGroupFiles = <int>{};+ final Set<int> seenSoloFiles = <int>{};++ for (final WrappedPeopleFile file in context.files) {+ if (file.faces.isEmpty) {+ continue;+ }+ final List<WrappedFaceRef> faces = file.faces;+ final int highQualityCount =+ faces.where((WrappedFaceRef face) => face.isHighQuality).length;+ final int effectiveCount =+ highQualityCount > 0 ? highQualityCount : faces.length;+ if (effectiveCount > 0) {+ totalFaceMoments += 1;+ }+ if (effectiveCount >= 3) {+ groupMoments += 1;+ if (seenGroupFiles.add(file.uploadedFileID)) {+ groupSamples.add(+ _FileSample(+ fileID: file.uploadedFileID,+ captureMicros: file.captureMicros,+ ),+ );+ }+ } else if (effectiveCount == 2) {+ duoMoments += 1;+ } else if (effectiveCount == 1) {+ soloMoments += 1;+ if (seenSoloFiles.add(file.uploadedFileID)) {+ soloSamples.add(+ _FileSample(+ fileID: file.uploadedFileID,+ captureMicros: file.captureMicros,+ ),+ );+ }+ }++ for (final WrappedFaceRef face in faces) {+ final String? personID = face.personID;+ if (personID == null) {+ continue;+ }+ final WrappedPersonEntry? personEntry = context.persons[personID];+ if (personEntry == null || personEntry.isHidden) {+ continue;+ }+ totalNamedFaceCount += 1;+ final _PersonStats stats = personStats.putIfAbsent(+ personID,+ () => _PersonStats(personEntry),+ );+ stats.addFace(file, face);+ }+ }++ final List<_PersonStats> orderedPeople =+ personStats.values.toList(growable: false)+ ..sort(+ (_PersonStats a, _PersonStats b) {+ if (b.faceCount != a.faceCount) {+ return b.faceCount.compareTo(a.faceCount);+ }+ if (b.uniqueMoments != a.uniqueMoments) {+ return b.uniqueMoments.compareTo(a.uniqueMoments);+ }+ return a.displayNameForTitle+ .toLowerCase()+ .compareTo(b.displayNameForTitle.toLowerCase());+ },+ );++ for (final _PersonStats stats in orderedPeople) {+ final int? seenYear = firstSeenYear[stats.personEntry.personID];+ stats.firstSeenYear = seenYear;+ }++ final List<_PersonStats> orderedNamedPeople = orderedPeople+ .where((_PersonStats stats) => stats.hasName)+ .toList(growable: false);++ groupSamples.sort(+ (_FileSample a, _FileSample b) =>+ b.captureMicros.compareTo(a.captureMicros),+ );+ soloSamples.sort(+ (_FileSample a, _FileSample b) =>+ b.captureMicros.compareTo(a.captureMicros),+ );++ return _PeopleDataset._(+ year: year,+ topPeople: orderedPeople,+ topNamedPeople: orderedNamedPeople,+ totalNamedFaceCount: totalNamedFaceCount,+ totalFaceMoments: totalFaceMoments,+ groupMoments: groupMoments,+ soloMoments: soloMoments,+ duoMoments: duoMoments,+ groupSamples: groupSamples,+ soloSamples: soloSamples,+ );+ }++ static _PeopleDataset _empty(int year) {+ return _PeopleDataset._(+ year: year,+ topPeople: const <_PersonStats>[],+ topNamedPeople: const <_PersonStats>[],+ totalNamedFaceCount: 0,+ totalFaceMoments: 0,+ groupMoments: 0,+ soloMoments: 0,+ duoMoments: 0,+ groupSamples: const <_FileSample>[],+ soloSamples: const <_FileSample>[],+ );+ }+}++class _PersonStats {+ _PersonStats(this.personEntry);++ final WrappedPersonEntry personEntry;+ final Map<int, _PersonCapture> _captures = <int, _PersonCapture>{};+ int faceCount = 0;+ int highQualityFaces = 0;+ int? firstSeenYear;++ int get uniqueMoments => _captures.length;++ bool get hasName => personEntry.displayName.trim().isNotEmpty;++ String get displayNameForTitle =>+ hasName ? personEntry.displayName.trim() : "Someone special";++ String get mentionForSentence =>+ hasName ? personEntry.displayName.trim() : "someone special";++ void addFace(WrappedPeopleFile file, WrappedFaceRef face) {+ faceCount += 1;+ if (face.isHighQuality) {+ highQualityFaces += 1;+ }+ final _PersonCapture capture = _captures.putIfAbsent(+ file.uploadedFileID,+ () => _PersonCapture(+ fileID: file.uploadedFileID,+ captureMicros: file.captureMicros,+ ),+ );+ capture.registerFace(face);+ }++ List<int> topMediaFileIDs(int count) {+ final List<_PersonCapture> captures =+ _captures.values.toList(growable: false)+ ..sort(+ (_PersonCapture a, _PersonCapture b) {+ if (b.highQualityFaces != a.highQualityFaces) {+ return b.highQualityFaces.compareTo(a.highQualityFaces);+ }+ if ((b.bestScore ?? 0) != (a.bestScore ?? 0)) {+ return (b.bestScore ?? 0).compareTo(a.bestScore ?? 0);+ }+ return b.captureMicros.compareTo(a.captureMicros);+ },+ );+ return captures+ .where((_PersonCapture capture) => capture.fileID > 0)+ .map((_PersonCapture capture) => capture.fileID)+ .take(count)+ .toList(growable: false);+ }+}++class _PersonCapture {+ _PersonCapture({+ required this.fileID,+ required this.captureMicros,+ });++ final int fileID;+ final int captureMicros;+ double? bestScore;+ int highQualityFaces = 0;++ void registerFace(WrappedFaceRef face) {+ if (bestScore == null || face.score > bestScore!) {+ bestScore = face.score;+ }+ if (face.isHighQuality) {+ highQualityFaces += 1;+ }+ }+}++class _FileSample {+ const _FileSample({+ required this.fileID,+ required this.captureMicros,+ });++ final int fileID;+ final int captureMicros;+}++List<String> _cleanChips(List<String> chips) {+ return chips.where((String chip) => chip.trim().isNotEmpty).toList(+ growable: false,+ );+}++String _formatNameList(List<String> names) {+ if (names.isEmpty) return "";+ if (names.length == 1) return names.first;+ if (names.length == 2) {+ return "${names[0]} and ${names[1]}";+ }+ return "${names[0]}, ${names[1]}, and ${names[2]}";+}++int _percentOf(double value) {+ if (value.isNaN || value.isInfinite) {+ return 0;}+ final double clamped = value.clamp(0.0, 1.0);+ return (clamped * 100).round();}diff --git a/mobile/apps/photos/lib/services/wrapped/candidate_builders.dart b/mobile/apps/photos/lib/services/wrapped/candidate_builders.dartindex 83209a90cc..6aaa52102f 100644--- a/mobile/apps/photos/lib/services/wrapped/candidate_builders.dart+++ b/mobile/apps/photos/lib/services/wrapped/candidate_builders.dart@@ -21,11 +21,14 @@ class WrappedEngineContext {required this.year,required this.now,required List<EnteFile> files,- }) : files = List<EnteFile>.unmodifiable(files);+ WrappedPeopleContext? people,+ }) : files = List<EnteFile>.unmodifiable(files),+ people = people ?? WrappedPeopleContext.empty();final int year;final DateTime now;final List<EnteFile> files;+ final WrappedPeopleContext people;}/// Contract for producing Wrapped candidate cards for a specific domain.diff --git a/mobile/apps/photos/lib/services/wrapped/models.dart b/mobile/apps/photos/lib/services/wrapped/models.dartindex 39a640b150..36485b1ce2 100644--- a/mobile/apps/photos/lib/services/wrapped/models.dart+++ b/mobile/apps/photos/lib/services/wrapped/models.dart@@ -1,6 +1,205 @@import "dart:convert";import "package:flutter/foundation.dart" show immutable;+import "package:photos/services/machine_learning/face_ml/face_filtering/face_filtering_constants.dart";++@immutable+class WrappedPeopleContext {+ WrappedPeopleContext({+ required List<WrappedPeopleFile> files,+ required Map<String, WrappedPersonEntry> persons,+ required Map<String, int> personFirstCaptureMicros,+ }) : files = List<WrappedPeopleFile>.unmodifiable(files),+ persons = Map<String, WrappedPersonEntry>.unmodifiable(persons),+ personFirstCaptureMicros =+ Map<String, int>.unmodifiable(personFirstCaptureMicros);++ factory WrappedPeopleContext.empty() {+ return WrappedPeopleContext(+ files: const <WrappedPeopleFile>[],+ persons: const <String, WrappedPersonEntry>{},+ personFirstCaptureMicros: const <String, int>{},+ );+ }++ final List<WrappedPeopleFile> files;+ final Map<String, WrappedPersonEntry> persons;+ final Map<String, int> personFirstCaptureMicros;++ bool get hasPeople => files.isNotEmpty && persons.isNotEmpty;++ Map<String, Object?> toJson() {+ return <String, Object?>{+ "files": files.map((WrappedPeopleFile file) => file.toJson()).toList(),+ "persons": persons.map(+ (String key, WrappedPersonEntry value) => MapEntry(+ key,+ value.toJson(),+ ),+ ),+ "firstCaptureMicros": personFirstCaptureMicros,+ };+ }++ static WrappedPeopleContext fromJson(Map<String, Object?> json) {+ final List<dynamic> rawFiles = json["files"] as List<dynamic>? ?? const [];+ final Map<String, Object?> rawPersons =+ (json["persons"] as Map?)?.cast<String, Object?>() ??+ <String, Object?>{};+ final Map<String, WrappedPersonEntry> persons =+ <String, WrappedPersonEntry>{+ for (final MapEntry<String, Object?> entry in rawPersons.entries)+ entry.key: WrappedPersonEntry.fromJson(+ (entry.value as Map).cast<String, Object?>(),+ ),+ };+ final Map<String, int> firstCaptureMicros =+ (json["firstCaptureMicros"] as Map?)?.map(+ (Object? key, Object? value) => MapEntry(+ key?.toString() ?? "",+ (value as num).toInt(),+ ),+ ) ??+ <String, int>{};+ return WrappedPeopleContext(+ files: rawFiles+ .map(+ (dynamic entry) => WrappedPeopleFile.fromJson(+ (entry as Map).cast<String, Object?>(),+ ),+ )+ .toList(growable: false),+ persons: persons,+ personFirstCaptureMicros: firstCaptureMicros,+ );+ }+}++@immutable+class WrappedPeopleFile {+ WrappedPeopleFile({+ required this.uploadedFileID,+ required this.captureMicros,+ required List<WrappedFaceRef> faces,+ }) : faces = List<WrappedFaceRef>.unmodifiable(faces);++ final int uploadedFileID;+ final int captureMicros;+ final List<WrappedFaceRef> faces;++ Map<String, Object?> toJson() {+ return <String, Object?>{+ "uploadedFileID": uploadedFileID,+ "captureMicros": captureMicros,+ "faces": faces.map((WrappedFaceRef ref) => ref.toJson()).toList(),+ };+ }++ static WrappedPeopleFile fromJson(Map<String, Object?> json) {+ final List<dynamic> rawFaces =+ json["faces"] as List<dynamic>? ?? const <dynamic>[];+ return WrappedPeopleFile(+ uploadedFileID: json["uploadedFileID"] as int? ?? 0,+ captureMicros: json["captureMicros"] as int? ?? 0,+ faces: rawFaces+ .map(+ (dynamic entry) => WrappedFaceRef.fromJson(+ (entry as Map).cast<String, Object?>(),+ ),+ )+ .toList(growable: false),+ );+ }+}++@immutable+class WrappedFaceRef {+ const WrappedFaceRef({+ required this.faceID,+ required this.score,+ required this.blur,+ this.personID,+ this.clusterID,+ });++ final String faceID;+ final double score;+ final double blur;+ final String? personID;+ final String? clusterID;++ bool get isHighQuality =>+ score > kMinimumQualityFaceScore && blur >= kLaplacianHardThreshold;++ Map<String, Object?> toJson() {+ return <String, Object?>{+ "faceID": faceID,+ "score": score,+ "blur": blur,+ "personID": personID,+ "clusterID": clusterID,+ };+ }++ static WrappedFaceRef fromJson(Map<String, Object?> json) {+ return WrappedFaceRef(+ faceID: json["faceID"] as String? ?? "",+ score: (json["score"] as num?)?.toDouble() ?? 0.0,+ blur: (json["blur"] as num?)?.toDouble() ?? 0.0,+ personID: json["personID"] as String?,+ clusterID: json["clusterID"] as String?,+ );+ }+}++@immutable+class WrappedPersonEntry {+ WrappedPersonEntry({+ required this.personID,+ required this.displayName,+ required this.isHidden,+ required Map<String, int> clusterFaceCounts,+ }) : clusterFaceCounts = Map<String, int>.unmodifiable(clusterFaceCounts);++ final String personID;+ final String displayName;+ final bool isHidden;+ final Map<String, int> clusterFaceCounts;++ int get totalClusterFaceCount {+ int sum = 0;+ for (final int value in clusterFaceCounts.values) {+ sum += value;+ }+ return sum;+ }++ Map<String, Object?> toJson() {+ return <String, Object?>{+ "personID": personID,+ "displayName": displayName,+ "isHidden": isHidden,+ "clusterFaceCounts": clusterFaceCounts,+ };+ }++ static WrappedPersonEntry fromJson(Map<String, Object?> json) {+ final Map<String, int> clusterFaceCounts =+ (json["clusterFaceCounts"] as Map?)?.map(+ (Object? key, Object? value) => MapEntry(+ key?.toString() ?? "",+ (value as num).toInt(),+ ),+ ) ??+ <String, int>{};+ return WrappedPersonEntry(+ personID: json["personID"] as String? ?? "",+ displayName: json["displayName"] as String? ?? "",+ isHidden: json["isHidden"] as bool? ?? false,+ clusterFaceCounts: clusterFaceCounts,+ );+ }+}/// Sentinel value used in heatmap grids when a day should be hidden but space/// must still be reserved (e.g. future dates).diff --git a/mobile/apps/photos/lib/services/wrapped/wrapped_engine.dart b/mobile/apps/photos/lib/services/wrapped/wrapped_engine.dartindex 65ce2b7ea7..9eae37492d 100644--- a/mobile/apps/photos/lib/services/wrapped/wrapped_engine.dart+++ b/mobile/apps/photos/lib/services/wrapped/wrapped_engine.dart@@ -1,7 +1,12 @@import "package:computer/computer.dart";import "package:logging/logging.dart";+import "package:photos/db/ml/db.dart";import "package:photos/models/file/extensions/file_props.dart";import "package:photos/models/file/file.dart";+import "package:photos/models/ml/face/face_with_embedding.dart";+import "package:photos/models/ml/face/person.dart";+import "package:photos/services/machine_learning/face_ml/person/person_service.dart";+import "package:photos/services/machine_learning/ml_result.dart";import "package:photos/services/search_service.dart";import "package:photos/services/wrapped/candidate_builders.dart";import "package:photos/services/wrapped/models.dart";@@ -18,9 +23,15 @@ class WrappedEngine {final DateTime now = DateTime.now();_engineLogger.fine("Scheduling Wrapped compute for $year at $now");- final List<EnteFile> yearFiles = await _collectFilesForYear(year);+ final _CollectedFiles collected = await _collectFilesForYear(year);_engineLogger.fine(- "Collected ${yearFiles.length} media items for Wrapped $year compute",+ "Collected ${collected.yearFiles.length} media items for Wrapped $year compute",+ );++ final WrappedPeopleContext peopleContext = await _collectPeopleContext(+ year: year,+ yearFiles: collected.yearFiles,+ fileByUploadedId: collected.fileByUploadedId,);return await Computer.shared().compute(@@ -28,20 +39,26 @@ class WrappedEngine {param: <String, Object?>{"year": year,"now": now,- "files": yearFiles,+ "files": collected.yearFiles,+ "people": peopleContext.toJson(),},taskName: "wrapped_compute_$year",) as WrappedResult;}- static Future<List<EnteFile>> _collectFilesForYear(int year) async {+ static Future<_CollectedFiles> _collectFilesForYear(int year) async {final List<EnteFile> allFiles =await SearchService.instance.getAllFilesForSearch();final List<EnteFile> filtered = <EnteFile>[];+ final Map<int, EnteFile> fileByUploadedId = <int, EnteFile>{};for (final EnteFile file in allFiles) {if (!file.isOwner) {continue;}+ final int? uploadedId = file.uploadedFileID;+ if (uploadedId != null) {+ fileByUploadedId[uploadedId] = file;+ }final int? creationTime = file.creationTime;if (creationTime == null) {continue;@@ -65,7 +82,154 @@ class WrappedEngine {},);- return filtered;+ return _CollectedFiles(+ yearFiles: filtered,+ fileByUploadedId: fileByUploadedId,+ );+ }++ static Future<WrappedPeopleContext> _collectPeopleContext({+ required int year,+ required List<EnteFile> yearFiles,+ required Map<int, EnteFile> fileByUploadedId,+ }) async {+ if (yearFiles.isEmpty) {+ return WrappedPeopleContext.empty();+ }++ final Set<int> yearFileIDs = <int>{+ for (final EnteFile file in yearFiles)+ if (file.uploadedFileID != null) file.uploadedFileID!,+ };+ if (yearFileIDs.isEmpty) {+ return WrappedPeopleContext.empty();+ }++ final Map<int, List<FaceWithoutEmbedding>> facesByFile =+ <int, List<FaceWithoutEmbedding>>{};+ try {+ final Map<int, List<FaceWithoutEmbedding>> allFaces =+ await MLDataDB.instance.getFileIDsToFacesWithoutEmbedding();+ if (allFaces.isNotEmpty) {+ for (final MapEntry<int, List<FaceWithoutEmbedding>> entry+ in allFaces.entries) {+ if (yearFileIDs.contains(entry.key)) {+ facesByFile[entry.key] = entry.value;+ }+ }+ }+ } catch (error, stackTrace) {+ _engineLogger.warning(+ "Failed to fetch faces for Wrapped $year people context",+ error,+ stackTrace,+ );+ return WrappedPeopleContext.empty();+ }++ final Map<String, WrappedPersonEntry> personEntries =+ <String, WrappedPersonEntry>{};+ final Map<String, int> personFirstCaptureMicros = <String, int>{};+ final Map<String, String> faceIdToPerson = <String, String>{};+ final Map<String, String> faceIdToCluster = <String, String>{};++ if (PersonService.isInitialized) {+ try {+ final List<PersonEntity> persons =+ await PersonService.instance.getPersons();+ for (final PersonEntity person in persons) {+ final PersonData data = person.data;+ if (data.assigned.isEmpty) {+ continue;+ }+ final Map<String, int> clusterFaceCounts = <String, int>{};+ int? earliestMicros;+ for (final ClusterInfo cluster in data.assigned) {+ if (cluster.faces.isEmpty) {+ continue;+ }+ clusterFaceCounts[cluster.id] = cluster.faces.length;+ for (final String faceID in cluster.faces) {+ faceIdToPerson[faceID] = person.remoteID;+ faceIdToCluster[faceID] = cluster.id;+ final int? fileID = tryGetFileIdFromFaceId(faceID);+ if (fileID == null) {+ continue;+ }+ final EnteFile? file = fileByUploadedId[fileID];+ final int? captureMicros = file?.creationTime;+ if (captureMicros == null || captureMicros <= 0) {+ continue;+ }+ if (earliestMicros == null || captureMicros < earliestMicros) {+ earliestMicros = captureMicros;+ }+ }+ }+ if (clusterFaceCounts.isEmpty) {+ continue;+ }+ personEntries[person.remoteID] = WrappedPersonEntry(+ personID: person.remoteID,+ displayName: data.name,+ isHidden: data.isHidden,+ clusterFaceCounts: clusterFaceCounts,+ );+ if (earliestMicros != null) {+ personFirstCaptureMicros[person.remoteID] = earliestMicros;+ }+ }+ } catch (error, stackTrace) {+ _engineLogger.warning(+ "Failed to load persons for Wrapped $year",+ error,+ stackTrace,+ );+ }+ }++ final List<WrappedPeopleFile> peopleFiles = <WrappedPeopleFile>[];+ for (final EnteFile file in yearFiles) {+ final int? uploadedFileID = file.uploadedFileID;+ if (uploadedFileID == null) {+ continue;+ }+ final List<FaceWithoutEmbedding>? faces = facesByFile[uploadedFileID];+ if (faces == null || faces.isEmpty) {+ continue;+ }+ final List<WrappedFaceRef> faceRefs = faces+ .map(+ (FaceWithoutEmbedding face) => WrappedFaceRef(+ faceID: face.faceID,+ score: face.score,+ blur: face.blur,+ personID: faceIdToPerson[face.faceID],+ clusterID: faceIdToCluster[face.faceID],+ ),+ )+ .toList(growable: false);+ if (faceRefs.isEmpty) {+ continue;+ }+ peopleFiles.add(+ WrappedPeopleFile(+ uploadedFileID: uploadedFileID,+ captureMicros: file.creationTime ?? 0,+ faces: faceRefs,+ ),+ );+ }++ if (peopleFiles.isEmpty && personEntries.isEmpty) {+ return WrappedPeopleContext.empty();+ }++ return WrappedPeopleContext(+ files: peopleFiles,+ persons: personEntries,+ personFirstCaptureMicros: personFirstCaptureMicros,+ );}}@@ -75,8 +239,10 @@ Future<WrappedResult> _wrappedComputeIsolate(final int year = args["year"] as int;final DateTime now = args["now"] as DateTime;final List<EnteFile> files =- (args["files"] as List<dynamic>? ?? const <dynamic>[])- .cast<EnteFile>();+ (args["files"] as List<dynamic>? ?? const <dynamic>[]).cast<EnteFile>();+ final Map<String, Object?> peopleRaw =+ (args["people"] as Map?)?.cast<String, Object?>() ?? <String, Object?>{};+ final WrappedPeopleContext people = WrappedPeopleContext.fromJson(peopleRaw);_computeLogger.fine("Wrapped compute isolate running for $year with ${files.length} media items",@@ -86,6 +252,7 @@ Future<WrappedResult> _wrappedComputeIsolate(year: year,now: now,files: files,+ people: people,);final List<WrappedCard> cards = <WrappedCard>[];for (final WrappedCandidateBuilder builder in wrappedCandidateBuilders) {@@ -116,3 +283,14 @@ Future<WrappedResult> _wrappedComputeIsolate(year: year,);}++class _CollectedFiles {+ _CollectedFiles({+ required List<EnteFile> yearFiles,+ required Map<int, EnteFile> fileByUploadedId,+ }) : yearFiles = List<EnteFile>.unmodifiable(yearFiles),+ fileByUploadedId = Map<int, EnteFile>.unmodifiable(fileByUploadedId);++ final List<EnteFile> yearFiles;+ final Map<int, EnteFile> fileByUploadedId;+}diff --git a/mobile/apps/photos/lib/ui/wrapped/cards/people_card_content.dart b/mobile/apps/photos/lib/ui/wrapped/cards/people_card_content.dartindex 433ab4e566..fa722dbe6c 100644--- a/mobile/apps/photos/lib/ui/wrapped/cards/people_card_content.dart+++ b/mobile/apps/photos/lib/ui/wrapped/cards/people_card_content.dart@@ -5,5 +5,232 @@ Widget? buildPeopleCardContent(EnteColorScheme colorScheme,EnteTextTheme textTheme,) {- return null;+ switch (card.type) {+ case WrappedCardType.topPerson:+ return _TopPersonCardContent(+ card: card,+ colorScheme: colorScheme,+ textTheme: textTheme,+ );+ case WrappedCardType.topThreePeople:+ return _TopThreePeopleCardContent(+ card: card,+ colorScheme: colorScheme,+ textTheme: textTheme,+ );+ case WrappedCardType.groupVsSolo:+ return _GroupVsSoloCardContent(+ card: card,+ colorScheme: colorScheme,+ textTheme: textTheme,+ );+ case WrappedCardType.newFaces:+ return _NewFacesCardContent(+ card: card,+ colorScheme: colorScheme,+ textTheme: textTheme,+ );+ default:+ return null;+ }+}++class _TopPersonCardContent extends StatelessWidget {+ const _TopPersonCardContent({+ required this.card,+ required this.colorScheme,+ required this.textTheme,+ });++ final WrappedCard card;+ final EnteColorScheme colorScheme;+ final EnteTextTheme textTheme;++ @override+ Widget build(BuildContext context) {+ final List<String> chips = _stringListFromMeta(card.meta, "detailChips");++ return Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ _HeroMediaCollage(+ media: card.media,+ colorScheme: colorScheme,+ ),+ const SizedBox(height: 24),+ Text(+ card.title,+ style: textTheme.h2Bold,+ ),+ if (card.subtitle != null && card.subtitle!.isNotEmpty)+ Padding(+ padding: const EdgeInsets.only(top: 12),+ child: Text(+ card.subtitle!,+ style: textTheme.bodyMuted,+ ),+ ),+ if (chips.isNotEmpty) ...[+ const SizedBox(height: 20),+ _DetailChips(+ chips: chips,+ colorScheme: colorScheme,+ textTheme: textTheme,+ ),+ ],+ const Spacer(),+ ],+ );+ }+}++class _TopThreePeopleCardContent extends StatelessWidget {+ const _TopThreePeopleCardContent({+ required this.card,+ required this.colorScheme,+ required this.textTheme,+ });++ final WrappedCard card;+ final EnteColorScheme colorScheme;+ final EnteTextTheme textTheme;++ @override+ Widget build(BuildContext context) {+ final List<String> chips = _stringListFromMeta(card.meta, "detailChips");++ return Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(+ card.title,+ style: textTheme.h2Bold,+ ),+ if (card.subtitle != null && card.subtitle!.isNotEmpty)+ Padding(+ padding: const EdgeInsets.only(top: 12),+ child: Text(+ card.subtitle!,+ style: textTheme.bodyMuted,+ ),+ ),+ if (card.media.isNotEmpty) ...[+ const SizedBox(height: 24),+ _MediaRow(+ media: card.media.take(3).toList(growable: false),+ colorScheme: colorScheme,+ ),+ ],+ if (chips.isNotEmpty) ...[+ const SizedBox(height: 20),+ _DetailChips(+ chips: chips,+ colorScheme: colorScheme,+ textTheme: textTheme,+ ),+ ],+ const Spacer(),+ ],+ );+ }+}++class _GroupVsSoloCardContent extends StatelessWidget {+ const _GroupVsSoloCardContent({+ required this.card,+ required this.colorScheme,+ required this.textTheme,+ });++ final WrappedCard card;+ final EnteColorScheme colorScheme;+ final EnteTextTheme textTheme;++ @override+ Widget build(BuildContext context) {+ final List<String> chips = _stringListFromMeta(card.meta, "detailChips");++ return Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(+ card.title,+ style: textTheme.h2Bold,+ ),+ if (card.subtitle != null && card.subtitle!.isNotEmpty)+ Padding(+ padding: const EdgeInsets.only(top: 12),+ child: Text(+ card.subtitle!,+ style: textTheme.bodyMuted,+ ),+ ),+ if (card.media.isNotEmpty) ...[+ const SizedBox(height: 20),+ _MediaRow(+ media: card.media.take(3).toList(growable: false),+ colorScheme: colorScheme,+ ),+ ],+ if (chips.isNotEmpty) ...[+ const SizedBox(height: 20),+ _DetailChips(+ chips: chips,+ colorScheme: colorScheme,+ textTheme: textTheme,+ ),+ ],+ const Spacer(),+ ],+ );+ }+}++class _NewFacesCardContent extends StatelessWidget {+ const _NewFacesCardContent({+ required this.card,+ required this.colorScheme,+ required this.textTheme,+ });++ final WrappedCard card;+ final EnteColorScheme colorScheme;+ final EnteTextTheme textTheme;++ @override+ Widget build(BuildContext context) {+ final List<String> chips = _stringListFromMeta(card.meta, "detailChips");++ return Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ _HeroMediaCollage(+ media: card.media,+ colorScheme: colorScheme,+ ),+ const SizedBox(height: 24),+ Text(+ card.title,+ style: textTheme.h2Bold,+ ),+ if (card.subtitle != null && card.subtitle!.isNotEmpty)+ Padding(+ padding: const EdgeInsets.only(top: 12),+ child: Text(+ card.subtitle!,+ style: textTheme.bodyMuted,+ ),+ ),+ if (chips.isNotEmpty) ...[+ const SizedBox(height: 20),+ _DetailChips(+ chips: chips,+ colorScheme: colorScheme,+ textTheme: textTheme,+ ),+ ],+ const Spacer(),+ ],+ );+ }}