feat: implement base architecture and core repositories for weapon tracking and target analysis functionality
This commit is contained in:
@@ -1,112 +1,83 @@
|
||||
import 'shot.dart';
|
||||
import 'target_type.dart';
|
||||
import 'target_analysis.dart';
|
||||
|
||||
class Session {
|
||||
final String id;
|
||||
final TargetType targetType;
|
||||
final String imagePath;
|
||||
final List<Shot> shots;
|
||||
final int totalScore;
|
||||
final double? groupingDiameter;
|
||||
final double? groupingCenterX;
|
||||
final double? groupingCenterY;
|
||||
final String weapon;
|
||||
final String? weaponId;
|
||||
final int maxShotsPerTarget;
|
||||
final List<TargetAnalysis> analyses;
|
||||
final DateTime createdAt;
|
||||
final String? notes;
|
||||
|
||||
// Target detection data
|
||||
final double? targetCenterX;
|
||||
final double? targetCenterY;
|
||||
final double? targetRadius;
|
||||
final int distance; // Shooting distance in meters
|
||||
|
||||
Session({
|
||||
required this.id,
|
||||
required this.targetType,
|
||||
required this.imagePath,
|
||||
required this.shots,
|
||||
required this.totalScore,
|
||||
this.groupingDiameter,
|
||||
this.groupingCenterX,
|
||||
this.groupingCenterY,
|
||||
required this.weapon,
|
||||
this.weaponId,
|
||||
required this.maxShotsPerTarget,
|
||||
required this.analyses,
|
||||
required this.createdAt,
|
||||
this.notes,
|
||||
this.targetCenterX,
|
||||
this.targetCenterY,
|
||||
this.targetRadius,
|
||||
this.distance = 25, // Default distance
|
||||
});
|
||||
|
||||
int get shotCount => shots.length;
|
||||
int get targetCount => analyses.length;
|
||||
|
||||
int get totalShots => analyses.fold(0, (sum, a) => sum + a.shotCount);
|
||||
|
||||
int get totalScore => analyses.fold(0, (sum, a) => sum + a.totalScore);
|
||||
|
||||
double get averageScore => shots.isEmpty ? 0.0 : totalScore / shots.length;
|
||||
double get averageScore => analyses.isEmpty ? 0.0 : totalScore / analyses.length;
|
||||
|
||||
Session copyWith({
|
||||
String? id,
|
||||
TargetType? targetType,
|
||||
String? imagePath,
|
||||
List<Shot>? shots,
|
||||
int? totalScore,
|
||||
double? groupingDiameter,
|
||||
double? groupingCenterX,
|
||||
double? groupingCenterY,
|
||||
String? weapon,
|
||||
String? weaponId,
|
||||
int? maxShotsPerTarget,
|
||||
List<TargetAnalysis>? analyses,
|
||||
DateTime? createdAt,
|
||||
String? notes,
|
||||
double? targetCenterX,
|
||||
double? targetCenterY,
|
||||
double? targetRadius,
|
||||
int? distance,
|
||||
}) {
|
||||
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,
|
||||
weapon: weapon ?? this.weapon,
|
||||
weaponId: weaponId ?? this.weaponId,
|
||||
maxShotsPerTarget: maxShotsPerTarget ?? this.maxShotsPerTarget,
|
||||
analyses: analyses ?? this.analyses,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
notes: notes ?? this.notes,
|
||||
targetCenterX: targetCenterX ?? this.targetCenterX,
|
||||
targetCenterY: targetCenterY ?? this.targetCenterY,
|
||||
targetRadius: targetRadius ?? this.targetRadius,
|
||||
distance: distance ?? this.distance,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> 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,
|
||||
'weapon': weapon,
|
||||
'weapon_id': weaponId,
|
||||
'max_shots_per_target': maxShotsPerTarget,
|
||||
'created_at': createdAt.toIso8601String(),
|
||||
'notes': notes,
|
||||
'target_center_x': targetCenterX,
|
||||
'target_center_y': targetCenterY,
|
||||
'target_radius': targetRadius,
|
||||
'distance': distance,
|
||||
};
|
||||
}
|
||||
|
||||
factory Session.fromMap(Map<String, dynamic> map, List<Shot> shots) {
|
||||
factory Session.fromMap(Map<String, dynamic> map, List<TargetAnalysis> analyses) {
|
||||
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?,
|
||||
weapon: map['weapon'] as String? ?? 'Inconnue',
|
||||
weaponId: map['weapon_id'] as String?,
|
||||
maxShotsPerTarget: map['max_shots_per_target'] as int? ?? 5,
|
||||
analyses: analyses,
|
||||
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?,
|
||||
distance: map['distance'] as int? ?? 25,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Session(id: $id, targetType: $targetType, shots: ${shots.length}, totalScore: $totalScore, createdAt: $createdAt)';
|
||||
return 'Session(id: $id, weapon: $weapon, distance: ${distance}m, targets: ${analyses.length}, createdAt: $createdAt)';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user