import 'shot.dart'; import 'target_type.dart'; class Session { final String id; final TargetType targetType; final String imagePath; final List shots; final int totalScore; final double? groupingDiameter; final double? groupingCenterX; final double? groupingCenterY; final DateTime createdAt; final String? notes; // Target detection data final double? targetCenterX; final double? targetCenterY; final double? targetRadius; Session({ required this.id, required this.targetType, required this.imagePath, required this.shots, required this.totalScore, this.groupingDiameter, this.groupingCenterX, this.groupingCenterY, required this.createdAt, this.notes, this.targetCenterX, this.targetCenterY, this.targetRadius, }); int get shotCount => shots.length; double get averageScore => shots.isEmpty ? 0.0 : totalScore / shots.length; Session copyWith({ String? id, TargetType? targetType, String? imagePath, List? shots, int? totalScore, double? groupingDiameter, double? groupingCenterX, double? groupingCenterY, DateTime? createdAt, String? notes, double? targetCenterX, double? targetCenterY, double? targetRadius, }) { return Session( id: id ?? this.id, targetType: targetType ?? this.targetType, imagePath: imagePath ?? this.imagePath, shots: shots ?? this.shots, totalScore: totalScore ?? this.totalScore, groupingDiameter: groupingDiameter ?? this.groupingDiameter, groupingCenterX: groupingCenterX ?? this.groupingCenterX, groupingCenterY: groupingCenterY ?? this.groupingCenterY, createdAt: createdAt ?? this.createdAt, notes: notes ?? this.notes, targetCenterX: targetCenterX ?? this.targetCenterX, targetCenterY: targetCenterY ?? this.targetCenterY, targetRadius: targetRadius ?? this.targetRadius, ); } Map toMap() { return { 'id': id, 'target_type': targetType.name, 'image_path': imagePath, 'total_score': totalScore, 'grouping_diameter': groupingDiameter, 'grouping_center_x': groupingCenterX, 'grouping_center_y': groupingCenterY, 'created_at': createdAt.toIso8601String(), 'notes': notes, 'target_center_x': targetCenterX, 'target_center_y': targetCenterY, 'target_radius': targetRadius, }; } factory Session.fromMap(Map map, List shots) { return Session( id: map['id'] as String, targetType: TargetType.fromString(map['target_type'] as String), imagePath: map['image_path'] as String, shots: shots, totalScore: map['total_score'] as int, groupingDiameter: map['grouping_diameter'] as double?, groupingCenterX: map['grouping_center_x'] as double?, groupingCenterY: map['grouping_center_y'] as double?, createdAt: DateTime.parse(map['created_at'] as String), notes: map['notes'] as String?, targetCenterX: map['target_center_x'] as double?, targetCenterY: map['target_center_y'] as double?, targetRadius: map['target_radius'] as double?, ); } @override String toString() { return 'Session(id: $id, targetType: $targetType, shots: ${shots.length}, totalScore: $totalScore, createdAt: $createdAt)'; } }