omniverse1 commited on
Commit
c699178
·
verified ·
1 Parent(s): 2ae2328

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -24
app.py CHANGED
@@ -163,38 +163,55 @@ def create_chart_analysis(interval, asset_name):
163
  def analyze_sentiment(asset_name):
164
  """Analyze market sentiment for selected asset"""
165
  try:
166
- sentiment_score, news_summary = sentiment_analyzer.analyze_sentiment(asset_name)
 
 
 
167
 
168
  # Create sentiment gauge using matplotlib
169
  fig, ax = plt.subplots(figsize=(6, 4), facecolor='white')
170
  fig.patch.set_facecolor('white')
171
 
172
- # Create gauge
173
- ax.set_xlim(-1.5, 1.5)
174
- ax.set_ylim(0, 1)
175
  ax.set_aspect('equal')
176
 
177
- # Draw gauge background
178
  theta = np.linspace(np.pi, 0, 100)
179
- ax.plot(np.cos(theta), np.sin(theta), color='lightgray', linewidth=10)
180
-
181
- # Draw colored regions
182
- ax.fill_between(np.cos(theta[50:]), np.sin(theta[50:]), 0,
183
- where=np.cos(theta[50:])<0, color='red', alpha=0.3)
184
- ax.fill_between(np.cos(theta[25:75]), np.sin(theta[25:75]), 0,
185
- color='gray', alpha=0.3)
186
- ax.fill_between(np.cos(theta[:50]), np.sin(theta[:50]), 0,
187
- where=np.cos(theta[:50])>0, color='green', alpha=0.3)
188
-
189
- # Draw needle
190
- needle_angle = np.pi * (1 - (sentiment_score + 1) / 2)
191
- ax.plot([0, 0.8*np.cos(needle_angle)], [0, 0.8*np.sin(needle_angle)],
192
- color='gold', linewidth=4)
193
-
194
- # Add score text
195
- ax.text(0, -0.2, f"{sentiment_score:.2f}", ha='center', va='center',
196
- fontsize=16, color='black', weight='bold')
197
- ax.set_title(f'{asset_name} Market Sentiment', color='black')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
 
199
  # Remove axes
200
  ax.axis('off')
 
163
  def analyze_sentiment(asset_name):
164
  """Analyze market sentiment for selected asset"""
165
  try:
166
+ ticker = asset_map[asset_name]
167
+ sentiment_score, news_summary = sentiment_analyzer.analyze_sentiment(ticker)
168
+
169
+ # --- Modifikasi untuk tampilan Gauge yang lebih baik ---
170
 
171
  # Create sentiment gauge using matplotlib
172
  fig, ax = plt.subplots(figsize=(6, 4), facecolor='white')
173
  fig.patch.set_facecolor('white')
174
 
175
+ # Setup Gauge limits
176
+ ax.set_xlim(-1.1, 1.1) # Diperluas sedikit untuk label
177
+ ax.set_ylim(-0.2, 1.1) # Diperluas sedikit ke bawah untuk skor
178
  ax.set_aspect('equal')
179
 
180
+ # Draw gauge background segments
181
  theta = np.linspace(np.pi, 0, 100)
182
+ x, y = np.cos(theta), np.sin(theta)
183
+
184
+ # Segments: Red (-1.0 to -0.5), Gray/Yellow (-0.5 to 0.5), Green (0.5 to 1.0)
185
+ ax.fill_between(x[75:], y[75:], 0, where=x[75:]<=-0.5, color='#F08080', alpha=0.9, linewidth=0) # Red (Bearish)
186
+ ax.fill_between(x[25:75], y[25:75], 0, color='#D3D3D3', alpha=0.9, linewidth=0) # Gray (Neutral)
187
+ ax.fill_between(x[:25], y[:25], 0, where=x[:25]>=0.5, color='#90EE90', alpha=0.9, linewidth=0) # Green (Bullish)
188
+
189
+ # Draw main arc line
190
+ ax.plot(x, y, color='#D3D3D3', linewidth=10, solid_capstyle='round', zorder=1)
191
+
192
+ # Draw needle (using a small triangle/arrow)
193
+ needle_angle = np.pi * (1 - (sentiment_score + 1) / 2) # Angle from pi (180 deg) to 0 (0 deg)
194
+ needle_x = 0.8 * np.cos(needle_angle)
195
+ needle_y = 0.8 * np.sin(needle_angle)
196
+
197
+ # Draw a line/needle for the pointer
198
+ ax.plot([0, needle_x], [0, needle_y], color='black', linewidth=3, zorder=3)
199
+ ax.plot([0], [0], marker='o', color='black', markersize=6, zorder=4)
200
+
201
+ # Draw score number (similar to the image)
202
+ score_color = 'red' if sentiment_score < 0 else 'green' if sentiment_score > 0 else 'black'
203
+ ax.text(0, -0.15, f"{sentiment_score:+.3f}", ha='center', va='center',
204
+ fontsize=24, color=score_color, weight='bold', zorder=5)
205
+
206
+ # Add labels for the scale
207
+ ax.text(-1, 0, "-1", ha='center', va='top', fontsize=10, color='black')
208
+ ax.text(-0.5, 0.5, "-0.5", ha='center', va='center', fontsize=10, color='black')
209
+ ax.text(0, 1.05, "0", ha='center', va='bottom', fontsize=10, color='black')
210
+ ax.text(0.5, 0.5, "0.5", ha='center', va='center', fontsize=10, color='black')
211
+ ax.text(1, 0, "1", ha='center', va='top', fontsize=10, color='black')
212
+
213
+ # Add Title
214
+ ax.set_title(f'{ticker} Market Sentiment (Simulated)', color='black', pad=20)
215
 
216
  # Remove axes
217
  ax.axis('off')