feat: Enhance compatibility scoring and report generation with new methods and models
This commit is contained in:
@@ -4,6 +4,10 @@ from typing import Any, Dict, List, Optional
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
from playwright.async_api import async_playwright
|
||||
|
||||
# Import database models and compatibility score service
|
||||
from db.models import InvestorTable, ProjectTable
|
||||
from services.compatibility_score import calculate_project_investor_compatibility
|
||||
|
||||
|
||||
class ReportGenerator:
|
||||
"""Service for generating PDF reports from HTML templates"""
|
||||
@@ -17,6 +21,8 @@ class ReportGenerator:
|
||||
self,
|
||||
investor_data: Dict[str, Any],
|
||||
project_data: Optional[Dict[str, Any]] = None,
|
||||
investor_model: Optional[InvestorTable] = None,
|
||||
project_model: Optional[ProjectTable] = None,
|
||||
) -> bytes:
|
||||
"""
|
||||
Generate a PDF report for an investor profile.
|
||||
@@ -24,12 +30,16 @@ class ReportGenerator:
|
||||
Args:
|
||||
investor_data: Dictionary containing investor information
|
||||
project_data: Optional dictionary containing project information for compatibility analysis
|
||||
investor_model: Optional database model for investor (used for compatibility scoring)
|
||||
project_model: Optional database model for project (used for compatibility scoring)
|
||||
|
||||
Returns:
|
||||
bytes: PDF file content
|
||||
"""
|
||||
# Prepare template context
|
||||
context = self._prepare_context(investor_data, project_data)
|
||||
context = self._prepare_context(
|
||||
investor_data, project_data, investor_model, project_model
|
||||
)
|
||||
|
||||
# Render HTML from template
|
||||
template = self.env.get_template("report.html")
|
||||
@@ -43,6 +53,8 @@ class ReportGenerator:
|
||||
self,
|
||||
investor_data: Dict[str, Any],
|
||||
project_data: Optional[Dict[str, Any]] = None,
|
||||
investor_model: Optional[InvestorTable] = None,
|
||||
project_model: Optional[ProjectTable] = None,
|
||||
) -> Dict[str, Any]:
|
||||
"""Prepare the context dictionary for template rendering"""
|
||||
context = {
|
||||
@@ -55,9 +67,20 @@ class ReportGenerator:
|
||||
|
||||
# If project data is provided, calculate compatibility
|
||||
if project_data:
|
||||
context["compatibility_score"] = self._calculate_compatibility_score(
|
||||
investor_data, project_data
|
||||
)
|
||||
# Use the compatibility_score service if models are provided
|
||||
if investor_model and project_model:
|
||||
# Calculate using the standardized compatibility score service
|
||||
# Returns score between 0 and 1, convert to percentage (0-100)
|
||||
score_decimal = calculate_project_investor_compatibility(
|
||||
project=project_model, investor=investor_model, use_funds=True
|
||||
)
|
||||
context["compatibility_score"] = int(score_decimal * 100)
|
||||
else:
|
||||
# Fallback to old calculation method if models not provided
|
||||
context["compatibility_score"] = self._calculate_compatibility_score(
|
||||
investor_data, project_data
|
||||
)
|
||||
|
||||
context["match_criteria"] = self._generate_match_criteria(
|
||||
investor_data, project_data
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user