Skip to content

Commit

Permalink
fix(stats): update api schema for bucket statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbrt committed Jun 28, 2024
1 parent 7b7eaa4 commit 84c6b18
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
27 changes: 26 additions & 1 deletion api/src/resources/bucket_statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,32 @@ pub struct GetBucketStatisticsResponse {
pub statistics: Statistics,
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[serde(tag = "kind")]
pub enum Count {
#[serde(rename = "lower_bound")]
LowerBoundBucketCount {
value: i32,
},
#[serde(rename = "exact")]
ExactBucketCount {
value: i32,
},
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct Statistics {
pub count: usize,
pub count: Count,
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct LowerBoundBucketCount {
pub kind: String,
pub value: i32,
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct ExactBucketCount {
pub kind: String,
pub value: i32,
}
9 changes: 7 additions & 2 deletions cli/src/commands/get/emails.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::{Context, Result};

use colored::Colorize;
use reinfer_client::{BucketIdentifier, Client};
use reinfer_client::{resources::bucket_statistics::Count, BucketIdentifier, Client};
use std::{
fs::File,
io::{self, BufWriter, Write},
Expand Down Expand Up @@ -63,7 +63,12 @@ fn download_emails(

let statistics = Arc::new(Statistics::new());

let _progress = get_emails_progress_bar(bucket_statistics.count as u64, &statistics);
let progress_bytes = match bucket_statistics.count {
Count::LowerBoundBucketCount { value } => value,
Count::ExactBucketCount { value } => value,
} as u64;

let _progress = get_emails_progress_bar(progress_bytes, &statistics);

client
.get_emails_iter(&bucket.full_name(), None)
Expand Down
16 changes: 10 additions & 6 deletions cli/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use colored::Colorize;
use prettytable::{format, row, Row, Table};
use reinfer_client::{
resources::{
audit::PrintableAuditEvent, bucket_statistics::Statistics as BucketStatistics,
audit::PrintableAuditEvent, bucket_statistics::{Count, Statistics as BucketStatistics},
dataset::DatasetAndStats, integration::Integration, quota::Quota,
},
Bucket, CommentStatistics, Dataset, Project, Source, Stream, User,
Expand Down Expand Up @@ -207,15 +207,19 @@ impl DisplayTable for PrintableBucket {
"/".dimmed(),
self.bucket.name.0
);
let count_str = if let Some(stats) = &self.stats {
match &stats.count {
Count::LowerBoundBucketCount { value } => format!(">={}", value),
Count::ExactBucketCount { value } => format!("={}", value),
}
} else {
"none".dimmed().to_string()
};
row![
full_name,
self.bucket.id.0,
self.bucket.created_at.format("%Y-%m-%d %H:%M:%S"),
if let Some(stats) = &self.stats {
stats.count.to_string().as_str().into()
} else {
"none".dimmed()
}
count_str
]
}
}
Expand Down

0 comments on commit 84c6b18

Please sign in to comment.