aliicemill commited on
Commit
f565cfb
·
verified ·
1 Parent(s): b970726

Delete arapca.py

Browse files
Files changed (1) hide show
  1. arapca.py +0 -163
arapca.py DELETED
@@ -1,163 +0,0 @@
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
- # العنوان
8
- st.title("تطبيق محلل الدرجات باستخدام Streamlit")
9
-
10
- # حالة عرض الصور
11
- if "show_images" not in st.session_state:
12
- st.session_state.show_images = True # الافتراضي: يتم عرض الصور
13
-
14
- # منطقة إدخال البيانات في الشريط الجانبي
15
- st.sidebar.header("حقول الإدخال")
16
-
17
- # اختيار رفع ملف أو إدخال النصوص يدويًا
18
- input_method = st.sidebar.radio(
19
- "كيف ستقدم الدرجات؟",
20
- options=["رفع ملف", "نسخ ولصق"]
21
- )
22
-
23
- uploaded_file = None
24
- text_input = None
25
-
26
- if input_method == "رفع ملف":
27
- uploaded_file = st.sidebar.file_uploader("قم برفع ملف الدرجات (TXT)", type=["txt"])
28
- elif input_method == "نسخ ولصق":
29
- text_input = st.sidebar.text_area("قم بلصق الدرجات هنا", height=200)
30
-
31
- # المعلمات الأخرى
32
- lecture_name = st.sidebar.text_input("اسم المادة", value="اسم المادة")
33
- perfect_score = st.sidebar.number_input("الدرجة الكاملة", value=100, step=1)
34
- my_note = st.sidebar.number_input("درجتي", value=0.0, step=0.1)
35
- note_s_axis_diff = st.sidebar.number_input("حجم خطوات المحور السيني للدرجات", value=5, step=1)
36
- amount_s_axis_diff = st.sidebar.number_input("حجم خطوات المحور الصادي للتكرار", value=1, step=1)
37
- first_step = st.sidebar.number_input("الخطوة الأولى", value=0, step=1)
38
- increase_amount = st.sidebar.number_input("مقدار الزيادة", value=1, step=1)
39
-
40
- if st.sidebar.button("تشغيل التحليل"):
41
- # إخفاء الصور عند النقر على الزر
42
- st.session_state.show_images = False
43
-
44
- # عرض الصور فقط إذا كانت show_images صحيحة
45
- if st.session_state.show_images:
46
- st.subheader("كيفية عمل التطبيق")
47
-
48
- # قائمة بأسماء ملفات الصور بالترتيب
49
- image_files = ["arabic/a.png", "arabic/b.png", "arabic/c.png", "arabic/d.png"]
50
-
51
- # عرض الصور واحدة تحت الأخرى
52
- for image_file in image_files:
53
- st.image(image_file, use_container_width=True)
54
-
55
- # تحميل ومعالجة الدرجات (يعمل فقط إذا تم النقر على الزر)
56
- if not st.session_state.show_images:
57
- if input_method == "رفع ملف" and uploaded_file is None:
58
- st.error("يرجى رفع ملف!")
59
- elif input_method == "نسخ ولصق" and not text_input:
60
- st.error("يرجى لصق الدرجات في مربع النص!")
61
- else:
62
- try:
63
- # قراءة المحتوى من الملف أو مربع النص
64
- if uploaded_file:
65
- content = uploaded_file.read().decode("utf-8")
66
- elif text_input:
67
- content = text_input
68
-
69
- # معالجة البيانات
70
- result = re.split(r'[ \n]+', content)
71
-
72
- # تنظيف وتصنيف البيانات
73
- notes_result = [x.strip() for x in result[first_step::increase_amount] if x.strip() != '∅' and x.strip() != "NA"]
74
- notes_result = list(map(lambda x: float(x), notes_result))
75
- notes_result = np.array(notes_result)
76
-
77
- # الإحصائيات
78
- average_x = np.average(notes_result)
79
- min_x = notes_result.min()
80
- max_x = notes_result.max()
81
- std = np.std(notes_result)
82
- z_score = (my_note - average_x) / std
83
-
84
- # عرض الإحصائيات
85
- st.subheader("المعلومات العامة")
86
- st.write(f"عدد المشاركين: {len(notes_result)}")
87
- st.write(f"أقل درجة: {min_x:.2f}")
88
- st.write(f"أعلى درجة: {max_x:.2f}")
89
- st.write(f"متوسط الدرجات: {average_x:.2f}")
90
- st.write(f"الانحراف المعياري: {std:.2f}")
91
- st.write(f"درجة Z: {z_score:.2f}")
92
-
93
- # إنشاء الرسم البياني
94
- st.subheader("رسم توزيع الدرجات")
95
- unique_values, counts = np.unique(notes_result, return_counts=True)
96
- plt.figure(figsize=(10, 6))
97
- bars = plt.bar(unique_values, counts, width=0.3)
98
- plt.axvline(x=average_x, color='red', linestyle='--')
99
- plt.text(average_x + 1.5, max(counts), 'متوسط الدرجات', color='red', rotation=0, ha='center', va='bottom')
100
-
101
- if my_note in unique_values:
102
- plt.text(my_note, counts[unique_values == my_note][0], 'درجتي', color='green', rotation=0, ha='center', va='bottom')
103
-
104
- for bar in bars:
105
- if bar.get_x() <= my_note < bar.get_x() + bar.get_width():
106
- bar.set_color('green')
107
-
108
- plt.title(f'رسم توزيع الدرجات لمادة {lecture_name}')
109
- plt.xlabel('الدرجات')
110
- plt.ylabel('التكرار')
111
- plt.xticks(range(0, int(perfect_score), note_s_axis_diff), rotation=90)
112
- plt.yticks(range(0, max(counts), amount_s_axis_diff), rotation=0)
113
-
114
- # إضافة معلومات إلى الرسم البياني
115
- info_text = (
116
- f"عدد المشاركين: {len(notes_result)}\n"
117
- f"أقل درجة: {min_x:.2f}\n"
118
- f"أعلى درجة: {max_x:.2f}\n"
119
- f"درجتي: {my_note:.2f}\n"
120
- f"متوسط الدرجات: {average_x:.2f}\n"
121
- f"الانحراف المعياري: {std:.2f}\n"
122
- f"درجة Z: {z_score:.2f}"
123
- )
124
- plt.text(
125
- 1.05 * max(unique_values), 0.8 * max(counts),
126
- info_text,
127
- fontsize=10,
128
- color="black",
129
- ha="left",
130
- va="top",
131
- bbox=dict(boxstyle="round,pad=0.3", edgecolor="blue", facecolor="lightgrey")
132
- )
133
- plt.subplots_adjust(left=0.055, bottom=0.065, right=0.90, top=0.962, wspace=0.2, hspace=0.2)
134
-
135
- # عرض الرسم البياني
136
- st.pyplot(plt)
137
-
138
- # زر لتحميل الرسم البياني
139
- buf = BytesIO()
140
- plt.savefig(buf, format="png")
141
- buf.seek(0)
142
- st.download_button(
143
- label="تحميل الرسم البياني",
144
- data=buf,
145
- file_name="score_distribution.png",
146
- mime="image/png"
147
- )
148
-
149
- except Exception as e:
150
- st.error(f"خطأ: {e}")
151
-
152
- # التذييل
153
- st.markdown("---")
154
- st.write("تم التطوير بواسطة: علي جميل أوزدمير")
155
- st.write("التاريخ: 01.12.2024")
156
- st.write("للتعليقات والاقتراحات، يمكنك التواصل عبر: alicemilozdemir7@gmail.com")
157
-
158
- # إضافة ملاحظة أسفل الزاوية اليمنى
159
- st.markdown("""
160
- <p style="position:absolute; bottom:0px; right:0px; font-size: 12px; color: gray;">
161
- تم الإنشاء باستخدام محلل الدرجات
162
- </p>
163
- """, unsafe_allow_html=True)