Rivalcoder
Add Files
4b022af
raw
history blame
1.55 kB
from typing import List, Tuple
from app.schemas import AnalyzedClause, RiskFinding
# Risk definitions as specified in the requirements
RISK_DEFINITIONS = {
"UNLIMITED_LIABILITY": {"score": 10, "description": "Clause imposes unlimited liability on the client."},
"ONE_SIDED_TERMINATION": {"score": 8, "description": "Termination rights are unfairly one-sided."},
"UNCLEAR_JURISDICTION": {"score": 6, "description": "Governing law or jurisdiction for disputes is ambiguous."},
"DPDP_NON_COMPLIANCE": {"score": 7, "description": "Data protection clause may not comply with the DPDP Act 2023."}
}
def calculate_scores(analyzed_clauses: List[AnalyzedClause]) -> Tuple[int, List[RiskFinding]]:
"""
Calculate the total risk score and return detailed findings.
Args:
analyzed_clauses: List of analyzed clauses with identified risks
Returns:
Tuple of (final_risk_score, all_findings)
"""
total_score = 0
all_findings = []
for clause in analyzed_clauses:
for risk in clause.risks:
# Add the risk finding to our collection
all_findings.append(risk)
# Add the score to our total
total_score += risk.score
return total_score, all_findings
def get_risk_definition(risk_id: str) -> dict:
"""
Get risk definition by ID.
Args:
risk_id: The risk identifier
Returns:
Dictionary with score and description
"""
return RISK_DEFINITIONS.get(risk_id, {"score": 0, "description": "Unknown risk"})