impl Default for FeedbackCollector {
fn default() -> Self {
Self::new()
}
}
impl FeedbackCollector {
#[must_use]
pub fn new() -> Self {
Self {
accepted: Vec::new(),
rejected: Vec::new(),
metrics: FeedbackMetrics::default(),
}
}
pub fn record(&mut self, pattern_id: &str, accepted: bool, outcome: Option<String>) {
use std::time::SystemTime;
self.metrics.total_suggestions += 1;
if accepted {
self.metrics.accepted += 1;
self.accepted.push(AcceptedSuggestion {
pattern_id: pattern_id.to_string(),
violation_type: ViolationType::Complexity,
timestamp: SystemTime::now(),
outcome: outcome.map_or(SuggestionOutcome::Success, |msg| {
if msg.contains("partial") {
SuggestionOutcome::PartialSuccess
} else {
SuggestionOutcome::Failure(msg)
}
}),
});
} else {
self.metrics.rejected += 1;
self.rejected.push(RejectedSuggestion {
pattern_id: pattern_id.to_string(),
violation_type: ViolationType::Complexity,
timestamp: SystemTime::now(),
reason: outcome.unwrap_or_else(|| "No reason provided".to_string()),
});
}
self.metrics.success_rate =
self.metrics.accepted as f64 / self.metrics.total_suggestions as f64;
}
}
impl Default for ConfidenceScorer {
fn default() -> Self {
Self::new()
}
}
impl ConfidenceScorer {
#[must_use]
pub fn new() -> Self {
Self {
weights: ScoringWeights::default(),
}
}
#[must_use]
pub fn score(&self, pattern: &Pattern, _violation: &Violation) -> f64 {
let mut score = 0.0;
score += pattern.success_rate * self.weights.pattern_success_rate;
let context_match = if pattern.contexts.contains(&"high_complexity".to_string()) {
1.0
} else {
0.5
};
score += context_match * self.weights.context_match;
let similarity = 0.7; score += similarity * self.weights.code_similarity;
let user_preference = 0.8; score += user_preference * self.weights.user_history;
score.min(1.0)
}
}