use std::collections::HashMap; use crate::model::user::User; pub fn exceeding( users: &[User], user_incomes: &HashMap, user_payments: &HashMap, ) -> Vec<(String, i64)> { let ratios = users.iter().map(|u| { let income = *user_incomes.get(&u.id).unwrap_or(&0); if income == 0 { (u.name.clone(), 0, 0.0) } else { let payments = *user_payments.get(&u.id).unwrap_or(&0); let ratio = payments as f64 / income as f64; (u.name.clone(), income, ratio) } }); let min_ratio = ratios .clone() .map(|r| r.2) .min_by(|r1, r2| { ((r1 * 100_000_000.0).round() as i64) .cmp(&((r2 * 100_000_000.0).round() as i64)) }) .unwrap_or(0.0); ratios .filter_map(|r| { let exceeding = ((r.2 - min_ratio) * r.1 as f64).round() as i64; if exceeding == 0 { None } else { Some((r.0, exceeding)) } }) .collect() }