use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use super::{classification::CodeType, scope::AnalysisScope, semantic_unit::SemanticUnit};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Change {
pub file_path: PathBuf,
pub unit: SemanticUnit,
pub classification: CodeType,
pub lines_added: usize,
pub lines_removed: usize,
}
impl Change {
pub fn new(
file_path: PathBuf,
unit: SemanticUnit,
classification: CodeType,
lines_added: usize,
lines_removed: usize,
) -> Self {
Self {
file_path,
unit,
classification,
lines_added,
lines_removed,
}
}
pub fn total_lines(&self) -> usize {
self.lines_added + self.lines_removed
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct Summary {
pub prod_functions: usize,
pub prod_structs: usize,
pub prod_other: usize,
pub test_units: usize,
pub prod_lines_added: usize,
pub prod_lines_removed: usize,
pub test_lines_added: usize,
pub test_lines_removed: usize,
pub weighted_score: usize,
pub exceeds_limit: bool,
}
impl Summary {
pub fn total_prod_units(&self) -> usize {
self.prod_functions + self.prod_structs + self.prod_other
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct AnalysisResult {
pub changes: Vec<Change>,
pub summary: Summary,
pub scope: AnalysisScope,
}
impl AnalysisResult {
pub fn new(changes: Vec<Change>, summary: Summary, scope: AnalysisScope) -> Self {
Self {
changes,
summary,
scope,
}
}
pub fn production_changes(&self) -> impl Iterator<Item = &Change> {
self.changes
.iter()
.filter(|c| c.classification.is_production())
}
pub fn test_changes(&self) -> impl Iterator<Item = &Change> {
self.changes
.iter()
.filter(|c| c.classification.is_test_related())
}
}