-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathdata_structures.py
More file actions
162 lines (145 loc) · 7.13 KB
/
Copy pathdata_structures.py
File metadata and controls
162 lines (145 loc) · 7.13 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
from dataclasses import dataclass
from typing import Dict, List, Any, Optional
from datetime import datetime
import json
@dataclass
class AnalysisResult:
"""Structured analysis result with confidence scoring"""
content: Dict[str, Any]
confidence_score: float
timestamp: datetime
metadata: Dict[str, Any]
def to_dict(self) -> Dict:
"""Convert to dictionary format"""
return {
"content": self.content,
"confidence_score": self.confidence_score,
"timestamp": self.timestamp.isoformat(),
"metadata": self.metadata
}
@classmethod
def from_dict(cls, data: Dict) -> 'AnalysisResult':
"""Create from dictionary format"""
return cls(
content=data["content"],
confidence_score=data["confidence_score"],
timestamp=datetime.fromisoformat(data["timestamp"]),
metadata=data["metadata"]
)
@dataclass
class TaskAnalysisReport:
"""Final task analysis report combining all expert analyses"""
dataset_analysis: AnalysisResult
problem_investigation: AnalysisResult
baseline_assessment: AnalysisResult
refinement_comments: List[Dict[str, Any]]
final_recommendations: Dict[str, Any]
timestamp: datetime
def to_dict(self) -> Dict:
"""Convert to dictionary format"""
return {
"dataset_analysis": self.dataset_analysis.to_dict(),
"problem_investigation": self.problem_investigation.to_dict(),
"baseline_assessment": self.baseline_assessment.to_dict(),
"refinement_comments": self.refinement_comments,
"final_recommendations": self.final_recommendations,
"timestamp": self.timestamp.isoformat()
}
@classmethod
def from_dict(cls, data: Dict) -> 'TaskAnalysisReport':
"""Create from dictionary format"""
return cls(
dataset_analysis=AnalysisResult.from_dict(data["dataset_analysis"]),
problem_investigation=AnalysisResult.from_dict(data["problem_investigation"]),
baseline_assessment=AnalysisResult.from_dict(data["baseline_assessment"]),
refinement_comments=data["refinement_comments"],
final_recommendations=data["final_recommendations"],
timestamp=datetime.fromisoformat(data["timestamp"])
)
def to_markdown(self) -> str:
"""Convert to markdown format with enhanced structure and formatting"""
sections = [
"# Task Analysis Report",
f"Generated on: {self.timestamp.strftime('%Y-%m-%d %H:%M:%S')}\n",
"## 1. Dataset Analysis",
"### Experimental Design & Scale",
self._format_section(self.dataset_analysis.content.get("experimental_design", {})),
"\n### Data Characteristics",
self._format_section(self.dataset_analysis.content.get("data_characteristics", {})),
"\n### Preprocessing Considerations",
self._format_section(self.dataset_analysis.content.get("preprocessing", {})),
"\n### Quality Assessment",
self._format_section(self.dataset_analysis.content.get("quality_assessment", {})),
"\n## 2. Problem Investigation",
"### Formal Definition",
self._format_section(self.problem_investigation.content.get("formal_definition", {})),
"\n### Key Challenges",
self._format_section(self.problem_investigation.content.get("key_challenges", {})),
"\n### Research Questions",
self._format_section(self.problem_investigation.content.get("research_questions", {})),
"\n### Analysis Methods",
self._format_section(self.problem_investigation.content.get("analysis_methods", {})),
"\n## 3. Baseline Assessment",
"### Baseline Models Analysis",
self._format_section(self.baseline_assessment.content.get("baseline_models", {})),
"\n### Evaluation Framework",
self._format_section(self.baseline_assessment.content.get("evaluation_framework", {})),
"\n### Performance Analysis",
self._format_section(self.baseline_assessment.content.get("performance_analysis", {})),
"\n### Improvement Suggestions",
self._format_section(self.baseline_assessment.content.get("improvement_suggestions", {})),
"\n## 4. Refinement Process",
*[f"\n### Round {i+1}\n" + self._format_refinement_round(comment)
for i, comment in enumerate(self.refinement_comments)],
"\n## 5. Final Recommendations",
"### Data Processing Pipeline",
self._format_section(self.final_recommendations.get("data_processing", {})),
"\n### Model Architecture",
self._format_section(self.final_recommendations.get("model_architecture", {})),
"\n### Training Strategy",
self._format_section(self.final_recommendations.get("training_strategy", {})),
"\n### Evaluation Protocol",
self._format_section(self.final_recommendations.get("evaluation_protocol", {})),
"\n### Implementation Roadmap",
self._format_section(self.final_recommendations.get("implementation_roadmap", {}))
]
return "\n".join(sections)
def _format_section(self, content: Dict[str, Any]) -> str:
"""Format a section with proper markdown structure"""
if not content:
return ""
formatted_lines = []
for key, value in content.items():
if isinstance(value, list):
formatted_lines.append(f"\n#### {key.title()}")
for item in value:
formatted_lines.append(f"- {item}")
elif isinstance(value, dict):
formatted_lines.append(f"\n#### {key.title()}")
for subkey, subvalue in value.items():
if isinstance(subvalue, list):
formatted_lines.append(f"\n**{subkey.title()}**:")
for item in subvalue:
formatted_lines.append(f"- {item}")
else:
formatted_lines.append(f"\n**{subkey.title()}**: {subvalue}")
else:
formatted_lines.append(f"\n**{key.title()}**: {value}")
return "\n".join(formatted_lines)
def _format_refinement_round(self, comment: Dict[str, Any]) -> str:
"""Format a refinement round with proper structure"""
sections = []
for analysis_type, feedback in comment.items():
sections.append(f"\n#### {analysis_type.replace('_', ' ').title()}")
for category, items in feedback.items():
sections.append(f"\n**{category.title()}**:")
if isinstance(items, list):
for item in items:
sections.append(f"- {item}")
else:
sections.append(f"- {items}")
return "\n".join(sections)
def save_report(self, filepath: str):
"""Save report to markdown file"""
with open(filepath, "w", encoding="utf-8") as f:
f.write(self.to_markdown())