Spaces:
Sleeping
Sleeping
File size: 1,550 Bytes
4b022af |
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 |
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"})
|