kopitiam_document/validation/
report.rs1const MIN_RECOVERY_RATIO: f64 = 0.95;
2
3#[derive(Debug, Clone, Default, PartialEq)]
4pub struct ConversionReport {
5 pub pages: usize,
6 pub extracted_words: usize,
7 pub rendered_words: usize,
8 pub headings_found: usize,
9 pub lists_found: usize,
10 pub tables_found: usize,
11 pub citations_found: usize,
12}
13
14impl ConversionReport {
15 pub fn recovery_ratio(&self) -> f64 {
16 if self.extracted_words == 0 {
17 return 1.0;
18 }
19 self.rendered_words as f64 / self.extracted_words as f64
20 }
21
22 pub fn passes(&self) -> bool {
23 self.recovery_ratio() >= MIN_RECOVERY_RATIO
24 }
25}
26
27impl std::fmt::Display for ConversionReport {
28 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29 writeln!(f, "Pages: {}", self.pages)?;
30 writeln!(f)?;
31 writeln!(f, "Words:")?;
32 writeln!(f, " Extracted: {}", self.extracted_words)?;
33 writeln!(f, " Rendered: {}", self.rendered_words)?;
34 writeln!(f)?;
35 writeln!(f, "Headings: {}", self.headings_found)?;
36 writeln!(f, "Lists: {}", self.lists_found)?;
37 writeln!(f, "Tables: {}", self.tables_found)?;
38 writeln!(f, "Citations: {}", self.citations_found)?;
39 writeln!(f)?;
40 write!(f, "Status: {}", if self.passes() { "PASS" } else { "FAIL" })
41 }
42}