Skip to main content

Question

Struct Question 

Source
pub struct Question {
    pub id: String,
    pub bar: String,
    pub bars: Vec<String>,
    pub staves: Vec<String>,
    pub kind: String,
    pub ask: String,
    pub why: String,
    pub page: usize,
    pub spot: Vec<[f64; 4]>,
    pub choices: Vec<Choice>,
    pub draft: Vec<BarText>,
}
Expand description

A question on one or more bars.

Fields§

§id: String

Stable within this reading.

§bar: String

The bar’s label as in the .fmn (the first, where it settles several).

§bars: Vec<String>

Every bar it settles.

§staves: Vec<String>

The staves it settles, as the .fmn names them.

§kind: String

dot, tuplet, rest-or-longer, cross-staff, chord-voices, part, ink (a read bar whose printed stems, beams or flags its reading leaves unused) or other.

§ask: String

The question in plain words.

§why: String

The reader’s own reason.

§page: usize

The page, from 0.

§spot: Vec<[f64; 4]>

What it is about: boxes [x0, y0, x1, y1] in page points from the page’s top left.

§choices: Vec<Choice>

The likeliest first. Two to six; none where the reader has no reading that fits, and then the person writes the bar, starting from Question::draft.

§draft: Vec<BarText>

The notes the reader saw in the bar as it saw them, its lines a voice split by stem, for a person to start writing the bar from. They need not add up, nor compile; empty where the reader cannot write them.

Implementations§

Source§

impl Question

Source

pub fn to_json(&self) -> String

Examples found in repository?
examples/review.rs (line 55)
6fn main() {
7    let a: Vec<String> = std::env::args().collect();
8    if a.len() < 2 {
9        eprintln!("usage: review SCORE.pdf [--count | --svg PAGE X0 Y0 X1 Y1]");
10        std::process::exit(2);
11    }
12    let bytes = std::fs::read(&a[1]).expect("reading the PDF");
13    if a.get(2).map(String::as_str) == Some("--svg") {
14        let n: Vec<f64> = a[3..]
15            .iter()
16            .map(|x| x.parse().expect("a number"))
17            .collect();
18        match fm_vector::page_svg(&bytes, n[0] as usize, [n[1], n[2], n[3], n[4]]) {
19            Ok(svg) => print!("{svg}"),
20            Err(e) => {
21                println!("refused: {}", e.why);
22                std::process::exit(1);
23            }
24        }
25        return;
26    }
27    let t = std::time::Instant::now();
28    let review = match fm_vector::read_pdf_review(&bytes) {
29        Ok(r) => r,
30        Err(e) => {
31            println!("refused: {}", e.why);
32            std::process::exit(1);
33        }
34    };
35    if a.get(2).map(String::as_str) == Some("--count") {
36        let mut kinds = std::collections::BTreeMap::new();
37        for q in &review.questions {
38            *kinds.entry(q.kind.as_str()).or_insert(0) += 1;
39        }
40        let kinds: Vec<String> = kinds.iter().map(|(k, n)| format!("{k}={n}")).collect();
41        let choices: usize = review.questions.iter().map(|q| q.choices.len()).sum();
42        let latent: usize = review.latent.iter().map(|q| q.choices.len()).sum();
43        println!(
44            "questions {}\tunread {}\tlatent {}\tchoices {}\tms {}\t{}\tlatent choices {}",
45            review.questions.len(),
46            review.reading.unread.len(),
47            review.latent.len(),
48            choices,
49            t.elapsed().as_millis(),
50            kinds.join(" "),
51            latent
52        );
53        return;
54    }
55    let qs: Vec<String> = review.questions.iter().map(|q| q.to_json()).collect();
56    let latent: Vec<String> = review.latent.iter().map(|q| q.to_json()).collect();
57    println!(
58        "{{\"questions\":[\n{}\n],\n\"latent\":[\n{}\n]}}",
59        qs.join(",\n"),
60        latent.join(",\n")
61    );
62}

Trait Implementations§

Source§

impl Clone for Question

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 Question

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Question

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Question

Auto Trait Implementations§

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.