use serde::{Deserialize, Serialize};
use dirtydata_core::types::{StableId, IntentId, PatchId, Timestamp};
use dirtydata_core::patch::Patch;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SoundTrace {
pub sample_index: u64,
pub node_id: StableId,
pub parameter_name: String,
pub value: f32,
pub attribution: Attribution,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Attribution {
pub intent_id: Option<IntentId>,
pub intent_description: Option<String>,
pub patch_id: PatchId,
pub source: String,
pub timestamp: Timestamp,
pub commit_hash: Option<String>, }
pub struct Attributor;
impl Attributor {
pub fn trace_parameter(
node_id: StableId,
param_name: &str,
patches: &[Patch],
) -> Option<Attribution> {
for patch in patches.iter().rev() {
for op in &patch.operations {
match op {
dirtydata_core::patch::Operation::ModifyConfig { node_id: id, delta } if *id == node_id => {
if delta.contains_key(param_name) {
return Some(Attribution {
intent_id: patch.intent_ref,
intent_description: None, patch_id: patch.identity,
source: format!("{:?}", patch.source),
timestamp: patch.timestamp,
commit_hash: None, });
}
}
_ => {}
}
}
}
None
}
}