aliicemill commited on
Commit
ab8efe4
·
verified ·
1 Parent(s): 0d5544f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -18
app.py CHANGED
@@ -1,15 +1,35 @@
 
1
  import re
2
  import numpy as np
3
  import matplotlib.pyplot as plt
4
  from io import BytesIO
5
- import streamlit as st
6
 
7
  # Başlık
8
  st.title("Note Analyzer Streamlit Uygulaması")
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  # Kullanıcıdan veri alma (Sidebar sabit kalıyor)
11
  st.sidebar.header("Girdi Alanları")
12
- input_method = st.sidebar.radio("Notları nasıl gireceksiniz?", options=["Dosya Yükle", "Kopyala-Yapıştır"])
 
 
 
 
 
 
13
  uploaded_file = None
14
  text_input = None
15
 
@@ -18,6 +38,7 @@ if input_method == "Dosya Yükle":
18
  elif input_method == "Kopyala-Yapıştır":
19
  text_input = st.sidebar.text_area("Notları Yapıştırın", height=200)
20
 
 
21
  lecture_name = st.sidebar.text_input("Ders Adı", value="Ders Adı")
22
  perfect_score = st.sidebar.number_input("Sınav Puanı Üst Limiti", value=100, step=1)
23
  my_note = st.sidebar.number_input("Benim Notum", value=0.0, step=0.1)
@@ -27,12 +48,17 @@ first_step = st.sidebar.number_input("İlk Adım", value=0, step=1)
27
  increase_amount = st.sidebar.number_input("Artış Miktarı", value=1, step=1)
28
 
29
  if st.sidebar.button("Analizi Çalıştır"):
 
 
 
 
30
  if input_method == "Dosya Yükle" and uploaded_file is None:
31
  st.error("Lütfen bir dosya yükleyin!")
32
  elif input_method == "Kopyala-Yapıştır" and not text_input:
33
  st.error("Lütfen notları metin kutusuna yapıştırın!")
34
  else:
35
  try:
 
36
  if uploaded_file:
37
  content = uploaded_file.read().decode("utf-8")
38
  elif text_input:
@@ -40,8 +66,9 @@ if st.sidebar.button("Analizi Çalıştır"):
40
 
41
  # Veriyi işleme
42
  result = re.split(r'[ \n]+', content)
43
- notes_result = result[first_step::increase_amount]
44
- notes_result = [x.strip() for x in notes_result if x.strip() != '∅' and x.strip() != "NA"]
 
45
  notes_result = list(map(lambda x: float(x), notes_result))
46
  notes_result = np.array(notes_result)
47
 
@@ -52,6 +79,7 @@ if st.sidebar.button("Analizi Çalıştır"):
52
  std = np.std(notes_result)
53
  z_score = (my_note - average_x) / std
54
 
 
55
  st.subheader("Genel Bilgiler")
56
  st.write(f"Katilimci Sayısı: {len(notes_result)}")
57
  st.write(f"En Düşük Not: {min_x:.2f}")
@@ -61,26 +89,27 @@ if st.sidebar.button("Analizi Çalıştır"):
61
  st.write(f"Z-Skoru: {z_score:.2f}")
62
 
63
  # Grafik oluşturma
 
64
  unique_values, counts = np.unique(notes_result, return_counts=True)
65
- fig, ax = plt.subplots(figsize=(10, 6)) # Grafik boyutunu ayarlıyoruz
66
-
67
- bars = ax.bar(unique_values, counts, width=0.3)
68
- ax.axvline(x=average_x, color='red', linestyle='--')
69
- ax.text(average_x + 1.5, max(counts), 'Ortalama Not', color='red', rotation=0, ha='center', va='bottom')
70
 
71
  if my_note in unique_values:
72
- ax.text(my_note, counts[unique_values == my_note][0], 'Benim\nNotum', color='green', rotation=0, ha='center', va='bottom')
73
 
74
  for bar in bars:
75
  if bar.get_x() <= my_note < bar.get_x() + bar.get_width():
76
  bar.set_color('green')
77
 
78
- ax.set_title(f'{lecture_name} Not Sayıları Grafiği')
79
- ax.set_xlabel('Notlar')
80
- ax.set_ylabel('Adet')
81
- ax.set_xticks(range(0, int(perfect_score), note_s_axis_diff))
82
- ax.set_yticks(range(0, max(counts), amount_s_axis_diff))
83
 
 
84
  info_text = (
85
  f"Katilimci sayısı: {len(notes_result)}\n"
86
  f"En düşük not: {min_x:.2f}\n"
@@ -90,7 +119,7 @@ if st.sidebar.button("Analizi Çalıştır"):
90
  f"Standart sapma: {std:.2f}\n"
91
  f"Z-skoru: {z_score:.2f}"
92
  )
93
- ax.text(
94
  1.05 * max(unique_values), 0.8 * max(counts),
95
  info_text,
96
  fontsize=10,
@@ -99,12 +128,15 @@ if st.sidebar.button("Analizi Çalıştır"):
99
  va="top",
100
  bbox=dict(boxstyle="round,pad=0.3", edgecolor="blue", facecolor="lightgrey")
101
  )
 
 
 
 
102
 
103
  # Grafik indirme bağlantısı
104
  buf = BytesIO()
105
  plt.savefig(buf, format="png")
106
  buf.seek(0)
107
-
108
  st.download_button(
109
  label="Grafiği İndir",
110
  data=buf,
@@ -113,4 +145,17 @@ if st.sidebar.button("Analizi Çalıştır"):
113
  )
114
 
115
  except Exception as e:
116
- st.error(f"Hata: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
  import re
3
  import numpy as np
4
  import matplotlib.pyplot as plt
5
  from io import BytesIO
 
6
 
7
  # Başlık
8
  st.title("Note Analyzer Streamlit Uygulaması")
9
 
10
+ # Resimleri sadece butona basılmadan önce gösterme
11
+ show_images = True
12
+
13
+ # Uygulamanın çalışma prensibini açıklayan resimler
14
+ if show_images:
15
+ st.subheader("Uygulamanın Çalışma Prensibi")
16
+
17
+ # Resimlerin dosya isimlerini sırayla listele
18
+ image_files = ["turkish\\a.png", "turkish\\b.png", "turkish\\c.png", "turkish\\d.png", "turkish\\e.png", "turkish\\f.png", "turkish\\g.png"]
19
+
20
+ # Resimleri alt alta ekle
21
+ for image_file in image_files:
22
+ st.image(image_file, use_container_width=True) # Yeni parametre kullanıldı
23
+
24
  # Kullanıcıdan veri alma (Sidebar sabit kalıyor)
25
  st.sidebar.header("Girdi Alanları")
26
+
27
+ # Dosya yükleme veya metin girişi seçimi
28
+ input_method = st.sidebar.radio(
29
+ "Notları nasıl gireceksiniz?",
30
+ options=["Dosya Yükle", "Kopyala-Yapıştır"]
31
+ )
32
+
33
  uploaded_file = None
34
  text_input = None
35
 
 
38
  elif input_method == "Kopyala-Yapıştır":
39
  text_input = st.sidebar.text_area("Notları Yapıştırın", height=200)
40
 
41
+ # Diğer parametreler
42
  lecture_name = st.sidebar.text_input("Ders Adı", value="Ders Adı")
43
  perfect_score = st.sidebar.number_input("Sınav Puanı Üst Limiti", value=100, step=1)
44
  my_note = st.sidebar.number_input("Benim Notum", value=0.0, step=0.1)
 
48
  increase_amount = st.sidebar.number_input("Artış Miktarı", value=1, step=1)
49
 
50
  if st.sidebar.button("Analizi Çalıştır"):
51
+ # Butona basıldığında resimleri gizle
52
+ show_images = False
53
+
54
+ # Notları yükleme ve işleme
55
  if input_method == "Dosya Yükle" and uploaded_file is None:
56
  st.error("Lütfen bir dosya yükleyin!")
57
  elif input_method == "Kopyala-Yapıştır" and not text_input:
58
  st.error("Lütfen notları metin kutusuna yapıştırın!")
59
  else:
60
  try:
61
+ # Dosya veya metin kutusundan içerik okuma
62
  if uploaded_file:
63
  content = uploaded_file.read().decode("utf-8")
64
  elif text_input:
 
66
 
67
  # Veriyi işleme
68
  result = re.split(r'[ \n]+', content)
69
+
70
+ # Strip fonksiyonu ve kaçış dizisi temizliği
71
+ notes_result = [x.strip() for x in result[first_step::increase_amount] if x.strip() != '∅' and x.strip() != "NA"]
72
  notes_result = list(map(lambda x: float(x), notes_result))
73
  notes_result = np.array(notes_result)
74
 
 
79
  std = np.std(notes_result)
80
  z_score = (my_note - average_x) / std
81
 
82
+ # İstatistikleri ekrana yazdırma
83
  st.subheader("Genel Bilgiler")
84
  st.write(f"Katilimci Sayısı: {len(notes_result)}")
85
  st.write(f"En Düşük Not: {min_x:.2f}")
 
89
  st.write(f"Z-Skoru: {z_score:.2f}")
90
 
91
  # Grafik oluşturma
92
+ st.subheader("Not Dağılım Grafiği")
93
  unique_values, counts = np.unique(notes_result, return_counts=True)
94
+ plt.figure(figsize=(10, 6))
95
+ bars = plt.bar(unique_values, counts, width=0.3)
96
+ plt.axvline(x=average_x, color='red', linestyle='--')
97
+ plt.text(average_x + 1.5, max(counts), 'Ortalama Not', color='red', rotation=0, ha='center', va='bottom')
 
98
 
99
  if my_note in unique_values:
100
+ plt.text(my_note, counts[unique_values == my_note][0], 'Benim\nNotum', color='green', rotation=0, ha='center', va='bottom')
101
 
102
  for bar in bars:
103
  if bar.get_x() <= my_note < bar.get_x() + bar.get_width():
104
  bar.set_color('green')
105
 
106
+ plt.title(f'{lecture_name} Not Sayıları Grafiği')
107
+ plt.xlabel('Notlar')
108
+ plt.ylabel('Adet')
109
+ plt.xticks(range(0, int(perfect_score), note_s_axis_diff), rotation=90)
110
+ plt.yticks(range(0, max(counts), amount_s_axis_diff), rotation=0)
111
 
112
+ # Grafik bilgileri
113
  info_text = (
114
  f"Katilimci sayısı: {len(notes_result)}\n"
115
  f"En düşük not: {min_x:.2f}\n"
 
119
  f"Standart sapma: {std:.2f}\n"
120
  f"Z-skoru: {z_score:.2f}"
121
  )
122
+ plt.text(
123
  1.05 * max(unique_values), 0.8 * max(counts),
124
  info_text,
125
  fontsize=10,
 
128
  va="top",
129
  bbox=dict(boxstyle="round,pad=0.3", edgecolor="blue", facecolor="lightgrey")
130
  )
131
+ plt.subplots_adjust(left=0.055, bottom=0.065, right=0.90, top=0.962, wspace=0.2, hspace=0.2)
132
+
133
+ # Grafik gösterimi
134
+ st.pyplot(plt)
135
 
136
  # Grafik indirme bağlantısı
137
  buf = BytesIO()
138
  plt.savefig(buf, format="png")
139
  buf.seek(0)
 
140
  st.download_button(
141
  label="Grafiği İndir",
142
  data=buf,
 
145
  )
146
 
147
  except Exception as e:
148
+ st.error(f"Hata: {e}")
149
+
150
+ # Web sayfasının altına isim ve tarih
151
+ st.markdown("---")
152
+ st.write("Developed by: Ali Cemil Özdemir")
153
+ st.write("Date: 01.12.2024")
154
+ st.write("For feedback and suggestions, you can contact me at alicemilozdemir7@gmail.com")
155
+
156
+ # Grafiklerin sağ alt köşesine yazı ekleme
157
+ st.markdown("""
158
+ <p style="position:absolute; bottom:0px; right:0px; font-size: 12px; color: gray;">
159
+ Created with Note Analyzer
160
+ </p>
161
+ """, unsafe_allow_html=True)