| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- /// 照片分类类型
- enum PhotoImageClassifyType {
- similar,
- people,
- screenshot,
- blurry,
- }
- /// 分类进度信息
- class ClassificationProgress {
- /// 总批次数
- final int totalBatches;
-
- /// 当前批次
- final int currentBatch;
-
- /// 是否已完成
- final bool isLastBatch;
-
- /// 完成百分比 (0.0-1.0)
- final double rate;
-
- /// 当前批次处理时间(秒)
- final double batchDuration;
-
- /// 总耗时(秒)
- final double totalDuration;
- /// 是否已完成
- bool get isCompleted => isLastBatch;
-
- ClassificationProgress({
- required this.totalBatches,
- required this.currentBatch,
- required this.isLastBatch,
- required this.rate,
- required this.batchDuration,
- required this.totalDuration,
- });
- static double _toDouble(dynamic v) => v is int ? v.toDouble() : (v as double);
- static ClassificationProgress fromJson(Map<String, dynamic> json) {
- return ClassificationProgress(
- totalBatches: json['totalBatches'],
- currentBatch: json['currentBatch'],
- isLastBatch: json['isLastBatch'],
- rate: _toDouble(json['rate']),
- batchDuration: _toDouble(json['batchDuration']),
- totalDuration: _toDouble(json['totalDuration']),
- );
- }
- }
- class ClassifiedImageGroup {
- final List<ClassifiedImage> images;
- int get groupFileSize => images.fold(0, (sum, image) => sum + image.fileSize);
- int get groupImageCount => images.length;
- ClassifiedImageGroup({
- required this.images,
- });
- static ClassifiedImageGroup fromList(List<ClassifiedImage> images) {
- return ClassifiedImageGroup(
- images: images,
- );
- }
- }
- class ImageLocation {
- final double latitude; // 纬度
- final double longitude; // 经度
- ImageLocation({
- required this.latitude,
- required this.longitude,
- });
- static ImageLocation fromJson(Map<String, dynamic> json) {
- return ImageLocation(
- latitude: json['latitude'],
- longitude: json['longitude'],
- );
- }
- }
- class ClassifiedImage {
- final String assetsId;
- final double createdAt;
- final ImageLocation? location;
- final int fileSize;
- final int pixelWidth;
- final int pixelHeight;
- ClassifiedImage({
- required this.assetsId,
- required this.createdAt,
- this.location,
- required this.fileSize,
- required this.pixelWidth,
- required this.pixelHeight,
- });
- static ClassifiedImage fromJson(Map<String, dynamic> json) {
- return ClassifiedImage(
- assetsId: json['assetsId'],
- createdAt: json['createdAt'],
- location: json['location'] != null ? ImageLocation.fromJson(Map<String, dynamic>.from(json['location'])) : null,
- fileSize: json['fileSize'],
- pixelWidth: json['pixelWidth'],
- pixelHeight: json['pixelHeight'],
- );
- }
- }
- class ClassificationResult {
- final List<ClassifiedImageGroup>? similarGroups;
- final List<ClassifiedImage>? peopleGroups;
- final List<ClassifiedImage>? screenshotGroups;
- final List<ClassifiedImage>? blurryGroups;
-
- ClassificationResult({
- required this.similarGroups,
- required this.peopleGroups,
- required this.screenshotGroups,
- required this.blurryGroups,
- });
- static ClassificationResult fromJson(Map<String, dynamic> json) {
- List<ClassifiedImage> processedImages(dynamic images) {
- var imageList = List<Map<dynamic, dynamic>>.from(images ?? []);
- return imageList.map((image) => ClassifiedImage.fromJson(Map<String, dynamic>.from(image))).toList();
- }
-
- return ClassificationResult(
- similarGroups: json['similarGroups']?['groups']?.isEmpty ?? true
- ? null
- : List<ClassifiedImageGroup>.from((json['similarGroups']?['groups'] ?? []).map((group) =>
- ClassifiedImageGroup.fromList(
- processedImages(group)
- )
- )),
- peopleGroups: json['peopleImages']?.isEmpty ?? true
- ? null
- : processedImages(json['peopleImages']),
- screenshotGroups: json['screenshotImages']?.isEmpty ?? true
- ? null
- : processedImages(json['screenshotImages']),
- blurryGroups: json['blurryImages']?.isEmpty ?? true
- ? null
- : processedImages(json['blurryImages']),
- );
- }
- }
- /// 分类事件,包含进度和结果
- class ClassificationEvent {
- /// 分类进度
- final ClassificationProgress? progress;
-
- /// 分类结果
- final ClassificationResult? result;
-
- ClassificationEvent({
- required this.progress,
- this.result,
- });
- }
|