Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
  • Loading branch information
gwbres committed May 21, 2023
1 parent cf3d250 commit 762a743
Show file tree
Hide file tree
Showing 47 changed files with 3,876 additions and 3,970 deletions.
124 changes: 61 additions & 63 deletions rinex-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::fops::filename;
use crate::parser::parse_epoch;
use clap::{Arg, ArgAction, ArgMatches, ColorChoice, Command};
use log::{error, info, warn};
use rinex::{prelude::*, Merge, quality::QcOpts};
use rinex::{prelude::*, quality::QcOpts, Merge};
use std::str::FromStr;

pub struct Cli {
Expand Down Expand Up @@ -291,24 +291,22 @@ Refer to README"))
pub fn quality_check(&self) -> bool {
self.matches.get_flag("qc")
}
fn qc_config_path(&self) -> Option<&String> {
if let Some(path) = self.matches.get_one::<String>("qc-config") {
Some(path)
} else {
None
}
}
pub fn qc_config(&self) -> QcOpts {
if let Some(path) = self.qc_config_path() {
let s = std::fs::read_to_string(path)
.expect(&format!("failed to read \"{}\"", path));
let opts: QcOpts = serde_json::from_str(&s)
.expect("faulty qc configuration");
opts
} else {
QcOpts::default()
}
}
fn qc_config_path(&self) -> Option<&String> {
if let Some(path) = self.matches.get_one::<String>("qc-config") {
Some(path)
} else {
None
}
}
pub fn qc_config(&self) -> QcOpts {
if let Some(path) = self.qc_config_path() {
let s = std::fs::read_to_string(path).expect(&format!("failed to read \"{}\"", path));
let opts: QcOpts = serde_json::from_str(&s).expect("faulty qc configuration");
opts
} else {
QcOpts::default()
}
}
pub fn quality_check_separate(&self) -> bool {
self.matches.get_flag("qc-separate")
}
Expand Down Expand Up @@ -504,51 +502,51 @@ Refer to README"))
}
None
}
fn manual_ecef(&self) -> Option<&String> {
self.matches.get_one::<String>("pos-ecef")
}
fn manual_geodetic(&self) -> Option<&String> {
self.matches.get_one::<String>("pos-geo")
}
fn manual_ecef(&self) -> Option<&String> {
self.matches.get_one::<String>("pos-ecef")
}
fn manual_geodetic(&self) -> Option<&String> {
self.matches.get_one::<String>("pos-geo")
}
/// Returns Ground Position possibly specified by user
pub fn manual_position(&self) -> Option<GroundPosition> {
if let Some(args) = self.manual_ecef() {
let content: Vec<&str> = args.split(",").collect();
if content.len() != 3 {
panic!("expecting \"x, y, z\" description");
}
if let Ok(pos_x) = f64::from_str(content[0].trim()) {
if let Ok(pos_y) = f64::from_str(content[1].trim()) {
if let Ok(pos_z) = f64::from_str(content[2].trim()) {
return Some(GroundPosition::from_ecef_wgs84((pos_x, pos_y, pos_z)));
} else {
error!("pos(z) should be f64 ECEF [m]");
}
} else {
error!("pos(y) should be f64 ECEF [m]");
}
} else {
error!("pos(x) should be f64 ECEF [m]");
}
} else if let Some(args) = self.manual_geodetic() {
let content: Vec<&str> = args.split(",").collect();
if content.len() != 3 {
panic!("expecting \"lat, lon, alt\" description");
}
if let Ok(lat) = f64::from_str(content[0].trim()) {
if let Ok(long) = f64::from_str(content[1].trim()) {
if let Ok(alt) = f64::from_str(content[2].trim()) {
return Some(GroundPosition::from_geodetic((lat, long, alt)));
} else {
error!("altitude should be f64 [ddeg]");
}
} else {
error!("altitude should be f64 [ddeg]");
}
} else {
error!("altitude should be f64 [ddeg]");
}
}
None
if let Some(args) = self.manual_ecef() {
let content: Vec<&str> = args.split(",").collect();
if content.len() != 3 {
panic!("expecting \"x, y, z\" description");
}
if let Ok(pos_x) = f64::from_str(content[0].trim()) {
if let Ok(pos_y) = f64::from_str(content[1].trim()) {
if let Ok(pos_z) = f64::from_str(content[2].trim()) {
return Some(GroundPosition::from_ecef_wgs84((pos_x, pos_y, pos_z)));
} else {
error!("pos(z) should be f64 ECEF [m]");
}
} else {
error!("pos(y) should be f64 ECEF [m]");
}
} else {
error!("pos(x) should be f64 ECEF [m]");
}
} else if let Some(args) = self.manual_geodetic() {
let content: Vec<&str> = args.split(",").collect();
if content.len() != 3 {
panic!("expecting \"lat, lon, alt\" description");
}
if let Ok(lat) = f64::from_str(content[0].trim()) {
if let Ok(long) = f64::from_str(content[1].trim()) {
if let Ok(alt) = f64::from_str(content[2].trim()) {
return Some(GroundPosition::from_geodetic((lat, long, alt)));
} else {
error!("altitude should be f64 [ddeg]");
}
} else {
error!("altitude should be f64 [ddeg]");
}
} else {
error!("altitude should be f64 [ddeg]");
}
}
None
}
}
6 changes: 3 additions & 3 deletions rinex-cli/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ impl Context {
let ground_position = match &primary_rinex.header.ground_position {
Some(position) => {
info!("antenna position: {}", position);
Some(position.clone())
Some(position.clone())
},
_ => {
if let Some(ref nav) = nav_rinex {
if let Some(pos) = &nav.header.ground_position {
info!("antenna position: {}", pos);
info!("antenna position: {}", pos);
Some(pos.clone())
} else {
if let Some(pos) = &cli.manual_position() {
info!("user defined antenna position: {}", pos);
info!("user defined antenna position: {}", pos);
Some(pos.clone())
} else {
trace!("undetermined antenna position");
Expand Down
123 changes: 63 additions & 60 deletions rinex-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod preprocessing;
use preprocessing::preprocess;

//use horrorshow::Template;
use rinex::{merge::Merge, processing::*, split::Split, quality::*};
use rinex::{merge::Merge, processing::*, quality::*, split::Split};

use cli::Cli;
pub use context::Context;
Expand All @@ -26,7 +26,7 @@ extern crate pretty_env_logger;
#[macro_use]
extern crate log;

use fops::{open_with_web_browser, filename};
use fops::{filename, open_with_web_browser};
use std::io::Write;

pub fn main() -> Result<(), rinex::Error> {
Expand All @@ -46,14 +46,14 @@ pub fn main() -> Result<(), rinex::Error> {
*/
preprocess(&mut ctx, &cli);

/* <!> <!> <!> <!> <!> <!> <!>
* Observation RINEX:
* align phase origins at this point
* this allows easy GNSS combination and processing,
* gives more meaningful phase data plots..
<!> <!> <!> <!> <!> <!> <!> */
/* <!> <!> <!> <!> <!> <!> <!>
* Observation RINEX:
* align phase origins at this point
* this allows easy GNSS combination and processing,
* gives more meaningful phase data plots..
<!> <!> <!> <!> <!> <!> <!> */
//ctx.primary_rinex
//.observation_align_phase_origins_mut();
//.observation_align_phase_origins_mut();

/*
* Basic file identification
Expand Down Expand Up @@ -110,7 +110,9 @@ pub fn main() -> Result<(), rinex::Error> {
* [GF] recombination visualization requested
*/
if cli.gf_recombination() {
let data = ctx.primary_rinex.observation_combination(Combination::GeometryFree);
let data = ctx
.primary_rinex
.observation_combination(Combination::GeometryFree);
plot::plot_gnss_recombination(
&mut plot_ctx,
"Geometry Free signal combination",
Expand All @@ -131,7 +133,9 @@ pub fn main() -> Result<(), rinex::Error> {
* [WL] recombination
*/
if cli.wl_recombination() {
let data = ctx.primary_rinex.observation_combination(Combination::WideLane);
let data = ctx
.primary_rinex
.observation_combination(Combination::WideLane);
plot::plot_gnss_recombination(
&mut plot_ctx,
"Wide Lane signal combination",
Expand All @@ -144,7 +148,9 @@ pub fn main() -> Result<(), rinex::Error> {
* [NL] recombination
*/
if cli.nl_recombination() {
let data = ctx.primary_rinex.observation_combination(Combination::NarrowLane);
let data = ctx
.primary_rinex
.observation_combination(Combination::NarrowLane);
plot::plot_gnss_recombination(
&mut plot_ctx,
"Narrow Lane signal combination",
Expand All @@ -157,7 +163,9 @@ pub fn main() -> Result<(), rinex::Error> {
* [MW] recombination
*/
if cli.mw_recombination() {
let data = ctx.primary_rinex.observation_combination(Combination::MelbourneWubbena);
let data = ctx
.primary_rinex
.observation_combination(Combination::MelbourneWubbena);
plot::plot_gnss_recombination(
&mut plot_ctx,
"Melbourne-Wübbena signal combination",
Expand Down Expand Up @@ -242,68 +250,63 @@ pub fn main() -> Result<(), rinex::Error> {
/*
* Render Graphs (HTML)
*/
if !qc_only {
let html_path = ctx.prefix.to_owned() + "/graphs.html";
let mut html_fd = std::fs::File::create(&html_path)
.expect(&format!("failed to create \"{}\"", &html_path));
write!(html_fd, "{}", plot_ctx.to_html())
.expect(&format!("failed to render graphs"));
info!("graphs rendered in \"{}\"", &html_path);
if !quiet {
open_with_web_browser(&html_path);
}
}

/*
if !qc_only {
let html_path = ctx.prefix.to_owned() + "/graphs.html";
let mut html_fd = std::fs::File::create(&html_path)
.expect(&format!("failed to create \"{}\"", &html_path));
write!(html_fd, "{}", plot_ctx.to_html()).expect(&format!("failed to render graphs"));
info!("graphs rendered in \"{}\"", &html_path);
if !quiet {
open_with_web_browser(&html_path);
}
}

/*
* QC Mode
*/
if qc {
info!("qc - enabled");

let mut qc_opts = cli.qc_config();
/*
* ground position:
let mut qc_opts = cli.qc_config();
/*
* ground position:
* if not defined in the configuration,
* and user defined it through the CLI
* ==> use this value
*/
if qc_opts.ground_position.is_none() { // config did not specify it
if let Some(pos) = cli.manual_position() { // manually passed
qc_opts = qc_opts
.with_ground_position_ecef(
pos.to_ecef_wgs84()
);
trace!("qc - antenna position manual set to {}", pos);
* and user defined it through the CLI
* ==> use this value
*/
if qc_opts.ground_position.is_none() {
// config did not specify it
if let Some(pos) = cli.manual_position() {
// manually passed
qc_opts = qc_opts.with_ground_position_ecef(pos.to_ecef_wgs84());
trace!("qc - antenna position manual set to {}", pos);
} else if ctx.ground_position.is_none() {
warn!("qc - undetermined antenna position");
warn!("qc - undetermined antenna position");
}
}
}

if qc_opts.min_snr_db > 0.0 {
trace!("qc - minimal SNR: {} dB", qc_opts.min_snr_db);
}
if qc_opts.min_snr_db > 0.0 {
trace!("qc - minimal SNR: {} dB", qc_opts.min_snr_db);
}

let nav_paths: Vec<_> = cli.nav_paths()
.iter()
.map(|k| filename(&k))
.collect();
let nav_paths: Vec<_> = cli.nav_paths().iter().map(|k| filename(&k)).collect();

let report = QcReport::new(
&filename(cli.input_path()),
&ctx.primary_rinex,
&filename(cli.input_path()),
&ctx.primary_rinex,
nav_paths,
ctx.nav_rinex,
qc_opts); // &ctx.nav_rinex
qc_opts,
); // &ctx.nav_rinex

let qc_path = ctx.prefix.to_owned() + "/report.html";
let mut qc_fd = std::fs::File::create(&qc_path)
.expect(&format!("failed to create \"{}\"", &qc_path));
write!(qc_fd, "{}", report.to_html())
.expect("failed to generate QC summary report");
info!("qc - summary report \"{}\" generated", &qc_path);
if !quiet {
open_with_web_browser(&qc_path);
}
let qc_path = ctx.prefix.to_owned() + "/report.html";
let mut qc_fd =
std::fs::File::create(&qc_path).expect(&format!("failed to create \"{}\"", &qc_path));
write!(qc_fd, "{}", report.to_html()).expect("failed to generate QC summary report");
info!("qc - summary report \"{}\" generated", &qc_path);
if !quiet {
open_with_web_browser(&qc_path);
}
}
Ok(())
} // main
Loading

0 comments on commit 762a743

Please sign in to comment.