fund-flow-backend / src /state.py
Aniket2006's picture
feat: calibrate account risk scores and threat tiers, resolve clumping in alert queue
37f9507
Raw
History Blame Contribute Delete
2.4 kB
class AppState:
df = None
node_features = None
graph = None
louvain_partition = None
pagerank_scores = None
betweenness_scores = None
full_features = None
alerts = []
xgb_bundle = None
model_metrics = None
gnn_metrics = None
# Pre-built caches for fast API responses
features_by_account = {} # account_id -> feature dict (O(1) lookup)
cached_channel_stats = [] # pre-computed channel breakdown
cached_overview = {} # pre-computed overview numbers
cached_typo_counts = {} # pre-computed alerts typologies
cached_crit_alerts = 0 # pre-computed critical count
accounts_by_number = {} # account_number -> {bank_name, bank_id, entity_id, entity_name} (O(1) lookup from accounts.csv)
# Entity/bank network intelligence — built once from accounts_by_number (no second CSV read)
entities_by_id = {} # entity_id -> {entity_id, entity_name, entity_type, account_numbers, bank_ids, bank_names}
banks_by_id = {} # bank_id -> {bank_id, bank_name, country_label, account_numbers, entity_ids}
network_summary_cache = {} # pre-computed /network/summary payload
bank_profiles_cache = {} # bank_id -> pre-computed /bank/{id}/profile payload
clusters_by_id = {} # community_id -> pre-computed /network/cluster/{id} aggregate (Louvain-derived "mule ring" groups)
alerts_by_account = {} # account_id -> [alert dict, ...] (O(1) index into AppState.alerts for entity-level typology breakdowns)
# Uploaded-dataset tracking — when the user ingests their own data via the
# Upload page, validation metrics (F1, AUC-ROC, confusion matrices) are no
# longer meaningful because the upload carries no ground-truth labels.
is_uploaded_dataset = False # True once a user dataset replaces the IBM data
uploaded_dataset_name = None # original filename of the uploaded dataset
uploaded_has_labels = False # True if the upload included an 'Is Laundering' column
# Startup tracking — lets the frontend show a loading screen
startup_ready = False # dashboard data ready
graph_ready = False # graph built; investigation/subgraph endpoints available
startup_status = {
'current_step': 'Initializing...',
'steps_done': 0,
'total_steps': 7,
'errors': []
}