GuglielmoTor commited on
Commit
db9e84a
·
verified ·
1 Parent(s): b30e5c5

Update services/analytics_handlers.py

Browse files
Files changed (1) hide show
  1. services/analytics_handlers.py +22 -10
services/analytics_handlers.py CHANGED
@@ -99,7 +99,7 @@ class AnalyticsHandlers:
99
  ):
100
  logging.info(f"Refreshing analytics graph UI. Filter: {date_filter_val}. Token set: {'yes' if current_token_state_val.get('token') else 'no'}")
101
  start_time = time.time()
102
-
103
  # Call the function that generates plot figures and summaries
104
  # Ensure update_analytics_plots_figures is adapted to return:
105
  # status_msg (str), figures_dict (dict: {plot_id: fig}), summaries_dict (dict: {plot_id: summary_text})
@@ -112,22 +112,34 @@ class AnalyticsHandlers:
112
  )
113
  # Expected: status_msg, list_of_figures, dict_of_plot_summaries
114
  # Original: status_msg, gen_figs (list), new_summaries (dict)
115
-
116
  status_msg = plot_gen_results[0]
117
- gen_figs_list = plot_gen_results[1] # This should be a list of figures in order of plot_configs
118
  new_summaries_dict = plot_gen_results[2] # This should be a dict {plot_id: summary}
119
-
 
 
 
 
 
 
 
 
120
  all_updates = [gr.update(value=status_msg)] # For analytics_status_md
121
-
122
  # Update plot components with new figures
123
  if len(gen_figs_list) == len(self.plot_configs):
124
  for fig in gen_figs_list:
125
  all_updates.append(fig) # fig itself is the update for gr.Plot
126
  else:
127
  logging.error(f"Figure list length mismatch: got {len(gen_figs_list)}, expected {len(self.plot_configs)}")
128
- for _ in self.plot_configs:
129
- all_updates.append(create_placeholder_plot("Error", "Figura mancante"))
130
-
 
 
 
 
131
  # Reset action panel UI elements
132
  all_updates.extend([
133
  gr.update(visible=False), # global_actions_column_ui
@@ -159,7 +171,7 @@ class AnalyticsHandlers:
159
  ])
160
 
161
  all_updates.append(None) # explored_plot_id_state (reset)
162
-
163
  # Reset section title visibility
164
  for _ in self.unique_ordered_sections:
165
  all_updates.append(gr.update(visible=True))
@@ -173,7 +185,7 @@ class AnalyticsHandlers:
173
  logging.error(f"Output length mismatch in refresh_analytics_graphs_ui. Got {len(all_updates)}, expected {expected_len}")
174
  # Pad with gr.update() if lengths don't match, to avoid Gradio errors, though this indicates a logic flaw.
175
  all_updates.extend([gr.update()] * (expected_len - len(all_updates)))
176
-
177
  return tuple(all_updates)
178
 
179
  def _get_action_panel_outputs_list(self):
 
99
  ):
100
  logging.info(f"Refreshing analytics graph UI. Filter: {date_filter_val}. Token set: {'yes' if current_token_state_val.get('token') else 'no'}")
101
  start_time = time.time()
102
+
103
  # Call the function that generates plot figures and summaries
104
  # Ensure update_analytics_plots_figures is adapted to return:
105
  # status_msg (str), figures_dict (dict: {plot_id: fig}), summaries_dict (dict: {plot_id: summary_text})
 
112
  )
113
  # Expected: status_msg, list_of_figures, dict_of_plot_summaries
114
  # Original: status_msg, gen_figs (list), new_summaries (dict)
115
+
116
  status_msg = plot_gen_results[0]
117
+ gen_figs_result = plot_gen_results[1] # This might be a single figure or a list
118
  new_summaries_dict = plot_gen_results[2] # This should be a dict {plot_id: summary}
119
+
120
+ # Handle the case where gen_figs_result might be a single figure or a list
121
+ if isinstance(gen_figs_result, list):
122
+ gen_figs_list = gen_figs_result
123
+ else:
124
+ # If it's a single figure, wrap it in a list
125
+ gen_figs_list = [gen_figs_result]
126
+ logging.warning(f"Expected list of figures but got single figure of type {type(gen_figs_result)}")
127
+
128
  all_updates = [gr.update(value=status_msg)] # For analytics_status_md
129
+
130
  # Update plot components with new figures
131
  if len(gen_figs_list) == len(self.plot_configs):
132
  for fig in gen_figs_list:
133
  all_updates.append(fig) # fig itself is the update for gr.Plot
134
  else:
135
  logging.error(f"Figure list length mismatch: got {len(gen_figs_list)}, expected {len(self.plot_configs)}")
136
+ # If we have fewer figures than expected, pad with placeholders
137
+ for i in range(len(self.plot_configs)):
138
+ if i < len(gen_figs_list):
139
+ all_updates.append(gen_figs_list[i])
140
+ else:
141
+ all_updates.append(create_placeholder_plot("Error", "Figura mancante"))
142
+
143
  # Reset action panel UI elements
144
  all_updates.extend([
145
  gr.update(visible=False), # global_actions_column_ui
 
171
  ])
172
 
173
  all_updates.append(None) # explored_plot_id_state (reset)
174
+
175
  # Reset section title visibility
176
  for _ in self.unique_ordered_sections:
177
  all_updates.append(gr.update(visible=True))
 
185
  logging.error(f"Output length mismatch in refresh_analytics_graphs_ui. Got {len(all_updates)}, expected {expected_len}")
186
  # Pad with gr.update() if lengths don't match, to avoid Gradio errors, though this indicates a logic flaw.
187
  all_updates.extend([gr.update()] * (expected_len - len(all_updates)))
188
+
189
  return tuple(all_updates)
190
 
191
  def _get_action_panel_outputs_list(self):