1use serde::{Deserialize, Serialize};
2use std::fmt;
3
4#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
5pub struct ChunkQuality {
6 pub avg_chunk_length: usize,
7 pub sentence_integrity: f32,
8 pub word_integrity: f32,
9 pub chunk_quality: f32,
10}
11
12#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
13#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
14pub enum QualityTier {
15 Empty,
16 Purge,
17 Warn,
18 Good,
19 Excellent,
20}
21
22#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
23#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
24pub enum AuditRecommendation {
25 Empty,
26 Purge,
27 Warn,
28 Good,
29 Excellent,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
33pub struct AuditResult {
34 pub namespace: String,
35 pub document_count: usize,
36 pub avg_chunk_length: usize,
37 pub sentence_integrity: f32,
38 pub word_integrity: f32,
39 pub chunk_quality: f32,
40 pub overall_score: f32,
41 pub recommendation: AuditRecommendation,
42 pub passes_threshold: bool,
43}
44
45impl AuditResult {
46 pub fn chunk_quality_metrics(&self) -> ChunkQuality {
47 ChunkQuality {
48 avg_chunk_length: self.avg_chunk_length,
49 sentence_integrity: self.sentence_integrity,
50 word_integrity: self.word_integrity,
51 chunk_quality: self.chunk_quality,
52 }
53 }
54
55 pub fn quality_tier(&self) -> QualityTier {
56 match self.recommendation {
57 AuditRecommendation::Empty => QualityTier::Empty,
58 AuditRecommendation::Purge => QualityTier::Purge,
59 AuditRecommendation::Warn => QualityTier::Warn,
60 AuditRecommendation::Good => QualityTier::Good,
61 AuditRecommendation::Excellent => QualityTier::Excellent,
62 }
63 }
64}
65
66impl AuditRecommendation {
67 pub const fn as_str(self) -> &'static str {
68 match self {
69 AuditRecommendation::Empty => "EMPTY",
70 AuditRecommendation::Purge => "PURGE",
71 AuditRecommendation::Warn => "WARN",
72 AuditRecommendation::Good => "GOOD",
73 AuditRecommendation::Excellent => "EXCELLENT",
74 }
75 }
76}
77
78impl fmt::Display for AuditRecommendation {
79 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
80 f.write_str(self.as_str())
81 }
82}
83
84impl QualityTier {
85 pub const fn as_str(self) -> &'static str {
86 match self {
87 QualityTier::Empty => "EMPTY",
88 QualityTier::Purge => "PURGE",
89 QualityTier::Warn => "WARN",
90 QualityTier::Good => "GOOD",
91 QualityTier::Excellent => "EXCELLENT",
92 }
93 }
94}
95
96impl fmt::Display for QualityTier {
97 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
98 f.write_str(self.as_str())
99 }
100}