[mob] Read person info from entity
This commit is contained in:
parent
d8bf0ad2d5
commit
3fb323ef29
7 changed files with 51 additions and 18 deletions
|
@ -629,14 +629,9 @@ class FaceMLDataDB {
|
|||
return result;
|
||||
}
|
||||
|
||||
Future<(Map<int, PersonEntity>, Map<String, PersonEntity>)>
|
||||
getClusterIdToPerson() async {
|
||||
Future<Map<int, PersonEntity>> getClusterIdToPerson(
|
||||
Map<String, PersonEntity> personMap,) async {
|
||||
final db = await instance.database;
|
||||
final List<PersonEntity> persons = await getPersons();
|
||||
final Map<String, PersonEntity> personMap = {};
|
||||
for (final p in persons) {
|
||||
personMap[p.remoteID] = p;
|
||||
}
|
||||
final List<Map<String, dynamic>> maps = await db.rawQuery(
|
||||
'SELECT $personIdColumn, $cluserIDColumn FROM $clusterPersonTable',
|
||||
);
|
||||
|
@ -652,7 +647,7 @@ class FaceMLDataDB {
|
|||
);
|
||||
}
|
||||
}
|
||||
return (result, personMap);
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<List<PersonEntity>> getPersons() async {
|
||||
|
|
|
@ -52,6 +52,8 @@ class PersonData {
|
|||
List<ClusterInfo>? rejected = List<ClusterInfo>.empty();
|
||||
final String? birthDate;
|
||||
|
||||
bool hasAvatar() => avatarFaceId != null;
|
||||
|
||||
PersonData({
|
||||
required this.name,
|
||||
this.assigned,
|
||||
|
@ -93,10 +95,14 @@ class PersonData {
|
|||
return PersonData(
|
||||
name: json['name'] as String,
|
||||
assigned: List<ClusterInfo>.from(
|
||||
(json['assigned'] as List<dynamic>).map((e) => ClusterInfo.fromJson(e)),
|
||||
(json['assigned'] as List<dynamic>?)
|
||||
?.map((e) => ClusterInfo.fromJson(e)) ??
|
||||
List<ClusterInfo>.empty(),
|
||||
),
|
||||
rejected: List<ClusterInfo>.from(
|
||||
(json['rejected'] as List<dynamic>).map((e) => ClusterInfo.fromJson(e)),
|
||||
(json['rejected'] as List<dynamic>?)
|
||||
?.map((e) => ClusterInfo.fromJson(e)) ??
|
||||
List<ClusterInfo>.empty(),
|
||||
),
|
||||
avatarFaceId: json['avatarFaceId'] as String?,
|
||||
isHidden: json['isHidden'] as bool? ?? false,
|
||||
|
|
|
@ -28,6 +28,31 @@ class PersonService {
|
|||
_instance = PersonService(entityService, faceMLDataDB, prefs);
|
||||
}
|
||||
|
||||
Future<List<PersonEntity>> getPersons() async {
|
||||
final entities = await entityService.getEntities(EntityType.person);
|
||||
return entities
|
||||
.map(
|
||||
(e) => PersonEntity(e.id, PersonData.fromJson(json.decode(e.data))),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
Future<Map<String, PersonEntity>> getPersonsMap() async {
|
||||
final entities = await entityService.getEntities(EntityType.person);
|
||||
final Map<String, PersonEntity> map = {};
|
||||
entities.forEach((e) {
|
||||
final person =
|
||||
PersonEntity(e.id, PersonData.fromJson(json.decode(e.data)));
|
||||
map[person.remoteID] = person;
|
||||
});
|
||||
return map;
|
||||
}
|
||||
|
||||
Future<Set<String>> personIDs() async {
|
||||
final entities = await entityService.getEntities(EntityType.person);
|
||||
return entities.map((e) => e.id).toSet();
|
||||
}
|
||||
|
||||
Future<PersonEntity> addPerson(String name, int clusterID) async {
|
||||
final faceIds = await faceMLDataDB.getFaceIDsForCluster(clusterID);
|
||||
final data = PersonData(
|
||||
|
|
|
@ -28,6 +28,7 @@ import "package:photos/models/search/search_constants.dart";
|
|||
import "package:photos/models/search/search_types.dart";
|
||||
import 'package:photos/services/collections_service.dart';
|
||||
import "package:photos/services/location_service.dart";
|
||||
import "package:photos/services/machine_learning/face_ml/person/person_service.dart";
|
||||
import 'package:photos/services/machine_learning/semantic_search/semantic_search_service.dart';
|
||||
import "package:photos/states/location_screen_state.dart";
|
||||
import "package:photos/ui/viewer/location/add_location_sheet.dart";
|
||||
|
@ -739,8 +740,10 @@ class SearchService {
|
|||
debugPrint("getting faces");
|
||||
final Map<int, Set<int>> fileIdToClusterID =
|
||||
await FaceMLDataDB.instance.getFileIdToClusterIds();
|
||||
final (clusterIDToPerson, personIdToPerson) =
|
||||
await FaceMLDataDB.instance.getClusterIdToPerson();
|
||||
final Map<String, PersonEntity> personIdToPerson =
|
||||
await PersonService.instance.getPersonsMap();
|
||||
final clusterIDToPerson =
|
||||
await FaceMLDataDB.instance.getClusterIdToPerson(personIdToPerson);
|
||||
|
||||
debugPrint("building result");
|
||||
final List<GenericSearchResult> facesResult = [];
|
||||
|
|
|
@ -11,6 +11,7 @@ import "package:photos/face/model/person.dart";
|
|||
import "package:photos/services/machine_learning/face_ml/face_filtering/face_filtering_constants.dart";
|
||||
import 'package:photos/services/machine_learning/face_ml/face_ml_service.dart';
|
||||
import 'package:photos/services/machine_learning/face_ml/feedback/cluster_feedback.dart';
|
||||
import "package:photos/services/machine_learning/face_ml/person/person_service.dart";
|
||||
// import "package:photos/services/search_service.dart";
|
||||
import 'package:photos/theme/ente_theme.dart';
|
||||
import 'package:photos/ui/components/captioned_text_widget.dart';
|
||||
|
@ -244,7 +245,7 @@ class _FaceDebugSectionWidgetState extends State<FaceDebugSectionWidget> {
|
|||
onTap: () async {
|
||||
try {
|
||||
final List<PersonEntity> persons =
|
||||
await FaceMLDataDB.instance.getPersons();
|
||||
await PersonService.instance.getPersons();
|
||||
final EnteWatch w = EnteWatch('feedback')..start();
|
||||
for (final PersonEntity p in persons) {
|
||||
await ClusterFeedbackService.instance
|
||||
|
|
|
@ -5,6 +5,7 @@ import "package:photos/face/model/face.dart";
|
|||
import "package:photos/face/model/person.dart";
|
||||
import "package:photos/models/file/file.dart";
|
||||
import "package:photos/services/machine_learning/face_ml/feedback/cluster_feedback.dart";
|
||||
import "package:photos/services/machine_learning/face_ml/person/person_service.dart";
|
||||
import "package:photos/ui/components/buttons/chip_button_widget.dart";
|
||||
import "package:photos/ui/components/info_item_widget.dart";
|
||||
import "package:photos/ui/viewer/file_details/face_widget.dart";
|
||||
|
@ -66,8 +67,10 @@ class FacesItemWidget extends StatelessWidget {
|
|||
// TODO: add deduplication of faces of same person
|
||||
final faceIdsToClusterIds = await FaceMLDataDB.instance
|
||||
.getFaceIdsToClusterIds(faces.map((face) => face.faceID));
|
||||
final (clusterIDToPerson, _) =
|
||||
await FaceMLDataDB.instance.getClusterIdToPerson();
|
||||
final Map<String, PersonEntity> persons =
|
||||
await PersonService.instance.getPersonsMap();
|
||||
final clusterIDToPerson =
|
||||
await FaceMLDataDB.instance.getClusterIdToPerson(persons);
|
||||
|
||||
final lastViewedClusterID = ClusterFeedbackService.lastViewedClusterID;
|
||||
|
||||
|
|
|
@ -178,7 +178,7 @@ class _PersonActionSheetState extends State<PersonActionSheet> {
|
|||
return Flexible(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 24, 4, 0),
|
||||
child: FutureBuilder<List<PersonEntity>>(
|
||||
child: FutureBuilder<Iterable<PersonEntity>>(
|
||||
future: _getPersons(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
|
@ -290,7 +290,7 @@ class _PersonActionSheetState extends State<PersonActionSheet> {
|
|||
}
|
||||
}
|
||||
|
||||
Future<List<PersonEntity>> _getPersons() async {
|
||||
return FaceMLDataDB.instance.getPersons();
|
||||
Future<Iterable<PersonEntity>> _getPersons() async {
|
||||
return PersonService.instance.getPersons();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue