diff --git a/JeuHoyEtudiants/JeuHoy_WPF_Natif/JeuHoy_WPF_Natif.csproj b/JeuHoyEtudiants/JeuHoy_WPF_Natif/JeuHoy_WPF_Natif.csproj index ca5d1a6..9dbe294 100644 --- a/JeuHoyEtudiants/JeuHoy_WPF_Natif/JeuHoy_WPF_Natif.csproj +++ b/JeuHoyEtudiants/JeuHoy_WPF_Natif/JeuHoy_WPF_Natif.csproj @@ -64,6 +64,7 @@ + diff --git a/JeuHoyEtudiants/JeuHoy_WPF_Natif/Model/ROGER.cs b/JeuHoyEtudiants/JeuHoy_WPF_Natif/Model/ROGER.cs new file mode 100644 index 0000000..3761f26 --- /dev/null +++ b/JeuHoyEtudiants/JeuHoy_WPF_Natif/Model/ROGER.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Presentation3Tiers.DAL +{ + /// + /// Auteur : Hugo St-Louis + /// Description : Classe concrète qui gère un fichier texte. + /// Date : 2023-03-29 + /// + public class GestionFichierTexte : ILectureFichier + { + public BDApprentissageAuto BD { get; set; } + /// + /// permet de remplir la structure de données pour l'apprentissage automatique à partir dun fichier texte + /// + /// + public BDApprentissageAuto RemplirDonneesBD(string sNomFichier) + { + StreamReader lecteur = new StreamReader(sNomFichier); + string sLigne = ""; + BD = new BDApprentissageAuto(); + string[] sTabElements = null; + + if (!lecteur.EndOfStream) + { + sLigne = lecteur.ReadLine(); + BD.NbElements = Convert.ToInt32(sLigne); + + sLigne = lecteur.ReadLine(); + BD.NbAttributs = Convert.ToInt32(sLigne); + + BD.Elements = new double[BD.NbElements, BD.NbAttributs - 1]; + BD.Resultats = new int[BD.NbElements]; + for (int i = 0; i < BD.NbElements; i++) + { + sLigne = lecteur.ReadLine(); + sTabElements = sLigne.Split('\t'); + for (int j = 0; j < sTabElements.Length - 1; j++) + { + BD.Elements[i, j] = Convert.ToDouble(sTabElements[j]); + } + BD.Resultats[i] = Convert.ToInt32(sTabElements[sTabElements.Length - 1]); + } + } + return BD; + } + + /// + /// rempli et affiche les resultats dun fichier dapprentissage auto + /// + /// + /// + public string RemplirEtAfficherDonneesBD(string sNomFichier) + { + RemplirDonneesBD(sNomFichier); + string sResultat = ""; + sResultat = "nb elements : " + BD.NbElements + "\r\n"; + sResultat += "nb attribut : " + BD.NbAttributs + "\r\n"; + sResultat += "Voici les attribut et valeur de verité" + "\r\n"; + for (int i = 0; i < BD.NbElements; i++) + { + for (int j = 0; j < BD.NbAttributs - 1; j++) + { + sResultat += BD.Elements[i, j] + "\t"; + } + sResultat += "\r\nValeur de verite : " + BD.Resultats[i] + "\r\n"; + } + return sResultat; + } + + + /// + /// Lit et retourne le contenu d'un fichier texte + /// pour lequel le nom est passé en paramètre. + /// + /// + /// + public string LireFichierTexte(string sNomFichier) + { + bool bFichierExiste = File.Exists(sNomFichier); + string sContenuFichier = ""; + StreamReader sr = null; + if (!bFichierExiste) + return "Le fichier n'existe pas ...."; + try + { + sr = new StreamReader(sNomFichier); + sContenuFichier = sr.ReadToEnd(); + return sContenuFichier; + } + catch (Exception ex) + { + return "Erreur lors de la lecture du fichier : " + + ex.Message; + } + } + } +}