aliicemill commited on
Commit
80f1e79
·
verified ·
1 Parent(s): 830e866

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +96 -11
app.py CHANGED
@@ -4,7 +4,7 @@ import numpy as np
4
  import matplotlib.pyplot as plt
5
  from io import BytesIO
6
 
7
- # CSS ile kaydırılabilir sidebar oluşturma
8
  st.markdown("""
9
  <style>
10
  [data-testid="stSidebar"] {
@@ -20,11 +20,9 @@ st.markdown("""
20
  if "analysis_run" not in st.session_state:
21
  st.session_state.analysis_run = False
22
 
23
- # Başlık
24
  if not st.session_state.analysis_run:
25
  st.title("Note Analyzer Streamlit Uygulaması")
26
-
27
- # Açıklama Resimleri
28
  st.subheader("Uygulamanın Çalışma Prensibi")
29
 
30
  # Resimlerin dosya isimlerini sırayla listele
@@ -32,9 +30,9 @@ if not st.session_state.analysis_run:
32
 
33
  # Resimleri alt alta ekle
34
  for image_file in image_files:
35
- st.image(image_file, use_container_width=True) # Yeni parametre kullanıldı
36
 
37
- # Kullanıcıdan veri alma (Sidebar sabit kalıyor)
38
  st.sidebar.header("Girdi Alanları")
39
 
40
  # Dosya yükleme veya metin girişi seçimi
@@ -62,10 +60,97 @@ increase_amount = st.sidebar.number_input("Artış Miktarı", value=1, step=1)
62
 
63
  if st.sidebar.button("Analizi Çalıştır"):
64
  st.session_state.analysis_run = True
65
- # Analiz işlemleri buradan itibaren devam edecek...
66
 
67
- # Analiz çıktıları aşağıda yer alır.
68
  if st.session_state.analysis_run:
69
- # Analiz kodunu buraya yaz
70
- st.subheader("Analiz Sonuçları")
71
- st.write("Burada analiz sonuçları görüntülenecek.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  import matplotlib.pyplot as plt
5
  from io import BytesIO
6
 
7
+ # CSS ile sidebar'ı sabit ve kaydırılabilir hale getirme
8
  st.markdown("""
9
  <style>
10
  [data-testid="stSidebar"] {
 
20
  if "analysis_run" not in st.session_state:
21
  st.session_state.analysis_run = False
22
 
23
+ # Başlık ve açıklamalar (butona basılmadan önce)
24
  if not st.session_state.analysis_run:
25
  st.title("Note Analyzer Streamlit Uygulaması")
 
 
26
  st.subheader("Uygulamanın Çalışma Prensibi")
27
 
28
  # Resimlerin dosya isimlerini sırayla listele
 
30
 
31
  # Resimleri alt alta ekle
32
  for image_file in image_files:
33
+ st.image(image_file, use_container_width=True)
34
 
35
+ # Kullanıcıdan veri alma (Sidebar)
36
  st.sidebar.header("Girdi Alanları")
37
 
38
  # Dosya yükleme veya metin girişi seçimi
 
60
 
61
  if st.sidebar.button("Analizi Çalıştır"):
62
  st.session_state.analysis_run = True
 
63
 
64
+ # Analiz işlemleri (butona basıldıktan sonra)
65
  if st.session_state.analysis_run:
66
+ try:
67
+ # Dosya veya metin kutusundan içerik okuma
68
+ if uploaded_file:
69
+ content = uploaded_file.read().decode("utf-8")
70
+ elif text_input:
71
+ content = text_input
72
+ else:
73
+ st.error("Lütfen notlar için bir dosya yükleyin ya da metin kutusuna yapıştırın!")
74
+ st.stop()
75
+
76
+ # Veriyi işleme
77
+ result = re.split(r'[ \n]+', content)
78
+ notes_result = result[first_step::increase_amount]
79
+ notes_result = [x for x in notes_result if x != '∅' and x != "NA"]
80
+ notes_result = list(map(lambda x: float(x), notes_result))
81
+ notes_result = np.array(notes_result)
82
+
83
+ # İstatistikler
84
+ average_x = np.average(notes_result)
85
+ min_x = notes_result.min()
86
+ max_x = notes_result.max()
87
+ std = np.std(notes_result)
88
+ z_score = (my_note - average_x) / std
89
+
90
+ # İstatistikleri ekrana yazdırma
91
+ st.subheader("Genel Bilgiler")
92
+ st.write(f"Katilimci Sayısı: {len(notes_result)}")
93
+ st.write(f"En Düşük Not: {min_x:.2f}")
94
+ st.write(f"En Yüksek Not: {max_x:.2f}")
95
+ st.write(f"Ortalama Not: {average_x:.2f}")
96
+ st.write(f"Standart Sapma: {std:.2f}")
97
+ st.write(f"Z-Skoru: {z_score:.2f}")
98
+
99
+ # Grafik oluşturma
100
+ st.subheader("Not Dağılım Grafiği")
101
+ unique_values, counts = np.unique(notes_result, return_counts=True)
102
+ plt.figure(figsize=(10, 6))
103
+ bars = plt.bar(unique_values, counts, width=0.3)
104
+ plt.axvline(x=average_x, color='red', linestyle='--')
105
+ plt.text(average_x + 1.5, max(counts), 'Ortalama Not', color='red', rotation=0, ha='center', va='bottom')
106
+
107
+ if my_note in unique_values:
108
+ plt.text(my_note, counts[unique_values == my_note][0], 'Benim\nNotum', color='green', rotation=0, ha='center', va='bottom')
109
+
110
+ for bar in bars:
111
+ if bar.get_x() <= my_note < bar.get_x() + bar.get_width():
112
+ bar.set_color('green')
113
+
114
+ plt.title(f'{lecture_name} Not Sayıları Grafiği')
115
+ plt.xlabel('Notlar')
116
+ plt.ylabel('Adet')
117
+ plt.xticks(range(0, int(perfect_score), note_s_axis_diff), rotation=90)
118
+ plt.yticks(range(0, max(counts), amount_s_axis_diff), rotation=0)
119
+
120
+ # Grafik bilgileri
121
+ info_text = (
122
+ f"Katilimci sayısı: {len(notes_result)}\n"
123
+ f"En düşük not: {min_x:.2f}\n"
124
+ f"En yüksek not: {max_x:.2f}\n"
125
+ f"Benim notum: {my_note:.2f}\n"
126
+ f"Ortalama not: {average_x:.2f}\n"
127
+ f"Standart sapma: {std:.2f}\n"
128
+ f"Z-skoru: {z_score:.2f}"
129
+ )
130
+ plt.text(
131
+ 1.05 * max(unique_values), 0.8 * max(counts),
132
+ info_text,
133
+ fontsize=10,
134
+ color="black",
135
+ ha="left",
136
+ va="top",
137
+ bbox=dict(boxstyle="round,pad=0.3", edgecolor="blue", facecolor="lightgrey")
138
+ )
139
+ plt.subplots_adjust(left=0.055, bottom=0.065, right=0.90, top=0.962, wspace=0.2, hspace=0.2)
140
+
141
+ # Grafik gösterimi
142
+ st.pyplot(plt)
143
+
144
+ # Grafik indirme bağlantısı
145
+ buf = BytesIO()
146
+ plt.savefig(buf, format="png")
147
+ buf.seek(0)
148
+ st.download_button(
149
+ label="Grafiği İndir",
150
+ data=buf,
151
+ file_name="not_dagilimi.png",
152
+ mime="image/png"
153
+ )
154
+
155
+ except Exception as e:
156
+ st.error(f"Hata: {e}")