-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgorithm_1.py
More file actions
232 lines (194 loc) · 8.28 KB
/
algorithm_1.py
File metadata and controls
232 lines (194 loc) · 8.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# -*- coding: utf-8 -*-
"""Algorithm-1.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1_PjXbhTucXp_k9eTvz91IDFR8lcODjpQ
"""
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
from IPython.display import display, HTML
import base64
import io
# Sabit Konteyner Genişliği (Metinlerin taşmasını engeller)
PLOT_WIDTH = 900
# Sabit Konteyner Yüksekliği
BAR_HEIGHT = 380
HEATMAP_HEIGHT = 420
RADAR_HEIGHT = 600
# -----------------------------------------------------------
# 1. KULLANICI GİRİŞİ VE YAPILANDIRMA (AYNI)
# -----------------------------------------------------------
KRITER_VE_SORULAR = {
"YNT": "Yönetim ve Organizasyon Kalitesi",
"ETK": "Etkinlik ve Proje Üretkenliği",
"GOR": "Etki ve Görünürlük",
"SUR": "Sürdürülebilirlik ve Kurumsallaşma",
"UYE": "Üyelik ve Katılım",
"KAT": "Katma Değer ve Yenilikçilik"
}
WEIGHTS = {
"YNT": 20, "ETK": 20, "GOR": 15,
"SUR": 15, "UYE": 15, "KAT": 15
}
KULUPLER_VE_PUANLARI = {
"Robotik Kulübü": {
"YNT": 4.33, "ETK": 4.67, "GOR": 4.50, "SUR": 4.50, "UYE": 5.00, "KAT": 4.50
},
"Tarih Kulübü": {
"YNT": 3.33, "ETK": 2.67, "GOR": 1.50, "SUR": 3.50, "UYE": 3.50, "KAT": 2.50
},
"Müzik Kulübü": {
"YNT": 4.67, "ETK": 4.33, "GOR": 5.00, "SUR": 4.50, "UYE": 4.50, "KAT": 4.00
},
"Edebiyat Kulübü": {
"YNT": 3.00, "ETK": 3.50, "GOR": 3.00, "SUR": 3.00, "UYE": 4.00, "KAT": 3.50
}
}
# -----------------------------------------------------------
# 2. VERİ İŞLEME VE PUAN HESAPLAMA (AYNI)
# -----------------------------------------------------------
tum_kulupler = []
for kulup_adi, puanlar in KULUPLER_VE_PUANLARI.items():
toplam_skor = sum((puan / 5) * WEIGHTS[kriter_kodu] for kriter_kodu, puan in puanlar.items())
if toplam_skor >= 80: kategori = "Davete Hak Kazanır"
elif toplam_skor >= 60: kategori = "Gelişmeye Açık"
else: kategori = "Yeniden Yapılanma"
data = {"Kulüp": kulup_adi, "Toplam Skor": round(toplam_skor, 2), "Kategori": kategori}
for kod, ortalama in puanlar.items():
data[KRITER_VE_SORULAR[kod]] = round(ortalama, 2)
tum_kulupler.append(data)
df = pd.DataFrame(tum_kulupler)
df_sorted = df.sort_values("Toplam Skor", ascending=False)
uzun_kriter_isimleri = list(KRITER_VE_SORULAR.values())
# -----------------------------------------------------------
# 3. GÖRSELLEŞTİRME FONKSİYONLARI (KESİN DÜZELTME)
# -----------------------------------------------------------
# --- 3.1. İnteraktif Tablo (go.Table) ---
def create_interactive_table(df):
all_columns = ['Kulüp', 'Toplam Skor', 'Kategori'] + uzun_kriter_isimleri
fig = go.Figure(data=[go.Table(
header=dict(values=all_columns, fill_color='lightgrey', align='center', font=dict(color='black', size=11)),
cells=dict(values=[df[col] for col in all_columns], fill_color=[['white', 'aliceblue'] * (len(df) // 2 + 1)], align='center', font=dict(color='black', size=10))
)])
fig.update_layout(title_text="1. Genel Skor Tablosu ve Detaylı Kriter Puanları (1-5)", height=450, width=PLOT_WIDTH)
return fig
# --- 3.2. Kıyaslama Grafiği (Bar) ---
def create_comparison_bar(df_sorted):
fig = px.bar(df_sorted,
x="Toplam Skor",
y="Kulüp",
color="Kategori",
orientation='h',
height=BAR_HEIGHT,
color_discrete_map={
"Davete Hak Kazanır": "#2ECC71", "Gelişmeye Açık": "#F1C40F", "Yeniden Yapılanma": "#E74C3C"
})
fig.update_layout(
title_text="2. Kulüpler Arası Toplam Skor Sıralaması",
xaxis_title="Toplam Skor (Maks. 100)",
yaxis_title="",
width=PLOT_WIDTH/2 - 10, # Konteynerin yarısı
margin=dict(l=10, r=10, t=50, b=50),
xaxis=dict(tickangle=0)
)
return fig
# --- 3.3. Isı Haritası (Heatmap) - Kriter Yazıları Düzeltildi ---
def create_heatmap(df):
df_heatmap = df[['Kulüp'] + uzun_kriter_isimleri].set_index('Kulüp')
fig = px.imshow(df_heatmap,
labels=dict(x="Kriterler", y="Kulüpler", color="Ortalama Puan (1-5)"),
x=df_heatmap.columns,
y=df_heatmap.index,
color_continuous_scale="RdYlGn",
range_color=[1, 5]
)
fig.update_xaxes(side="top")
fig.update_layout(
title_text="3. Kriter Bazlı Detaylı Performans (Ortalama Puan)",
height=HEATMAP_HEIGHT,
width=PLOT_WIDTH/2 - 10, # Konteynerin yarısı
# Sol marjin artırılarak Kulüp isimlerinin kesilmesi engellendi
margin=dict(l=150, r=10, t=100, b=10),
xaxis=dict(tickangle=45, tickfont=dict(size=10))
)
return fig
# --- 3.4. Radar Grafiği (Tüm Kulüplerin Kıyaslaması) ---
def create_radar_plot(df):
fig = go.Figure()
for _, row in df.iterrows():
r_values = [row[k] for k in uzun_kriter_isimleri]
fig.add_trace(go.Scatterpolar(
r=r_values, theta=uzun_kriter_isimleri, fill='toself', name=row['Kulüp'], opacity=0.6
))
fig.update_layout(
title_text="4. Kriter Performans Dağılımı (Tüm Kulüplerin Kıyaslaması)",
width=PLOT_WIDTH * 0.85, # Tek başına geniş yer kapla
height=RADAR_HEIGHT,
polar=dict(
radialaxis=dict(visible=True, range=[1, 5]),
angularaxis=dict(
tickfont=dict(size=9),
rotation=90,
direction="clockwise",
period=6
)
),
showlegend=True,
# Kriter ve Legend'ın kesilmemesi için marjini artırıldı.
margin=dict(t=80, b=50, l=100, r=100)
)
return fig
# -----------------------------------------------------------
# 4. RAPORUN OLUŞTURULMASI VE GÖSTERİMİ
# -----------------------------------------------------------
def generate_html_report_and_display(df_sorted):
table_fig = create_interactive_table(df_sorted)
bar_fig = create_comparison_bar(df_sorted)
heatmap_fig = create_heatmap(df_sorted)
radar_fig = create_radar_plot(df_sorted)
html_content = f"""
<!DOCTYPE html>
<html>
<head>
<title>Kulüp Kıyaslama Raporu</title>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<style>body {{ font-family: Arial, sans-serif; }}</style>
</head>
<body>
<h1 style="text-align: center; color: #2980b9;">🎓 Öğrenci Kulüpleri Performans Raporu</h1>
<hr>
<div style="width: {PLOT_WIDTH}px; margin: 0 auto;">
{table_fig.to_html(full_html=False, include_plotlyjs='cdn')}
</div>
<h2 style="margin-top: 30px; text-align: center;">2. Görsel Kıyaslama</h2>
<div style="display: flex; flex-direction: row; flex-wrap: wrap; width: {PLOT_WIDTH}px; margin: 0 auto;">
<div style="width: 50%; min-width: 450px;">
{bar_fig.to_html(full_html=False, include_plotlyjs=False)}
</div>
<div style="width: 50%; min-width: 450px;">
{heatmap_fig.to_html(full_html=False, include_plotlyjs=False)}
</div>
</div>
<h2 style="margin-top: 30px; text-align: center;">3. Kriter Dağılım Analizi</h2>
<div style="width: {PLOT_WIDTH}px; margin: 0 auto; display: flex; justify-content: center;">
{radar_fig.to_html(full_html=False, include_plotlyjs=False)}
</div>
<div style="margin-top: 40px; text-align: center; color: #7f8c8d;">
Rapor Tarihi: {pd.Timestamp('now').strftime('%Y-%m-%d')} | Plotly ile Oluşturulmuştur.
</div>
</body>
</html>
"""
display(HTML(html_content))
html_bytes = html_content.encode('utf-8')
encoded_html = base64.b64encode(html_bytes).decode('utf-8')
display(HTML(f"""
<a href="data:text/html;base64,{encoded_html}" download="Kulup_Kiyaslama_Raporu.html">
<button style="padding: 10px; background-color: #3498db; color: white; border: none; border-radius: 5px; cursor: pointer; margin-top: 20px;">
⬇️ HTML Raporunu İndir (Tamamen Etkileşimli)
</button>
</a>
"""))
# Raporu çalıştır
generate_html_report_and_display(df)