Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(stats): update api schema for bucket statistics #281

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion api/src/resources/bucket_statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,28 @@ 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
21 changes: 14 additions & 7 deletions cli/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ use colored::Colorize;
use prettytable::{format, row, Row, Table};
use reinfer_client::{
resources::{
audit::PrintableAuditEvent, bucket_statistics::Statistics as BucketStatistics,
dataset::DatasetAndStats, integration::Integration, quota::Quota,
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 +210,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
Loading