Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
33 changes: 22 additions & 11 deletions backend/app/services/summary/report_summary_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,28 @@ def generate_scores(self, data: Dict[str, Any]) -> Dict[str, float]:

return scores

def build_final_summary(self, nlg_outputs: Dict[str, str], scores: Dict[str, float]) -> str:
summary_parts = []
summary_parts.append("--- Comprehensive Report Summary ---")

def build_final_summary(self, nlg_outputs: Dict[str, str], scores: Dict[str, float]) -> Dict[str, Any]:
overall_summary_parts = []
for agent, output in nlg_outputs.items():
summary_parts.append(f"\n{agent.replace('_', ' ').title()} Insights:")
summary_parts.append(output)
overall_summary_parts.append(f"{agent.replace('_', ' ').title()} Insights: {output}")
overall_summary = "\n\n".join(overall_summary_parts)

weaknesses = [
score_name.replace('_', ' ').title()
for score_name, score_value in scores.items()
if score_value < 5.0
]

summary_parts.append("\n--- Overall Scores (out of 10) ---")
for score_name, score_value in scores.items():
summary_parts.append(f"{score_name.replace('_', ' ').title()}: {score_value:.2f}/10")
strengths = [
score_name.replace('_', ' ').title()
for score_name, score_value in scores.items()
if score_value >= 7.0
]

summary_parts.append("\n--- End of Report ---")
return "\n".join(summary_parts)
final_summary = {
"overall_summary": overall_summary,
"scores": {score_name.replace('_', ' ').title(): round(score_value, 2) for score_name, score_value in scores.items()},
"weaknesses": weaknesses,
"strengths": strengths,
}
return final_summary
Binary file not shown.
42 changes: 32 additions & 10 deletions backend/app/services/summary/tests/test_report_summary_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,41 @@ def test_build_final_summary(summary_engine):
nlg_outputs = {
"tokenomics": "Tokenomics insights text.",
"social_sentiment": "Social sentiment insights text.",
"code_audit": "Code audit insights text.",
}
scores = {
"tokenomics_strength": 7.5,
"sentiment_health": 8.2,
"sentiment_health": 4.2,
"code_maturity": 8.9,
"audit_confidence": 3.0,
}
summary = summary_engine.build_final_summary(nlg_outputs, scores)

assert "--- Comprehensive Report Summary ---" in summary
assert "Tokenomics Insights:" in summary
assert "Tokenomics insights text." in summary
assert "Social Sentiment Insights:" in summary
assert "Social sentiment insights text." in summary
assert "--- Overall Scores (out of 10) ---" in summary
assert "Tokenomics Strength: 7.50/10" in summary
assert "Sentiment Health: 8.20/10" in summary
assert "--- End of Report ---" in summary
assert isinstance(summary, dict)
assert "overall_summary" in summary
assert "scores" in summary
assert "weaknesses" in summary
assert "strengths" in summary

# Verify overall_summary content
assert "Tokenomics Insights: Tokenomics insights text." in summary["overall_summary"]
assert "Social Sentiment Insights: Social sentiment insights text." in summary["overall_summary"]
assert "Code Audit Insights: Code audit insights text." in summary["overall_summary"]

# Verify scores content
assert summary["scores"] == {
"Tokenomics Strength": 7.5,
"Sentiment Health": 4.2,
"Code Maturity": 8.9,
"Audit Confidence": 3.0,
}

# Verify weaknesses
assert "Sentiment Health" in summary["weaknesses"]
assert "Audit Confidence" in summary["weaknesses"]
assert len(summary["weaknesses"]) == 2

# Verify strengths
assert "Tokenomics Strength" in summary["strengths"]
assert "Code Maturity" in summary["strengths"]
assert len(summary["strengths"]) == 2