QAway-to commited on
Commit
49d9149
·
1 Parent(s): 5691238

New tabs and functions v3.5

Browse files
Files changed (1) hide show
  1. core/crypto_dashboard.py +52 -35
core/crypto_dashboard.py CHANGED
@@ -1,9 +1,6 @@
1
  """
2
- Crypto Dashboard — Plotly Edition + KPI Line
3
- Source: Coinlore API
4
- Changes:
5
- - KPI строка (без карточек), чтобы не прыгала вёрстка
6
- - Больше заполнение блока графиками (меньше отступов)
7
  """
8
  import requests
9
  import pandas as pd
@@ -22,10 +19,7 @@ def fetch_coinlore_data(limit=100):
22
 
23
 
24
  def _kpi_line(df) -> str:
25
- """
26
- Возвращает одну строку: BTC $xx (Δ%), ETH $yy (Δ%), ...
27
- чтобы место не прыгало при подгрузке.
28
- """
29
  tracked = ["BTC", "ETH", "SOL", "DOGE"]
30
  parts = []
31
  for sym in tracked:
@@ -36,57 +30,80 @@ def _kpi_line(df) -> str:
36
  ch = float(row["percent_change_24h"])
37
  arrow = "↑" if ch > 0 else "↓"
38
  color = "#4ade80" if ch > 0 else "#f87171"
39
- parts.append(f"<span class='kpi-item'><b>{sym}</b> ${price:,.0f} <span style='color:{color}'>{arrow} {abs(ch):.2f}%</span></span>")
40
- # Разделение запятой с пробелом
 
 
41
  return " , ".join(parts)
42
 
43
 
44
  def build_crypto_dashboard(top_n=50):
45
  df = fetch_coinlore_data(top_n)
46
 
47
- # Treemap плотный
48
  fig_treemap = px.treemap(
49
- df, path=["symbol"], values="market_cap_usd",
50
- color="percent_change_24h", color_continuous_scale="RdYlGn",
51
- title="Market Composition by Market Cap (Top Coins)",
52
- height=420
 
 
53
  )
54
  fig_treemap.update_layout(
55
- template="plotly_dark", autosize=True,
56
- margin=dict(l=5, r=5, t=28, b=5),
57
- paper_bgcolor="rgba(0,0,0,0)", plot_bgcolor="rgba(0,0,0,0)"
 
 
 
58
  )
59
 
60
- # Top gainers плотный
61
  top = df.sort_values("percent_change_24h", ascending=False).head(12)
62
  fig_bar = px.bar(
63
- top, x="percent_change_24h", y="symbol",
64
- orientation="h", color="percent_change_24h",
 
 
 
65
  color_continuous_scale="Blues",
66
- title="Top 12 Gainers (24h)", height=320
67
  )
68
  fig_bar.update_layout(
69
- template="plotly_dark", autosize=True,
70
- margin=dict(l=40, r=10, t=28, b=18),
71
- paper_bgcolor="rgba(0,0,0,0)", plot_bgcolor="rgba(0,0,0,0)"
 
 
 
72
  )
73
 
74
- # Bubble
75
  fig_bubble = px.scatter(
76
- df.head(60), x="market_cap_usd", y="volume24",
77
- size="price_usd", color="percent_change_7d", hover_name="symbol",
78
- log_x=True, log_y=True, color_continuous_scale="RdYlGn",
79
- title="Market Cap vs 24h Volume", height=320
 
 
 
 
 
 
80
  )
81
  fig_bubble.update_layout(
82
- template="plotly_dark", autosize=True,
83
- margin=dict(l=36, r=10, t=28, b=18),
84
- paper_bgcolor="rgba(0,0,0,0)", plot_bgcolor="rgba(0,0,0,0)"
 
 
 
85
  )
86
 
87
- # AI summary
88
  summary = _ai_summary(df)
89
  kpi_text = _kpi_line(df)
 
90
  return fig_treemap, fig_bar, fig_bubble, summary, kpi_text
91
 
92
 
 
1
  """
2
+ Crypto Dashboard — Plotly Edition + KPI Line (clean version)
3
+ Удалены встроенные заголовки из графиков.
 
 
 
4
  """
5
  import requests
6
  import pandas as pd
 
19
 
20
 
21
  def _kpi_line(df) -> str:
22
+ """Возвращает строку KPI: BTC $xx (Δ%), ETH $yy (Δ%), ..."""
 
 
 
23
  tracked = ["BTC", "ETH", "SOL", "DOGE"]
24
  parts = []
25
  for sym in tracked:
 
30
  ch = float(row["percent_change_24h"])
31
  arrow = "↑" if ch > 0 else "↓"
32
  color = "#4ade80" if ch > 0 else "#f87171"
33
+ parts.append(
34
+ f"<span class='kpi-item'><b>{sym}</b> ${price:,.0f} "
35
+ f"<span style='color:{color}'>{arrow} {abs(ch):.2f}%</span></span>"
36
+ )
37
  return " , ".join(parts)
38
 
39
 
40
  def build_crypto_dashboard(top_n=50):
41
  df = fetch_coinlore_data(top_n)
42
 
43
+ # === Treemap (чистый, без заголовка) ===
44
  fig_treemap = px.treemap(
45
+ df,
46
+ path=["symbol"],
47
+ values="market_cap_usd",
48
+ color="percent_change_24h",
49
+ color_continuous_scale="RdYlGn",
50
+ height=420,
51
  )
52
  fig_treemap.update_layout(
53
+ title=None, # 🔹 Убираем встроенный заголовок
54
+ template="plotly_dark",
55
+ autosize=True,
56
+ margin=dict(l=5, r=5, t=5, b=5),
57
+ paper_bgcolor="rgba(0,0,0,0)",
58
+ plot_bgcolor="rgba(0,0,0,0)",
59
  )
60
 
61
+ # === Top Gainers (24h) ===
62
  top = df.sort_values("percent_change_24h", ascending=False).head(12)
63
  fig_bar = px.bar(
64
+ top,
65
+ x="percent_change_24h",
66
+ y="symbol",
67
+ orientation="h",
68
+ color="percent_change_24h",
69
  color_continuous_scale="Blues",
70
+ height=320,
71
  )
72
  fig_bar.update_layout(
73
+ title=None, # 🔹 убран встроенный title
74
+ template="plotly_dark",
75
+ autosize=True,
76
+ margin=dict(l=40, r=10, t=5, b=18),
77
+ paper_bgcolor="rgba(0,0,0,0)",
78
+ plot_bgcolor="rgba(0,0,0,0)",
79
  )
80
 
81
+ # === Market Cap vs Volume ===
82
  fig_bubble = px.scatter(
83
+ df.head(60),
84
+ x="market_cap_usd",
85
+ y="volume24",
86
+ size="price_usd",
87
+ color="percent_change_7d",
88
+ hover_name="symbol",
89
+ log_x=True,
90
+ log_y=True,
91
+ color_continuous_scale="RdYlGn",
92
+ height=320,
93
  )
94
  fig_bubble.update_layout(
95
+ title=None, # 🔹 убран встроенный title
96
+ template="plotly_dark",
97
+ autosize=True,
98
+ margin=dict(l=36, r=10, t=5, b=18),
99
+ paper_bgcolor="rgba(0,0,0,0)",
100
+ plot_bgcolor="rgba(0,0,0,0)",
101
  )
102
 
103
+ # === AI summary ===
104
  summary = _ai_summary(df)
105
  kpi_text = _kpi_line(df)
106
+
107
  return fig_treemap, fig_bar, fig_bubble, summary, kpi_text
108
 
109