LinkedinMonitor / ui /insights_ui_generator.py
GuglielmoTor's picture
Update ui/insights_ui_generator.py
0d20f23 verified
raw
history blame
3.44 kB
import logging
from typing import Dict, Any, List, Optional
import pandas as pd
# Configure logger for this module. Assumes logging is configured in app.py or main entry point.
logger = logging.getLogger(__name__)
def format_report_for_display(report_data: Optional[pd.Series]) -> Dict[str, str]:
"""
Enhanced report formatting. Returns a dictionary with separate HTML for the header
and Markdown for the report body, allowing flexible rendering.
Args:
report_data: A pandas Series representing a single row from the agentic analysis DataFrame.
It should contain 'report_text', 'report_type', and 'Created Date'.
Returns:
A dictionary with 'header_html' and 'body_markdown' keys.
'header_html' contains the HTML for the report title and subtitle.
'body_markdown' contains the raw Markdown text for the report body.
If data is invalid, it returns empty state HTML for both.
"""
if report_data is None or report_data.empty:
empty_state_html = """
<div class="empty-state">
<div class="empty-state-icon">πŸ“„</div>
<div class="empty-state-title">Report Not Available</div>
<div class="empty-state-description">
The selected report could not be loaded. Please try selecting a different report
or refresh the page.
</div>
</div>
"""
return {'header_html': '', 'body_markdown': empty_state_html}
# Extract report data
# Ensure 'report_text' is treated as raw text that will be interpreted as Markdown
report_text = report_data.get('report_text', '*Report content not found.*')
report_type = report_data.get('report_type')
created_date_str = report_data.get('Created Date')
# Generate dynamic title and subtitle
title = "Comprehensive Analysis Report"
subtitle = ""
try:
if report_type == 'Quarter':
title = "πŸ“ˆ Quarterly Insights Report"
subtitle = "Strategic analysis of your quarterly performance"
elif report_type == 'Week' and pd.notna(created_date_str):
# Ensure pandas is used for datetime conversion
created_date = pd.to_datetime(created_date_str)
day_name = created_date.strftime('%A')
title = f"πŸ“Š {day_name}'s Weekly Update"
subtitle = f"Weekly performance analysis for {created_date.strftime('%B %d, %Y')}"
except Exception as e:
logger.error(f"Error generating dynamic report title: {e}")
# In case of an error, default title and no subtitle will be used.
# Format the report header HTML
header_html = f"""
<div class="report-header-content">
<h1>{title}</h1>
{f'<p style="font-size: 1.1rem; color: #6b6b6b; margin-bottom: 0;">{subtitle}</p>' if subtitle else ''}
</div>
"""
# The report_text itself should be the raw Markdown for the body
body_markdown = report_text.strip()
return {'header_html': header_html, 'body_markdown': body_markdown}
# The following functions (extract_key_results_for_selection, format_single_okr_for_display)
# are no longer needed as their functionality is now handled by the new `ui/okr_ui_generator.py`
# which directly formats the full OKR structure into HTML.
# The 'format_report_to_markdown' function was also removed as it was redundant and not used.