feat: include bonus
Pipeline / check (pull_request) Successful in 12m11s
Pipeline / docs (pull_request) Skipped
Pipeline / nightly (pull_request) Skipped
Pipeline / release (pull_request) Skipped

This commit is contained in:
alexm committed 2026-11-02 08:22:07 -05:00
1 parent c8d6f4a5dd
commit 15175f64fd
16 files changed
+773 -83

No files matched your search

+51 -1
View File
@@ -206,16 +206,33 @@ pub struct Score {
pub points: f64,
/// Points available on scored items.
pub points_possible: f64,
/// Percentage on scored items.
/// Every point earned, bonus and curve included: the total on the platform.
pub total_points: f64,
/// `total_points` as a percentage of `points_possible`, the same percentage
/// the platform shows. It can pass 100.
pub percent: f64,
/// Bonus points earned.
pub bonus_points: f64,
/// Points a curve added.
pub curve_points: f64,
/// The bonus questions on the exam, so the total can be added up by hand.
pub bonus_questions: Vec<BonusQuestion>,
/// Items answered correctly.
pub correct: usize,
/// Scored items administered.
pub n_items: usize,
}
/// One bonus question's contribution to a student's total.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct BonusQuestion {
/// The recorded question number.
pub number: u32,
/// Points the student earned on it.
pub points: f64,
}
/// Where a score sits in the class.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "kebab-case")]
@@ -585,14 +602,26 @@ pub fn student(
.map(|a| a.items.iter().map(|i| (i.number, i.p_value)).collect())
.unwrap_or_default();
// A curve is on the total but was never a question on the paper, so a box for
// it would send the student looking for something that was not there.
let questions = if opts.questions {
rows.iter()
.filter(|row| !row.is_curve())
.map(|row| question_row(row, catalog, &class_rates, opts))
.collect()
} else {
Vec::new()
};
let bonus_questions = rows
.iter()
.filter(|r| r.bonus && !r.dropped && !r.is_curve())
.map(|r| BonusQuestion {
number: r.item_number,
points: r.score,
})
.collect();
let mut dropped_questions: Vec<DroppedQuestion> = rows
.iter()
.filter(|r| r.dropped)
@@ -630,8 +659,11 @@ pub fn student(
score: Score {
points: summary.points,
points_possible: summary.points_possible,
total_points: summary.total_points,
percent: summary.percent,
bonus_points: summary.bonus_points,
curve_points: summary.curve_points,
bonus_questions,
correct: summary.correct,
n_items: summary.n_items,
},
@@ -972,6 +1004,10 @@ fn readings_for(course: &CourseFile, objective: &str, limit: usize) -> Vec<Study
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct CohortDiagnostic {
/// Mean bonus points per student, which the distribution includes.
pub mean_bonus: f64,
/// Mean curve points per student, which the distribution includes.
pub mean_curve: f64,
/// How many students sat it.
pub n_students: usize,
/// How many scored items.
@@ -1758,6 +1794,8 @@ pub fn cohort(
n_students: cohort.students.len(),
n_items: analysis.reliability.n_items,
distribution: distribution(&percents),
mean_bonus: mean_of(cohort, |s| s.bonus_points),
mean_curve: mean_of(cohort, |s| s.curve_points),
grades,
lectures,
dropped_questions,
@@ -2419,6 +2457,15 @@ fn form_rows(set: &ResponseSet, cohort: &Cohort) -> Vec<FormRow> {
.collect()
}
/// The class mean of one per-student number.
fn mean_of(cohort: &Cohort, value: impl Fn(&StudentSummary) -> f64) -> f64 {
if cohort.students.is_empty() {
0.0
} else {
cohort.students.iter().map(value).sum::<f64>() / cohort.students.len() as f64
}
}
/// Bins a set of percentages into a distribution.
fn distribution(percents: &[f64]) -> Distribution {
let mut sorted: Vec<f64> = percents.to_vec();
@@ -2504,8 +2551,11 @@ mod tests {
score: Score {
points: 1.0,
points_possible: 2.0,
total_points: 1.0,
percent: 50.0,
bonus_points: 0.0,
curve_points: 0.0,
bonus_questions: Vec::new(),
correct: 1,
n_items: 2,
},