Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,15 @@
|
|
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 |
# Kullanıcıdan veri alma (Sidebar sabit kalıyor)
|
11 |
st.sidebar.header("Girdi Alanları")
|
12 |
-
|
13 |
-
# Dosya yükleme veya metin girişi seçimi
|
14 |
-
input_method = st.sidebar.radio(
|
15 |
-
"Notları nasıl gireceksiniz?",
|
16 |
-
options=["Dosya Yükle", "Kopyala-Yapıştır"]
|
17 |
-
)
|
18 |
-
|
19 |
uploaded_file = None
|
20 |
text_input = None
|
21 |
|
@@ -24,7 +18,6 @@ if input_method == "Dosya Yükle":
|
|
24 |
elif input_method == "Kopyala-Yapıştır":
|
25 |
text_input = st.sidebar.text_area("Notları Yapıştırın", height=200)
|
26 |
|
27 |
-
# Diğer parametreler
|
28 |
lecture_name = st.sidebar.text_input("Ders Adı", value="Ders Adı")
|
29 |
perfect_score = st.sidebar.number_input("Sınav Puanı Üst Limiti", value=100, step=1)
|
30 |
my_note = st.sidebar.number_input("Benim Notum", value=0.0, step=0.1)
|
@@ -33,43 +26,23 @@ amount_s_axis_diff = st.sidebar.number_input("Miktar Y Ekseni Ortak Farkı", val
|
|
33 |
first_step = st.sidebar.number_input("İlk Adım", value=0, step=1)
|
34 |
increase_amount = st.sidebar.number_input("Artış Miktarı", value=1, step=1)
|
35 |
|
36 |
-
|
37 |
-
analysis_run = st.sidebar.button("Analizi Çalıştır")
|
38 |
-
|
39 |
-
# Uygulamanın Çalışma Prensibi bölümü, analiz çalıştırılmadığında gösterilir
|
40 |
-
if not analysis_run:
|
41 |
-
st.subheader("Uygulamanın Çalışma Prensibi")
|
42 |
-
# Resimlerin dosya isimlerini sırayla listele
|
43 |
-
image_files = ["a.png", "b.png", "c.png", "d.png", "e.png", "f.png", "g.png"]
|
44 |
-
|
45 |
-
# Resimleri alt alta ekle
|
46 |
-
for image_file in image_files:
|
47 |
-
st.image(image_file, use_container_width=True) # Yeni parametre kullanıldı
|
48 |
-
|
49 |
-
if analysis_run:
|
50 |
-
# Notları yükleme ve işleme
|
51 |
if input_method == "Dosya Yükle" and uploaded_file is None:
|
52 |
st.error("Lütfen bir dosya yükleyin!")
|
53 |
elif input_method == "Kopyala-Yapıştır" and not text_input:
|
54 |
st.error("Lütfen notları metin kutusuna yapıştırın!")
|
55 |
else:
|
56 |
try:
|
57 |
-
# Dosya veya metin kutusundan içerik okuma
|
58 |
if uploaded_file:
|
59 |
content = uploaded_file.read().decode("utf-8")
|
60 |
elif text_input:
|
61 |
content = text_input
|
62 |
|
63 |
-
# Veriyi işleme
|
64 |
result = re.split(r'[ \n]+', content)
|
65 |
notes_result = result[first_step::increase_amount]
|
66 |
-
|
67 |
-
|
68 |
-
notes_result = [re.sub(r'\\[^\n]*', '', x.strip()) for x in notes_result]
|
69 |
-
notes_result = [x for x in notes_result if x != '∅' and x != "NA"]
|
70 |
-
|
71 |
-
# float dönüşümü için veriye strip ve temizleme
|
72 |
-
notes_result = list(map(lambda x: float(x) if x else 0.0, notes_result))
|
73 |
notes_result = np.array(notes_result)
|
74 |
|
75 |
# İstatistikler
|
@@ -79,7 +52,6 @@ if analysis_run:
|
|
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,31 +61,26 @@ if analysis_run:
|
|
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 |
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
# Grafik çizimi
|
99 |
-
bars = plt.bar(unique_values, counts, width=0.3)
|
100 |
-
plt.axvline(x=average_x, color='red', linestyle='--')
|
101 |
-
plt.text(average_x + 1.5, max(counts), 'Ortalama Not', color='red', rotation=0, ha='center', va='bottom')
|
102 |
|
103 |
if my_note in unique_values:
|
104 |
-
|
105 |
|
106 |
for bar in bars:
|
107 |
if bar.get_x() <= my_note < bar.get_x() + bar.get_width():
|
108 |
bar.set_color('green')
|
109 |
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
|
116 |
-
# Grafik bilgileri
|
117 |
info_text = (
|
118 |
f"Katilimci sayısı: {len(notes_result)}\n"
|
119 |
f"En düşük not: {min_x:.2f}\n"
|
@@ -123,7 +90,7 @@ if analysis_run:
|
|
123 |
f"Standart sapma: {std:.2f}\n"
|
124 |
f"Z-skoru: {z_score:.2f}"
|
125 |
)
|
126 |
-
|
127 |
1.05 * max(unique_values), 0.8 * max(counts),
|
128 |
info_text,
|
129 |
fontsize=10,
|
@@ -133,27 +100,11 @@ if analysis_run:
|
|
133 |
bbox=dict(boxstyle="round,pad=0.3", edgecolor="blue", facecolor="lightgrey")
|
134 |
)
|
135 |
|
136 |
-
# Grafik altına not
|
137 |
-
plt.text(
|
138 |
-
0.95 * max(unique_values),
|
139 |
-
-0.1 * max(counts),
|
140 |
-
"Generated with Note Analyzer",
|
141 |
-
fontsize=9,
|
142 |
-
color="gray",
|
143 |
-
ha="right",
|
144 |
-
va="bottom",
|
145 |
-
transform=plt.gca().transAxes
|
146 |
-
)
|
147 |
-
|
148 |
-
plt.subplots_adjust(left=0.055, bottom=0.15, right=0.90, top=0.962, wspace=0.2, hspace=0.2)
|
149 |
-
|
150 |
-
# Grafik gösterimi
|
151 |
-
st.pyplot(plt)
|
152 |
-
|
153 |
# Grafik indirme bağlantısı
|
154 |
buf = BytesIO()
|
155 |
plt.savefig(buf, format="png")
|
156 |
buf.seek(0)
|
|
|
157 |
st.download_button(
|
158 |
label="Grafiği İndir",
|
159 |
data=buf,
|
@@ -163,12 +114,3 @@ if analysis_run:
|
|
163 |
|
164 |
except Exception as e:
|
165 |
st.error(f"Hata: {e}")
|
166 |
-
|
167 |
-
# Web arayüzü altına isim, tarih ve e-posta
|
168 |
-
st.markdown(
|
169 |
-
"""
|
170 |
-
---
|
171 |
-
Developed by **Ali Cemil Özdemir** on **01.12.2024**.
|
172 |
-
For feedback and suggestions, please email: [[email protected]](mailto:[email protected])
|
173 |
-
"""
|
174 |
-
)
|
|
|
|
|
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 |
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)
|
|
|
26 |
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:
|
39 |
content = text_input
|
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 |
|
48 |
# İstatistikler
|
|
|
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 |
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 |
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,
|
|
|
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,
|
|
|
114 |
|
115 |
except Exception as e:
|
116 |
st.error(f"Hata: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|