use crate::analysis::events::tags::OverrideTag;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum PerformanceImpact {
Minimal,
Low,
Medium,
High,
Critical,
}
#[must_use]
pub fn calculate_animation_score(tags: &[OverrideTag<'_>]) -> u8 {
tags.iter()
.map(|tag| match tag.name() {
"b" | "i" | "u" | "s" | "c" | "1c" | "2c" | "3c" | "4c" | "alpha" | "1a" | "2a"
| "3a" | "4a" => 1,
"frx" | "fry" | "frz" | "fscx" | "fscy" | "fsp" | "fad" | "fade" | "clip" | "iclip" => {
3
}
"move" => 4,
"t" | "pbo" => 5,
"p" => 8,
_ => 2,
})
.sum::<u8>()
.min(10)
}
#[must_use]
pub fn calculate_complexity_score(
animation_score: u8,
char_count: usize,
override_count: usize,
) -> u8 {
let mut score = u32::from(animation_score) * 5;
score += match char_count {
0..=50 => 0,
51..=200 => 5,
201..=500 => 15,
501..=1000 => 30,
_ => 50,
};
score += match override_count {
0 => 0,
1..=5 => 5,
6..=15 => 15,
16..=30 => 25,
_ => 35,
};
(score.min(255) as u8).min(100)
}
#[must_use]
pub const fn get_performance_impact(complexity_score: u8) -> PerformanceImpact {
match complexity_score {
0..=20 => PerformanceImpact::Minimal,
21..=40 => PerformanceImpact::Low,
41..=60 => PerformanceImpact::Medium,
61..=80 => PerformanceImpact::High,
_ => PerformanceImpact::Critical,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[cfg(not(feature = "std"))]
use alloc::vec;
#[test]
fn test_animation_score_empty() {
let tags = vec![];
assert_eq!(calculate_animation_score(&tags), 0);
}
#[test]
fn test_animation_score_basic_formatting() {
let tags = vec![];
assert_eq!(calculate_animation_score(&tags), 0);
}
#[test]
fn test_complexity_score_minimal() {
let score = calculate_complexity_score(0, 10, 0);
assert_eq!(score, 0);
}
#[test]
fn test_complexity_score_high() {
let score = calculate_complexity_score(10, 1000, 50);
assert_eq!(score, 100);
}
#[test]
fn test_performance_impact_mapping() {
assert_eq!(get_performance_impact(0), PerformanceImpact::Minimal);
assert_eq!(get_performance_impact(30), PerformanceImpact::Low);
assert_eq!(get_performance_impact(50), PerformanceImpact::Medium);
assert_eq!(get_performance_impact(70), PerformanceImpact::High);
assert_eq!(get_performance_impact(90), PerformanceImpact::Critical);
}
#[test]
fn test_complexity_score_medium_char_count() {
let score = calculate_complexity_score(0, 750, 0);
assert_eq!(score, 30); }
}