Spaces:
Sleeping
Sleeping
import streamlit as st | |
import re | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from io import BytesIO | |
# Başlık | |
st.title("Note Analyzer Streamlit Uygulaması") | |
# Kullanıcıdan veri alma | |
st.sidebar.header("Girdi Alanları") | |
uploaded_file = st.sidebar.file_uploader("Notlar Dosyasını Yükleyin (TXT)", type=["txt"]) | |
lecture_name = st.sidebar.text_input("Ders Adı", value="Ders Adı") | |
perfect_score = st.sidebar.number_input("Sınav Puanı Üst Limiti", value=100, step=1) | |
my_note = st.sidebar.number_input("Benim Notum", value=0.0, step=0.1) | |
note_s_axis_diff = st.sidebar.number_input("Notlar X Ekseni Ortak Farkı", value=5, step=1) | |
amount_s_axis_diff = st.sidebar.number_input("Miktar Y Ekseni Ortak Farkı", value=1, step=1) | |
first_step = st.sidebar.number_input("İlk Adım", value=0, step=1) | |
increase_amount = st.sidebar.number_input("Artış Miktarı", value=1, step=1) | |
if st.sidebar.button("Analizi Çalıştır"): | |
if uploaded_file is None: | |
st.error("Lütfen bir dosya yükleyin!") | |
else: | |
try: | |
# Dosya içeriğini okuma | |
content = uploaded_file.read().decode("utf-8") | |
result = re.split(r'[ \n]+', content) | |
# Veriyi filtreleme ve işleme | |
notes_result = result[first_step::increase_amount] | |
notes_result = [x for x in notes_result if x != '∅' and x != "NA"] | |
notes_result = list(map(lambda x: float(x), notes_result)) | |
notes_result = np.array(notes_result) | |
# İstatistikler | |
average_x = np.average(notes_result) | |
min_x = notes_result.min() | |
max_x = notes_result.max() | |
std = np.std(notes_result) | |
z_score = (my_note - average_x) / std | |
# İstatistikleri ekrana yazdırma | |
st.subheader("Genel Bilgiler") | |
st.write(f"Katilimci Sayısı: {len(notes_result)}") | |
st.write(f"En Düşük Not: {min_x:.2f}") | |
st.write(f"En Yüksek Not: {max_x:.2f}") | |
st.write(f"Ortalama Not: {average_x:.2f}") | |
st.write(f"Standart Sapma: {std:.2f}") | |
st.write(f"Z-Skoru: {z_score:.2f}") | |
# Grafik oluşturma | |
st.subheader("Not Dağılım Grafiği") | |
unique_values, counts = np.unique(notes_result, return_counts=True) | |
plt.figure(figsize=(10, 6)) | |
bars = plt.bar(unique_values, counts, width=0.3) | |
plt.axvline(x=average_x, color='red', linestyle='--') | |
plt.text(average_x + 1.5, max(counts), 'Ortalama Not', color='red', rotation=0, ha='center', va='bottom') | |
if my_note in unique_values: | |
plt.text(my_note, counts[unique_values == my_note][0], 'Benim\nNotum', color='green', rotation=0, ha='center', va='bottom') | |
for bar in bars: | |
if bar.get_x() <= my_note < bar.get_x() + bar.get_width(): | |
bar.set_color('green') | |
plt.title(f'{lecture_name} Not Sayıları Grafiği') | |
plt.xlabel('Notlar') | |
plt.ylabel('Adet') | |
plt.xticks(range(0, int(perfect_score), note_s_axis_diff), rotation=90) | |
plt.yticks(range(0, max(counts), amount_s_axis_diff), rotation=0) | |
# Grafik bilgileri | |
info_text = ( | |
f"Katilimci sayısı: {len(notes_result)}\n" | |
f"En düşük not: {min_x:.2f}\n" | |
f"En yüksek not: {max_x:.2f}\n" | |
f"Benim notum: {my_note:.2f}\n" | |
f"Ortalama not: {average_x:.2f}\n" | |
f"Standart sapma: {std:.2f}\n" | |
f"Z-skoru: {z_score:.2f}" | |
) | |
plt.text( | |
1.05 * max(unique_values), 0.8 * max(counts), | |
info_text, | |
fontsize=10, | |
color="black", | |
ha="left", | |
va="top", | |
bbox=dict(boxstyle="round,pad=0.3", edgecolor="blue", facecolor="lightgrey") | |
) | |
plt.subplots_adjust(left=0.055, bottom=0.065, right=0.90, top=0.962, wspace=0.2, hspace=0.2) | |
# Grafik gösterimi | |
st.pyplot(plt) | |
# Grafik indirme bağlantısı | |
buf = BytesIO() | |
plt.savefig(buf, format="png") | |
buf.seek(0) | |
st.download_button( | |
label="Grafiği İndir", | |
data=buf, | |
file_name="not_dagilimi.png", | |
mime="image/png" | |
) | |
except Exception as e: | |
st.error(f"Hata: {e}") |