ruvector_dag/qudag/
proposal.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct PatternProposal {
7 pub pattern_vector: Vec<f32>,
8 pub metadata: serde_json::Value,
9 pub quality_score: f64,
10 pub noise_epsilon: Option<f64>, }
12
13impl PatternProposal {
14 pub fn new(pattern_vector: Vec<f32>, metadata: serde_json::Value, quality_score: f64) -> Self {
15 Self {
16 pattern_vector,
17 metadata,
18 quality_score,
19 noise_epsilon: None,
20 }
21 }
22
23 pub fn with_differential_privacy(mut self, epsilon: f64) -> Self {
24 self.noise_epsilon = Some(epsilon);
25 self.add_laplace_noise(epsilon);
27 self
28 }
29
30 fn add_laplace_noise(&mut self, epsilon: f64) {
31 let scale = 1.0 / epsilon;
32 for v in &mut self.pattern_vector {
33 let u: f64 = rand::random::<f64>() - 0.5;
35 let noise = -scale * u.signum() * (1.0 - 2.0 * u.abs()).ln();
36 *v += noise as f32;
37 }
38 }
39}
40
41#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
42pub enum ProposalStatus {
43 Pending,
44 Voting,
45 Accepted,
46 Rejected,
47 Finalized,
48}
49
50impl std::fmt::Display for ProposalStatus {
51 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52 match self {
53 ProposalStatus::Pending => write!(f, "pending"),
54 ProposalStatus::Voting => write!(f, "voting"),
55 ProposalStatus::Accepted => write!(f, "accepted"),
56 ProposalStatus::Rejected => write!(f, "rejected"),
57 ProposalStatus::Finalized => write!(f, "finalized"),
58 }
59 }
60}
61
62#[allow(dead_code)]
63#[derive(Debug, Clone)]
64pub struct ProposalResult {
65 pub proposal_id: String,
66 pub status: ProposalStatus,
67 pub votes_for: u64,
68 pub votes_against: u64,
69 pub finalized_at: Option<std::time::SystemTime>,
70}