Skip to main content

rustkernel_audit/
types.rs

1//! Audit types for financial audit kernels.
2
3use std::collections::HashMap;
4
5// ============================================================================
6// Audit Record Types
7// ============================================================================
8
9/// Audit record for feature extraction.
10#[derive(Debug, Clone)]
11pub struct AuditRecord {
12    /// Record ID.
13    pub id: String,
14    /// Record type.
15    pub record_type: AuditRecordType,
16    /// Entity ID.
17    pub entity_id: String,
18    /// Timestamp.
19    pub timestamp: u64,
20    /// Amount (if applicable).
21    pub amount: Option<f64>,
22    /// Currency (if applicable).
23    pub currency: Option<String>,
24    /// Account (if applicable).
25    pub account: Option<String>,
26    /// Counter-party (if applicable).
27    pub counter_party: Option<String>,
28    /// Category.
29    pub category: String,
30    /// Attributes.
31    pub attributes: HashMap<String, String>,
32}
33
34/// Audit record type.
35#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
36pub enum AuditRecordType {
37    /// Journal entry.
38    JournalEntry,
39    /// Invoice.
40    Invoice,
41    /// Payment.
42    Payment,
43    /// Receipt.
44    Receipt,
45    /// Adjustment.
46    Adjustment,
47    /// Transfer.
48    Transfer,
49    /// Expense.
50    Expense,
51    /// Revenue.
52    Revenue,
53}
54
55// ============================================================================
56// Feature Extraction Types
57// ============================================================================
58
59/// Feature vector for an entity.
60#[derive(Debug, Clone)]
61pub struct EntityFeatureVector {
62    /// Entity ID.
63    pub entity_id: String,
64    /// Feature values.
65    pub features: Vec<f64>,
66    /// Feature names.
67    pub feature_names: Vec<String>,
68    /// Metadata.
69    pub metadata: HashMap<String, String>,
70}
71
72/// Feature extraction result.
73#[derive(Debug, Clone)]
74pub struct FeatureExtractionResult {
75    /// Feature vectors by entity.
76    pub entity_features: Vec<EntityFeatureVector>,
77    /// Global statistics.
78    pub global_stats: FeatureStats,
79    /// Anomaly scores.
80    pub anomaly_scores: HashMap<String, f64>,
81}
82
83/// Feature statistics.
84#[derive(Debug, Clone)]
85pub struct FeatureStats {
86    /// Number of entities.
87    pub entity_count: usize,
88    /// Number of records processed.
89    pub record_count: usize,
90    /// Feature means.
91    pub means: Vec<f64>,
92    /// Feature standard deviations.
93    pub std_devs: Vec<f64>,
94    /// Feature names.
95    pub feature_names: Vec<String>,
96}
97
98// ============================================================================
99// Hypergraph Types
100// ============================================================================
101
102/// Hypergraph node.
103#[derive(Debug, Clone)]
104pub struct HypergraphNode {
105    /// Node ID.
106    pub id: String,
107    /// Node type.
108    pub node_type: NodeType,
109    /// Attributes.
110    pub attributes: HashMap<String, String>,
111}
112
113/// Node type in the hypergraph.
114#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
115pub enum NodeType {
116    /// Entity (company, person).
117    Entity,
118    /// Account.
119    Account,
120    /// Transaction.
121    Transaction,
122    /// Document.
123    Document,
124    /// Category.
125    Category,
126    /// Time period.
127    TimePeriod,
128}
129
130/// Hyperedge connecting multiple nodes.
131#[derive(Debug, Clone)]
132pub struct Hyperedge {
133    /// Edge ID.
134    pub id: String,
135    /// Edge type.
136    pub edge_type: HyperedgeType,
137    /// Connected node IDs.
138    pub nodes: Vec<String>,
139    /// Weight.
140    pub weight: f64,
141    /// Timestamp (if applicable).
142    pub timestamp: Option<u64>,
143    /// Attributes.
144    pub attributes: HashMap<String, String>,
145}
146
147/// Hyperedge type.
148#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
149pub enum HyperedgeType {
150    /// Transaction linking entities.
151    Transaction,
152    /// Document reference.
153    DocumentRef,
154    /// Account relationship.
155    AccountRel,
156    /// Temporal co-occurrence.
157    Temporal,
158    /// Category membership.
159    CategoryMembership,
160    /// Approval chain.
161    ApprovalChain,
162}
163
164/// Hypergraph structure.
165#[derive(Debug, Clone)]
166pub struct Hypergraph {
167    /// Nodes.
168    pub nodes: HashMap<String, HypergraphNode>,
169    /// Hyperedges.
170    pub edges: Vec<Hyperedge>,
171    /// Node to edges mapping.
172    pub node_edges: HashMap<String, Vec<String>>,
173}
174
175/// Hypergraph analysis result.
176#[derive(Debug, Clone)]
177pub struct HypergraphResult {
178    /// Constructed hypergraph.
179    pub hypergraph: Hypergraph,
180    /// Node centrality scores.
181    pub node_centrality: HashMap<String, f64>,
182    /// Edge weights.
183    pub edge_weights: HashMap<String, f64>,
184    /// Detected patterns.
185    pub patterns: Vec<HypergraphPattern>,
186    /// Statistics.
187    pub stats: HypergraphStats,
188}
189
190/// Detected pattern in hypergraph.
191#[derive(Debug, Clone)]
192pub struct HypergraphPattern {
193    /// Pattern ID.
194    pub id: String,
195    /// Pattern type.
196    pub pattern_type: PatternType,
197    /// Involved nodes.
198    pub nodes: Vec<String>,
199    /// Involved edges.
200    pub edges: Vec<String>,
201    /// Confidence score.
202    pub confidence: f64,
203    /// Description.
204    pub description: String,
205}
206
207/// Pattern type.
208#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
209pub enum PatternType {
210    /// Circular transaction pattern.
211    CircularTransaction,
212    /// Unusual connection.
213    UnusualConnection,
214    /// High centrality hub.
215    HighCentralityHub,
216    /// Isolated component.
217    IsolatedComponent,
218    /// Dense subgraph.
219    DenseSubgraph,
220    /// Temporal anomaly.
221    TemporalAnomaly,
222}
223
224/// Hypergraph statistics.
225#[derive(Debug, Clone)]
226pub struct HypergraphStats {
227    /// Number of nodes.
228    pub node_count: usize,
229    /// Number of hyperedges.
230    pub edge_count: usize,
231    /// Average hyperedge size.
232    pub avg_edge_size: f64,
233    /// Average node degree.
234    pub avg_node_degree: f64,
235    /// Number of connected components.
236    pub component_count: usize,
237    /// Network density.
238    pub density: f64,
239}