/// <summary> /// Ogreci profil'ini veritabanından getirir /// </summary> /// <returns>List(OgrenciProfilModel)</returns> public List <OgrenciProfilModel> ProfilOgrenciGetir() { using (SQLiteConnection con = DatabaseHelper.GetConnection()) { List <OgrenciProfilModel> ogrencis = new List <OgrenciProfilModel>(); string sqlCommand = "select * from ogrenciprofil"; ; SQLiteCommand cmd = new SQLiteCommand(con); cmd.CommandText = sqlCommand; SQLiteDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { OgrenciProfilModel ogrenciProfil = new OgrenciProfilModel(); ogrenciProfil.ProfilID = dr.GetInt32(dr.GetOrdinal("ogrenciprofilID")); ogrenciProfil.Numarasi = dr.GetString(dr.GetOrdinal("Kendisi")); ogrenciProfil.A1 = dr.GetInt32(dr.GetOrdinal("A1")); ogrenciProfil.A2 = dr.GetInt32(dr.GetOrdinal("A2")); ogrenciProfil.A3 = dr.GetInt32(dr.GetOrdinal("A3")); ogrenciProfil.A4 = dr.GetInt32(dr.GetOrdinal("A4")); ogrenciProfil.A5 = dr.GetInt32(dr.GetOrdinal("A5")); ogrenciProfil.A6 = dr.GetInt32(dr.GetOrdinal("A6")); ogrenciProfil.A7 = dr.GetInt32(dr.GetOrdinal("A7")); ogrenciProfil.A8 = dr.GetInt32(dr.GetOrdinal("A8")); ogrenciProfil.A9 = dr.GetInt32(dr.GetOrdinal("A9")); ogrenciProfil.A10 = dr.GetInt32(dr.GetOrdinal("A10")); ogrenciProfil.A11 = dr.GetInt32(dr.GetOrdinal("A11")); ogrenciProfil.A12 = dr.GetInt32(dr.GetOrdinal("A12")); ogrenciProfil.A13 = dr.GetInt32(dr.GetOrdinal("A13")); ogrenciProfil.A14 = dr.GetInt32(dr.GetOrdinal("A14")); ogrenciProfil.A15 = dr.GetInt32(dr.GetOrdinal("A15")); ogrencis.Add(ogrenciProfil); } con.Close(); return(ogrencis); } }
/// <summary> /// Ogrenci profil nesnesini veritabanına kaydeder. /// </summary> /// <param name="ogrenciProfil"></param> public void OgrenciProfilKaydet(OgrenciProfilModel ogrenciProfil) { using (SQLiteConnection con = DatabaseHelper.GetConnection()) { string sqlCommand = "insert into ogrenciprofil(Kendisi,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15) values(@numara,@a1,@a2,@a3,@a4,@a5,@a6,@a7,@a8,@a9,@a10,@a11,@a12,@a13,@a14,@a15)"; SQLiteCommand cmd = new SQLiteCommand(con); cmd.CommandText = sqlCommand; cmd.Parameters.AddWithValue("@numara", ogrenciProfil.Numarasi); cmd.Parameters.AddWithValue("@a1", ogrenciProfil.A1); cmd.Parameters.AddWithValue("@a2", ogrenciProfil.A2); cmd.Parameters.AddWithValue("@a3", ogrenciProfil.A3); cmd.Parameters.AddWithValue("@a4", ogrenciProfil.A4); cmd.Parameters.AddWithValue("@a5", ogrenciProfil.A5); cmd.Parameters.AddWithValue("@a6", ogrenciProfil.A6); cmd.Parameters.AddWithValue("@a7", ogrenciProfil.A7); cmd.Parameters.AddWithValue("@a8", ogrenciProfil.A8); cmd.Parameters.AddWithValue("@a9", ogrenciProfil.A9); cmd.Parameters.AddWithValue("@a10", ogrenciProfil.A10); cmd.Parameters.AddWithValue("@a11", ogrenciProfil.A11); cmd.Parameters.AddWithValue("@a12", ogrenciProfil.A12); cmd.Parameters.AddWithValue("@a13", ogrenciProfil.A13); cmd.Parameters.AddWithValue("@a14", ogrenciProfil.A14); cmd.Parameters.AddWithValue("@a15", ogrenciProfil.A15); cmd.ExecuteNonQuery(); con.Close(); } }
/// <summary> /// İlk olarak hangi dosya seçildiği belirlenir.Seçilen dosya belirlendikten sonra /// csv dosyası okunur. Her bir satır diziye atılır. /// dizinin elemanı split edilir ve gerekli alanlar modele atılır. /// her kayıt veritabına doğru sıra ile eklenir. /// </summary> /// <param name="openFileSafeFileName">Açılan dosyanın ismi</param> /// <param name="openFileFileName">Dosyanın tam yolu</param> public void ExelRead(string openFileSafeFileName, string openFileFileName) { OgreciNetworkProvider = new OgreciNetworkProvider(); OgrenciProfilProvider = new OgrenciProfilProvider(); if (openFileSafeFileName == "ogrenciNetwork.csv") { string[] allLinesnetwork = File.ReadAllLines(openFileFileName); for (int i = 0; i < allLinesnetwork.Length; i++) { OgreciNetworkModel ogreciNetworkModel = new OgreciNetworkModel(); string[] ogrenci = allLinesnetwork[i].Split(','); ogreciNetworkModel.Numarasi = ogrenci[0]; ogreciNetworkModel.Ark1 = ogrenci[1]; ogreciNetworkModel.Ark2 = ogrenci[2]; ogreciNetworkModel.Ark3 = ogrenci[3]; ogreciNetworkModel.Ark4 = ogrenci[4]; ogreciNetworkModel.Ark5 = ogrenci[5]; ogreciNetworkModel.Ark6 = ogrenci[6]; ogreciNetworkModel.Ark7 = ogrenci[7]; ogreciNetworkModel.Ark8 = ogrenci[8]; ogreciNetworkModel.Ark9 = ogrenci[9]; ogreciNetworkModel.Ark10 = ogrenci[10]; OgreciNetworkProvider.OgrenciNetworkEkle(ogreciNetworkModel); } } if (openFileSafeFileName == "ogrenciProfil.csv") { string[] allLineprofil = File.ReadAllLines(openFileFileName); for (int i = 0; i < allLineprofil.Length; i++) { OgrenciProfilModel ogrenciProfil = new OgrenciProfilModel(); string[] profil = allLineprofil[i].Split(','); ogrenciProfil.Numarasi = profil[0]; ogrenciProfil.A1 = Convert.ToInt32(profil[1]); ogrenciProfil.A2 = Convert.ToInt32(profil[2]); ogrenciProfil.A3 = Convert.ToInt32(profil[3]); ogrenciProfil.A4 = Convert.ToInt32(profil[4]); ogrenciProfil.A5 = Convert.ToInt32(profil[5]); ogrenciProfil.A6 = Convert.ToInt32(profil[6]); ogrenciProfil.A7 = Convert.ToInt32(profil[7]);; ogrenciProfil.A8 = Convert.ToInt32(profil[8]); ogrenciProfil.A9 = Convert.ToInt32(profil[9]); ogrenciProfil.A10 = Convert.ToInt32(profil[10]); ogrenciProfil.A11 = Convert.ToInt32(profil[11]); ogrenciProfil.A12 = Convert.ToInt32(profil[12]); ogrenciProfil.A13 = Convert.ToInt32(profil[13]); ogrenciProfil.A14 = Convert.ToInt32(profil[14]); ogrenciProfil.A15 = Convert.ToInt32(profil[15]); OgrenciProfilProvider.OgrenciProfilKaydet(ogrenciProfil); } } }
public List <StudentModel> BestTenFriend(string ArananOgrenci, ObservableCollection <OgrenciProfilModel> ProfilList) { var OgrenciVarmi = ExcelReader.OgrenciListesiOku(); //ogrencilistesi.xlsx dosyası okunur ve dosyadaki tüm //tüm veriler OgrenciVarmi listesine atılır. for (int i = 0; i < OgrenciVarmi.Count; i++) //tüm liste dolaşılır. { if (OgrenciVarmi[i].Adi == ArananOgrenci || OgrenciVarmi[i].No == ArananOgrenci) //Girilen numara veya isim excel'deki veriler ile //aynı olması kontrol edilir. { BulunanOgrenci.No = OgrenciVarmi[i].No; //isim veya numara eşleşirse numarayı bulunan öğrencinin numarasına atar. } } if (string.IsNullOrEmpty(BulunanOgrenci.No)) // Aradığımız öğrenci yok ise ekrana öğrenci yoktur diye mesaj verir { System.Windows.MessageBox.Show("Girdiğiniz öğrenci yoktur..."); } else { var ogrenciArkadaslari = FindFriendProvider.ArkdaslariBul(BulunanOgrenci.No); //Aranan öğrencinin arkadaşları (Veritabanından)FindFriendProvider nesnesinin // ArkdaslariBul metodu ile hepsi bulunur. BulunanOgrenci.No = null; //Başka bir öğrenci aramak için null'larız. if (string.IsNullOrEmpty(ogrenciArkadaslari[0])) //Veritabanında bir hata(olması gereken kaydın olmaması gibi) meydana gelirse mesaj çıkar. { System.Windows.MessageBox.Show("Veritabanında hatalı kayıt vardır.." + ogrenciArkadaslari[0]); } else { //Burada regresyona sokacağım anketList tanımladım. List <AnketModel> anketList = new List <AnketModel>(); foreach (var item in ProfilList) { for (int i = 1; i <= 10; i++) { if (!string.IsNullOrEmpty(ogrenciArkadaslari[i])) //Aranan öğrencinin arkadaşlarını anketList'e attım arkadasmı alanına 1 verdim. { if (ogrenciArkadaslari[i] == item.Numarasi) { AnketModel anket = new AnketModel(); anket.Arkadasmi = 1; anket.ArkadaslikDegeri = 0; anket.ARKADAS = item.Numarasi; anket.A1 = item.A1; anket.A2 = item.A2; anket.A3 = item.A3; anket.A4 = item.A4; anket.A5 = item.A5; anket.A6 = item.A6; anket.A7 = item.A7; anket.A8 = item.A8; anket.A9 = item.A9; anket.A10 = item.A10; anket.A11 = item.A11; anket.A12 = item.A12; anket.A13 = item.A13; anket.A14 = item.A14; anket.A15 = item.A15; anketList.Add(anket); } } } } List <OgrenciProfilModel> list = new List <OgrenciProfilModel>(); //yeni bir OgrenciProfilModel listesi tanımlıyorum. list = OgrenciProfilProvider.ProfilOgrenciGetir(); //OgrenciProfil kayıtlarının hepsi çekilir. OgrenciProfilModel ogrenci = new OgrenciProfilModel(); for (int i = 0; i < ogrenciArkadaslari.Length; i++) { if (!string.IsNullOrEmpty(ogrenciArkadaslari[i])) //Boş değerler de geldiği için kontrol ettik. { ogrenci = list.FirstOrDefault(x => x.Numarasi == ogrenciArkadaslari[i]); //listenin içerisinden aranan öğrenci ve arkadaşlarını siler. list.Remove(ogrenci); } } for (int i = 0; i < list.Count / 2; i++) //Arkadaşı olmayanların yarısıda anketList'e atılır ve arkadasmi alanına 0 verilir. { AnketModel anket = new AnketModel(); anket.Arkadasmi = 0; anket.ARKADAS = list[i].Numarasi; anket.A1 = list[i].A1; anket.A2 = list[i].A2; anket.A3 = list[i].A3; anket.A4 = list[i].A4; anket.A5 = list[i].A5; anket.A6 = list[i].A6; anket.A7 = list[i].A7; anket.A8 = list[i].A8; anket.A9 = list[i].A9; anket.A10 = list[i].A10; anket.A11 = list[i].A11; anket.A12 = list[i].A12; anket.A13 = list[i].A13; anket.A14 = list[i].A14; anket.A15 = list[i].A15; anket.ArkadaslikDegeri = 0; anketList.Add(anket); } for (int i = 0; i < anketList.Count; i++) //listenin içersininden anketList'e olan tüm değerler silinir. //Böylece elimizde hiç dokunmadığımız yarısı kalır(ortalama 40 kişi). { var sil = list.FirstOrDefault(x => x.Numarasi == anketList[i].ARKADAS); list.Remove(sil); } List <AnketModel> aranacakList = new List <AnketModel>(); //Hiç dokunmadığımız 40 kişi 10 arkadaşın aranacağı aranacakList'e atılır. for (int i = 0; i < list.Count; i++) { AnketModel anket = new AnketModel(); anket.Arkadasmi = 0; anket.ARKADAS = list[i].Numarasi; anket.A1 = list[i].A1; anket.A2 = list[i].A2; anket.A3 = list[i].A3; anket.A4 = list[i].A4; anket.A5 = list[i].A5; anket.A6 = list[i].A6; anket.A7 = list[i].A7; anket.A8 = list[i].A8; anket.A9 = list[i].A9; anket.A10 = list[i].A10; anket.A11 = list[i].A11; anket.A12 = list[i].A12; anket.A13 = list[i].A13; anket.A14 = list[i].A14; anket.A15 = list[i].A15; anket.ArkadaslikDegeri = 0; aranacakList.Add(anket); } var Best10Student = LogisticRegression(anketList, aranacakList); //LogisticRegression metoduna anketList(betaları bulmak için) //ve aranacakList(10 arkadaşı bulmak için) yollanır. return(Best10Student); } } return(null); }