application layer

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-05-04 01:19:59 +02:00
parent 810bad1126
commit 65bab7fd44
16 changed files with 392 additions and 31 deletions

View File

@@ -12,35 +12,35 @@ pub enum Trend {
impl ReviewHistoryAnalyzer {
pub fn sort_chronologically(history: &mut ReviewHistory) {
history
.viewings
.viewings_mut()
.sort_by(|a, b| a.watched_at().cmp(&b.watched_at()));
}
pub fn get_latest_rating(history: &ReviewHistory) -> Option<&Rating> {
history
.viewings
.viewings()
.iter()
.max_by_key(|r| r.watched_at())
.map(|r| r.rating())
}
pub fn rating_trend(history: &ReviewHistory) -> Result<Trend, DomainError> {
if history.viewings.len() < 2 {
if history.viewings().len() < 2 {
return Ok(Trend::Neutral);
}
let mut sorted_history = history.clone();
Self::sort_chronologically(&mut sorted_history);
let latest_review = sorted_history.viewings.pop().unwrap();
let latest_review = sorted_history.viewings().last().unwrap();
let latest_rating = latest_review.rating().value() as f32;
let previous_sum: u32 = sorted_history
.viewings
.viewings()
.iter()
.map(|r| r.rating().value() as u32)
.sum();
let historical_average = previous_sum as f32 / sorted_history.viewings.len() as f32;
let historical_average = previous_sum as f32 / sorted_history.viewings().len() as f32;
if latest_rating > historical_average {
Ok(Trend::Improved)