Skip to content

Commit 44622c0

Browse files
committed
Fix end of files
1 parent 201e14e commit 44622c0

5 files changed

Lines changed: 40 additions & 39 deletions

File tree

.github/workflows/dagger-fraud-sim.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@ jobs:
2626
GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }}
2727
DAGGER_CLOUD_TOKEN: ${{ secrets.DAGGER_CLOUD_TOKEN }}
2828
run: |
29-
mkdir -p dashboard
30-
dagger call run-fraud-sim --source . --gemini-api-key env:GEMINI_API_KEY --groq-api-key env:GROQ_API_KEY export --path dashboard/summary.json
29+
mkdir -p results
30+
dagger call run-fraud-sim --source . --gemini-api-key env:GEMINI_API_KEY --groq-api-key env:GROQ_API_KEY export --path results/summary.json
3131
3232
- name: Run AI Agent Analysis
3333
env:
3434
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
3535
run: |
3636
echo "Generating fraud summary insights via AI Agent"
37-
dagger call analyze-results --summary dashboard/summary.json > dashboard/insights.txt
37+
dagger call analyze-results --summary results/summary.json > results/insights.txt
3838
3939
- name: Create Pull Request
4040
uses: peter-evans/create-pull-request@v5
4141
with:
42-
commit-message: "Update fraud dashboard with AI insights"
43-
title: "Update Fraud Dashboard"
42+
commit-message: "Update fraud results with AI insights"
43+
title: "Update Fraud Results"
4444
body: "Automated update of fraud simulation results and AI insights."
45-
branch: "fraud-dashboard-update"
45+
branch: "fraud-results-update"
4646
base: "main"
4747
delete-branch: true

dagger/src/fraud_simulation/process_logs.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ async def process_logs():
3838
"Groq": os.environ.get("AI_MODEL_GROQ", "Groq-Llama-3")
3939
}
4040

41+
account_stats = {} # user_id -> {total_score, count, alerts}
42+
4143
for log in logs:
4244
if log.get("event_type") == "signup":
4345
accounts_created += 1
@@ -95,17 +97,44 @@ async def process_logs():
9597
"reasons": final_reasons
9698
}
9799
results.append(result)
98-
total_score += max(primary_ai_score, rule_score)
99100

100-
avg_score = total_score / len(results) if results else 0
101+
# Track per account stats
102+
user_id = log["user_id"]
103+
score = max(primary_ai_score, rule_score)
104+
if user_id not in account_stats:
105+
account_stats[user_id] = {"total_score": 0.0, "count": 0, "alerts": 0}
106+
account_stats[user_id]["total_score"] += score
107+
account_stats[user_id]["count"] += 1
108+
if is_anomaly:
109+
account_stats[user_id]["alerts"] += 1
110+
111+
total_score += score
112+
113+
# Calculate per account metrics
114+
account_metrics = []
115+
for user_id, stats in account_stats.items():
116+
account_metrics.append({
117+
"user_id": user_id,
118+
"average_score": round(stats["total_score"] / stats["count"], 2) if stats["count"] > 0 else 0,
119+
"total_alerts": stats["alerts"]
120+
})
121+
# Sort by score descending to highlight suspicious accounts
122+
account_metrics.sort(key=lambda x: x["average_score"], reverse=True)
101123

102124
output = {
125+
"report_type": "Fraud Simulation Summary (Per Iteration)",
103126
"timestamp": datetime.now().isoformat(),
104127
"accounts_created": accounts_created,
105128
"total_logins": len(results),
106129
"normal_logins": len(results) - suspicious_count,
107130
"suspicious_logins": suspicious_count,
108-
"average_score": round(avg_score, 2),
131+
"average_score": round(total_score / len(results) if results else 0, 2),
132+
"average_fraud_score_per_account": [
133+
{"user_id": m["user_id"], "score": m["average_score"]} for m in account_metrics
134+
],
135+
"total_alerts_per_account": [
136+
{"user_id": m["user_id"], "alerts": m["total_alerts"]} for m in account_metrics
137+
],
109138
"details": results
110139
}
111140

dashboard/index.html

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@
4141
* **Rule Set Expansion:** Review and potentially expand the rule-based detection to include other suspicious patterns identified (e.g., logins from new/unusual geographical locations, rapid succession of logins from different IPs).
4242
4. **User Education:**
4343
* **Security Best Practices:** Periodically educate users on password hygiene, phishing awareness, and the importance of MFA.
44-
5. **Broader Anomaly Detection:** Monitor the overall `suspicious_logins` and `average_score` metrics to detect any increasing trends that might indicate a larger attack or a new fraud vector.
44+
5. **Broader Anomaly Detection:** Monitor the overall `suspicious_logins` and `average_score` metrics to detect any increasing trends that might indicate a larger attack or a new fraud vector.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,4 +445,4 @@
445445
"reasons": []
446446
}
447447
]
448-
}
448+
}

0 commit comments

Comments
 (0)