Skip to main content

cli_denoiser/tracker/
mod.rs

1mod db;
2
3pub use db::TrackerDb;
4
5use chrono::Utc;
6
7/// A single recorded filter event.
8#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
9pub struct FilterEvent {
10    pub command: String,
11    pub original_tokens: usize,
12    pub filtered_tokens: usize,
13    pub savings: usize,
14    pub timestamp: String,
15}
16
17impl FilterEvent {
18    #[must_use]
19    pub fn new(command: &str, original_tokens: usize, filtered_tokens: usize) -> Self {
20        Self {
21            command: command.to_string(),
22            original_tokens,
23            filtered_tokens,
24            savings: original_tokens.saturating_sub(filtered_tokens),
25            timestamp: Utc::now().to_rfc3339(),
26        }
27    }
28}
29
30/// Summary stats for the `gain` command.
31#[derive(Debug, Clone, serde::Serialize)]
32pub struct GainSummary {
33    pub total_events: usize,
34    pub total_original_tokens: usize,
35    pub total_filtered_tokens: usize,
36    pub total_savings: usize,
37    pub savings_percent: f64,
38    pub top_commands: Vec<CommandSavings>,
39    pub period_days: u32,
40}
41
42#[derive(Debug, Clone, serde::Serialize)]
43pub struct CommandSavings {
44    pub command: String,
45    pub events: usize,
46    pub savings: usize,
47}
48
49/// Daily stats for the report command.
50#[derive(Debug, Clone, serde::Serialize)]
51pub struct DailyStats {
52    pub date: String,
53    pub events: usize,
54    pub original_tokens: usize,
55    pub filtered_tokens: usize,
56    pub savings: usize,
57    pub savings_percent: f64,
58}