GuglielmoTor commited on
Commit
77b3a80
·
verified ·
1 Parent(s): 95bff88

Update ui/insights_ui_generator.py

Browse files
Files changed (1) hide show
  1. ui/insights_ui_generator.py +42 -4
ui/insights_ui_generator.py CHANGED
@@ -1,10 +1,49 @@
1
- # insights_ui_generator.py
2
  import logging
3
  from typing import Dict, Any, List, Optional
 
4
 
5
  # Configure logger for this module. Assumes logging is configured in app.py or main entry point.
6
  logger = logging.getLogger(__name__)
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  def format_report_to_markdown(report_string: Optional[str]) -> str:
9
  """
10
  Formats the comprehensive analysis report string into a displayable Markdown format.
@@ -37,8 +76,8 @@ def extract_key_results_for_selection(
37
 
38
  Args:
39
  actionable_okrs_and_tasks_dict: The dictionary representation of TaskExtractionOutput,
40
- typically `orchestration_results["actionable_okrs_and_tasks"]`.
41
- Expected structure: {'okrs': List[OKR_dict], ...}
42
 
43
  Returns:
44
  A list of dictionaries, where each dictionary represents a Key Result:
@@ -198,4 +237,3 @@ def format_single_okr_for_display(
198
  md_parts.append("\n*No Key Results matching the 'accepted' filter for this objective.*")
199
 
200
  return "\n".join(md_parts)
201
-
 
 
1
  import logging
2
  from typing import Dict, Any, List, Optional
3
+ import pandas as pd
4
 
5
  # Configure logger for this module. Assumes logging is configured in app.py or main entry point.
6
  logger = logging.getLogger(__name__)
7
 
8
+
9
+ def format_report_for_display(report_data: Optional[pd.Series]) -> str:
10
+ """
11
+ Generates a complete Markdown string for a single report, including a dynamic title
12
+ based on the report's type and creation date.
13
+
14
+ Args:
15
+ report_data: A pandas Series representing a single row from the agentic analysis DataFrame.
16
+ It should contain 'comprehensive_analysis_text', 'report_type', and 'Created Date'.
17
+
18
+ Returns:
19
+ A Markdown formatted string for the report.
20
+ """
21
+ if report_data is None or report_data.empty:
22
+ return "## Report Details\n\n*Please select a report from the library to view its contents.*"
23
+
24
+ # Assuming the main report text is in a column named 'comprehensive_analysis_text'
25
+ # You may need to adjust this column name based on your Bubble.io data structure.
26
+ report_text = report_data.get('comprehensive_analysis_text', '*Report content not found.*')
27
+ report_type = report_data.get('report_type')
28
+ created_date_str = report_data.get('Created Date') # Bubble's default field name
29
+
30
+ title = "Comprehensive Analysis Report" # Default title
31
+
32
+ try:
33
+ if report_type == 'Quarte': # As per your request for "Quarter" type
34
+ title = "Quarterly Insights Report"
35
+ elif report_type == 'Week' and pd.notna(created_date_str):
36
+ # Bubble dates are typically in ISO format, e.g., '2024-06-11T14:30:00.000Z'
37
+ created_date = pd.to_datetime(created_date_str)
38
+ day_name = created_date.strftime('%A') # e.g., 'Tuesday'
39
+ title = f"{day_name}'s Weekly Update Report"
40
+ except Exception as e:
41
+ logger.error(f"Error generating dynamic report title: {e}")
42
+ # In case of an error, the default title will be used.
43
+
44
+ return f"## {title}\n\n{report_text.strip()}"
45
+
46
+
47
  def format_report_to_markdown(report_string: Optional[str]) -> str:
48
  """
49
  Formats the comprehensive analysis report string into a displayable Markdown format.
 
76
 
77
  Args:
78
  actionable_okrs_and_tasks_dict: The dictionary representation of TaskExtractionOutput,
79
+ typically `orchestration_results["actionable_okrs_and_tasks"]`.
80
+ Expected structure: {'okrs': List[OKR_dict], ...}
81
 
82
  Returns:
83
  A list of dictionaries, where each dictionary represents a Key Result:
 
237
  md_parts.append("\n*No Key Results matching the 'accepted' filter for this objective.*")
238
 
239
  return "\n".join(md_parts)