branch backend + ajout du serveur backend, next, et sqlite

This commit is contained in:
streaper2
2026-04-29 15:45:09 +02:00
parent 105eb1cab0
commit cea2fab989
42 changed files with 10566 additions and 4 deletions

View File

@@ -18,6 +18,7 @@ import '../../services/score_calculator_service.dart';
import '../../services/grouping_analyzer_service.dart';
import '../../services/distortion_correction_service.dart';
import '../../services/opencv_target_service.dart';
import '../../services/ai_export_service.dart';
enum AnalysisState { initial, loading, success, error }
@@ -688,6 +689,42 @@ class AnalysisProvider extends ChangeNotifier {
_groupingResult = _groupingAnalyzerService.analyzeGrouping(_shots);
}
/// Exporte l'image et le json vers le backend IA
Future<bool> exportToAiBackend() async {
if (_imagePath == null || _targetType == null) {
_errorMessage = "Impossible d'exporter : image ou type de cible manquant.";
notifyListeners();
return false;
}
// Identifiant de session temporaire si non sauvegardée
final sessionId = _shots.isNotEmpty && _shots.first.sessionId.isNotEmpty
? _shots.first.sessionId
: 'session_${DateTime.now().millisecondsSinceEpoch}';
final service = AiExportService(); // Local instanciation for simplicity
_state = AnalysisState.loading;
notifyListeners();
final success = await service.exportData(
imagePath: _imagePath!,
sessionId: sessionId,
targetType: _targetType!,
targetCenterX: _targetCenterX,
targetCenterY: _targetCenterY,
targetRadius: _targetRadius,
shots: _shots,
);
_state = AnalysisState.success;
if (!success) {
_errorMessage = "Échec de l'export vers le serveur IA.";
}
notifyListeners();
return success;
}
/// Save the session
Future<Session> saveSession({String? notes}) async {
if (_imagePath == null || _targetType == null) {

View File

@@ -15,6 +15,7 @@ import '../../data/repositories/session_repository.dart';
import '../../services/target_detection_service.dart';
import '../../services/score_calculator_service.dart';
import '../../services/grouping_analyzer_service.dart';
import '../../services/wallet_identity_service.dart';
import 'analysis_provider.dart';
import 'widgets/target_overlay.dart';
import 'widgets/target_calibration.dart';
@@ -133,6 +134,47 @@ class _AnalysisScreenContentState extends State<_AnalysisScreenContent> {
);
},
),
FutureBuilder<bool>(
future: WalletIdentityService().isUploadEnabled(),
builder: (context, snapshot) {
final isEnabled = snapshot.data ?? false;
if (!isEnabled) return const SizedBox.shrink();
return IconButton(
icon: const Icon(Icons.cloud_upload),
onPressed: () async {
final provider = context.read<AnalysisProvider>();
if (provider.state != AnalysisState.success) return;
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Exportation en cours...')),
);
final success = await provider.exportToAiBackend();
if (context.mounted) {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
if (success) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Export réussi vers le backend IA !'),
backgroundColor: AppTheme.successColor,
),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(provider.errorMessage ?? 'Erreur d\'export'),
backgroundColor: AppTheme.errorColor,
),
);
}
}
},
tooltip: 'Exporter pour IA',
);
},
),
IconButton(
icon: const Icon(Icons.help_outline),
onPressed: () => _showHelpDialog(context),