aliicemill commited on
Commit
d373161
·
verified ·
1 Parent(s): fa5a05b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +130 -109
app.py CHANGED
@@ -1,109 +1,130 @@
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
11
- st.sidebar.header("Girdi Alanları")
12
- uploaded_file = st.sidebar.file_uploader("Notlar Dosyasını Yükleyin (TXT)", type=["txt"])
13
- lecture_name = st.sidebar.text_input("Ders Adı", value="Ders Adı")
14
- perfect_score = st.sidebar.number_input("Sınav Puanı Üst Limiti", value=100, step=1)
15
- my_note = st.sidebar.number_input("Benim Notum", value=0.0, step=0.1)
16
- note_s_axis_diff = st.sidebar.number_input("Notlar X Ekseni Ortak Farkı", value=5, step=1)
17
- amount_s_axis_diff = st.sidebar.number_input("Miktar Y Ekseni Ortak Farkı", value=1, step=1)
18
- first_step = st.sidebar.number_input("İlk Adım", value=0, step=1)
19
- increase_amount = st.sidebar.number_input("Artış Miktarı", value=1, step=1)
20
-
21
- if st.sidebar.button("Analizi Çalıştır"):
22
- if uploaded_file is None:
23
- st.error("Lütfen bir dosya yükleyin!")
24
- else:
25
- try:
26
- # Dosya içeriğini okuma
27
- content = uploaded_file.read().decode("utf-8")
28
- result = re.split(r'[ \n]+', content)
29
-
30
- # Veriyi filtreleme ve işleme
31
- notes_result = result[first_step::increase_amount]
32
- notes_result = [x for x in notes_result if x != '∅' and x != "NA"]
33
- notes_result = list(map(lambda x: float(x), notes_result))
34
- notes_result = np.array(notes_result)
35
-
36
- # İstatistikler
37
- average_x = np.average(notes_result)
38
- min_x = notes_result.min()
39
- max_x = notes_result.max()
40
- std = np.std(notes_result)
41
- z_score = (my_note - average_x) / std
42
-
43
- # İstatistikleri ekrana yazdırma
44
- st.subheader("Genel Bilgiler")
45
- st.write(f"Katilimci Sayısı: {len(notes_result)}")
46
- st.write(f"En Düşük Not: {min_x:.2f}")
47
- st.write(f"En Yüksek Not: {max_x:.2f}")
48
- st.write(f"Ortalama Not: {average_x:.2f}")
49
- st.write(f"Standart Sapma: {std:.2f}")
50
- st.write(f"Z-Skoru: {z_score:.2f}")
51
-
52
- # Grafik oluşturma
53
- st.subheader("Not Dağılım Grafiği")
54
- unique_values, counts = np.unique(notes_result, return_counts=True)
55
- plt.figure(figsize=(10, 6))
56
- bars = plt.bar(unique_values, counts, width=0.3)
57
- plt.axvline(x=average_x, color='red', linestyle='--')
58
- plt.text(average_x + 1.5, max(counts), 'Ortalama Not', color='red', rotation=0, ha='center', va='bottom')
59
-
60
- if my_note in unique_values:
61
- plt.text(my_note, counts[unique_values == my_note][0], 'Benim\nNotum', color='green', rotation=0, ha='center', va='bottom')
62
-
63
- for bar in bars:
64
- if bar.get_x() <= my_note < bar.get_x() + bar.get_width():
65
- bar.set_color('green')
66
-
67
- plt.title(f'{lecture_name} Not Sayıları Grafiği')
68
- plt.xlabel('Notlar')
69
- plt.ylabel('Adet')
70
- plt.xticks(range(0, int(perfect_score), note_s_axis_diff), rotation=90)
71
- plt.yticks(range(0, max(counts), amount_s_axis_diff), rotation=0)
72
-
73
- # Grafik bilgileri
74
- info_text = (
75
- f"Katilimci sayısı: {len(notes_result)}\n"
76
- f"En düşük not: {min_x:.2f}\n"
77
- f"En yüksek not: {max_x:.2f}\n"
78
- f"Benim notum: {my_note:.2f}\n"
79
- f"Ortalama not: {average_x:.2f}\n"
80
- f"Standart sapma: {std:.2f}\n"
81
- f"Z-skoru: {z_score:.2f}"
82
- )
83
- plt.text(
84
- 1.05 * max(unique_values), 0.8 * max(counts),
85
- info_text,
86
- fontsize=10,
87
- color="black",
88
- ha="left",
89
- va="top",
90
- bbox=dict(boxstyle="round,pad=0.3", edgecolor="blue", facecolor="lightgrey")
91
- )
92
- plt.subplots_adjust(left=0.055, bottom=0.065, right=0.90, top=0.962, wspace=0.2, hspace=0.2)
93
-
94
- # Grafik gösterimi
95
- st.pyplot(plt)
96
-
97
- # Grafik indirme bağlantısı
98
- buf = BytesIO()
99
- plt.savefig(buf, format="png")
100
- buf.seek(0)
101
- st.download_button(
102
- label="Grafiği İndir",
103
- data=buf,
104
- file_name="not_dagilimi.png",
105
- mime="image/png"
106
- )
107
-
108
- except Exception as e:
109
- 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
+ # Kullanıcıdan veri alma
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
+
22
+ if input_method == "Dosya Yükle":
23
+ uploaded_file = st.sidebar.file_uploader("Notlar Dosyasını Yükleyin (TXT)", type=["txt"])
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)
31
+ note_s_axis_diff = st.sidebar.number_input("Notlar X Ekseni Ortak Farkı", value=5, step=1)
32
+ amount_s_axis_diff = st.sidebar.number_input("Miktar Y Ekseni Ortak Farkı", value=1, step=1)
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
+ if st.sidebar.button("Analizi Çalıştır"):
37
+ # Notları yükleme ve işleme
38
+ if input_method == "Dosya Yükle" and uploaded_file is None:
39
+ st.error("Lütfen bir dosya yükleyin!")
40
+ elif input_method == "Kopyala-Yapıştır" and not text_input:
41
+ st.error("Lütfen notları metin kutusuna yapıştırın!")
42
+ else:
43
+ try:
44
+ # Dosya veya metin kutusundan içerik okuma
45
+ if uploaded_file:
46
+ content = uploaded_file.read().decode("utf-8")
47
+ elif text_input:
48
+ content = text_input
49
+
50
+ # Veriyi işleme
51
+ result = re.split(r'[ \n]+', content)
52
+ notes_result = result[first_step::increase_amount]
53
+ notes_result = [x for x in notes_result if x != '∅' and x != "NA"]
54
+ notes_result = list(map(lambda x: float(x), notes_result))
55
+ notes_result = np.array(notes_result)
56
+
57
+ # İstatistikler
58
+ average_x = np.average(notes_result)
59
+ min_x = notes_result.min()
60
+ max_x = notes_result.max()
61
+ std = np.std(notes_result)
62
+ z_score = (my_note - average_x) / std
63
+
64
+ # İstatistikleri ekrana yazdırma
65
+ st.subheader("Genel Bilgiler")
66
+ st.write(f"Katilimci Sayısı: {len(notes_result)}")
67
+ st.write(f"En Düşük Not: {min_x:.2f}")
68
+ st.write(f"En Yüksek Not: {max_x:.2f}")
69
+ st.write(f"Ortalama Not: {average_x:.2f}")
70
+ st.write(f"Standart Sapma: {std:.2f}")
71
+ st.write(f"Z-Skoru: {z_score:.2f}")
72
+
73
+ # Grafik oluşturma
74
+ st.subheader("Not Dağılım Grafiği")
75
+ unique_values, counts = np.unique(notes_result, return_counts=True)
76
+ plt.figure(figsize=(10, 6))
77
+ bars = plt.bar(unique_values, counts, width=0.3)
78
+ plt.axvline(x=average_x, color='red', linestyle='--')
79
+ plt.text(average_x + 1.5, max(counts), 'Ortalama Not', color='red', rotation=0, ha='center', va='bottom')
80
+
81
+ if my_note in unique_values:
82
+ plt.text(my_note, counts[unique_values == my_note][0], 'Benim\nNotum', color='green', rotation=0, ha='center', va='bottom')
83
+
84
+ for bar in bars:
85
+ if bar.get_x() <= my_note < bar.get_x() + bar.get_width():
86
+ bar.set_color('green')
87
+
88
+ plt.title(f'{lecture_name} Not Sayıları Grafiği')
89
+ plt.xlabel('Notlar')
90
+ plt.ylabel('Adet')
91
+ plt.xticks(range(0, int(perfect_score), note_s_axis_diff), rotation=90)
92
+ plt.yticks(range(0, max(counts), amount_s_axis_diff), rotation=0)
93
+
94
+ # Grafik bilgileri
95
+ info_text = (
96
+ f"Katilimci sayısı: {len(notes_result)}\n"
97
+ f"En düşük not: {min_x:.2f}\n"
98
+ f"En yüksek not: {max_x:.2f}\n"
99
+ f"Benim notum: {my_note:.2f}\n"
100
+ f"Ortalama not: {average_x:.2f}\n"
101
+ f"Standart sapma: {std:.2f}\n"
102
+ f"Z-skoru: {z_score:.2f}"
103
+ )
104
+ plt.text(
105
+ 1.05 * max(unique_values), 0.8 * max(counts),
106
+ info_text,
107
+ fontsize=10,
108
+ color="black",
109
+ ha="left",
110
+ va="top",
111
+ bbox=dict(boxstyle="round,pad=0.3", edgecolor="blue", facecolor="lightgrey")
112
+ )
113
+ plt.subplots_adjust(left=0.055, bottom=0.065, right=0.90, top=0.962, wspace=0.2, hspace=0.2)
114
+
115
+ # Grafik gösterimi
116
+ st.pyplot(plt)
117
+
118
+ # Grafik indirme bağlantısı
119
+ buf = BytesIO()
120
+ plt.savefig(buf, format="png")
121
+ buf.seek(0)
122
+ st.download_button(
123
+ label="Grafiği İndir",
124
+ data=buf,
125
+ file_name="not_dagilimi.png",
126
+ mime="image/png"
127
+ )
128
+
129
+ except Exception as e:
130
+ st.error(f"Hata: {e}")