diff --git a/mobile/lib/face/model/person.dart b/mobile/lib/face/model/person.dart index ee1cb724b..e93bebe4e 100644 --- a/mobile/lib/face/model/person.dart +++ b/mobile/lib/face/model/person.dart @@ -1,6 +1,8 @@ // PersonEntity represents information about a Person in the context of FaceClustering that is stored. // On the remote server, the PersonEntity is stored as {Entity} with type person. // On the device, this information is stored as [LocalEntityData] with type person. +import "package:flutter/foundation.dart"; + class PersonEntity { final String remoteID; final PersonData data; @@ -80,6 +82,25 @@ class PersonData { ); } + void logStats() { + if (kDebugMode == false) return; + // log number of assigned and rejected clusters and total number of faces in each cluster + final StringBuffer sb = StringBuffer(); + sb.writeln('Person: $name'); + int assignedCount = 0; + for (final a in (assigned ?? [])) { + assignedCount += a.faces.length; + } + sb.writeln('Assigned: ${assigned?.length} withFaces $assignedCount'); + sb.writeln('Rejected: ${rejected?.length}'); + if (assigned != null) { + for (var cluster in assigned!) { + sb.writeln('Cluster: ${cluster.id} - ${cluster.faces.length}'); + } + } + debugPrint(sb.toString()); + } + // toJson Map toJson() => { 'name': name, diff --git a/mobile/lib/services/machine_learning/face_ml/person/person_service.dart b/mobile/lib/services/machine_learning/face_ml/person/person_service.dart index 4d78101f0..774267de1 100644 --- a/mobile/lib/services/machine_learning/face_ml/person/person_service.dart +++ b/mobile/lib/services/machine_learning/face_ml/person/person_service.dart @@ -111,6 +111,7 @@ class PersonService { personID: personID, clusterID: clusterID, ); + personData.logStats(); } Future removeClusterToPerson({ @@ -129,6 +130,7 @@ class PersonService { personID: personID, clusterID: clusterID, ); + personData.logStats(); } Future deletePerson(String personID, {bool onlyMapping = true}) async { @@ -145,6 +147,7 @@ class PersonService { id: personID, ); await faceMLDataDB.removePerson(personID); + justName.data.logStats(); } else { await entityService.deleteEntry(personID); await faceMLDataDB.removePerson(personID); @@ -173,10 +176,9 @@ class PersonService { } clusterToPersonID[cluster.id] = e.id; } - if(kDebugMode) { + if (kDebugMode) { logger.info( - "Person ${e.id} ${personData.name} has ${personData.assigned! - .length} clusters with $faceCount faces", + "Person ${e.id} ${personData.name} has ${personData.assigned!.length} clusters with $faceCount faces", ); } } @@ -186,11 +188,33 @@ class PersonService { await faceMLDataDB.bulkAssignClusterToPersonID(clusterToPersonID); } - Future updatePerson(PersonEntity updatePerson) async { + Future updateAttributes( + String id, { + String? name, + String? avatarFaceId, + bool? isHidden, + int? version, + String? birthDate, + }) async { + final person = (await getPerson(id))!; + final updatedPerson = person.copyWith( + data: person.data.copyWith( + name: name, + avatarFaceId: avatarFaceId, + isHidden: isHidden, + version: version, + birthDate: birthDate, + ), + ); + await _updatePerson(updatedPerson); + } + + Future _updatePerson(PersonEntity updatePerson) async { await entityService.addOrUpdate( EntityType.person, json.encode(updatePerson.data.toJson()), id: updatePerson.remoteID, ); + updatePerson.data.logStats(); } } diff --git a/mobile/lib/ui/viewer/actions/file_selection_actions_widget.dart b/mobile/lib/ui/viewer/actions/file_selection_actions_widget.dart index eb3b44f29..bb5e77818 100644 --- a/mobile/lib/ui/viewer/actions/file_selection_actions_widget.dart +++ b/mobile/lib/ui/viewer/actions/file_selection_actions_widget.dart @@ -653,11 +653,10 @@ class _FileSelectionActionsWidgetState Future _setPersonCover() async { final EnteFile file = widget.selectedFiles.files.first; - final PersonEntity newPerson = widget.person!.copyWith( - data: widget.person!.data - .copyWith(avatarFaceId: file.uploadedFileID.toString()), + await PersonService.instance.updateAttributes( + widget.person!.remoteID, + avatarFaceId: file.uploadedFileID.toString(), ); - await PersonService.instance.updatePerson(newPerson); widget.selectedFiles.clearAll(); if (mounted) { setState(() => {}); diff --git a/mobile/lib/ui/viewer/people/people_app_bar.dart b/mobile/lib/ui/viewer/people/people_app_bar.dart index 14741b5e2..6dfcd77fd 100644 --- a/mobile/lib/ui/viewer/people/people_app_bar.dart +++ b/mobile/lib/ui/viewer/people/people_app_bar.dart @@ -110,9 +110,8 @@ class _AppBarWidgetState extends State { } try { - final updatePerson = widget.person - .copyWith(data: widget.person.data.copyWith(name: text)); - await PersonService.instance.updatePerson(updatePerson); + await PersonService.instance + .updateAttributes(widget.person.remoteID, name: text); if (mounted) { _appBarTitle = text; setState(() {});