Skip to main content

Audit

Struct Audit 

Source
pub struct Audit {
    pub reading: Reading,
    pub systems: Vec<SystemAudit>,
    pub score: f64,
    pub findings: BTreeMap<String, usize>,
    pub pages: Vec<[f64; 2]>,
}
Expand description

A PDF’s reading and what is suspect in it.

Fields§

§reading: Reading§systems: Vec<SystemAudit>§score: f64

The systems’ scores, summed.

§findings: BTreeMap<String, usize>

Each kind of finding and how many bars or systems have it.

§pages: Vec<[f64; 2]>

The pages’ sizes, in points.

Implementations§

Source§

impl Audit

Source

pub fn to_json(&self) -> String

The audit as JSON, the reading’s .fmn and MusicXML left out: the PDF’s score, its bars and systems counted, the findings by kind, the marks printed and written by kind, and every system (its page, frame, score, reasons, and its bars with theirs).

Examples found in repository?
examples/audit.rs (line 22)
7fn main() {
8    let a: Vec<String> = std::env::args().collect();
9    if a.len() < 2 {
10        eprintln!("usage: audit SCORE.pdf [OUT.json [OUT.musicxml [OUT.fmn]]]");
11        std::process::exit(2);
12    }
13    let bytes = std::fs::read(&a[1]).expect("reading the PDF");
14    let audit = match fm_vector::audit_pdf(&bytes) {
15        Ok(x) => x,
16        Err(e) => {
17            println!("refused: {}", e.why.replace('\n', " "));
18            std::process::exit(1);
19        }
20    };
21    if let Some(out) = a.get(2) {
22        std::fs::write(out, audit.to_json()).expect("writing the JSON");
23    }
24    if let Some(out) = a.get(3) {
25        std::fs::write(out, &audit.reading.musicxml).expect("writing the MusicXML");
26    }
27    if let Some(out) = a.get(4) {
28        std::fs::write(out, &audit.reading.fmn).expect("writing the .fmn");
29    }
30    let bars: usize = audit.systems.iter().map(|s| s.bars.len()).sum();
31    let findings: Vec<String> = (audit.findings.iter())
32        .map(|(k, n)| format!("{k}={n}"))
33        .collect();
34    println!(
35        "audited\t{:.1}\t{} systems\t{bars} bars\t{} unread\t{}",
36        audit.score,
37        audit.systems.len(),
38        audit.reading.unread.len(),
39        findings.join("; ")
40    );
41    let mut worst: Vec<&fm_vector::SystemAudit> = audit.systems.iter().collect();
42    worst.sort_by(|x, y| y.score.total_cmp(&x.score));
43    for s in worst.iter().take(10).filter(|s| s.score > 0.0) {
44        let mut why = s.reasons.clone();
45        for b in &s.bars {
46            why.extend(b.reasons.iter().map(|r| format!("bar {}: {r}", b.bar)));
47        }
48        println!(
49            "system\t{}\tpage {}\t{:.1}\t{}",
50            s.system + 1,
51            s.page + 1,
52            s.score,
53            why.join("; ")
54        );
55    }
56}

Trait Implementations§

Source§

impl Clone for Audit

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Audit

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for Audit

§

impl Freeze for Audit
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, PhantomData<String>: Freeze, PhantomData<Unread>: Freeze, *const LeafNode<(i64, String), Seen> is !null: Freeze, PhantomData<(Owned, LeafOrInternal)>: Freeze, PhantomData<Box<((i64, String), Seen)>>: Freeze, *const LeafNode<(i64, String), Place> is !null: Freeze, PhantomData<Box<((i64, String), Place)>>: Freeze, *const LeafNode<i64, usize> is !null: Freeze, PhantomData<Box<(i64, usize)>>: Freeze, PhantomData<NoteMark>: Freeze, PhantomData<SystemAudit>: Freeze, *const LeafNode<String, usize> is !null: Freeze, PhantomData<Box<(String, usize)>>: Freeze, PhantomData<[f64; 2]>: Freeze,

§

impl Move for Audit

§

impl RefUnwindSafe for Audit

§

impl Send for Audit
where RawVecInner: Send, NodeRef<Owned, (i64, String), Seen, LeafOrInternal>: Send, BoxRaw<((i64, String), Seen)>: Send, NodeRef<Owned, (i64, String), Place, LeafOrInternal>: Send, BoxRaw<((i64, String), Place)>: Send, NodeRef<Owned, i64, usize, LeafOrInternal>: Send, BoxRaw<(i64, usize)>: Send, NodeRef<Owned, String, usize, LeafOrInternal>: Send, BoxRaw<(String, usize)>: Send,

§

impl Sync for Audit
where RawVecInner: Sync, NodeRef<Owned, (i64, String), Seen, LeafOrInternal>: Sync, BoxRaw<((i64, String), Seen)>: Sync, NodeRef<Owned, (i64, String), Place, LeafOrInternal>: Sync, BoxRaw<((i64, String), Place)>: Sync, NodeRef<Owned, i64, usize, LeafOrInternal>: Sync, BoxRaw<(i64, usize)>: Sync, NodeRef<Owned, String, usize, LeafOrInternal>: Sync, BoxRaw<(String, usize)>: Sync,

§

impl Unpin for Audit
where *const u8 is !null: Unpin, *const LeafNode<(i64, String), Seen> is !null: Unpin, Box<((i64, String), Seen)>: Unpin, *const LeafNode<(i64, String), Place> is !null: Unpin, Box<((i64, String), Place)>: Unpin, *const LeafNode<i64, usize> is !null: Unpin, Box<(i64, usize)>: Unpin, *const LeafNode<String, usize> is !null: Unpin, Box<(String, usize)>: Unpin,

§

impl UnsafeUnpin for Audit

§

impl UnwindSafe for Audit

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.