diff --git a/mobile/lib/face/db.dart b/mobile/lib/face/db.dart index 17055234b..02a49ff4a 100644 --- a/mobile/lib/face/db.dart +++ b/mobile/lib/face/db.dart @@ -251,7 +251,7 @@ class FaceMLDataDB { final List fileId = [recentFileID]; int? avatarFileId; if (avatarFaceId != null) { - avatarFileId = int.tryParse(avatarFaceId.split('_')[0]); + avatarFileId = tryGetFileIdFromFaceId(avatarFaceId); if (avatarFileId != null) { fileId.add(avatarFileId); } @@ -480,8 +480,7 @@ class FaceMLDataDB { for (final map in maps) { final clusterID = map[fcClusterID] as int; final faceID = map[fcFaceId] as String; - final x = faceID.split('_').first; - final fileID = int.parse(x); + final fileID = getFileIdFromFaceId(faceID); result[fileID] = (result[fileID] ?? {})..add(clusterID); } return result; @@ -804,7 +803,7 @@ class FaceMLDataDB { for (final map in maps) { final clusterID = map[clusterIDColumn] as int; final String faceID = map[fcFaceId] as String; - final fileID = int.parse(faceID.split('_').first); + final fileID = getFileIdFromFaceId(faceID); result[fileID] = (result[fileID] ?? {})..add(clusterID); } return result; @@ -823,8 +822,8 @@ class FaceMLDataDB { final Map> result = {}; for (final map in maps) { final clusterID = map[fcClusterID] as int; - final faceId = map[fcFaceId] as String; - final fileID = int.parse(faceId.split("_").first); + final faceID = map[fcFaceId] as String; + final fileID = getFileIdFromFaceId(faceID); result[fileID] = (result[fileID] ?? {})..add(clusterID); } return result; @@ -973,7 +972,7 @@ class FaceMLDataDB { final Map faceIDToClusterID = {}; for (final row in faceIdsResult) { final faceID = row[fcFaceId] as String; - if (fileIds.contains(faceID.split('_').first)) { + if (fileIds.contains(getFileIdFromFaceId(faceID))) { maxClusterID += 1; faceIDToClusterID[faceID] = maxClusterID; } @@ -999,7 +998,7 @@ class FaceMLDataDB { final Map faceIDToClusterID = {}; for (final row in faceIdsResult) { final faceID = row[fcFaceId] as String; - if (fileIds.contains(faceID.split('_').first)) { + if (fileIds.contains(getFileIdFromFaceId(faceID))) { maxClusterID += 1; faceIDToClusterID[faceID] = maxClusterID; } diff --git a/mobile/lib/services/machine_learning/face_ml/face_ml_result.dart b/mobile/lib/services/machine_learning/face_ml/face_ml_result.dart index 19f954013..9f87b8722 100644 --- a/mobile/lib/services/machine_learning/face_ml/face_ml_result.dart +++ b/mobile/lib/services/machine_learning/face_ml/face_ml_result.dart @@ -310,5 +310,9 @@ class FaceResultBuilder { } int getFileIdFromFaceId(String faceId) { - return int.parse(faceId.split("_")[0]); + return int.parse(faceId.split("_").first); } + +int? tryGetFileIdFromFaceId(String faceId) { + return int.tryParse(faceId.split("_").first); +} \ No newline at end of file