feat: cooked up something fierce
Pipeline / check (pull_request) Successful in 3m9s
Pipeline / docs (pull_request) Skipped
Pipeline / nightly (pull_request) Skipped
Pipeline / release (pull_request) Skipped

This commit is contained in:
alexm committed 2026-09-26 18:22:25 -04:00
1 parent eabc98ad31
commit 5ac1e317c0
26 files changed
+1485 -44

No files matched your search

+112 -7
View File
@@ -20,13 +20,13 @@
use std::collections::{BTreeMap, BTreeSet};
use std::path::{Path, PathBuf};
use crate::assessment::AssessmentFile;
use crate::assessment::{AssessmentFile, Placement};
use crate::bank::BankFile;
use crate::course::CourseFile;
use crate::error::{Error, Result};
use crate::item::Item;
use crate::layout::Layout;
use crate::taxonomy::{Level, Status, Tier};
use crate::taxonomy::{Format, Level, Status, Tier};
use crate::yaml;
/// One item plus everything needed to locate it again.
@@ -261,6 +261,115 @@ impl Catalog {
Ok(issues)
}
/// Checks one placement's option set against the item's pool.
///
/// The checks that moved here from the bank when options became a pool. A
/// bank holding two defensible keys and six distractors is sound; what has
/// to hold for a *form* is that exactly one key reached the student, that
/// none of the distractors was true, and that the count matches policy.
/// None of that can be decided by looking at the item alone.
///
/// # Arguments
///
/// * `p` - the placement.
/// * `item` - the item it names.
///
/// # Returns
///
/// One message per problem.
fn validate_placement(&self, p: &Placement, item: &Item) -> Vec<String> {
let mut issues = Vec::new();
if !item.format.has_options() {
return issues;
}
let at = |number: u32| format!("question {number} ({})", p.item);
for id in p.key.iter().chain(p.distractors.iter()) {
if item.option(id).is_none() {
issues.push(format!(
"{}: `{id}` is not an option of this item",
at(p.number)
));
}
}
for id in &p.distractors {
if p.key.iter().any(|k| k == id) {
issues.push(format!(
"{}: `{id}` is listed as both the key and a distractor",
at(p.number)
));
}
if item.option(id).is_some_and(|o| o.correct) {
issues.push(format!(
"{}: `{id}` is offered as a distractor but the bank keys it correct",
at(p.number)
));
}
}
for id in &p.key {
if item.option(id).is_some_and(|o| !o.correct) {
issues.push(format!(
"{}: `{id}` is keyed correct here but the bank does not key it. An option is \
true or it is not; which true option a form uses is this record's choice, \
but not whether it is true.",
at(p.number)
));
}
}
let single = item.format == Format::SingleBestAnswer;
if single && p.key.len() > 1 {
issues.push(format!(
"{}: single_best_answer administers exactly one key, this names {}",
at(p.number),
p.key.len()
));
}
// No distractor list means the whole pool, which is what a pre-2.0
// record means and what an item whose pool is its form still means.
// The record still has to say which key, when the pool offers a choice.
if p.distractors.is_empty() {
let (keys, _) = item.pool();
if p.key.is_empty() && keys.len() > 1 && single {
issues.push(format!(
"{}: the item offers {} defensible keys, so the record has to say which one \
this assessment used",
at(p.number),
keys.len()
));
}
} else {
let shown = item.administered(&p.key, &p.distractors);
let expected = self.course.policy.options_per_item;
if shown.len() != expected {
issues.push(format!(
"{}: administers {} option(s), but course policy is {expected} per item",
at(p.number),
shown.len()
));
}
if single && p.key.is_empty() {
issues.push(format!(
"{}: names its distractors but not its key, so what was marked correct is \
left to whatever the bank says today",
at(p.number)
));
}
}
if let Some(recorded) = &p.variant {
if *recorded != item.variant_digest(&p.key, &p.distractors) {
issues.push(format!(
"{}: an administered option has been reworded since this assessment. \
Statistics pooled under this variant describe the older wording.",
at(p.number)
));
}
}
issues
}
/// Checks every sealed administration's stems against the bank.
///
/// The seal is the authority on what was administered, so this is the
@@ -334,11 +443,7 @@ impl Catalog {
));
}
}
if !p.key.is_empty() && p.key != entry.item.key_letters() {
issues.push(format!(
"question {} ({}): the recorded key {:?} differs from the item's current key {:?}",
p.number, p.item, p.key, entry.item.key_letters()));
}
issues.extend(self.validate_placement(p, &entry.item));
}
}
}