ESMATUGBA commited on
Commit
517d7bd
·
verified ·
1 Parent(s): 6484ff3

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +44 -47
src/streamlit_app.py CHANGED
@@ -56,50 +56,47 @@ else:
56
 
57
  st.divider()
58
 
59
- # 5. ANA GRAFİK (Sabit Konteyner)
60
- st.markdown(f"## 📈 {year} Analizi / Analysis")
61
- main_container = st.container()
62
-
63
- with main_container:
64
- if not filtered_df.empty:
65
- # Titremeyi azaltmak için figürü fonksiyona bağlamadan direkt çiziyoruz
66
- fig1, ax1 = plt.subplots(figsize=(8, 2.8))
67
- ax1.plot(filtered_df['Date'], filtered_df['GLD'], color='gold', linewidth=2)
68
- ax1.fill_between(filtered_df['Date'], filtered_df['GLD'], color='gold', alpha=0.1)
69
-
70
- y_min, y_max = filtered_df['GLD'].min(), filtered_df['GLD'].max()
71
- ax1.set_ylim(y_min * 0.98, y_max * 1.02)
72
-
73
- st.pyplot(fig1)
74
- plt.close(fig1)
75
-
76
- st.markdown(f"#### 📝 Not: Bu grafik {year} yılındaki günlük fiyat hareketlerini gösterir. / Note: This chart shows daily price movements in {year}.")
77
- st.divider()
78
-
79
- # 6. DİĞER GRAFİKLER (YAN YANA)
80
- col_left, col_right = st.columns(2)
81
-
82
- with col_left:
83
- st.markdown("### 🎯 Dağılım / Distribution")
84
- fig2, ax2 = plt.subplots(figsize=(5, 3.5))
85
- sns.kdeplot(x=filtered_df['GLD'], fill=True, color="orange", ax=ax2)
86
- st.pyplot(fig2)
87
- plt.close(fig2)
88
-
89
- with col_right:
90
- st.markdown("### 🌡️ Korelasyon / Correlation")
91
- fig3, ax3 = plt.subplots(figsize=(5, 3.5))
92
- num_df = filtered_df.select_dtypes(include=['number'])
93
- sns.heatmap(num_df.corr(), annot=True, cmap='YlOrBr', ax=ax3, annot_kws={"size": 8})
94
- st.pyplot(fig3)
95
- plt.close(fig3)
96
-
97
- st.divider()
98
-
99
- # 7. VERİ TABLOSU (Artık Hep Açık)
100
- st.markdown("### 📋 Veri Tablosu / Data Table")
101
- # Verileri Gör kısmını direkt tablo olarak bastık, expander'ı kaldırdık
102
- st.dataframe(filtered_df.head(10), use_container_width=True)
103
-
104
- csv = filtered_df.to_csv(index=False).encode('utf-8')
105
- st.download_button("📥 Veriyi İndir / Download CSV", data=csv, file_name=f'gold_{year}.csv')
 
56
 
57
  st.divider()
58
 
59
+ # 5. GRAFİKLER VE TABLO (Titremeyi önleyen Fragment yapısı)
60
+ @st.fragment
61
+ def render_analysis(data, selected_year):
62
+ st.markdown(f"## 📈 {selected_year} Analizi / Analysis")
63
+
64
+ # Ana Grafik
65
+ fig1, ax1 = plt.subplots(figsize=(8, 2.8))
66
+ ax1.plot(data['Date'], data['GLD'], color='gold', linewidth=2)
67
+ ax1.fill_between(data['Date'], data['GLD'], color='gold', alpha=0.1)
68
+ y_min, y_max = data['GLD'].min(), data['GLD'].max()
69
+ ax1.set_ylim(y_min * 0.98, y_max * 1.02)
70
+ st.pyplot(fig1)
71
+ plt.close(fig1)
72
+
73
+ st.markdown(f"#### 📝 Not: Bu grafik {selected_year} yılındaki günlük fiyat hareketlerini gösterir.")
74
+ st.divider()
75
+
76
+ # Yan Yana Grafikler
77
+ c1, c2 = st.columns(2)
78
+ with c1:
79
+ st.markdown("### 🎯 Dağılım / Distribution")
80
+ fig2, ax2 = plt.subplots(figsize=(5, 3.5))
81
+ sns.kdeplot(x=data['GLD'], fill=True, color="orange", ax=ax2)
82
+ st.pyplot(fig2)
83
+ plt.close(fig2)
84
+ with c2:
85
+ st.markdown("### 🌡️ Korelasyon / Correlation")
86
+ fig3, ax3 = plt.subplots(figsize=(5, 3.5))
87
+ num_df = data.select_dtypes(include=['number'])
88
+ sns.heatmap(num_df.corr(), annot=True, cmap='YlOrBr', ax=ax3, annot_kws={"size": 8})
89
+ st.pyplot(fig3)
90
+ plt.close(fig3)
91
+
92
+ st.divider()
93
+
94
+ # Veri Tablosu (Loglardaki width hatası için width='stretch' eklendi)
95
+ st.markdown("### 📋 Veri Tablosu / Data Table")
96
+ st.dataframe(data.head(10), width="stretch") # Logdaki hatayı bu düzeltecek
97
+
98
+ csv = data.to_csv(index=False).encode('utf-8')
99
+ st.download_button("📥 Veriyi İndir / Download CSV", data=csv, file_name=f'gold_{selected_year}.csv')
100
+
101
+ # Fonksiyonu çağır
102
+ render_analysis(filtered_df, year)