How to use the nbgrader.api.SubmittedNotebook 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 / nbgrader / api.py View on Github external
-------
        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()

        except (IntegrityError, FlushError) as e:
            self.db.rollback()
            raise InvalidEntry(*e.args)

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

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

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)
github jupyter / nbgrader / nbgrader / api.py View on Github external
notebook : string
            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
## Cell type

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


## Failed tests

Grade.failed_tests = column_property(
    (Grade.auto_score < Grade.max_score) & (Grade.cell_type == "code"))

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


class Gradebook(object):
    """The gradebook object to interface with the database holding
    nbgrader grades.

    """

    def __init__(self, db_url):
        """Initialize the connection to the database.

        Parameters
github jupyter / nbgrader / nbgrader / api.py View on Github external
----------
        notebook : string
            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
.correlate_except(Grade), deferred=True)


## Overall max scores

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

Notebook.max_score = column_property(
    select([func.coalesce(func.sum(GradeCell.max_score), 0.0)])\
        .where(GradeCell.notebook_id == Notebook.id)\
        .correlate_except(GradeCell), deferred=True)

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

Assignment.max_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))\
        .correlate_except(GradeCell), deferred=True)

SubmittedAssignment.max_score = column_property(
    select([Assignment.max_score])\
        .where(SubmittedAssignment.assignment_id == Assignment.id)\
        .correlate_except(Assignment), deferred=True)
github jupyter / nbgrader / nbgrader / api.py View on Github external
).join(SubmittedAssignment, Assignment, Notebook)\
         .filter(
             Grade.notebook_id == SubmittedNotebook.id,
             Grade.failed_tests)\
         .group_by(SubmittedNotebook.id)\
         .subquery()

        # full query
        submissions = self.db.query(
            SubmittedNotebook.id, Notebook.name, Student.id,
            func.sum(Grade.score), func.sum(GradeCell.max_score),
            code_scores.c.code_score, code_scores.c.max_code_score,
            written_scores.c.written_score, written_scores.c.max_written_score,
            func.coalesce(manual_grade.c.needs_manual_grade, False),
            func.coalesce(failed_tests.c.failed_tests, False),
            SubmittedNotebook.flagged
        ).join(SubmittedAssignment, Notebook, Assignment, Student, Grade, GradeCell)\
         .outerjoin(code_scores, SubmittedNotebook.id == code_scores.c.id)\
         .outerjoin(written_scores, SubmittedNotebook.id == written_scores.c.id)\
         .outerjoin(manual_grade, SubmittedNotebook.id == manual_grade.c.id)\
         .outerjoin(failed_tests, SubmittedNotebook.id == failed_tests.c.id)\
         .filter(and_(
             Notebook.name == notebook_id,
             Assignment.name == assignment_id,
             Student.id == SubmittedAssignment.student_id,
             SubmittedAssignment.id == SubmittedNotebook.assignment_id,
             SubmittedNotebook.id == Grade.notebook_id,
             GradeCell.id == Grade.cell_id))\
         .group_by(Student.id)\
         .all()

        keys = [
github jupyter / nbgrader / nbgrader / api.py View on Github external
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"))\
        .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)
github jupyter / nbgrader / nbgrader / api.py View on Github external
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

Grade.failed_tests = column_property(
    (Grade.auto_score < Grade.max_score) & (Grade.cell_type == "code"))

SubmittedNotebook.failed_tests = column_property(