Fixed Progress Bar
Build Library / Build Library (push) Successful in 6m22s

Changed date math so that the last date from the first response from the API is the minimum value for the progress bar. This gives true progress percentages from the first date to the last date on the last request. #36
This commit is contained in:
brotoskyj
2025-12-04 11:57:49 -05:00
parent 76bd3a6087
commit b19eeb6c96
5 changed files with 17 additions and 10 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ dependencies = [
[[package]] [[package]]
name = "airlock_libs" name = "airlock_libs"
version = "5.1.0" version = "5.1.1"
dependencies = [ dependencies = [
"chrono", "chrono",
"crossbeam", "crossbeam",
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "airlock_libs" name = "airlock_libs"
version = "5.1.0" version = "5.1.1"
edition = "2024" edition = "2024"
[lib] [lib]
+1 -1
View File
@@ -4,7 +4,7 @@ build-backend = "maturin"
[project] [project]
name = "airlock_libs" name = "airlock_libs"
version = "5.1.0" version = "5.1.1"
description = "Airlock Digital API Wrapper" description = "Airlock Digital API Wrapper"
readme = "README.md" readme = "README.md"
license = { text = "AGPL-3.0-only" } license = { text = "AGPL-3.0-only" }
+13 -6
View File
@@ -75,7 +75,7 @@ pub fn pull_policy_exec_histories(
} }
let mut checkpoint_number: String = SkipBack::find_checkpoint(days).to_string(); let mut checkpoint_number: String = SkipBack::find_checkpoint(days).to_string();
let multi_progress = MultiProgress::new(); let multi_progress = MultiProgress::new();
multi_progress.set_draw_target(ProgressDrawTarget::stdout()); multi_progress.set_draw_target(ProgressDrawTarget::stderr());
let progress_bar = multi_progress.add(ProgressBar::new(100)); let progress_bar = multi_progress.add(ProgressBar::new(100));
progress_bar.set_style( progress_bar.set_style(
ProgressStyle::default_bar() ProgressStyle::default_bar()
@@ -178,6 +178,7 @@ pub fn pull_policy_exec_histories(
} }
} }
}); });
let mut first_date: Option<NaiveDate> = None;
tracer.in_span("Airlock Data Retreival", |cx| { tracer.in_span("Airlock Data Retreival", |cx| {
let span = cx.span(); let span = cx.span();
span.set_attribute(Key::new("Days").string(days.to_string())); span.set_attribute(Key::new("Days").string(days.to_string()));
@@ -209,11 +210,17 @@ pub fn pull_policy_exec_histories(
"%Y-%m-%dT%H:%M:%SZ", "%Y-%m-%dT%H:%M:%SZ",
) )
{ {
let date_diff = Local::now().naive_local().date() - last_date; if first_date.is_none() {
let percentage_diff = first_date = Some(last_date);
((days - date_diff.num_days()) as f64 / days as f64 * 100.0).round() as u64; }
progress_bar.set_position(percentage_diff); if let Some(base_date) = first_date {
progress_bar.set_message("Total Percent Complete"); let date_diff = last_date - base_date;
let total_span = (Local::now().naive_local().date() - base_date).num_days();
let percentage = ((date_diff.num_days() as f64 / total_span as f64) * 100.0)
.clamp(0.0, 100.0)
.round() as u64;
progress_bar.set_position(percentage);
}
} }
} }
}); });
+1 -1
View File
@@ -11,4 +11,4 @@ urllib3==2.5.0
pyperclip==1.11.0 pyperclip==1.11.0
--extra-index-url https://git.racooncity.org/api/packages/brotoskyj/pypi/simple/ --extra-index-url https://git.racooncity.org/api/packages/brotoskyj/pypi/simple/
airlock_libs==5.1.0 airlock_libs==5.1.1