feat: Enhance compatibility scoring and report generation with new methods and models
This commit is contained in:
+22
-11
@@ -12,7 +12,11 @@ from schemas.router_schemas import (
|
||||
PaginatedResponse,
|
||||
SectorMinimal,
|
||||
)
|
||||
from services.compatibility_score import calculate_project_investor_compatibility
|
||||
from services.compatibility_score import (
|
||||
calculate_project_investor_compatibility,
|
||||
_calculate_project_fund_compatibility,
|
||||
_calculate_project_investor_direct_compatibility,
|
||||
)
|
||||
from sqlalchemy.orm import Session, selectinload
|
||||
|
||||
router = APIRouter(tags=["Investor Routes"])
|
||||
@@ -95,13 +99,6 @@ def read_investors(
|
||||
# Transform to InvestmentResponse format (one row per investor-fund combination)
|
||||
investment_responses = []
|
||||
for investor in investors:
|
||||
# Calculate compatibility score if project provided
|
||||
compatibility_score = 1.0
|
||||
if project is not None:
|
||||
compatibility_score = calculate_project_investor_compatibility(
|
||||
project=project, investor=investor, use_funds=True
|
||||
)
|
||||
|
||||
# Get top 3 portfolio companies (id and name only)
|
||||
portfolio_companies = [
|
||||
CompanyMinimal(id=company.id, name=company.name)
|
||||
@@ -111,6 +108,13 @@ def read_investors(
|
||||
# If investor has funds, create one entry per fund
|
||||
if investor.funds:
|
||||
for fund in investor.funds:
|
||||
# Calculate compatibility score for this specific fund
|
||||
compatibility_score = 1.0
|
||||
if project is not None:
|
||||
compatibility_score = _calculate_project_fund_compatibility(
|
||||
project=project, fund=fund
|
||||
)
|
||||
|
||||
# Get stage focus as comma-separated string
|
||||
stage_focus = (
|
||||
", ".join([stage.name for stage in fund.investment_stages])
|
||||
@@ -141,6 +145,13 @@ def read_investors(
|
||||
investment_responses.append(investment_response)
|
||||
else:
|
||||
# If no funds, create one entry with null fund fields
|
||||
# Calculate compatibility using investor-level data
|
||||
compatibility_score = 1.0
|
||||
if project is not None:
|
||||
compatibility_score = _calculate_project_investor_direct_compatibility(
|
||||
project=project, investor=investor
|
||||
)
|
||||
|
||||
investment_response = InvestmentResponse(
|
||||
id=investor.id,
|
||||
name=investor.name,
|
||||
@@ -255,11 +266,11 @@ def filter_investors(
|
||||
for fund in funds:
|
||||
investor = fund.investor
|
||||
|
||||
# Calculate compatibility score if project provided
|
||||
# Calculate compatibility score for this specific fund
|
||||
compatibility_score = 1.0
|
||||
if project is not None:
|
||||
compatibility_score = calculate_project_investor_compatibility(
|
||||
project=project, investor=investor, use_funds=True
|
||||
compatibility_score = _calculate_project_fund_compatibility(
|
||||
project=project, fund=fund
|
||||
)
|
||||
|
||||
# Get top 3 portfolio companies (id and name only)
|
||||
|
||||
@@ -106,7 +106,7 @@ async def generate_investor_report(
|
||||
# Generate PDF report
|
||||
report_generator = ReportGenerator()
|
||||
pdf_bytes = await report_generator.generate_investor_report(
|
||||
investor_data, project_data
|
||||
investor_data, project_data, investor_model=investor, project_model=project
|
||||
)
|
||||
|
||||
# Return PDF as downloadable file
|
||||
|
||||
Reference in New Issue
Block a user