From 32532246ebfef455ec2154e8029a1814a3aee66d Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Wed, 11 Jun 2025 23:05:00 +0200 Subject: [PATCH 1/2] add duplicate event check --- .../lib/pages/DisplayPictureScreen.dart | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/covas_mobile/lib/pages/DisplayPictureScreen.dart b/covas_mobile/lib/pages/DisplayPictureScreen.dart index e14612c..6d18c9f 100644 --- a/covas_mobile/lib/pages/DisplayPictureScreen.dart +++ b/covas_mobile/lib/pages/DisplayPictureScreen.dart @@ -102,6 +102,23 @@ class DisplayPictureScreenState extends State "L'IA de Google n'a pas su analyser l'image. Recommecer avec une autre"); } + Future _isDuplicateEvent(String accessToken, + Map jsonData, Map location) async { + final url = Uri.parse( + "${globals.api}/events/search?item=${jsonData["name"]}&date_event=${jsonData["start_date"]}" + "&min_lat=${location['lat']}&max_lat=${location['lat']}" + "&min_lon=${location['lng']}&max_lon=${location['lng']}"); + + final response = await http.get(url, + headers: {HttpHeaders.cookieHeader: 'access_token=$accessToken'}); + + if (response.statusCode == 200) { + final events = jsonDecode(utf8.decode(response.bodyBytes)); + return events.isNotEmpty; + } + return false; + } + Future searchEvents(String json, String imagePath) async { print(json.replaceAll("'''json", '').replaceAll("'''", "")); SharedPreferences prefs = await SharedPreferences.getInstance(); @@ -162,7 +179,7 @@ class DisplayPictureScreenState extends State gemini .textAndImage( text: - "Peux-tu donner le nom, la date avec l'année actuelle ou d'une année future proche et le lieu de l'évènement sous format JSON (sans le caratère json au début de la chaine de caractère) avec les valeurs suivantes : name, place, description, tags (tableau sans espace), organizers (tableau), start_date et end_date (si le end_date est vide, alors donnez une valeur de six de plus par rapport à start_date) sous le format en YYYY-MM-DD HH:mm:ssZ", + "Peux-tu donner le nom, la date (si l'année n'est pas précisé, mettez l'année actuelle ou future) et le lieu de l'évènement sous format JSON (sans le caratère json au début de la chaine de caractère) avec les valeurs suivantes : name, place, description, tags (tableau sans espace), organizers (tableau), start_date et end_date (si le end_date est vide, alors donnez une valeur de six de plus par rapport à start_date) sous le format en YYYY-MM-DD HH:mm:ssZ", images: [file.readAsBytesSync()], modelName: "models/gemini-1.5-pro-latest") .then((value) => searchEvents( -- 2.47.2 From 303447ff1ec416d5fd1c43edd66eccc8a0c163a9 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 16 Jun 2025 22:51:01 +0200 Subject: [PATCH 2/2] check duplicate event --- .../lib/pages/DisplayPictureScreen.dart | 41 +++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/covas_mobile/lib/pages/DisplayPictureScreen.dart b/covas_mobile/lib/pages/DisplayPictureScreen.dart index 6d18c9f..5d0ee55 100644 --- a/covas_mobile/lib/pages/DisplayPictureScreen.dart +++ b/covas_mobile/lib/pages/DisplayPictureScreen.dart @@ -102,6 +102,24 @@ class DisplayPictureScreenState extends State "L'IA de Google n'a pas su analyser l'image. Recommecer avec une autre"); } + void _showErrorDialog(BuildContext context, String title, String message) { + showAlertDialog(context, title, message); + } + + Future?> _fetchGeolocation(String place) async { + final apiKey = dotenv.env['PLACE_API_KEY'] ?? ''; + final response = await http.get(Uri.parse( + 'https://maps.googleapis.com/maps/api/place/textsearch/json?query=${place}}&key=$apiKey')); + + if (response.statusCode == 200) { + final data = json.decode(response.body); + if (data['results'].isNotEmpty) { + return data['results'][0]['geometry']['location']; + } + } + return null; + } + Future _isDuplicateEvent(String accessToken, Map jsonData, Map location) async { final url = Uri.parse( @@ -133,13 +151,22 @@ class DisplayPictureScreenState extends State var accessToken = prefs.getString("access_token") ?? ""; if (accessToken.isNotEmpty) { - var urlGet = Uri.parse( - "${globals.api}/events/search?item=${name}&date_event=${date}"); + final location = await _fetchGeolocation(place); + if (location == null) { + _showErrorDialog( + context, "Erreur serveur", "Aucune donnée geographique"); + return; + } - var responseGet = await http.get(urlGet, - headers: {HttpHeaders.cookieHeader: 'access_token=${accessToken}'}); - if (responseGet.statusCode == 200) { - var events = jsonDecode(utf8.decode(responseGet.bodyBytes)); + final url = Uri.parse( + "${globals.api}/events/search?item=${name}&date_event=${date}" + "&min_lat=${location['lat']}&max_lat=${location['lat']}" + "&min_lon=${location['lng']}&max_lon=${location['lng']}"); + + final response = await http.get(url, + headers: {HttpHeaders.cookieHeader: 'access_token=$accessToken'}); + if (response.statusCode == 200) { + var events = jsonDecode(utf8.decode(response.bodyBytes)); print("reponse http : ${events.length}"); if (events.length == 0) { Navigator.push( @@ -155,7 +182,7 @@ class DisplayPictureScreenState extends State } } else { showAlertDialog(context, 'Erreur de reponse', - "response status code update : ${responseGet.statusCode}"); + "response status code update : ${response.statusCode}"); } } else { showAlertDialog(context, "Erreur de reponse", "Erreur de token"); -- 2.47.2