Spaces:
Paused
Paused
Upload core/clean_architecture.py with huggingface_hub
Browse files- core/clean_architecture.py +34 -11
core/clean_architecture.py
CHANGED
|
@@ -300,7 +300,9 @@ class AnalyzeFraudUseCase:
|
|
| 300 |
analysis_results.append(result)
|
| 301 |
|
| 302 |
# Overall case analysis
|
| 303 |
-
case_analysis = await self.fraud_detection_service.analyze_case_pattern(
|
|
|
|
|
|
|
| 304 |
|
| 305 |
# Audit the analysis
|
| 306 |
await self.audit_service.log_action(
|
|
@@ -310,7 +312,9 @@ class AnalyzeFraudUseCase:
|
|
| 310 |
resource_id=case_id,
|
| 311 |
details={
|
| 312 |
"transaction_count": len(transactions),
|
| 313 |
-
"fraud_indicators": len(
|
|
|
|
|
|
|
| 314 |
},
|
| 315 |
)
|
| 316 |
|
|
@@ -390,7 +394,10 @@ class MockFraudDetectionService(FraudDetectionServicePort):
|
|
| 390 |
|
| 391 |
async def analyze_transaction(self, transaction: Transaction) -> dict[str, Any]:
|
| 392 |
# Simple mock analysis
|
| 393 |
-
is_fraudulent =
|
|
|
|
|
|
|
|
|
|
| 394 |
|
| 395 |
return {
|
| 396 |
"transaction_id": transaction.id,
|
|
@@ -448,18 +455,28 @@ class FraudInvestigationApplicationService:
|
|
| 448 |
notification_service: NotificationServicePort,
|
| 449 |
audit_service: AuditServicePort,
|
| 450 |
):
|
| 451 |
-
self.create_case_use_case = CreateFraudCaseUseCase(
|
| 452 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 453 |
|
| 454 |
-
async def create_investigation_case(
|
|
|
|
|
|
|
| 455 |
"""Create a new fraud investigation case"""
|
| 456 |
return await self.create_case_use_case.execute(case_data, created_by)
|
| 457 |
|
| 458 |
-
async def perform_fraud_analysis(
|
|
|
|
|
|
|
| 459 |
"""Perform comprehensive fraud analysis on a case"""
|
| 460 |
return await self.analyze_fraud_use_case.execute(case_id, analyzed_by)
|
| 461 |
|
| 462 |
-
async def assign_investigator(
|
|
|
|
|
|
|
| 463 |
"""Assign an investigator to a case"""
|
| 464 |
case = await self.create_case_use_case.fraud_case_repo.find_by_id(case_id)
|
| 465 |
if case:
|
|
@@ -543,7 +560,9 @@ class CleanArchitectureCompositionRoot:
|
|
| 543 |
for tx in sample_transactions:
|
| 544 |
await self.transaction_repo.save(tx)
|
| 545 |
|
| 546 |
-
logger.info(
|
|
|
|
|
|
|
| 547 |
|
| 548 |
async def demonstrate_clean_architecture(self) -> dict[str, Any]:
|
| 549 |
"""Demonstrate Clean Architecture capabilities"""
|
|
@@ -564,10 +583,14 @@ class CleanArchitectureCompositionRoot:
|
|
| 564 |
)
|
| 565 |
|
| 566 |
# Assign investigator
|
| 567 |
-
await self.application_service.assign_investigator(
|
|
|
|
|
|
|
| 568 |
|
| 569 |
# Perform fraud analysis
|
| 570 |
-
analysis_result = await self.application_service.perform_fraud_analysis(
|
|
|
|
|
|
|
| 571 |
|
| 572 |
return {
|
| 573 |
"new_case_created": new_case.id,
|
|
|
|
| 300 |
analysis_results.append(result)
|
| 301 |
|
| 302 |
# Overall case analysis
|
| 303 |
+
case_analysis = await self.fraud_detection_service.analyze_case_pattern(
|
| 304 |
+
case_id, analysis_results
|
| 305 |
+
)
|
| 306 |
|
| 307 |
# Audit the analysis
|
| 308 |
await self.audit_service.log_action(
|
|
|
|
| 312 |
resource_id=case_id,
|
| 313 |
details={
|
| 314 |
"transaction_count": len(transactions),
|
| 315 |
+
"fraud_indicators": len(
|
| 316 |
+
[r for r in analysis_results if r.get("is_fraudulent")]
|
| 317 |
+
),
|
| 318 |
},
|
| 319 |
)
|
| 320 |
|
|
|
|
| 394 |
|
| 395 |
async def analyze_transaction(self, transaction: Transaction) -> dict[str, Any]:
|
| 396 |
# Simple mock analysis
|
| 397 |
+
is_fraudulent = (
|
| 398 |
+
transaction.amount > 10000
|
| 399 |
+
or "suspicious" in transaction.description.lower()
|
| 400 |
+
)
|
| 401 |
|
| 402 |
return {
|
| 403 |
"transaction_id": transaction.id,
|
|
|
|
| 455 |
notification_service: NotificationServicePort,
|
| 456 |
audit_service: AuditServicePort,
|
| 457 |
):
|
| 458 |
+
self.create_case_use_case = CreateFraudCaseUseCase(
|
| 459 |
+
case_repo, notification_service, audit_service
|
| 460 |
+
)
|
| 461 |
+
self.analyze_fraud_use_case = AnalyzeFraudUseCase(
|
| 462 |
+
fraud_detection_service, transaction_repo, audit_service
|
| 463 |
+
)
|
| 464 |
|
| 465 |
+
async def create_investigation_case(
|
| 466 |
+
self, case_data: dict[str, Any], created_by: str
|
| 467 |
+
) -> FraudCase:
|
| 468 |
"""Create a new fraud investigation case"""
|
| 469 |
return await self.create_case_use_case.execute(case_data, created_by)
|
| 470 |
|
| 471 |
+
async def perform_fraud_analysis(
|
| 472 |
+
self, case_id: str, analyzed_by: str
|
| 473 |
+
) -> dict[str, Any]:
|
| 474 |
"""Perform comprehensive fraud analysis on a case"""
|
| 475 |
return await self.analyze_fraud_use_case.execute(case_id, analyzed_by)
|
| 476 |
|
| 477 |
+
async def assign_investigator(
|
| 478 |
+
self, case_id: str, investigator_id: str
|
| 479 |
+
) -> FraudCase | None:
|
| 480 |
"""Assign an investigator to a case"""
|
| 481 |
case = await self.create_case_use_case.fraud_case_repo.find_by_id(case_id)
|
| 482 |
if case:
|
|
|
|
| 560 |
for tx in sample_transactions:
|
| 561 |
await self.transaction_repo.save(tx)
|
| 562 |
|
| 563 |
+
logger.info(
|
| 564 |
+
f"Created sample case {sample_case.id} with {len(sample_transactions)} transactions"
|
| 565 |
+
)
|
| 566 |
|
| 567 |
async def demonstrate_clean_architecture(self) -> dict[str, Any]:
|
| 568 |
"""Demonstrate Clean Architecture capabilities"""
|
|
|
|
| 583 |
)
|
| 584 |
|
| 585 |
# Assign investigator
|
| 586 |
+
await self.application_service.assign_investigator(
|
| 587 |
+
new_case.id, "investigator_001"
|
| 588 |
+
)
|
| 589 |
|
| 590 |
# Perform fraud analysis
|
| 591 |
+
analysis_result = await self.application_service.perform_fraud_analysis(
|
| 592 |
+
new_case.id, "ai_analyzer"
|
| 593 |
+
)
|
| 594 |
|
| 595 |
return {
|
| 596 |
"new_case_created": new_case.id,
|