ESMATUGBA commited on
Commit
10fd909
·
verified ·
1 Parent(s): fe093b5

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +50 -71
src/streamlit_app.py CHANGED
@@ -5,24 +5,14 @@ import plotly.graph_objects as go
5
  import os
6
 
7
  # 1. SAYFA AYARLARI
8
- st.set_page_config(layout="wide", page_title="Gold Intelligence Dashboard")
9
 
10
- # CSS: Metrikler ve Konteynır Ayarları
11
  st.markdown("""
12
  <style>
13
  .stApp { background-color: #FFFFFF; }
14
- [data-testid="stMetricValue"] {
15
- font-size: 80px !important;
16
- font-weight: 900 !important;
17
- color: #B28F2D !important;
18
- }
19
- /* Grafiklerin Siyah Kutusu */
20
- .plot-container {
21
- background-color: #000000 !important;
22
- border-radius: 15px;
23
- padding: 25px;
24
- border: 2px solid #333333;
25
- }
26
  </style>
27
  """, unsafe_allow_html=True)
28
 
@@ -41,76 +31,65 @@ def load_data():
41
 
42
  df = load_data()
43
 
44
- # 3. SIDEBAR VE BAŞLIK
45
- year = st.sidebar.selectbox("Yıl Seçin", options=sorted(df['YEAR'].unique(), reverse=True))
 
46
  filtered_df = df[df['YEAR'] == year].copy()
47
 
48
- st.markdown("<h1 style='text-align: center; color: #B28F2D;'>💰 Gold Price Intelligence / Analiz Paneli</h1>", unsafe_allow_html=True)
 
49
  st.divider()
50
 
51
- # 4. DEV METRİKLER
52
- m1, m2, m3 = st.columns(3)
53
- m1.metric("Son Kapanış", f"{filtered_df['GLD'].iloc[-1]:.2f}")
54
- m2.metric(f"{year} Zirve", f"{filtered_df['GLD'].max():.2f}")
55
- m3.metric(f"{year} Dip", f"{filtered_df['GLD'].min():.2f}")
 
 
 
 
 
 
 
 
56
 
57
  st.divider()
58
 
59
- # 5. GRAFİKLER (OKUNABİLİRLİK GARANTİLİ)
60
-
61
- # --- ANA TREND GRAFİĞİ ---
62
- st.markdown(f"### 📈 {year} Fiyat Trendi")
63
  fig1 = go.Figure()
64
  fig1.add_trace(go.Scatter(x=filtered_df['Date'], y=filtered_df['GLD'],
65
- line=dict(color='#FFD700', width=5),
66
- fill='tozeroy', fillcolor='rgba(255, 215, 0, 0.15)'))
67
  fig1.update_layout(
68
  template="plotly_dark", paper_bgcolor='black', plot_bgcolor='black',
69
- height=550,
70
- margin=dict(l=80, r=40, t=40, b=80),
71
- xaxis=dict(tickfont=dict(size=18, color='white', family="Arial Black"), title=None),
72
- yaxis=dict(tickfont=dict(size=18, color='white', family="Arial Black"), title="Fiyat (USD)", gridcolor="#333333")
73
  )
74
  st.plotly_chart(fig1, use_container_width=True)
75
 
 
76
  st.divider()
77
 
78
- # --- DAĞILIM GRAFİĞİ ---
79
- st.markdown("### 🎯 Fiyat Dağılım Analizi")
80
- fig2 = px.histogram(filtered_df, x="GLD", nbins=40,
81
- color_discrete_sequence=['#FFD700'],
82
- template="plotly_dark")
83
- fig2.update_layout(
84
- paper_bgcolor='black', plot_bgcolor='black', height=550,
85
- margin=dict(l=80, r=40, t=40, b=80),
86
- xaxis=dict(tickfont=dict(size=18, color='white', family="Arial Black"), title="GLD Fiyat Aralığı"),
87
- yaxis=dict(tickfont=dict(size=18, color='white', family="Arial Black"), title="Gözlem Sayısı", gridcolor="#333333")
88
- )
89
- st.plotly_chart(fig2, use_container_width=True)
90
-
91
- st.divider()
92
-
93
- # --- KORELASYON MATRİSİ (ÖZEL OKUNABİLİRLİK AYARI) ---
94
- st.markdown("### 🌡️ Değişken Korelasyon Matrisi")
95
- numeric_cols = filtered_df.select_dtypes(include=['number']).drop(columns=['YEAR'], errors='ignore')
96
- corr_df = numeric_cols.corr()
97
-
98
- fig3 = px.imshow(corr_df,
99
- text_auto=".2f",
100
- color_continuous_scale='YlOrRd',
101
- template="plotly_dark")
102
-
103
- fig3.update_layout(
104
- paper_bgcolor='black', plot_bgcolor='black', height=700,
105
- margin=dict(l=100, r=100, t=100, b=100), # Yazıların kesilmemesi için pay bıraktık
106
- xaxis=dict(tickfont=dict(size=16, color='white', family="Arial Black")),
107
- yaxis=dict(tickfont=dict(size=16, color='white', family="Arial Black"))
108
- )
109
- # Kutuların içindeki rakamları dev gibi ve beyaz yapalım
110
- fig3.update_traces(textfont=dict(size=20, color="white", family="Arial Black"))
111
-
112
- st.plotly_chart(fig3, use_container_width=True)
113
-
114
- # 6. VERİ SETİ
115
- with st.expander("📋 Detaylı Verileri İncele"):
116
- st.dataframe(filtered_df, use_container_width=True)
 
5
  import os
6
 
7
  # 1. SAYFA AYARLARI
8
+ st.set_page_config(layout="wide", page_title="Gold Price Analysis")
9
 
10
+ # CSS: Sade ve Net Tasarım
11
  st.markdown("""
12
  <style>
13
  .stApp { background-color: #FFFFFF; }
14
+ [data-testid="stMetricValue"] { font-size: 55px !important; font-weight: bold !important; color: #B28F2D !important; }
15
+ .plot-container { border-radius: 10px; padding: 5px; }
 
 
 
 
 
 
 
 
 
 
16
  </style>
17
  """, unsafe_allow_html=True)
18
 
 
31
 
32
  df = load_data()
33
 
34
+ # 3. SIDEBAR
35
+ st.sidebar.header("📅 Filtreler / Filters")
36
+ year = st.sidebar.selectbox("Yıl Seçin / Select Year", options=sorted(df['YEAR'].unique(), reverse=True))
37
  filtered_df = df[df['YEAR'] == year].copy()
38
 
39
+ # 4. ANA BAŞLIK
40
+ st.markdown(f"<h1 style='text-align: center; color: #333;'>Gold Price Analysis / {year} Analizi</h1>", unsafe_allow_html=True)
41
  st.divider()
42
 
43
+ # 5. YÖNETİCİ BİLGİ NOTU (Paylaştığın görseldeki gibi)
44
+ st.markdown("### 💼 Yönetici Bilgi Notu / Executive Summary")
45
+ col1, col2 = st.columns(2)
46
+ with col1:
47
+ if year == 2008:
48
+ st.warning("**TR:** 2008'de altın güvenli limandır, alım faydalıdır.")
49
+ else:
50
+ st.success(f"**TR:** {year} yılı verileri istikrarlı görünüyor.")
51
+ with col2:
52
+ if year == 2008:
53
+ st.warning("**US:** Gold is a safe haven in 2008; buying is beneficial.")
54
+ else:
55
+ st.success(f"**US:** Data for {year} appears stable.")
56
 
57
  st.divider()
58
 
59
+ # 6. ANA GRAFİK (image_995583.png görselindeki gibi tek ince çizgi)
60
+ st.markdown(f"#### 📈 {year} Altın Fiyat Hareketi")
 
 
61
  fig1 = go.Figure()
62
  fig1.add_trace(go.Scatter(x=filtered_df['Date'], y=filtered_df['GLD'],
63
+ mode='lines',
64
+ line=dict(color='gold', width=2))) # İnce ve net tek çizgi
65
  fig1.update_layout(
66
  template="plotly_dark", paper_bgcolor='black', plot_bgcolor='black',
67
+ height=400, margin=dict(l=40, r=40, t=20, b=40),
68
+ xaxis=dict(showgrid=True, gridcolor='#222', tickfont=dict(color='white')),
69
+ yaxis=dict(showgrid=True, gridcolor='#222', tickfont=dict(color='white'))
 
70
  )
71
  st.plotly_chart(fig1, use_container_width=True)
72
 
73
+ st.markdown(f"📝 *Not: Bu grafik {year} yılındaki günlük fiyat hareketlerini gösterir.*")
74
  st.divider()
75
 
76
+ # 7. YAN YANA GRAFİKLER (image_98dcc5.png görselindeki gibi)
77
+ c1, c2 = st.columns(2)
78
+
79
+ with c1:
80
+ st.markdown("#### 🎯 Dağılım / Distribution")
81
+ fig2 = px.histogram(filtered_df, x="GLD", nbins=30, color_discrete_sequence=['gold'], template="plotly_dark")
82
+ fig2.update_layout(paper_bgcolor='black', plot_bgcolor='black', height=350, margin=dict(l=20,r=20,t=20,b=20))
83
+ st.plotly_chart(fig2, use_container_width=True)
84
+
85
+ with c2:
86
+ st.markdown("#### 🌡️ Korelasyon / Correlation")
87
+ num_df = filtered_df.select_dtypes(include=['number']).drop(columns=['YEAR'], errors='ignore')
88
+ fig3 = px.imshow(num_df.corr(), text_auto=".2f", color_continuous_scale='YlOrRd', template="plotly_dark")
89
+ fig3.update_layout(paper_bgcolor='black', plot_bgcolor='black', height=350, margin=dict(l=20,r=20,t=20,b=20))
90
+ st.plotly_chart(fig3, use_container_width=True)
91
+
92
+ # 8. VERİ TABLOSU (image_995886.png görselindeki gibi)
93
+ with st.expander("Verileri Gör / View Data"):
94
+ st.dataframe(filtered_df.head(), use_container_width=True)
95
+ st.download_button("📥 İndir / Download", data=filtered_df.to_csv(index=False), file_name=f'gold_{year}.csv')