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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
import os
|
| 5 |
+
import folium
|
| 6 |
+
|
| 7 |
+
# Veri setlerini yükleme
|
| 8 |
+
df_norm = pd.read_excel('norm_fazlasi.xlsx')
|
| 9 |
+
df_ihtiyac = pd.read_excel('ihtiyac_data.xlsx')
|
| 10 |
+
|
| 11 |
+
# İlçe koordinatları
|
| 12 |
+
ilce_kordinatlar = [
|
| 13 |
+
{"ilçe": 'SERİK', "enlem": 36.921822, "boylam": 31.101271},
|
| 14 |
+
{"ilçe": 'MURATPAŞA', "enlem": 36.882271, "boylam": 30.76759},
|
| 15 |
+
{"ilçe": 'MANAVGAT', "enlem": 36.783333, "boylam": 31.433332},
|
| 16 |
+
{"ilçe": 'KUMLUCA', "enlem": 36.609336, "boylam": 30.548309},
|
| 17 |
+
{"ilçe": 'KONYAALTI', "enlem": 36.87889, "boylam": 30.61007},
|
| 18 |
+
{"ilçe": 'KORKUTELİ', "enlem": 37.152289, "boylam": 30.236633},
|
| 19 |
+
{"ilçe": 'KEPEZ', "enlem": 36.912132, "boylam": 30.686714},
|
| 20 |
+
{"ilçe": 'KEMER', "enlem": 36.602792, "boylam": 30.559762},
|
| 21 |
+
{"ilçe": 'KAŞ', "enlem": 36.204441, "boylam": 29.638981},
|
| 22 |
+
{"ilçe": 'FİNİKE', "enlem": 36.311292, "boylam": 30.158957},
|
| 23 |
+
{"ilçe": 'GAZİPAŞA', "enlem": 36.297874, "boylam": 32.278589},
|
| 24 |
+
{"ilçe": 'GÜNDOĞMUŞ', "enlem": 36.814942, "boylam": 31.998952},
|
| 25 |
+
{"ilçe": 'İBRADI', "enlem": 37.096943, "boylam": 31.598356},
|
| 26 |
+
{"ilçe": 'DEMRE', "enlem": 36.244437, "boylam": 29.987471},
|
| 27 |
+
{"ilçe": 'DÖŞEMEALTI', "enlem": 37.023026, "boylam": 30.60121},
|
| 28 |
+
{"ilçe": 'ELMALI', "enlem": 36.737836, "boylam": 29.916657},
|
| 29 |
+
{"ilçe": 'ALANYA', "enlem": 36.610888, "boylam": 31.778913},
|
| 30 |
+
{"ilçe": 'AKSEKİ', "enlem": 37.04705, "boylam": 31.7903},
|
| 31 |
+
{"ilçe": 'AKSU', "enlem": 36.946678, "boylam": 30.839846}
|
| 32 |
+
]
|
| 33 |
+
ilce_df = pd.DataFrame(ilce_kordinatlar)
|
| 34 |
+
|
| 35 |
+
# İlçe koordinatlarını veri setlerine ekleme
|
| 36 |
+
df_ihtiyac = df_ihtiyac.merge(ilce_df, how='left', on='ilçe')
|
| 37 |
+
df_norm = df_norm.merge(ilce_df.rename(columns={'ilçe': 'İlçe Adı'}), how='left', left_on='İlçe Adı', right_on='İlçe Adı')
|
| 38 |
+
|
| 39 |
+
# Harita oluşturma fonksiyonu
|
| 40 |
+
def create_map(selected_ilce, selected_branş):
|
| 41 |
+
# Filtreleme
|
| 42 |
+
filtered_ihtiyac = df_ihtiyac[(df_ihtiyac['ilçe'] == selected_ilce) & (df_ihtiyac['branş'] == selected_branş)]
|
| 43 |
+
filtered_norm = df_norm[(df_norm['İlçe Adı'] == selected_ilce) & (df_norm['Branşı'] == selected_branş)]
|
| 44 |
+
|
| 45 |
+
# İhtiyaç ve norm fazlası değerlerini hesaplama
|
| 46 |
+
toplam_ihtiyac = filtered_ihtiyac['ihtiyac'].sum() if not filtered_ihtiyac.empty else 0
|
| 47 |
+
mazaretli_norm_fazlası = filtered_norm[filtered_norm['Açıklamalar'].notna()].shape[0]
|
| 48 |
+
mazaretsiz_norm_fazlası = filtered_norm[filtered_norm['Açıklamalar'].isna()].shape[0]
|
| 49 |
+
|
| 50 |
+
# İlçe koordinatlarını alın
|
| 51 |
+
row = ilce_df[ilce_df['ilçe'] == selected_ilce]
|
| 52 |
+
if row.empty:
|
| 53 |
+
return "<p>Seçilen ilçeye ait koordinat bulunamadı.</p>"
|
| 54 |
+
|
| 55 |
+
enlem, boylam = row.iloc[0]['enlem'], row.iloc[0]['boylam']
|
| 56 |
+
|
| 57 |
+
# Harita oluşturma
|
| 58 |
+
map_center = [enlem, boylam]
|
| 59 |
+
my_map = folium.Map(location=map_center, zoom_start=12)
|
| 60 |
+
|
| 61 |
+
# Harita üzerine bilgi ekleme
|
| 62 |
+
folium.Marker(
|
| 63 |
+
location=map_center,
|
| 64 |
+
popup=(f"<b>İlçe:</b> {selected_ilce}<br>"
|
| 65 |
+
f"<b>Branş:</b> {selected_branş}<br>"
|
| 66 |
+
f"<b>Toplam İhtiyaç:</b> {toplam_ihtiyac}<br>"
|
| 67 |
+
f"<b>Mazaretli Norm Fazlası:</b> {mazaretli_norm_fazlası}<br>"
|
| 68 |
+
f"<b>Mazaretsiz Norm Fazlası:</b> {mazaretsiz_norm_fazlası}"),
|
| 69 |
+
tooltip=f"{selected_ilce} - {selected_branş}"
|
| 70 |
+
).add_to(my_map)
|
| 71 |
+
|
| 72 |
+
# Haritayı HTML formatında döndür
|
| 73 |
+
return my_map._repr_html_()
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
# Filter the DataFrame based on user input
|
| 77 |
+
def filter_dataframe(ilce_values, brans_values, aciklama_values, include_empty_aciklama):
|
| 78 |
+
df = df_norm.copy()
|
| 79 |
+
|
| 80 |
+
# Apply filters if values are provided
|
| 81 |
+
if ilce_values and "Tüm İlçeler" not in ilce_values:
|
| 82 |
+
df = df[df['İlçe Adı'].isin(ilce_values)]
|
| 83 |
+
if brans_values:
|
| 84 |
+
df = df[df['Branşı'].isin(brans_values)]
|
| 85 |
+
if aciklama_values:
|
| 86 |
+
df = df[df['Açıklamalar'].isin(aciklama_values)]
|
| 87 |
+
if include_empty_aciklama:
|
| 88 |
+
df = pd.concat([df, df[df['Açıklamalar'].isna()]]).drop_duplicates()
|
| 89 |
+
|
| 90 |
+
return df, f"Kayıt Sayısı: {len(df)}"
|
| 91 |
+
|
| 92 |
+
# Calculate needs and norm excess per district
|
| 93 |
+
def calculate_needs_and_norm(ilce_values, brans_values):
|
| 94 |
+
# İlçe ve branş filtreleme işlemi
|
| 95 |
+
df_ihtiyac_filtered = df_ihtiyac.copy()
|
| 96 |
+
df_norm_filtered = df_norm.copy()
|
| 97 |
+
|
| 98 |
+
if ilce_values and "Tüm İlçeler" not in ilce_values:
|
| 99 |
+
df_ihtiyac_filtered = df_ihtiyac_filtered[df_ihtiyac_filtered['ilçe'].isin(ilce_values)]
|
| 100 |
+
if brans_values:
|
| 101 |
+
df_ihtiyac_filtered = df_ihtiyac_filtered[df_ihtiyac_filtered['branş'].isin(brans_values)]
|
| 102 |
+
|
| 103 |
+
# Özet bilgi için toplam ihtiyaç sayısını direkt olarak hesaplama
|
| 104 |
+
total_needs_sum = df_ihtiyac_filtered['ihtiyac'].sum()
|
| 105 |
+
|
| 106 |
+
# Sonuçları toplamak için liste
|
| 107 |
+
results = []
|
| 108 |
+
unique_ilce_values = ilce_values if ilce_values and "Tüm İlçeler" not in ilce_values else df_norm['İlçe Adı'].unique().tolist()
|
| 109 |
+
unique_brans_values = brans_values if brans_values else df_norm['Branşı'].unique().tolist()
|
| 110 |
+
|
| 111 |
+
for ilce in unique_ilce_values:
|
| 112 |
+
df_norm_ilce = df_norm_filtered[df_norm_filtered['İlçe Adı'] == ilce]
|
| 113 |
+
|
| 114 |
+
for brans in unique_brans_values:
|
| 115 |
+
# Her ilçe ve branş için ilgili ihtiyaç miktarını hesapla
|
| 116 |
+
total_needs = df_ihtiyac_filtered[(df_ihtiyac_filtered['ilçe'] == ilce) & (df_ihtiyac_filtered['branş'] == brans)]['ihtiyac'].sum()
|
| 117 |
+
mazaretli_count = df_norm_ilce[(df_norm_ilce['Branşı'] == brans) & (df_norm_ilce['Açıklamalar'].notna())].shape[0]
|
| 118 |
+
mazaretsiz_count = df_norm_ilce[(df_norm_ilce['Branşı'] == brans) & (df_norm_ilce['Açıklamalar'].isna())].shape[0]
|
| 119 |
+
|
| 120 |
+
results.append({
|
| 121 |
+
'İlçe': ilce,
|
| 122 |
+
'Branş': brans,
|
| 123 |
+
'Toplam İhtiyaç': total_needs, # Her ilçe ve branşa özgü toplam ihtiyaç
|
| 124 |
+
'Norm Fazlası (Mazaretli)': mazaretli_count,
|
| 125 |
+
'Norm Fazlası (Mazaretsiz)': mazaretsiz_count
|
| 126 |
+
})
|
| 127 |
+
|
| 128 |
+
result_df = pd.DataFrame(results)
|
| 129 |
+
total_mazaretli_sum = result_df['Norm Fazlası (Mazaretli)'].sum()
|
| 130 |
+
total_mazaretsiz_sum = result_df['Norm Fazlası (Mazaretsiz)'].sum()
|
| 131 |
+
|
| 132 |
+
summary_text = (f"Toplam İhtiyaç: {total_needs_sum} | "
|
| 133 |
+
f"Toplam Norm Fazlası (Mazaretli): {total_mazaretli_sum} | "
|
| 134 |
+
f"Toplam Norm Fazlası (Mazaretsiz): {total_mazaretsiz_sum}")
|
| 135 |
+
|
| 136 |
+
return result_df, summary_text
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
# Function to plot the results as a bar chart
|
| 140 |
+
def plot_results(df):
|
| 141 |
+
plt.figure(figsize=(14, 8)) # Grafik boyutunu artırıyoruz
|
| 142 |
+
df.groupby('İlçe')[['Toplam İhtiyaç', 'Norm Fazlası (Mazaretli)', 'Norm Fazlası (Mazaretsiz)']].sum().plot(kind='bar')
|
| 143 |
+
plt.title("İhtiyaç ve Norm Fazlası Dağılımı")
|
| 144 |
+
plt.xlabel("İlçe")
|
| 145 |
+
plt.ylabel("Sayı")
|
| 146 |
+
plt.xticks(rotation=45, ha="right") # Etiketleri biraz sağa yatırıyoruz
|
| 147 |
+
plt.tight_layout()
|
| 148 |
+
chart_path = 'bar_chart.png'
|
| 149 |
+
plt.savefig(chart_path)
|
| 150 |
+
return chart_path # Dosya yolunu döndür
|
| 151 |
+
|
| 152 |
+
# Function to filter "ihtiyac" data based on selected ilce and brans
|
| 153 |
+
def filter_ihtiyac_data(ilce_values, brans_values, include_empty_aciklama=False):
|
| 154 |
+
df_filtered = df_ihtiyac.copy()
|
| 155 |
+
|
| 156 |
+
if ilce_values and "Tüm İlçeler" not in ilce_values:
|
| 157 |
+
df_filtered = df_filtered[df_filtered['ilçe'].isin(ilce_values)]
|
| 158 |
+
if brans_values:
|
| 159 |
+
df_filtered = df_filtered[df_filtered['branş'].isin(brans_values)]
|
| 160 |
+
|
| 161 |
+
if include_empty_aciklama:
|
| 162 |
+
df_filtered = pd.concat([df_filtered, df_filtered[df_filtered['Açıklamalar'].isna()]]).drop_duplicates()
|
| 163 |
+
|
| 164 |
+
total_needs_sum = df_filtered['ihtiyac'].sum()
|
| 165 |
+
return df_filtered, f"Toplam İhtiyaç: {total_needs_sum}"
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
# Define Gradio interface components
|
| 172 |
+
with gr.Blocks() as demo:
|
| 173 |
+
with gr.Tab("Antalya Norm Fazlası Öğretmenler"):
|
| 174 |
+
ilce_choices = sorted(df_norm['İlçe Adı'].dropna().astype(str).unique().tolist())
|
| 175 |
+
ilce_multiselect = gr.Dropdown(choices=["Tüm İlçeler"] + ilce_choices, label="Select İlçe Adı", multiselect=True)
|
| 176 |
+
brans_multiselect = gr.Dropdown(choices=sorted(df_norm['Branşı'].dropna().unique().tolist()), label="Select Branşı", multiselect=True)
|
| 177 |
+
aciklama_choices = sorted(df_norm['Açıklamalar'].dropna().unique().tolist())
|
| 178 |
+
aciklama_multiselect = gr.Dropdown(choices=aciklama_choices, label="Mazaretliler", multiselect=True)
|
| 179 |
+
include_empty_aciklama = gr.Checkbox(label="Mazaretsizleri de ekle")
|
| 180 |
+
|
| 181 |
+
filter_button = gr.Button("Listele")
|
| 182 |
+
|
| 183 |
+
record_count = gr.Textbox(label="Kişi Sayısı", interactive=False)
|
| 184 |
+
output = gr.DataFrame()
|
| 185 |
+
filter_button.click(fn=filter_dataframe, inputs=[ilce_multiselect, brans_multiselect, aciklama_multiselect, include_empty_aciklama], outputs=[output, record_count])
|
| 186 |
+
|
| 187 |
+
with gr.Tab("İhtiyaç ve Norm Fazlası Analizi"):
|
| 188 |
+
ilce_choices_ihtiyac = sorted(df_ihtiyac['ilçe'].dropna().astype(str).unique().tolist())
|
| 189 |
+
ilce_multiselect_ihtiyac = gr.Dropdown(choices=["Tüm İlçeler"] + ilce_choices_ihtiyac, label="Select İlçe Adı", multiselect=True)
|
| 190 |
+
brans_multiselect_ihtiyac = gr.Dropdown(choices=sorted(df_ihtiyac['branş'].dropna().unique().tolist()), label="Select Branşı", multiselect=True)
|
| 191 |
+
|
| 192 |
+
analyze_button = gr.Button("Analiz Et")
|
| 193 |
+
analysis_chart = gr.Image()
|
| 194 |
+
analysis_record_count = gr.Textbox(label="Özet Bilgi", interactive=False)
|
| 195 |
+
analysis_output = gr.DataFrame()
|
| 196 |
+
|
| 197 |
+
def analyze_and_plot(ilce_values, brans_values):
|
| 198 |
+
result_df, summary_text = calculate_needs_and_norm(ilce_values, brans_values)
|
| 199 |
+
chart_path = plot_results(result_df)
|
| 200 |
+
return result_df, summary_text, chart_path
|
| 201 |
+
|
| 202 |
+
analyze_button.click(fn=analyze_and_plot, inputs=[ilce_multiselect_ihtiyac, brans_multiselect_ihtiyac], outputs=[analysis_output, analysis_record_count, analysis_chart])
|
| 203 |
+
|
| 204 |
+
with gr.Tab("İhtiyaç Verisi Filtreleme"):
|
| 205 |
+
ilce_multiselect_ihtiyac_filter = gr.Dropdown(choices=["Tüm İlçeler"] + ilce_choices_ihtiyac, label="İlçe Adı", multiselect=True)
|
| 206 |
+
brans_multiselect_ihtiyac_filter = gr.Dropdown(choices=sorted(df_ihtiyac['branş'].dropna().unique().tolist()), label="Branş", multiselect=True)
|
| 207 |
+
|
| 208 |
+
filter_ihtiyac_button = gr.Button("Filtrele")
|
| 209 |
+
|
| 210 |
+
ihtiyac_total_count = gr.Textbox(label="Toplam İhtiyaç", interactive=False)
|
| 211 |
+
ihtiyac_output = gr.DataFrame()
|
| 212 |
+
|
| 213 |
+
filter_ihtiyac_button.click(fn=filter_ihtiyac_data, inputs=[ilce_multiselect_ihtiyac_filter, brans_multiselect_ihtiyac_filter], outputs=[ihtiyac_output, ihtiyac_total_count])
|
| 214 |
+
|
| 215 |
+
# 4. Tab: Branşları Karşılaştırma
|
| 216 |
+
# 4. Tab: Branşları Karşılaştırma
|
| 217 |
+
with gr.Tab("Branşları Karşılaştırma"):
|
| 218 |
+
# İhtiyaç ve norm fazlası veri çerçevelerinde bulunan tüm benzersiz branşları alıyoruz
|
| 219 |
+
all_branches = sorted(set(df_ihtiyac['branş'].dropna().unique()).union(df_norm['Branşı'].dropna().unique()))
|
| 220 |
+
brans_multiselect_compare = gr.Dropdown(choices=all_branches, label="Karşılaştırılacak Branşları Seçin", multiselect=True)
|
| 221 |
+
|
| 222 |
+
compare_button = gr.Button("Karşılaştır")
|
| 223 |
+
compare_output = gr.DataFrame()
|
| 224 |
+
compare_chart = gr.Image()
|
| 225 |
+
|
| 226 |
+
def compare_branches(brans_values):
|
| 227 |
+
# Seçim yapılmadıysa tüm branşları al
|
| 228 |
+
selected_branches = brans_values if brans_values else all_branches
|
| 229 |
+
|
| 230 |
+
# Sonuçları toplamak için liste
|
| 231 |
+
results = []
|
| 232 |
+
for brans in selected_branches:
|
| 233 |
+
# İlgili branş için toplam ihtiyaç ve norm fazlası değerlerini al
|
| 234 |
+
total_needs = df_ihtiyac[df_ihtiyac['branş'] == brans]['ihtiyac'].sum() if brans in df_ihtiyac['branş'].values else 0
|
| 235 |
+
mazaretli_count = df_norm[(df_norm['Branşı'] == brans) & (df_norm['Açıklamalar'].notna())].shape[0] if brans in df_norm['Branşı'].values else 0
|
| 236 |
+
mazaretsiz_count = df_norm[(df_norm['Branşı'] == brans) & (df_norm['Açıklamalar'].isna())].shape[0] if brans in df_norm['Branşı'].values else 0
|
| 237 |
+
|
| 238 |
+
# Oran hesaplaması, sıfıra bölme hatasından kaçınmak için kontrol
|
| 239 |
+
if total_needs > 0:
|
| 240 |
+
ratio = (mazaretli_count + mazaretsiz_count) / total_needs
|
| 241 |
+
else:
|
| 242 |
+
ratio = float('nan') # Toplam ihtiyaç 0 ise oranı NaN olarak ayarla
|
| 243 |
+
|
| 244 |
+
results.append({
|
| 245 |
+
'Branş': brans,
|
| 246 |
+
'Toplam İhtiyaç': total_needs,
|
| 247 |
+
'Norm Fazlası (Mazaretli)': mazaretli_count,
|
| 248 |
+
'Norm Fazlası (Mazaretsiz)': mazaretsiz_count,
|
| 249 |
+
'Oran': ratio
|
| 250 |
+
})
|
| 251 |
+
|
| 252 |
+
# Sonuçları DataFrame olarak döndür
|
| 253 |
+
compare_df = pd.DataFrame(results)
|
| 254 |
+
|
| 255 |
+
# Branş sayısı 10'dan fazlaysa grafik çizdirme
|
| 256 |
+
if len(selected_branches) <= 10:
|
| 257 |
+
# Çubuk grafik oluşturma
|
| 258 |
+
fig, ax1 = plt.subplots(figsize=(10, 6))
|
| 259 |
+
|
| 260 |
+
# İhtiyaç ve norm fazlası verilerini çubuk grafik olarak çiz
|
| 261 |
+
compare_df.set_index('Branş')[['Toplam İhtiyaç', 'Norm Fazlası (Mazaretli)', 'Norm Fazlası (Mazaretsiz)']].plot(kind='bar', ax=ax1)
|
| 262 |
+
ax1.set_ylabel("Sayı")
|
| 263 |
+
ax1.set_xlabel("Branş")
|
| 264 |
+
ax1.set_title("Branş Bazında İhtiyaç, Norm Fazlası ve Oran Karşılaştırması")
|
| 265 |
+
plt.xticks(rotation=45, ha="right")
|
| 266 |
+
|
| 267 |
+
# Oran verilerini ikincil bir eksen olarak çiz
|
| 268 |
+
ax2 = ax1.twinx()
|
| 269 |
+
ax2.plot(compare_df['Branş'], compare_df['Oran'], color='red', marker='o', linestyle='-', linewidth=2)
|
| 270 |
+
ax2.set_ylabel("Oran", color='red')
|
| 271 |
+
ax2.tick_params(axis='y', labelcolor='red')
|
| 272 |
+
|
| 273 |
+
plt.tight_layout()
|
| 274 |
+
chart_path = 'branch_comparison_chart.png'
|
| 275 |
+
plt.savefig(chart_path)
|
| 276 |
+
plt.close()
|
| 277 |
+
else:
|
| 278 |
+
chart_path = None # Grafik gösterilmeyecek
|
| 279 |
+
|
| 280 |
+
return compare_df, chart_path
|
| 281 |
+
|
| 282 |
+
compare_button.click(fn=compare_branches, inputs=[brans_multiselect_compare], outputs=[compare_output, compare_chart])
|
| 283 |
+
# 5. Tab: İlçeleri Karşılaştırma
|
| 284 |
+
with gr.Tab("İlçeleri Karşılaştırma"):
|
| 285 |
+
# İhtiyaç ve norm fazlası veri çerçevelerinde bulunan tüm benzersiz ilçeleri alıyoruz
|
| 286 |
+
all_districts = sorted(set(df_ihtiyac['ilçe'].dropna().unique()).union(df_norm['İlçe Adı'].dropna().unique()))
|
| 287 |
+
ilce_multiselect_compare = gr.Dropdown(choices=all_districts, label="Karşılaştırılacak İlçeleri Seçin", multiselect=True)
|
| 288 |
+
|
| 289 |
+
compare_button_ilce = gr.Button("Karşılaştır")
|
| 290 |
+
compare_output_ilce = gr.DataFrame()
|
| 291 |
+
compare_chart_ilce = gr.Image()
|
| 292 |
+
|
| 293 |
+
def compare_districts(ilce_values):
|
| 294 |
+
# Seçim yapılmadıysa tüm ilçeleri al
|
| 295 |
+
selected_districts = ilce_values if ilce_values else all_districts
|
| 296 |
+
|
| 297 |
+
# Sonuçları toplamak için liste
|
| 298 |
+
results = []
|
| 299 |
+
for ilce in selected_districts:
|
| 300 |
+
# İlgili ilçe için toplam ihtiyaç ve norm fazlası değerlerini al
|
| 301 |
+
total_needs = df_ihtiyac[df_ihtiyac['ilçe'] == ilce]['ihtiyac'].sum() if ilce in df_ihtiyac['ilçe'].values else 0
|
| 302 |
+
mazaretli_count = df_norm[(df_norm['İlçe Adı'] == ilce) & (df_norm['Açıklamalar'].notna())].shape[0] if ilce in df_norm['İlçe Adı'].values else 0
|
| 303 |
+
mazaretsiz_count = df_norm[(df_norm['İlçe Adı'] == ilce) & (df_norm['Açıklamalar'].isna())].shape[0] if ilce in df_norm['İlçe Adı'].values else 0
|
| 304 |
+
|
| 305 |
+
# Oran hesaplaması, sıfıra bölme hatasından kaçınmak için kontrol
|
| 306 |
+
if total_needs > 0:
|
| 307 |
+
ratio = (mazaretli_count + mazaretsiz_count) / total_needs
|
| 308 |
+
else:
|
| 309 |
+
ratio = float('nan') # Toplam ihtiyaç 0 ise oranı NaN olarak ayarla
|
| 310 |
+
|
| 311 |
+
results.append({
|
| 312 |
+
'İlçe': ilce,
|
| 313 |
+
'Toplam İhtiyaç': total_needs,
|
| 314 |
+
'Norm Fazlası (Mazaretli)': mazaretli_count,
|
| 315 |
+
'Norm Fazlası (Mazaretsiz)': mazaretsiz_count,
|
| 316 |
+
'Oran': ratio
|
| 317 |
+
})
|
| 318 |
+
|
| 319 |
+
# Sonuçları DataFrame olarak döndür
|
| 320 |
+
compare_df_ilce = pd.DataFrame(results)
|
| 321 |
+
|
| 322 |
+
# İlçe sayısı 10'dan fazlaysa grafik çizdirme
|
| 323 |
+
if len(selected_districts) <= 10:
|
| 324 |
+
# Çubuk grafik oluşturma
|
| 325 |
+
fig, ax1 = plt.subplots(figsize=(10, 6))
|
| 326 |
+
|
| 327 |
+
# İhtiyaç ve norm fazlası verilerini çubuk grafik olarak çiz
|
| 328 |
+
compare_df_ilce.set_index('İlçe')[['Toplam İhtiyaç', 'Norm Fazlası (Mazaretli)', 'Norm Fazlası (Mazaretsiz)']].plot(kind='bar', ax=ax1)
|
| 329 |
+
ax1.set_ylabel("Sayı")
|
| 330 |
+
ax1.set_xlabel("İlçe")
|
| 331 |
+
ax1.set_title("İlçe Bazında İhtiyaç, Norm Fazlası ve Oran Karşılaştırması")
|
| 332 |
+
plt.xticks(rotation=45, ha="right")
|
| 333 |
+
|
| 334 |
+
# Oran verilerini ikincil bir eksen olarak çiz
|
| 335 |
+
ax2 = ax1.twinx()
|
| 336 |
+
ax2.plot(compare_df_ilce['İlçe'], compare_df_ilce['Oran'], color='red', marker='o', linestyle='-', linewidth=2)
|
| 337 |
+
ax2.set_ylabel("Oran", color='red')
|
| 338 |
+
ax2.tick_params(axis='y', labelcolor='red')
|
| 339 |
+
|
| 340 |
+
plt.tight_layout()
|
| 341 |
+
chart_path_ilce = 'district_comparison_chart.png'
|
| 342 |
+
plt.savefig(chart_path_ilce)
|
| 343 |
+
plt.close()
|
| 344 |
+
else:
|
| 345 |
+
chart_path_ilce = None # Grafik gösterilmeyecek
|
| 346 |
+
|
| 347 |
+
return compare_df_ilce, chart_path_ilce
|
| 348 |
+
|
| 349 |
+
compare_button_ilce.click(fn=compare_districts, inputs=[ilce_multiselect_compare], outputs=[compare_output_ilce, compare_chart_ilce])
|
| 350 |
+
|
| 351 |
+
with gr.Tab("İlçe ve Branş Haritası"):
|
| 352 |
+
gr.Markdown("### Seçilen İlçe ve Branş İçin Harita Üzerinde Görselleştirme")
|
| 353 |
+
ilce_dropdown = gr.Dropdown(choices=df_ihtiyac['ilçe'].unique().tolist(), label="İlçe Seçin")
|
| 354 |
+
brans_dropdown = gr.Dropdown(choices=df_ihtiyac['branş'].unique().tolist(), label="Branş Seçin")
|
| 355 |
+
map_output = gr.HTML()
|
| 356 |
+
analyze_button = gr.Button("Haritada Göster")
|
| 357 |
+
|
| 358 |
+
analyze_button.click(
|
| 359 |
+
fn=create_map,
|
| 360 |
+
inputs=[ilce_dropdown, brans_dropdown],
|
| 361 |
+
outputs=[map_output]
|
| 362 |
+
)
|
| 363 |
+
# Run the app
|
| 364 |
+
demo.launch()
|
ihtiyac_data.xlsx
ADDED
|
Binary file (51.4 kB). View file
|
|
|
norm_fazlasi.xlsx
ADDED
|
Binary file (137 kB). View file
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
pandas
|
| 3 |
+
matplotlib
|
| 4 |
+
folium
|
| 5 |
+
openpyxl
|