Spaces:
Running
Running
File size: 3,977 Bytes
1c7993b 77b3a80 1c7993b 77b3a80 6cbd816 77b3a80 6cbd816 77b3a80 6cbd816 527fc2f f67d3fd 527fc2f 6cbd816 527fc2f 6cbd816 be899f5 77b3a80 527fc2f 77b3a80 527fc2f f67d3fd 77b3a80 527fc2f 77b3a80 527fc2f 77b3a80 527fc2f 77b3a80 527fc2f 6cbd816 527fc2f f67d3fd 6cbd816 f67d3fd 6cbd816 77b3a80 f67d3fd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
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}
def format_report_to_markdown(report_string: Optional[str]) -> str:
"""
This function was previously for general Markdown formatting.
Given the new structure where 'format_report_for_display' handles the split,
this function might become redundant or repurposed.
Keeping it for now but noting its potential redundancy depending on upstream calls.
"""
if not report_string or not report_string.strip():
return "## Comprehensive Analysis Report\n\n*No analysis report was generated, or an error occurred during its generation.*"
# Simple formatting for now. Could be enhanced (e.g., looking for patterns like "Section X:" to make them H3)
formatted_report = f"## Comprehensive Analysis Report\n\n{report_string.strip()}"
return formatted_report
# REMOVED: extract_key_results_for_selection function
# REMOVED: format_single_okr_for_display function
|