use std::collections::BTreeMap;
use crate::language::Language;
use crate::text::TextStatistics;
pub mod grade_level;
pub mod helper;
pub mod impls;
pub mod registry;
pub use grade_level::GradeLevelInterpretation;
pub use helper::TextStatisticsHelper;
pub use registry::FormulaRegistry;
pub fn round_to(x: f64, places: i32) -> f64 {
let f = 10f64.powi(places);
(x * f).round() / f
}
pub fn grade_clamp(score: f64, lo: f64, hi: f64) -> f64 {
round_to(score, 1).clamp(lo, hi)
}
#[derive(Debug, Clone, PartialEq)]
pub struct FormulaResult {
pub formula_name: String,
pub language_code: String,
pub score: f64,
pub grade_level: Option<f64>,
pub interpretation: String,
pub inputs: BTreeMap<String, f64>,
}
pub trait Formula {
fn name(&self) -> &'static str;
fn description(&self) -> &'static str;
fn supported_languages(&self) -> &'static [&'static str];
fn calculate(&self, stats: &TextStatistics, language: &Language) -> FormulaResult;
}
pub(crate) fn inputs(pairs: &[(&str, f64)]) -> BTreeMap<String, f64> {
pairs.iter().map(|(k, v)| (k.to_string(), *v)).collect()
}