From c216ae5bb0df643dd1f2b6027df04dc43f9a5465 Mon Sep 17 00:00:00 2001 From: Enzo Date: Fri, 8 Dec 2023 10:13:27 +0100 Subject: [PATCH 1/2] add date to volume --- IA/categoryByData.py | 39 ++++++++++++++++++++++++++++++ IA/data/data_emple.csv | 10 ++++---- IA/distanceByTime.py | 29 ++++++++++++++++++++++ IA/modele_create.py | 36 --------------------------- lib/modele/activity.dart | 4 +-- lib/modele/user.dart | 1 + lib/view/volumes/volumes_view.dart | 7 +++--- 7 files changed, 80 insertions(+), 46 deletions(-) create mode 100644 IA/categoryByData.py create mode 100644 IA/distanceByTime.py delete mode 100644 IA/modele_create.py diff --git a/IA/categoryByData.py b/IA/categoryByData.py new file mode 100644 index 0000000..9983408 --- /dev/null +++ b/IA/categoryByData.py @@ -0,0 +1,39 @@ +import pandas as pd +import numpy as np +from sklearn.calibration import LabelEncoder +from sklearn.model_selection import train_test_split +from sklearn.linear_model import LinearRegression + +# Load data from CSV +df = pd.read_csv("data\\data_emple.csv") + +category = df.iloc[0:len(df),0].values + +otherData = df.iloc[0:len(df),1:6].values + +print(otherData) + +# Encode the categorical target variable +label_encoder = LabelEncoder() +category_encoded = label_encoder.fit_transform(category) + +model = LinearRegression() + +model.fit(otherData,category_encoded) + + +new_data = np.array([224.0,228.49,346.6000000000000,1.1007253886010361,101]).reshape(1, -1) + +# Faites une prédiction avec le modèle entraîné +prediction = model.predict(new_data) + +# Affichez la prédiction +print("Prédiction:", prediction) + +# Supposons que label_encoder soit l'objet LabelEncoder que vous avez utilisé lors de l'entraînement +inverse_prediction = label_encoder.inverse_transform(prediction.astype(int)) + +# Affichez la prédiction sous forme de chaîne de caractères +print("Prédiction (en chaîne de caractères):", inverse_prediction) + + diff --git a/IA/data/data_emple.csv b/IA/data/data_emple.csv index 49d5bd6..39d4d4d 100644 --- a/IA/data/data_emple.csv +++ b/IA/data/data_emple.csv @@ -1,6 +1,6 @@ -category,noteUser,distance,timeOfActivity,denivelePositif,speedAvg,bpmAvg -walking,80,2147.0,1716.5,471.5999999999999,1.2740575455079353,114 -walking,90,1013.0,933.24,393.2000000000004,1.2849015317286667,122 -walking,95,225.0,228.49,346.6000000000006,1.1007253886010366,99 -cycling,50,20525.4,6770.675,597.8000000000001,3.5130617816091947,143 +category,distance,timeOfActivity,denivelePositif,speedAvg,bpmAvg +walking,2147.0,1716.5,471.5999999999999,1.2740575455079353,114 +walking,1013.0,933.24,393.2000000000004,1.2849015317286667,122 +walking,225.0,228.49,346.6000000000006,1.1007253886010366,99 +cycling,20525.4,6770.675,597.8000000000001,3.5130617816091947,143 diff --git a/IA/distanceByTime.py b/IA/distanceByTime.py new file mode 100644 index 0000000..7bd2410 --- /dev/null +++ b/IA/distanceByTime.py @@ -0,0 +1,29 @@ +import pandas as pd +import numpy as np +import matplotlib.pyplot as plt +from sklearn.linear_model import LinearRegression +from sklearn.model_selection import train_test_split +df = pd.read_csv("data\\data_emple.csv") +distance = df.iloc[0:len(df),1].values.reshape(-1, 1) +time = df.iloc[0:len(df),2].values.reshape(-1, 1) + +model = LinearRegression() + +# Entrainement +model.fit(time,distance) + +# Afficher les coefficients du modèle +print("Coefficients :", model.coef_) +print("Intercept :", model.intercept_) + + +# Supposons que vous avez de nouvelles données pour lesquelles vous voulez faire des prédictions +new_time_data = np.array([1000]).reshape(1,-1) # Exemple de nouvelles données pour 'time' + +# Faire des prédictions sur les nouvelles données +predicted_distance = model.predict(new_time_data) + +# Afficher les prédictions +print("Prédictions de distance :", predicted_distance[0]) + + diff --git a/IA/modele_create.py b/IA/modele_create.py deleted file mode 100644 index 24ee10d..0000000 --- a/IA/modele_create.py +++ /dev/null @@ -1,36 +0,0 @@ -import pandas as pd -from sklearn.model_selection import train_test_split -from sklearn.linear_model import LinearRegression -from sklearn.metrics import mean_squared_error -from sklearn.preprocessing import LabelEncoder - -# Charger les données -data = pd.read_csv('data\\data_emple.csv') - -# Encoder les catégories 'category' et 'noteUser' -label_encoder = LabelEncoder() -data['category'] = label_encoder.fit_transform(data['category']) -data['noteUser'] = label_encoder.fit_transform(data['noteUser']) - -# Sélectionner les caractéristiques pour l'entraînement du modèle -features = ['category', 'noteUser', 'distance', 'timeOfActivity', 'denivelePositif', 'speedAvg', 'bpmAvg'] - -# Diviser les données en ensembles d'entraînement et de test -train_data, test_data = train_test_split(data[features], test_size=0.2, random_state=42) - -# Séparer les caractéristiques (X) de la cible (y) -X_train, y_train = train_data.drop('noteUser', axis=1), train_data['noteUser'] -X_test, y_test = test_data.drop('noteUser', axis=1), test_data['noteUser'] - -# Créer et entraîner le modèle de régression linéaire -model = LinearRegression() -model.fit(X_train, y_train) - -# Faire des prédictions sur l'ensemble de test -predictions = model.predict(X_test) - -print(predictions) - -# Évaluer le modèle -mse = mean_squared_error(y_test, predictions) -print(f'Mean Squared Error on Test Data: {mse}') diff --git a/lib/modele/activity.dart b/lib/modele/activity.dart index 5637d1c..bc247c1 100644 --- a/lib/modele/activity.dart +++ b/lib/modele/activity.dart @@ -18,7 +18,7 @@ class ActivityOfUser { ActivityInfo get activityInfo => _activityInfo; Map get enteteCSV => _enteteCSV; - // -- Getter/Setter -- Ancien // + // -- Getter/Setter -- // List> get contentActivity => _contentActivity; set contentActivity(List> content) { _contentActivity = content; @@ -39,7 +39,7 @@ class ActivityOfUser { } } - // -------------------------- FIN Localisation ---------------------- // + // -------------------------- ToMap ---------------------- // Map toMapGeneric() { Map map = { diff --git a/lib/modele/user.dart b/lib/modele/user.dart index d2129d8..3402614 100644 --- a/lib/modele/user.dart +++ b/lib/modele/user.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:smartfit_app_mobile/modele/activity.dart'; +import 'package:smartfit_app_mobile/modele/convertisseur.dart'; import 'package:smartfit_app_mobile/modele/manager_selected_activity.dart'; class User extends ChangeNotifier { diff --git a/lib/view/volumes/volumes_view.dart b/lib/view/volumes/volumes_view.dart index 1ddd5c2..2dedf65 100644 --- a/lib/view/volumes/volumes_view.dart +++ b/lib/view/volumes/volumes_view.dart @@ -21,6 +21,7 @@ class _VolumesViews extends State { Widget build(BuildContext context) { var media = MediaQuery.of(context).size; User user = context.watch(); + DateTime date = DateTime.now(); Map volume7Days = user.getVolumeWhithDuration(const Duration(days: 7)); @@ -47,7 +48,7 @@ class _VolumesViews extends State { height: media.width * 0.05, ), Text( - "Derniere semaine", + "Derniere semaine : ${date.day}/${date.month}/${date.year} - ${date.subtract(const Duration(days: 7)).day}/${date.subtract(const Duration(days: 7)).month}/${date.subtract(const Duration(days: 7)).year}", style: TextStyle( color: TColor.black, fontSize: 16, @@ -61,7 +62,7 @@ class _VolumesViews extends State { height: media.width * 0.03, ), Text( - "Dernier Mois", + "Dernier Mois : ${date.day}/${date.month}/${date.year} - ${date.subtract(const Duration(days: 30)).day}/${date.subtract(const Duration(days: 30)).month}/${date.subtract(const Duration(days: 30)).year}", style: TextStyle( color: TColor.black, fontSize: 16, @@ -72,7 +73,7 @@ class _VolumesViews extends State { height: media.width * 0.03, ), Text( - "Dernière année", + "Dernière année : ${date.day}/${date.month}/${date.year} - ${date.subtract(const Duration(days: 366)).day}/${date.subtract(const Duration(days: 366)).month}/${date.subtract(const Duration(days: 366)).year}", style: TextStyle( color: TColor.black, fontSize: 16, From 0f4a5d5932d919484899cb7ab6e4d328789b155e Mon Sep 17 00:00:00 2001 From: Enzo Date: Fri, 8 Dec 2023 10:15:07 +0100 Subject: [PATCH 2/2] clean --- lib/modele/user.dart | 1 - lib/view/map/chose_map.dart | 43 +++++++------------ .../profile_view_allplatforme.dart | 2 - 3 files changed, 16 insertions(+), 30 deletions(-) diff --git a/lib/modele/user.dart b/lib/modele/user.dart index 3402614..d2129d8 100644 --- a/lib/modele/user.dart +++ b/lib/modele/user.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:smartfit_app_mobile/modele/activity.dart'; -import 'package:smartfit_app_mobile/modele/convertisseur.dart'; import 'package:smartfit_app_mobile/modele/manager_selected_activity.dart'; class User extends ChangeNotifier { diff --git a/lib/view/map/chose_map.dart b/lib/view/map/chose_map.dart index 6788c11..4b1c8b1 100644 --- a/lib/view/map/chose_map.dart +++ b/lib/view/map/chose_map.dart @@ -42,24 +42,26 @@ class _ChoseMap extends State { height: media.height * 0.1, ), RoundButton( - title: "Use map with google map", - onPressed: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => const MobileMyMaps())); - }, - ), + title: "Use map with google map", + onPressed: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const MobileMyMaps())); + }, + ), SizedBox( height: media.height * 0.03, ), RoundButton( - title : "Use map with Open Street Map", - onPressed: () { - Navigator.push(context, - MaterialPageRoute(builder: (context) => const MyMapOSM())); - }, - ), + title: "Use map with Open Street Map", + onPressed: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const MyMapOSM())); + }, + ), Spacer(), ], ), @@ -67,18 +69,5 @@ class _ChoseMap extends State { ), ), ); - return Scaffold( - backgroundColor: TColor.white, - body: SafeArea( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - - const Text( - "Mettre une image la en mode une personne avec des jumelles") - ], - )), - ); } } diff --git a/lib/view/profile/all_platforme/profile_view_allplatforme.dart b/lib/view/profile/all_platforme/profile_view_allplatforme.dart index bc12c92..790ca58 100644 --- a/lib/view/profile/all_platforme/profile_view_allplatforme.dart +++ b/lib/view/profile/all_platforme/profile_view_allplatforme.dart @@ -4,7 +4,6 @@ import 'package:smartfit_app_mobile/common/colo_extension.dart'; import 'package:smartfit_app_mobile/common_widget/container/profile/profile_compte.dart'; import 'package:smartfit_app_mobile/common_widget/container/profile/profile_entete.dart'; import 'package:smartfit_app_mobile/common_widget/container/profile/profile_info_user.dart'; -import 'package:smartfit_app_mobile/common_widget/container/profile/profile_notification.dart'; import 'package:smartfit_app_mobile/common_widget/container/profile/profile_other.dart'; import 'package:smartfit_app_mobile/modele/user.dart'; @@ -55,7 +54,6 @@ class _ProfileViewAllPlatforme extends State { const SizedBox( height: 25, ), - ProfileOther(widget.otherArr) ], ),