rinex-cli 0.14.0

GNSS data post processing and quality control, powered by GNSS-Qc
//! Session section: inputs, configuration, engine statistics
use itertools::Itertools;

use crate::{
    engine::SessionContext,
    index::{format_duration, format_epoch},
    report::{Block, Section, Table},
    sink::RunSummary,
};

pub fn sections(context: &SessionContext, run: &RunSummary) -> Section {
    let mut section = Section::new("session", "Session");

    if !context.setup.is_empty() {
        section.push(Block::Heading("Configuration".to_string()));
        section.push(Block::KeyValue(context.setup.clone()));
    }

    section.push(Block::Heading("Input products".to_string()));

    let mut table = Table::new(&[
        "Type",
        "Identity",
        "Period",
        "Sampling",
        "Satellites",
        "Files",
    ]);

    for entry in context.manifest.iter() {
        let processed = if entry.kind.is_processed() {
            ""
        } else {
            " (not processed)"
        };

        table.push(vec![
            format!("{}{}", entry.kind, processed),
            entry.identity.to_string(),
            format!(
                "{} → {}",
                format_epoch(entry.first),
                format_epoch(entry.last)
            ),
            format_duration(entry.sampling),
            if entry.satellites.is_empty() {
                "-".to_string()
            } else {
                format!(
                    "{} ({})",
                    entry.satellites.len(),
                    entry
                        .constellations()
                        .iter()
                        .map(|c| format!("{:x}", c))
                        .unique()
                        .join(", ")
                )
            },
            entry
                .files
                .iter()
                .map(|path| {
                    path.file_name()
                        .map(|name| name.to_string_lossy().to_string())
                        .unwrap_or_default()
                })
                .join(", "),
        ]);
    }

    section.push(Block::Table(table));

    section.push(Block::Heading("Processing".to_string()));
    section.push(Block::KeyValue(vec![
        ("Epochs".to_string(), run.stats.epochs.to_string()),
        ("Input items".to_string(), run.stats.items.to_string()),
        ("Results".to_string(), run.results.to_string()),
        (
            "Late observations (dropped)".to_string(),
            run.stats.late_items.to_string(),
        ),
        ("First result".to_string(), format_epoch(run.first)),
        ("Last result".to_string(), format_epoch(run.last)),
        (
            "Processing time".to_string(),
            format!("{:.1} s", run.processing_time_s),
        ),
        ("Command line".to_string(), context.command_line.clone()),
        (
            "Software".to_string(),
            format!("rinex-cli v{}, gnss-qc v0.6", env!("CARGO_PKG_VERSION")),
        ),
    ]));

    section
}