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: StringStable within this reading.
bar: StringThe 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: Stringdot, 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: StringThe question in plain words.
why: StringThe reader’s own reason.
page: usizeThe 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
impl Question
Sourcepub fn to_json(&self) -> String
pub fn to_json(&self) -> String
Examples found in repository?
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}