feat: implement reports
This commit is contained in:
28 files changed
+7082
-63
No files matched your search
@@ -61,6 +61,9 @@ pub fn schema() -> Schema {
|
||||
Field::new("topics", DataType::Utf8, false),
|
||||
Field::new("bonus", DataType::Boolean, false),
|
||||
Field::new("dropped", DataType::Boolean, false),
|
||||
Field::new("form_position", DataType::UInt32, false),
|
||||
Field::new("selected_source", DataType::Utf8, false),
|
||||
Field::new("eliminated_source", DataType::Utf8, false),
|
||||
])
|
||||
}
|
||||
|
||||
@@ -120,6 +123,9 @@ fn to_batch(rows: &[FlatResponse]) -> Result<RecordBatch> {
|
||||
s(|r| &r.topics),
|
||||
boolc(|r| r.bonus),
|
||||
boolc(|r| r.dropped),
|
||||
u32c(|r| r.form_position),
|
||||
s(|r| &r.selected_source),
|
||||
s(|r| &r.eliminated_source),
|
||||
];
|
||||
|
||||
RecordBatch::try_new(Arc::new(schema()), columns).map_err(|e| {
|
||||
@@ -237,6 +243,20 @@ fn from_batch(batch: &RecordBatch, path: &Path) -> Result<Vec<FlatResponse>> {
|
||||
.ok_or_else(|| column_error(name, "boolean", path))
|
||||
};
|
||||
|
||||
// The three decode columns are read optionally rather than required, so a
|
||||
// file written before seals existed still loads. A missing column is not a
|
||||
// foreign file; it is last term's data.
|
||||
let optional_strings = |name: &str| -> Option<&StringArray> {
|
||||
batch
|
||||
.column_by_name(name)
|
||||
.and_then(|c| c.as_any().downcast_ref::<StringArray>())
|
||||
};
|
||||
let optional_uints = |name: &str| -> Option<&UInt32Array> {
|
||||
batch
|
||||
.column_by_name(name)
|
||||
.and_then(|c| c.as_any().downcast_ref::<UInt32Array>())
|
||||
};
|
||||
|
||||
let administration_id = strings("administration_id")?;
|
||||
let course = strings("course")?;
|
||||
let term = strings("term")?;
|
||||
@@ -263,6 +283,10 @@ fn from_batch(batch: &RecordBatch, path: &Path) -> Result<Vec<FlatResponse>> {
|
||||
let bonus = bools("bonus")?;
|
||||
let dropped = bools("dropped")?;
|
||||
|
||||
let form_position = optional_uints("form_position");
|
||||
let selected_source = optional_strings("selected_source");
|
||||
let eliminated_source = optional_strings("eliminated_source");
|
||||
|
||||
let mut out = Vec::with_capacity(batch.num_rows());
|
||||
for i in 0..batch.num_rows() {
|
||||
out.push(FlatResponse {
|
||||
@@ -272,6 +296,7 @@ fn from_batch(batch: &RecordBatch, path: &Path) -> Result<Vec<FlatResponse>> {
|
||||
assessment_id: assessment_id.value(i).to_string(),
|
||||
date: date.value(i).to_string(),
|
||||
form: form.value(i).to_string(),
|
||||
form_position: form_position.map(|a| a.value(i)).unwrap_or(0),
|
||||
student_key: student_key.value(i).to_string(),
|
||||
sid: sid.value(i).to_string(),
|
||||
email: email.value(i).to_string(),
|
||||
@@ -280,7 +305,13 @@ fn from_batch(batch: &RecordBatch, path: &Path) -> Result<Vec<FlatResponse>> {
|
||||
item_ref: item_ref.value(i).to_string(),
|
||||
item_version: item_version.value(i),
|
||||
selected: selected.value(i).to_string(),
|
||||
selected_source: selected_source
|
||||
.map(|a| a.value(i).to_string())
|
||||
.unwrap_or_default(),
|
||||
eliminated: eliminated.value(i).to_string(),
|
||||
eliminated_source: eliminated_source
|
||||
.map(|a| a.value(i).to_string())
|
||||
.unwrap_or_default(),
|
||||
correct: correct.value(i).to_string(),
|
||||
credit: credit.value(i),
|
||||
points_possible: points_possible.value(i),
|
||||
@@ -336,6 +367,9 @@ mod tests {
|
||||
topics: "kinetics".into(),
|
||||
bonus: false,
|
||||
dropped: false,
|
||||
form_position: 0,
|
||||
selected_source: String::new(),
|
||||
eliminated_source: String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user