GuglielmoTor commited on
Commit
0cc5a7d
·
verified ·
1 Parent(s): bd262cf

Update services/analytics_tab_module.py

Browse files
Files changed (1) hide show
  1. services/analytics_tab_module.py +15 -15
services/analytics_tab_module.py CHANGED
@@ -370,27 +370,29 @@ class AnalyticsTab:
370
  logging.info("Refreshing analytics graph UI elements and resetting actions/chat (within module).")
371
  start_time = time.time()
372
 
373
- # --- FIX STARTS HERE ---
374
- # The original code used complex slicing (plot_gen_results[1:-1]) which is brittle.
375
- # It assumes the figures are returned as a flat list. If update_analytics_plots_figures
376
- # returns a more standard (status, [list_of_figs], summary) tuple, the slicing fails.
377
- # This new unpacking is more robust and assumes update_analytics_plots_figures returns
378
- # a 3-element tuple/list where the second element is the list of figures.
379
  plot_gen_results = self.update_analytics_plots_figures(current_token_state_val, date_filter_val, custom_start_val, custom_end_val, PLOT_CONFIGS)
380
 
381
- # This direct unpacking is safer than slicing.
382
- # It assumes `update_analytics_plots_figures` returns a 3-element structure like:
383
- # (status_string, list_of_figure_objects, summaries_dict)
 
384
  try:
385
- status_msg, gen_figs, new_summaries_for_chatbot = plot_gen_results
386
- except (ValueError, TypeError) as e:
 
 
 
 
 
 
 
 
 
387
  logging.error(f"Could not unpack results from update_analytics_plots_figures. Error: {e}")
388
- logging.error(f"Expected 3 elements (status, figs_list, summaries), but received {len(plot_gen_results)} elements.")
389
  # Fallback to error state
390
  status_msg = f"Errore: L'aggiornamento dei grafici non è riuscito a causa di un formato di dati imprevisto."
391
  gen_figs = [self.create_placeholder_plot("Error", f"Dati non validi {i}") for i in range(len(PLOT_CONFIGS))]
392
  new_summaries_for_chatbot = {}
393
-
394
  # --- FIX ENDS HERE ---
395
 
396
  all_updates = []
@@ -398,12 +400,10 @@ class AnalyticsTab:
398
  all_updates.append(status_msg) # For self.analytics_status_md
399
 
400
  # 2. Plot components
401
- # This check is now more likely to succeed with the corrected unpacking.
402
  if isinstance(gen_figs, list) and len(gen_figs) == len(PLOT_CONFIGS):
403
  all_updates.extend(gen_figs)
404
  else:
405
  logging.error(f"Mismatch in generated figures ({len(gen_figs) if isinstance(gen_figs, list) else 'N/A'}) and plot_configs ({len(PLOT_CONFIGS)})")
406
- # If there's still a mismatch, create placeholders to avoid crashing Gradio
407
  all_updates.extend([self.create_placeholder_plot("Error", f"Figura mancante {i}") for i in range(len(PLOT_CONFIGS))])
408
 
409
  # 3. UI Resets for Action Panel (9 components)
 
370
  logging.info("Refreshing analytics graph UI elements and resetting actions/chat (within module).")
371
  start_time = time.time()
372
 
 
 
 
 
 
 
373
  plot_gen_results = self.update_analytics_plots_figures(current_token_state_val, date_filter_val, custom_start_val, custom_end_val, PLOT_CONFIGS)
374
 
375
+ # --- NEW FIX STARTS HERE ---
376
+ # The error "too many values to unpack (expected 3)" and "received 21 elements" confirms the function
377
+ # returns a flat tuple/list of (status, fig1, fig2, ..., fig19, summary_dict).
378
+ # This revised unpacking logic handles that specific structure by slicing.
379
  try:
380
+ # Check if we got the expected number of results (status + 19 plots + summary)
381
+ expected_count = len(PLOT_CONFIGS) + 2
382
+ if len(plot_gen_results) == expected_count:
383
+ status_msg = plot_gen_results[0]
384
+ # Gather all middle elements (the figures) into a list using slicing
385
+ gen_figs = list(plot_gen_results[1:-1])
386
+ new_summaries_for_chatbot = plot_gen_results[-1]
387
+ else:
388
+ # This will handle cases where the number of returned items is unexpected
389
+ raise ValueError(f"Expected {expected_count} elements, but got {len(plot_gen_results)}")
390
+ except (ValueError, TypeError, IndexError) as e:
391
  logging.error(f"Could not unpack results from update_analytics_plots_figures. Error: {e}")
 
392
  # Fallback to error state
393
  status_msg = f"Errore: L'aggiornamento dei grafici non è riuscito a causa di un formato di dati imprevisto."
394
  gen_figs = [self.create_placeholder_plot("Error", f"Dati non validi {i}") for i in range(len(PLOT_CONFIGS))]
395
  new_summaries_for_chatbot = {}
 
396
  # --- FIX ENDS HERE ---
397
 
398
  all_updates = []
 
400
  all_updates.append(status_msg) # For self.analytics_status_md
401
 
402
  # 2. Plot components
 
403
  if isinstance(gen_figs, list) and len(gen_figs) == len(PLOT_CONFIGS):
404
  all_updates.extend(gen_figs)
405
  else:
406
  logging.error(f"Mismatch in generated figures ({len(gen_figs) if isinstance(gen_figs, list) else 'N/A'}) and plot_configs ({len(PLOT_CONFIGS)})")
 
407
  all_updates.extend([self.create_placeholder_plot("Error", f"Figura mancante {i}") for i in range(len(PLOT_CONFIGS))])
408
 
409
  # 3. UI Resets for Action Panel (9 components)