solvastro 0.1.1

A Rust blind plate solver
Documentation
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::csv_record_mag5cat::Mag5CatRecord;
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())
        // .map(|r: Mag5CatRecord| r.into_star())
        .collect();

    info!("Stars successfully parsed from CSV: {:?}", stars.len());

    // sort stars in ascending v_mag order (ie BRIGHTEST first)
    stars.sort_by(|a, b| a.mag().partial_cmp(&b.mag()).unwrap());

    stars
}

/// Returns the first positional argument sent to this process. If there are no
/// positional arguments, then this returns an error.
#[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),
    }
}