Make printing a bit neater

This commit is contained in:
Sofia 2020-08-24 02:40:05 +03:00
parent 89460011eb
commit 18cddbab28
2 changed files with 15 additions and 13 deletions

View File

@ -67,18 +67,14 @@ impl Timestamped for LocationModel {
}
pub struct API {
config: Config,
pub last_response_ping: u32,
pub config: Config,
location_req_que: Vec<String>,
}
impl API {
pub fn new(config: Config) -> API {
API {
last_response_ping: config.throttle,
config: config,
location_req_que: Vec::new(),
}
}

View File

@ -11,6 +11,7 @@ use errors::{GenericError, MessagedError};
use std::fs::File;
use std::io::prelude::*;
use std::sync::mpsc::TryRecvError;
use std::time::Duration;
fn main() {
let env: EnvOpt = argh::from_env();
@ -72,13 +73,16 @@ fn run(config: &Config, from: Option<String>, to: Option<String>) -> Result<(),
Ok(res) => match res {
Ok(loc) => {
counter += 1;
println!(
"Currently: {:#.2}%",
counter as f32 / states.len() as f32 * 100.
let remaining = exp_time(&api, states.len() as u64 - counter as u64);
print!(
"Done: {:<5.2}% Remaining: {:<5.2} seconds\r",
counter as f32 / states.len() as f32 * 100.,
remaining.as_secs_f32()
);
std::io::stdout().lock().flush().ok();
match loc {
Ok(mut loc) => locations.append(&mut loc),
Err(e) => println!(
Err(e) => eprintln!(
"Error fetching location data: {}",
e.message.unwrap_or(String::new())
),
@ -93,14 +97,15 @@ fn run(config: &Config, from: Option<String>, to: Option<String>) -> Result<(),
}
}
}
println!("{:<100}", "Done!");
locations.sort_by(|loc1, loc2| loc2.timestamp.cmp(&loc1.timestamp));
let locs = API::get_between(&locations, from, to, false, &config);
dbg!(
/*dbg!(
&locs.iter().map(|loc| loc.0).collect::<Vec<NaiveDateTime>>(),
locs.len(),
locations.len()
);
);*/
Ok(())
}
@ -115,6 +120,7 @@ fn get_opt<A, B>(option: Option<Result<A, B>>) -> Result<Option<A>, B> {
}
}
fn exp_time(api: &API, reqs_left: u32) -> f32 {
(reqs_left * api.last_response_ping) as f32 / 1000.
fn exp_time(api: &API, reqs_left: u64) -> Duration {
let interval = 1_000 / api.config.throttle as u64;
Duration::from_millis(interval * reqs_left)
}