-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
55 lines (47 loc) · 1.62 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#![allow(warnings)]
mod libs;
use libs::constants::get_project_root;
use libs::structures::models::Galaxy;
use libs::utils::console_handler::{get_args, get_file_path_from_args, get_show};
use libs::utils::files_handler::read_data;
use libs::utils::hubble_handler::{calculate_age, get_h0};
use libs::utils::misc_handler::{format_f64, print_disclaimers};
fn main() {
let args: Vec<String> = match get_args() {
Ok(val) => val,
Err(_) => panic!("Error while getting command line arguments: Failed to parse arguments."),
};
let file_path: String = match get_file_path_from_args(&args) {
Ok(val) => val,
Err(_) => get_project_root()
.unwrap()
.join("data")
.join("galaxies.csv")
.to_str()
.unwrap()
.to_string(),
};
let data: Vec<Galaxy> = match read_data(&file_path, get_show(&args).unwrap_or_default()) {
Ok(val) => val,
Err(_) => panic!("Error while reading data file at {}.", file_path),
};
let h0: f64 = match get_h0(&data) {
Ok(val) => val,
Err(_) => panic!("Error while calculating Hubble Constant."),
};
let age: f64 = match calculate_age(h0) {
Ok(val) => val,
Err(_) => panic!("Error while calculating age of the universe."),
};
print_disclaimers();
println!(
"Hubble Constant was calculated to be:\t{} km/s/Mpc",
format_f64(h0).unwrap_or_else(|_| String::from("0.0"))
);
println!(
"Age of the Universe:\t{} years",
format_f64(age).unwrap_or_else(|_| String::from("0.0"))
);
}
#[cfg(test)]
mod tests;