use chrono::NaiveDate;
use crate::models::{EdgeType, Graph, GraphEdge, GraphNode, GraphType, NodeType};
pub fn create_test_graph() -> Graph {
let mut graph = Graph::new("test", GraphType::Transaction);
let n1 = graph.add_node(
GraphNode::new(0, NodeType::Account, "1000".to_string(), "Cash".to_string())
.with_feature(0.5),
);
let n2 = graph.add_node(
GraphNode::new(0, NodeType::Account, "2000".to_string(), "AP".to_string())
.with_feature(0.8),
);
graph.add_edge(
GraphEdge::new(0, n1, n2, EdgeType::Transaction)
.with_weight(1000.0)
.with_feature(6.9),
);
graph.compute_statistics();
graph
}
pub fn create_test_graph_with_company() -> Graph {
let mut graph = Graph::new("test_dgl", GraphType::Transaction);
let n1 = graph.add_node(
GraphNode::new(0, NodeType::Account, "1000".to_string(), "Cash".to_string())
.with_feature(0.5),
);
let n2 = graph.add_node(
GraphNode::new(0, NodeType::Account, "2000".to_string(), "AP".to_string())
.with_feature(0.8),
);
let n3 = graph.add_node(
GraphNode::new(
0,
NodeType::Company,
"ACME".to_string(),
"ACME Corp".to_string(),
)
.with_feature(0.3)
.as_anomaly("fraud"),
);
graph.add_edge(
GraphEdge::new(0, n1, n2, EdgeType::Transaction)
.with_weight(1000.0)
.with_feature(6.9),
);
graph.add_edge(
GraphEdge::new(0, n2, n3, EdgeType::Ownership)
.with_weight(100.0)
.with_feature(4.6),
);
graph.compute_statistics();
graph
}
pub fn create_test_graph_with_vendor() -> Graph {
let mut graph = Graph::new("test_graph", GraphType::Transaction);
let n1 = graph.add_node(
GraphNode::new(0, NodeType::Account, "1000".to_string(), "Cash".to_string())
.with_feature(0.5)
.with_feature(0.3)
.with_categorical("account_type", "Asset"),
);
let n2 = graph.add_node(
GraphNode::new(0, NodeType::Account, "2000".to_string(), "AP".to_string())
.with_feature(0.8)
.with_feature(0.2)
.as_anomaly("unusual_balance"),
);
let n3 = graph.add_node(
GraphNode::new(
0,
NodeType::Vendor,
"V001".to_string(),
"Acme Corp".to_string(),
)
.with_feature(1.0),
);
graph.add_edge(
GraphEdge::new(0, n1, n2, EdgeType::Transaction)
.with_weight(1000.0)
.with_feature(6.9)
.with_timestamp(chrono::NaiveDate::from_ymd_opt(2024, 1, 15).unwrap()),
);
graph.add_edge(
GraphEdge::new(0, n2, n3, EdgeType::Transaction)
.with_weight(500.0)
.as_anomaly("split_transaction"),
);
graph.compute_statistics();
graph
}
pub fn create_temporal_test_graph() -> Graph {
let mut graph = Graph::new("test", GraphType::Transaction);
let n1 = graph.add_node(GraphNode::new(
0,
NodeType::Account,
"1000".to_string(),
"Cash".to_string(),
));
let n2 = graph.add_node(GraphNode::new(
0,
NodeType::Account,
"2000".to_string(),
"AP".to_string(),
));
let n3 = graph.add_node(GraphNode::new(
0,
NodeType::Account,
"3000".to_string(),
"Revenue".to_string(),
));
for i in 0..10 {
let date = NaiveDate::from_ymd_opt(2024, 1, 1 + i).unwrap();
let amount = 100.0 + (i as f64 * 10.0);
let edge = GraphEdge::new(0, n1, n2, EdgeType::Transaction)
.with_weight(amount)
.with_timestamp(date);
graph.add_edge(edge);
if i % 2 == 0 {
let edge = GraphEdge::new(0, n1, n3, EdgeType::Transaction)
.with_weight(amount * 2.0)
.with_timestamp(date);
graph.add_edge(edge);
}
}
graph
}
pub fn create_entity_group_test_graph() -> Graph {
let mut graph = Graph::new("test", GraphType::Transaction);
let n1 = graph.add_node(GraphNode::new(
0,
NodeType::Account,
"A".to_string(),
"A".to_string(),
));
let n2 = graph.add_node(GraphNode::new(
0,
NodeType::Account,
"B".to_string(),
"B".to_string(),
));
let n3 = graph.add_node(GraphNode::new(
0,
NodeType::Account,
"C".to_string(),
"C".to_string(),
));
graph.add_edge(GraphEdge::new(0, n1, n2, EdgeType::Transaction).with_weight(100.0));
graph.add_edge(GraphEdge::new(0, n2, n3, EdgeType::Transaction).with_weight(100.0));
graph.add_edge(GraphEdge::new(0, n3, n1, EdgeType::Transaction).with_weight(100.0));
let n4 = graph.add_node(GraphNode::new(
0,
NodeType::Account,
"D".to_string(),
"D".to_string(),
));
let n5 = graph.add_node(GraphNode::new(
0,
NodeType::Account,
"E".to_string(),
"E".to_string(),
));
let n6 = graph.add_node(GraphNode::new(
0,
NodeType::Account,
"F".to_string(),
"F".to_string(),
));
graph.add_edge(GraphEdge::new(0, n4, n5, EdgeType::Transaction).with_weight(200.0));
graph.add_edge(GraphEdge::new(0, n5, n6, EdgeType::Transaction).with_weight(200.0));
graph
}
pub fn create_aggregation_test_graph() -> Graph {
let mut graph = Graph::new("test", GraphType::Transaction);
let n1 = graph.add_node(
GraphNode::new(0, NodeType::Account, "A".to_string(), "A".to_string())
.with_features(vec![1.0, 2.0, 3.0]),
);
let n2 = graph.add_node(
GraphNode::new(0, NodeType::Account, "B".to_string(), "B".to_string())
.with_features(vec![4.0, 5.0, 6.0]),
);
let n3 = graph.add_node(
GraphNode::new(0, NodeType::Account, "C".to_string(), "C".to_string())
.with_features(vec![7.0, 8.0, 9.0]),
);
graph.add_edge(GraphEdge::new(0, n1, n2, EdgeType::Transaction).with_weight(100.0));
graph.add_edge(GraphEdge::new(0, n2, n3, EdgeType::Transaction).with_weight(200.0));
graph.add_edge(GraphEdge::new(0, n1, n3, EdgeType::Transaction).with_weight(150.0));
graph
}
pub fn create_relationship_test_graph() -> Graph {
let mut graph = Graph::new("test", GraphType::Transaction);
let n1 = graph.add_node(GraphNode::new(
0,
NodeType::Account,
"A".to_string(),
"A".to_string(),
));
let n2 = graph.add_node(GraphNode::new(
0,
NodeType::Account,
"B".to_string(),
"B".to_string(),
));
let n3 = graph.add_node(GraphNode::new(
0,
NodeType::Account,
"C".to_string(),
"C".to_string(),
));
let n4 = graph.add_node(GraphNode::new(
0,
NodeType::Account,
"D".to_string(),
"D".to_string(),
));
graph.add_edge(
GraphEdge::new(0, n1, n2, EdgeType::Transaction)
.with_weight(1000.0)
.with_timestamp(NaiveDate::from_ymd_opt(2024, 1, 1).unwrap()),
);
graph.add_edge(
GraphEdge::new(0, n1, n2, EdgeType::Transaction)
.with_weight(2000.0)
.with_timestamp(NaiveDate::from_ymd_opt(2024, 6, 1).unwrap()),
);
graph.add_edge(
GraphEdge::new(0, n1, n3, EdgeType::Transaction)
.with_weight(500.0)
.with_timestamp(NaiveDate::from_ymd_opt(2024, 3, 1).unwrap()),
);
graph.add_edge(
GraphEdge::new(0, n2, n1, EdgeType::Transaction)
.with_weight(1500.0)
.with_timestamp(NaiveDate::from_ymd_opt(2024, 4, 1).unwrap()),
);
graph.add_edge(
GraphEdge::new(0, n1, n4, EdgeType::Transaction)
.with_weight(300.0)
.with_timestamp(NaiveDate::from_ymd_opt(2024, 12, 15).unwrap()),
);
graph
}
pub fn create_splits_test_graph() -> Graph {
let mut graph = Graph::new("test", GraphType::Transaction);
for i in 0..10 {
let mut node = GraphNode::new(
0,
NodeType::Account,
format!("{}", i),
format!("Account {}", i),
);
if i == 5 {
node.is_anomaly = true;
}
graph.add_node(node);
}
for i in 0..9 {
let edge = GraphEdge::new(0, i + 1, i + 2, EdgeType::Transaction)
.with_timestamp(chrono::NaiveDate::from_ymd_opt(2024, 1, i as u32 + 1).unwrap());
graph.add_edge(edge);
}
graph.compute_statistics();
graph
}