How to use the nbgrader.api.SubmittedAssignment function in nbgrader

To help you get started, we’ve selected a few nbgrader examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jupyter / nbgrader / testSub.py View on Github external
cd=coursedir.CourseDirectory(root='/home/daniel/Teaching/L2python')

api=NbGraderAPI(cd)

api.exchange='/home/daniel/Teaching/L2python/exchange'
#print (api.get_submissions('a_a'))

notebook_id='lessEmpty'
assignment_id='lessEmpty'

res = api.gradebook.db.query(
            SubmittedNotebook.id,
            func.sum(Grade.score).label("code_score"),
            func.sum(GradeCell.max_score).label("max_code_score"),
        ).join(SubmittedAssignment, Notebook, Assignment, Student, Grade, GradeCell)\
         .filter(GradeCell.cell_type == "code")\
         .group_by(SubmittedNotebook.id)\
         .all()

print (res)

import sys
#sys.exit()

res = api.gradebook.db.query(
            SubmittedNotebook.id,
            func.sum(Grade.score).label("written_score"),
            func.sum(GradeCell.max_score).label("max_written_score"),
        ).join(SubmittedAssignment, Notebook, Assignment, Student, Grade, GradeCell)\
         .filter(GradeCell.cell_type == "markdown")\
         .group_by(SubmittedNotebook.id)\
github jupyter / nbgrader / nbgrader / api.py View on Github external
student : string
            the name of an existing student
        `**kwargs`
            additional keyword arguments for :class:`~nbgrader.api.SubmittedAssignment`

        Returns
        -------
        submission : :class:`~nbgrader.api.SubmittedAssignment`

        """

        if 'timestamp' in kwargs:
            kwargs['timestamp'] = utils.parse_utc(kwargs['timestamp'])

        try:
            submission = SubmittedAssignment(
                assignment=self.find_assignment(assignment),
                student=self.find_student(student),
                **kwargs)

            for notebook in submission.assignment.notebooks:
                nb = SubmittedNotebook(notebook=notebook, assignment=submission)

                for grade_cell in notebook.grade_cells:
                    Grade(cell=grade_cell, notebook=nb)

                for solution_cell in notebook.solution_cells:
                    Comment(cell=solution_cell, notebook=nb)

            self.db.add(submission)
            self.db.commit()
github jupyter / nbgrader / nbgrader / apps / api.py View on Github external
1. There is a directory present in the `autograded` directory.
        2. The submission is present in the database.
        3. The timestamp of the autograded submission is the same as the
           timestamp of the original submission (in the `submitted` directory).

        Returns
        -------
        students: set
            A set of student ids

        """
        # get all autograded submissions
        with self.gradebook as gb:
            ag_timestamps = dict(gb.db\
                .query(Student.id, SubmittedAssignment.timestamp)\
                .join(SubmittedAssignment)\
                .filter(SubmittedAssignment.name == assignment_id)\
                .all())
            ag_students = set(ag_timestamps.keys())

        students = set([])
        for student_id in ag_students:
            # skip files that aren't directories
            filename = self.coursedir.format_path(
                self.coursedir.autograded_directory,
                student_id=student_id,
                assignment_id=assignment_id)
            if not os.path.isdir(filename):
                continue

            # get the timestamps and check whether the submitted timestamp is
github jupyter / nbgrader / nbgrader / api.py View on Github external
Parameters
        ----------
        assignment : string
            the name of an assignment
        student : string
            the unique id of a student

        Returns
        -------
        submission : :class:`~nbgrader.api.SubmittedAssignment`

        """

        try:
            submission = self.db.query(SubmittedAssignment)\
                .join(Assignment, Assignment.id == SubmittedAssignment.assignment_id)\
                .join(Student, Student.id == SubmittedAssignment.student_id)\
                .filter(Assignment.name == assignment, Student.id == student)\
                .one()
        except NoResultFound:
            raise MissingEntry("No such submission: {} for {}".format(
                assignment, student))

        return submission
github jupyter / nbgrader / nbgrader / api.py View on Github external
.correlate_except(GradeCell), deferred=True)

SubmittedNotebook.max_written_score = column_property(
    select([Notebook.max_written_score])\
        .where(Notebook.id == SubmittedNotebook.notebook_id)\
        .correlate_except(Notebook), deferred=True)

Assignment.max_written_score = column_property(
    select([func.coalesce(func.sum(GradeCell.max_score), 0.0)])\
        .where(and_(
            Notebook.assignment_id == Assignment.id,
            GradeCell.notebook_id == Notebook.id,
            GradeCell.cell_type == "markdown"))\
        .correlate_except(GradeCell), deferred=True)

SubmittedAssignment.max_written_score = column_property(
    select([Assignment.max_written_score])\
        .where(Assignment.id == SubmittedAssignment.assignment_id)\
        .correlate_except(Assignment), deferred=True)


## Code scores

SubmittedNotebook.code_score = column_property(
    select([func.coalesce(func.sum(Grade.score), 0.0)])\
        .where(and_(
            Grade.notebook_id == SubmittedNotebook.id,
            GradeCell.id == Grade.cell_id,
            GradeCell.cell_type == "code"))\
        .correlate_except(Grade), deferred=True)

SubmittedAssignment.code_score = column_property(
github jupyter / nbgrader / nbgrader / api.py View on Github external
the name of a notebook
        assignment : string
            the name of an assignment
        student : string
            the unique id of a student

        Returns
        -------
        notebook : :class:`~nbgrader.api.SubmittedNotebook`

        """

        try:
            notebook = self.db.query(SubmittedNotebook)\
                .join(Notebook, Notebook.id == SubmittedNotebook.notebook_id)\
                .join(SubmittedAssignment, SubmittedAssignment.id == SubmittedNotebook.assignment_id)\
                .join(Assignment, Assignment.id == SubmittedAssignment.assignment_id)\
                .join(Student, Student.id == SubmittedAssignment.student_id)\
                .filter(
                    Notebook.name == notebook,
                    Assignment.name == assignment,
                    Student.id == student)\
                .one()
        except NoResultFound:
            raise MissingEntry("No such submitted notebook: {}/{} for {}".format(
                assignment, notebook, student))

        return notebook
github jupyter / nbgrader / nbgrader / api.py View on Github external
Student.max_score = column_property(
    select([func.coalesce(func.sum(Assignment.max_score), 0.0)])\
        .correlate_except(Assignment), deferred=True)


## Written scores

SubmittedNotebook.written_score = column_property(
    select([func.coalesce(func.sum(Grade.score), 0.0)])\
        .where(and_(
            Grade.notebook_id == SubmittedNotebook.id,
            GradeCell.id == Grade.cell_id,
            GradeCell.cell_type == "markdown"))\
        .correlate_except(Grade), deferred=True)

SubmittedAssignment.written_score = column_property(
    select([func.coalesce(func.sum(Grade.score), 0.0)])\
        .where(and_(
            SubmittedNotebook.assignment_id == SubmittedAssignment.id,
            Grade.notebook_id == SubmittedNotebook.id,
            GradeCell.id == Grade.cell_id,
            GradeCell.cell_type == "markdown"))\
        .correlate_except(Grade), deferred=True)


## Written max scores

Notebook.max_written_score = column_property(
    select([func.coalesce(func.sum(GradeCell.max_score), 0.0)])\
        .where(and_(
            GradeCell.notebook_id == Notebook.id,
            GradeCell.cell_type == "markdown"))\
github jupyter / nbgrader / nbgrader / api.py View on Github external
GradeCell.notebook_id == Notebook.id,
            GradeCell.cell_type == "code"))\
        .correlate_except(GradeCell), deferred=True)

SubmittedAssignment.max_code_score = column_property(
    select([Assignment.max_code_score])\
        .where(Assignment.id == SubmittedAssignment.assignment_id)\
        .correlate_except(Assignment), deferred=True)


## Number of submissions

Assignment.num_submissions = column_property(
    select([func.count(SubmittedAssignment.id)])\
        .where(SubmittedAssignment.assignment_id == Assignment.id)\
        .correlate_except(SubmittedAssignment), deferred=True)

Notebook.num_submissions = column_property(
    select([func.count(SubmittedNotebook.id)])\
        .where(SubmittedNotebook.notebook_id == Notebook.id)\
        .correlate_except(SubmittedNotebook), deferred=True)


## Cell type

Grade.cell_type = column_property(
    select([GradeCell.cell_type])\
        .where(Grade.cell_id == GradeCell.id)\
        .correlate_except(GradeCell), deferred=True)


## Failed tests
github jupyter / nbgrader / nbgrader / api.py View on Github external
}

    def __repr__(self):
        return "Comment<{}/{}/{} for {}>".format(
            self.assignment.name, self.notebook.name, self.name, self.student.id)


## Needs manual grade

SubmittedNotebook.needs_manual_grade = column_property(
    exists().where(and_(
        Grade.notebook_id == SubmittedNotebook.id,
        Grade.needs_manual_grade))\
    .correlate_except(Grade), deferred=True)

SubmittedAssignment.needs_manual_grade = column_property(
    exists().where(and_(
        SubmittedNotebook.assignment_id == SubmittedAssignment.id,
        Grade.notebook_id == SubmittedNotebook.id,
        Grade.needs_manual_grade))\
    .correlate_except(Grade), deferred=True)

Notebook.needs_manual_grade = column_property(
    exists().where(and_(
        Notebook.id == SubmittedNotebook.notebook_id,
        Grade.notebook_id == SubmittedNotebook.id,
        Grade.needs_manual_grade))\
    .correlate_except(Grade), deferred=True)


## Overall scores