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:
@@ -75,7 +75,7 @@ pub fn pull_policy_exec_histories(
|
||||
}
|
||||
let mut checkpoint_number: String = SkipBack::find_checkpoint(days).to_string();
|
||||
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));
|
||||
progress_bar.set_style(
|
||||
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| {
|
||||
let span = cx.span();
|
||||
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",
|
||||
)
|
||||
{
|
||||
let date_diff = Local::now().naive_local().date() - last_date;
|
||||
let percentage_diff =
|
||||
((days - date_diff.num_days()) as f64 / days as f64 * 100.0).round() as u64;
|
||||
progress_bar.set_position(percentage_diff);
|
||||
progress_bar.set_message("Total Percent Complete");
|
||||
if first_date.is_none() {
|
||||
first_date = Some(last_date);
|
||||
}
|
||||
if let Some(base_date) = first_date {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user