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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +108 -124
app.py CHANGED
@@ -4,35 +4,20 @@ import numpy as np
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"] {
11
- position: fixed;
12
- top: 0;
13
- height: 100vh;
14
- overflow: auto;
15
- }
16
- </style>
17
- """, unsafe_allow_html=True)
18
-
19
- # "Analizi Çalıştır" butonuna basıldı mı kontrolü
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
29
- image_files = ["a.png", "b.png", "c.png", "d.png", "e.png", "f.png", "g.png"]
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
@@ -59,98 +44,97 @@ first_step = st.sidebar.number_input("İlk Adım", value=0, step=1)
59
  increase_amount = st.sidebar.number_input("Artış Miktarı", value=1, step=1)
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}")
 
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
+ # Açıklama Resimleri
11
+ st.subheader("Uygulamanın Çalışma Prensibi")
12
+
13
+ # Resimlerin dosya isimlerini sırayla listele
14
+ image_files = ["a.png", "b.png", "c.png", "d.png", "e.png", "f.png", "g.png"]
15
+
16
+ # Resimleri alt alta ekle
17
+ for image_file in image_files:
18
+ st.image(image_file, use_container_width=True) # Yeni parametre kullanıldı
19
+
20
+ # Kullanıcıdan veri alma (Sidebar sabit kalıyor)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  st.sidebar.header("Girdi Alanları")
22
 
23
  # Dosya yükleme veya metin girişi seçimi
 
44
  increase_amount = st.sidebar.number_input("Artış Miktarı", value=1, step=1)
45
 
46
  if st.sidebar.button("Analizi Çalıştır"):
47
+ # Notları yükleme ve işleme
48
+ if input_method == "Dosya Yükle" and uploaded_file is None:
49
+ st.error("Lütfen bir dosya yükleyin!")
50
+ elif input_method == "Kopyala-Yapıştır" and not text_input:
51
+ st.error("Lütfen notları metin kutusuna yapıştırın!")
52
+ else:
53
+ try:
54
+ # Dosya veya metin kutusundan içerik okuma
55
+ if uploaded_file:
56
+ content = uploaded_file.read().decode("utf-8")
57
+ elif text_input:
58
+ content = text_input
59
+
60
+ # Veriyi işleme
61
+ result = re.split(r'[ \n]+', content)
62
+ notes_result = result[first_step::increase_amount]
63
+ notes_result = [x for x in notes_result if x != '∅' and x != "NA"]
64
+ notes_result = list(map(lambda x: float(x), notes_result))
65
+ notes_result = np.array(notes_result)
66
+
67
+ # İstatistikler
68
+ average_x = np.average(notes_result)
69
+ min_x = notes_result.min()
70
+ max_x = notes_result.max()
71
+ std = np.std(notes_result)
72
+ z_score = (my_note - average_x) / std
73
+
74
+ # İstatistikleri ekrana yazdırma
75
+ st.subheader("Genel Bilgiler")
76
+ st.write(f"Katilimci Sayısı: {len(notes_result)}")
77
+ st.write(f"En Düşük Not: {min_x:.2f}")
78
+ st.write(f"En Yüksek Not: {max_x:.2f}")
79
+ st.write(f"Ortalama Not: {average_x:.2f}")
80
+ st.write(f"Standart Sapma: {std:.2f}")
81
+ st.write(f"Z-Skoru: {z_score:.2f}")
82
+
83
+ # Grafik oluşturma
84
+ st.subheader("Not Dağılım Grafiği")
85
+ unique_values, counts = np.unique(notes_result, return_counts=True)
86
+ plt.figure(figsize=(10, 6))
87
+ bars = plt.bar(unique_values, counts, width=0.3)
88
+ plt.axvline(x=average_x, color='red', linestyle='--')
89
+ plt.text(average_x + 1.5, max(counts), 'Ortalama Not', color='red', rotation=0, ha='center', va='bottom')
90
+
91
+ if my_note in unique_values:
92
+ plt.text(my_note, counts[unique_values == my_note][0], 'Benim\nNotum', color='green', rotation=0, ha='center', va='bottom')
93
+
94
+ for bar in bars:
95
+ if bar.get_x() <= my_note < bar.get_x() + bar.get_width():
96
+ bar.set_color('green')
97
+
98
+ plt.title(f'{lecture_name} Not Sayıları Grafiği')
99
+ plt.xlabel('Notlar')
100
+ plt.ylabel('Adet')
101
+ plt.xticks(range(0, int(perfect_score), note_s_axis_diff), rotation=90)
102
+ plt.yticks(range(0, max(counts), amount_s_axis_diff), rotation=0)
103
+
104
+ # Grafik bilgileri
105
+ info_text = (
106
+ f"Katilimci sayısı: {len(notes_result)}\n"
107
+ f"En düşük not: {min_x:.2f}\n"
108
+ f"En yüksek not: {max_x:.2f}\n"
109
+ f"Benim notum: {my_note:.2f}\n"
110
+ f"Ortalama not: {average_x:.2f}\n"
111
+ f"Standart sapma: {std:.2f}\n"
112
+ f"Z-skoru: {z_score:.2f}"
113
+ )
114
+ plt.text(
115
+ 1.05 * max(unique_values), 0.8 * max(counts),
116
+ info_text,
117
+ fontsize=10,
118
+ color="black",
119
+ ha="left",
120
+ va="top",
121
+ bbox=dict(boxstyle="round,pad=0.3", edgecolor="blue", facecolor="lightgrey")
122
+ )
123
+ plt.subplots_adjust(left=0.055, bottom=0.065, right=0.90, top=0.962, wspace=0.2, hspace=0.2)
124
+
125
+ # Grafik gösterimi
126
+ st.pyplot(plt)
127
+
128
+ # Grafik indirme bağlantısı
129
+ buf = BytesIO()
130
+ plt.savefig(buf, format="png")
131
+ buf.seek(0)
132
+ st.download_button(
133
+ label="Grafiği İndir",
134
+ data=buf,
135
+ file_name="not_dagilimi.png",
136
+ mime="image/png"
137
+ )
138
+
139
+ except Exception as e:
140
+ st.error(f"Hata: {e}")