bigroll commited on
Commit
381b5d4
·
verified ·
1 Parent(s): 7025d50

previous not bad

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -73,7 +73,7 @@ def get_data():
73
  # Connect to MotherDuck using the token
74
  con = duckdb.connect(f'md:?token={MOTHERDUCK_TOKEN}')
75
 
76
- # Updated query: Removed 'id' based on schema
77
  query = """
78
  SELECT entity, entity_score, domain, title_score, overall_score, created_at
79
  FROM sentiment_analysis
@@ -87,8 +87,8 @@ def get_data():
87
  else:
88
  df["created_at"] = pd.to_datetime(df["created_at"])
89
 
90
- # 2. FIX: Remove Timezone Information
91
- # This prevents "Invalid comparison between dtype=datetime64[ns, Europe/Paris] and Timestamp"
92
  if pd.api.types.is_datetime64_any_dtype(df["created_at"]):
93
  if df["created_at"].dt.tz is not None:
94
  df["created_at"] = df["created_at"].dt.tz_localize(None)
@@ -162,8 +162,6 @@ if selected_timeframe != "All":
162
  start_date = now - pd.Timedelta(days=365)
163
  end_date = now
164
 
165
- # Ensure start_date and end_date are Pandas Timestamps for comparison
166
- # (Since we stripped TZ from the DF, these naive timestamps will now work)
167
  if start_date and end_date:
168
  filtered_df = filtered_df[
169
  (filtered_df["created_at"] >= pd.Timestamp(start_date)) &
@@ -237,6 +235,8 @@ if not filtered_df.empty:
237
  labels={"date": "Date", "score": "Score", "label": "Legend"},
238
  title=T[LANG]["scores_over_time"]
239
  )
 
 
240
 
241
  else:
242
  group_cols = ["date", "entity"]
@@ -285,6 +285,8 @@ if not filtered_df.empty:
285
  labels={"date": "Date", score_type: "Score", "label": "Legend"},
286
  title=T[LANG]["avg_over_time"].format(score_type.replace("_", " ").title())
287
  )
 
 
288
 
289
  # Grid lines at every integer, thicker at -5 and 5
290
  shapes = []
 
73
  # Connect to MotherDuck using the token
74
  con = duckdb.connect(f'md:?token={MOTHERDUCK_TOKEN}')
75
 
76
+ # Query based on your schema
77
  query = """
78
  SELECT entity, entity_score, domain, title_score, overall_score, created_at
79
  FROM sentiment_analysis
 
87
  else:
88
  df["created_at"] = pd.to_datetime(df["created_at"])
89
 
90
+ # 2. FIX: Remove Timezone Information (Make it Naive)
91
+ # This solves the "Invalid comparison between Europe/Paris and Timestamp" error
92
  if pd.api.types.is_datetime64_any_dtype(df["created_at"]):
93
  if df["created_at"].dt.tz is not None:
94
  df["created_at"] = df["created_at"].dt.tz_localize(None)
 
162
  start_date = now - pd.Timedelta(days=365)
163
  end_date = now
164
 
 
 
165
  if start_date and end_date:
166
  filtered_df = filtered_df[
167
  (filtered_df["created_at"] >= pd.Timestamp(start_date)) &
 
235
  labels={"date": "Date", "score": "Score", "label": "Legend"},
236
  title=T[LANG]["scores_over_time"]
237
  )
238
+ # FIX: Ensure markers are shown even for single/few data points
239
+ fig.update_traces(mode="lines+markers")
240
 
241
  else:
242
  group_cols = ["date", "entity"]
 
285
  labels={"date": "Date", score_type: "Score", "label": "Legend"},
286
  title=T[LANG]["avg_over_time"].format(score_type.replace("_", " ").title())
287
  )
288
+ # FIX: Ensure markers are shown even for single/few data points
289
+ fig.update_traces(mode="lines+markers")
290
 
291
  # Grid lines at every integer, thicker at -5 and 5
292
  shapes = []