use core::convert::From;
use std::env;
use std::error::Error;
use std::ffi::OsString;
use std::fs::File;
use csv::Reader;
use log::info;
use crate::csv_record::CsvRecord;
use crate::csv_record_hygv3::HygV3Record;
use solvastro::structs_f64::star::Star;
pub fn parse_csv_file(file: File) -> Vec<Star> {
let mut stars: Vec<Star> = Reader::from_reader(file)
.deserialize()
.filter_map(Result::ok)
.map(|r: HygV3Record| r.into_star())
.collect();
info!("Stars successfully parsed from CSV: {:?}", stars.len());
stars.sort_by(|a, b| a.mag().partial_cmp(&b.mag()).unwrap());
stars
}
#[cfg(not(tarpaulin_include))]
pub fn get_first_arg() -> Result<OsString, Box<dyn Error>> {
info!("{:?}", env::args_os().nth(1));
match env::args_os().nth(1) {
None => Err(From::from("expected 1 argument, but got none")),
Some(file_path) => Ok(file_path),
}
}