Spaces:
Running
Running
Update ui/analytics_plot_generator.py
Browse files
ui/analytics_plot_generator.py
CHANGED
|
@@ -341,8 +341,8 @@ def generate_content_topic_breakdown_plot(df, topics_col='li_eb_labels', **kwarg
|
|
| 341 |
|
| 342 |
def generate_impressions_lineplot_component_data(df, post_details_map_ref):
|
| 343 |
"""
|
| 344 |
-
Generates a DataFrame for the Gradio LinePlot
|
| 345 |
-
|
| 346 |
"""
|
| 347 |
plot_df, post_map = generate_impressions_scatter_plot_data(
|
| 348 |
df,
|
|
@@ -357,11 +357,21 @@ def generate_impressions_lineplot_component_data(df, post_details_map_ref):
|
|
| 357 |
# If the df is empty, return an empty one to clear the plot while preserving the component type
|
| 358 |
if plot_df.empty:
|
| 359 |
logging.info("Returning an empty DataFrame to clear the line plot.")
|
| 360 |
-
|
|
|
|
| 361 |
|
| 362 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 363 |
|
| 364 |
-
# Return the DataFrame itself, not a gr.update() object
|
| 365 |
return plot_df
|
| 366 |
|
| 367 |
def update_analytics_plots_figures(token_state_value, date_filter_option, custom_start_date, custom_end_date, current_plot_configs):
|
|
|
|
| 341 |
|
| 342 |
def generate_impressions_lineplot_component_data(df, post_details_map_ref):
|
| 343 |
"""
|
| 344 |
+
Generates a DataFrame for the Gradio LinePlot, updates the post details map,
|
| 345 |
+
and formats columns for a rich tooltip.
|
| 346 |
"""
|
| 347 |
plot_df, post_map = generate_impressions_scatter_plot_data(
|
| 348 |
df,
|
|
|
|
| 357 |
# If the df is empty, return an empty one to clear the plot while preserving the component type
|
| 358 |
if plot_df.empty:
|
| 359 |
logging.info("Returning an empty DataFrame to clear the line plot.")
|
| 360 |
+
# Return all columns the component expects to avoid errors
|
| 361 |
+
return pd.DataFrame(columns=['date', 'impressions', 'label', 'tooltip_date', 'tooltip_impressions'])
|
| 362 |
|
| 363 |
+
# Format data for a better tooltip
|
| 364 |
+
# Ensure 'date' is datetime for correct plotting
|
| 365 |
+
plot_df['date'] = pd.to_datetime(plot_df['date'])
|
| 366 |
+
|
| 367 |
+
# Create a formatted date string for the tooltip
|
| 368 |
+
plot_df['tooltip_date'] = plot_df['date'].dt.strftime('%B %d, %Y')
|
| 369 |
+
|
| 370 |
+
# Create a formatted impressions string for the tooltip
|
| 371 |
+
plot_df['tooltip_impressions'] = 'Impressions: ' + plot_df['impressions'].astype(str)
|
| 372 |
+
|
| 373 |
+
logging.info(f"Generated LinePlot data with {len(plot_df)} points and formatted tooltip.")
|
| 374 |
|
|
|
|
| 375 |
return plot_df
|
| 376 |
|
| 377 |
def update_analytics_plots_figures(token_state_value, date_filter_option, custom_start_date, custom_end_date, current_plot_configs):
|