-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathai_advisory.py
More file actions
65 lines (55 loc) · 1.82 KB
/
Copy pathai_advisory.py
File metadata and controls
65 lines (55 loc) · 1.82 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from sqlalchemy.orm import Session
from models import StateVoter
def detect_possible_duplicates(reference_id: str, db: Session):
"""
Simulates AI-based duplicate detection.
Flags cases where the same reference appears in multiple states.
"""
records = (
db.query(StateVoter)
.filter(StateVoter.reference_id == reference_id)
.all()
)
if len(records) > 1:
return {
"alert": "POSSIBLE_DUPLICATE",
"count": len(records),
"message": "Voter reference found in multiple states. Human review required."
}
return {"alert": "CLEAR"}
def detect_suspicious_activity(state: str, db: Session):
"""
Simulates detection of suspicious registration spikes in a state.
"""
count = (
db.query(StateVoter)
.filter(
StateVoter.state == state,
StateVoter.status == "ACTIVE"
)
.count()
)
if count > 5: # Threshold chosen only for PoC demonstration
return {
"alert": "SUSPICIOUS_ACTIVITY",
"state": state,
"message": "High number of active registrations detected. Manual audit suggested."
}
return {"alert": "NORMAL"}
def analyze_migration_patterns(reference_id: str, db: Session):
"""
Simulates analysis of migration patterns for a voter.
Flags if a voter has migrated multiple times in a short period.
"""
records = (
db.query(StateVoter)
.filter(StateVoter.reference_id == reference_id)
.all()
)
if len(records) > 3: # Threshold chosen only for PoC demonstration
return {
"alert": "FREQUENT_MIGRATIONS",
"count": len(records),
"message": "Voter has migrated multiple times. Review recommended."
}
return {"alert": "STABLE"}