[−][src]Struct lab_grader::submission::Submission
A submission is a bundle of data that represents one student's submission. They will do some sort of work for a lab, then run a rust script that builds some criteria, runs those criteria with some data from the student, and submits a Submission to a central webserver where the instructor can collect the graded submissions.
Fields
time: DateTime<Local>
A local timestamp when the submission was created
name: String
The students name
id: u32
The students institutional ID
grade: i16
Numerical grade for the submission. Each criterion will add to this grade if it passes.
data: HashMap<String, String>
A hashmap of extra data that may be sent by the submission. Leave it empty if you don't need it
passed: Vec<String>
The criteria (name) that this submission passed
failed: Vec<String>
The citeria (name) that this submission failed
Methods
impl Submission
[src]
pub fn new<S: AsRef<str>>(name: S, id: u32) -> Submission
[src]
Creates a new submission with a name and id.
The data
field is set to an empty HashMap, and grade
is set to 0.
Hint: If you want to start with a grade and bring the grade down for every criterion not passed, set the grade manually here and set the point value for each criterion to be a negative number.
Example
use lab_grader::submission::Submission; // You probably want it to be mutable so // you can attach data and change the grade let mut sub = Submission::new("Luke", 1234); assert_eq!(sub.name, "Luke"); assert_eq!(sub.id, 1234); assert_eq!(sub.grade, 0); assert_eq!(sub.data.len(), 0);
pub fn from_cli() -> Submission
[src]
Prompts the user for a name and ID number
and returns a Submission. Equivalent to getting
a name and ID from the console and calling
Submission::new()
with those values
Warning: If the user doesn't enter valid values for name and id, this will terminate the program. Be sure that's what you want to do before using it.
Example
Rust:
let mut sub = Submission::from_cli();
In the terminal:
Name: Luke
ID: 123
With invalid input:
Name: Luke
ID: not a number
Could not parse input
pub fn use_data(&mut self, data: HashMap<String, String>)
[src]
Attaches data to a submission
The data must be a HashMap<String, String>
.
You may want to use the data!
macro to make it
easier to establish your data.
Example
let data = data! { "key" => "value", "key2" => "value2" }; let mut sub = Submission::new("Luke", 1234); sub.use_data(data); assert_eq!(sub.data["key"], "value"); assert_eq!(sub.data["key2"], "value2");
pub fn pass<C: AsRef<str>>(&mut self, criterion: C)
[src]
Marks a criterion as passed. Provide the name of the criterion.
This struct does not include an actual Criterion
struct in it's passed
and failed
fields, because it's impossible to
serialize a Criterion
. Submission
s must be serializable.
Example
let mut sub = Submission::new("Luke", 1234); sub.pass("Some criterion name"); assert!(sub.passed.contains(&"Some criterion name".to_string()));
pub fn fail<C: AsRef<str>>(&mut self, criterion: C)
[src]
Same as pass
, but adds to the failed
vector
pub fn grade_against(&mut self, criteria: &mut Vec<Criterion>)
[src]
Tests a submission against a list of criterion
The submissions grade will change for every passed criterion,
and every criterion will add it's name and message to the submissions
passed
or failed
vectors.
Example
let mut sub = Submission::new("Luke", 1234); sub.use_data(data! { "key" => "value" }); // Just one criterion here to save space let mut crits: Vec<Criterion> = vec![ Criterion::new("Test Criterion", 10, ("passed", "failed"), Box::new( |data: &HashMap<String, String>| { data["key"] == "value" } )) ]; sub.grade_against(&mut crits); assert_eq!(crits[0].status, Some(true)); assert_eq!(sub.grade, 10); assert_eq!(sub.passed.len(), 1); assert_eq!(sub.failed.len(), 0);
pub fn server(port: u16)
[src]
Spins up a webserver to accept submission.
Accepted submissions will be written to a ResultsFile
.
The web server will run on the provided port.
The results file will be placed in the directory you execute the code in,
and be called results.csv
.
Support for custom results file locations is coming...
use lab_grader::Submission; Submission::server(8080);
Trait Implementations
impl AsCsv for Submission
[src]
fn as_csv(&self) -> String
[src]
fn filename(&self) -> String
[src]
fn header(&self) -> &'static str
[src]
impl Debug for Submission
[src]
impl<'de> Deserialize<'de> for Submission
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl PartialEq<Submission> for Submission
[src]
fn eq(&self, other: &Submission) -> bool
[src]
fn ne(&self, other: &Submission) -> bool
[src]
impl Serialize for Submission
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl StructuralPartialEq for Submission
[src]
Auto Trait Implementations
impl RefUnwindSafe for Submission
impl Send for Submission
impl Sync for Submission
impl Unpin for Submission
impl UnwindSafe for Submission
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T, I> AsResult<T, I> for T where
I: Input,
I: Input,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> IntoCollection<T> for T
fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
A: Array<Item = T>,
fn mapped<U, F, A>(self, f: F) -> SmallVec<A> where
A: Array<Item = U>,
F: FnMut(T) -> U,
A: Array<Item = U>,
F: FnMut(T) -> U,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Typeable for T where
T: Any,
T: Any,