Example #1
0
 def get_submission_time(self, assignment):
     choice = self.submission_time.data
     if choice == "none":
         return None
     elif choice == "deadline":
         return assignment.due_date - dt.timedelta(seconds=1)
     elif choice == "early":
         return assignment.due_date - dt.timedelta(days=1, seconds=1)
     elif choice == "other":
         return utils.server_time_obj(self.custom_submission_time.data, assignment.course)
     else:
         raise Exception("Unknown submission time choice {}".format(choice))
Example #2
0
File: api.py Project: wmgeolab/ok
    def create_assignment(self, user, offering, name):
        args = self.parse_args()

        course = models.Course.by_name(offering)

        constructor_fields = dict(
            course=course,
            creator_id=user.id,
            display_name=args["display_name"],
            name=name,
            due_date=utils.server_time_obj(args["due_date"], course),
            lock_date=utils.server_time_obj(args["lock_date"], course),
            max_group_size=args["max_group_size"],
            url=args["url"],
            revisions_allowed=args["revisions_allowed"],
            autograding_key=args["autograding_key"],
            continuous_autograding=args["continuous_autograding"],
            uploads_enabled=args["uploads_enabled"],
            upload_info=args["upload_info"],
            visible=args["visible"],
        )

        assignment = models.Assignment.query.filter_by(name=name).one_or_none()
        if assignment is not None:
            for k, v in constructor_fields.items():
                setattr(assignment, k, v)
        else:
            assignment = models.Assignment(**constructor_fields)

        if not models.Assignment.can(assignment, user, "create"):
            models.db.session.remove()
            restful.abort(403)

        models.db.session.add(assignment)

        models.db.session.commit()

        return assignment
Example #3
0
def assign_scores(assign_id, score, kind, message, deadline,
                     include_backups=True):
    logger = jobs.get_job_logger()
    current_user = jobs.get_current_job().user

    assignment = Assignment.query.get(assign_id)
    students = [e.user_id for e in assignment.course.get_students()]
    submission_time = server_time_obj(deadline, assignment.course)

    # Find all submissions (or backups) before the deadline
    backups = Backup.query.filter(
        Backup.assignment_id == assign_id,
        or_(Backup.created <= deadline, Backup.custom_submission_time <= deadline)
    ).order_by(Backup.created.desc()).group_by(Backup.submitter_id)

    if not include_backups:
        backups = backups.filter(Backup.submit == True)

    all_backups =  backups.all()

    if not all_backups:
        logger.info("No submissions were found with a deadline of {}."
                    .format(deadline))
        return "No Scores Created"

    total_count = len(all_backups)
    logger.info("Found {} eligible submissions...".format(total_count))

    score_counter, seen = 0, set()

    for back in all_backups:
        if back.creator in seen:
            score_counter += 1
            continue
        new_score = Score(score=score, kind=kind, message=message,
                          user_id=back.submitter_id,
                          assignment=assignment, backup=back,
                          grader=current_user)
        db.session.add(new_score)
        new_score.archive_duplicates()
        db.session.commit()

        score_counter += 1
        if score_counter % 5 == 0:
            logger.info("Scored {} of {}".format(score_counter, total_count))
        seen |= back.owners()

    result = "Left {} '{}' scores of {}".format(score_counter, kind.title(), score)
    logger.info(result)
    return result
Example #4
0
 def get_submission_time(self, assignment):
     choice = self.submission_time.data
     if choice == 'none':
         return None
     elif choice == 'deadline':
         return (assignment.due_date - dt.timedelta(seconds=1))
     elif choice == 'early':
         return (assignment.due_date - dt.timedelta(days=1, seconds=1))
     elif choice == 'other':
         return utils.server_time_obj(
             self.custom_submission_time.data,
             assignment.course,
         )
     else:
         raise Exception('Unknown submission time choice {}'.format(choice))
Example #5
0
 def get_submission_time(self, assignment):
     choice = self.submission_time.data
     if choice == 'none':
         return None
     elif choice == 'deadline':
         return (assignment.due_date
             - dt.timedelta(seconds=1))
     elif choice == 'early':
         return (assignment.due_date
             - dt.timedelta(days=1, seconds=1))
     elif choice == 'other':
         return utils.server_time_obj(
             self.custom_submission_time.data,
             assignment.course,
         )
     else:
         raise Exception('Unknown submission time choice {}'.format(choice))
Example #6
0
    def populate_obj(self, obj):
        """ Updates obj attributes based on form contents. """

        super(AssignmentForm, self).populate_obj(obj)
        obj.due_date = utils.server_time_obj(self.due_date.data, self.course)
        obj.lock_date = utils.server_time_obj(self.lock_date.data, self.course)
Example #7
0
File: forms.py Project: gratimax/ok
    def populate_obj(self, obj):
        """ Updates obj attributes based on form contents. """

        super(AssignmentForm, self).populate_obj(obj)
        obj.due_date = utils.server_time_obj(self.due_date.data, self.course)
        obj.lock_date = utils.server_time_obj(self.lock_date.data, self.course)
Example #8
0
def assign_scores(assign_id,
                  score,
                  kind,
                  message,
                  deadline,
                  include_backups=True,
                  grade_backups=False):
    logger = jobs.get_job_logger()
    current_user = jobs.get_current_job().user

    assignment = Assignment.query.get(assign_id)
    students = [e.user_id for e in assignment.course.get_students()]
    submission_time = server_time_obj(deadline, assignment.course)

    # Find all submissions (or backups) before the deadline
    backups = Backup.query.filter(
        Backup.assignment_id == assign_id,
        or_(Backup.created <= deadline,
            Backup.custom_submission_time <= deadline)).group_by(
                Backup.submitter_id).order_by(Backup.created.desc())

    if not include_backups:
        backups = backups.filter(Backup.submit == True)

    all_backups = backups.all()

    if not all_backups:
        logger.info("No submissions were found with a deadline of {}.".format(
            deadline))
        return "No Scores Created"

    score_counter, seen = 0, set()

    unique_backups = []

    for back in all_backups:
        if back.creator not in seen:
            unique_backups.append(back)
            seen |= back.owners()

    total_count = len(unique_backups)
    logger.info(
        "Found {} unique and eligible submissions...".format(total_count))

    if grade_backups:
        logger.info('\nAutograding {} backups'.format(total_count))
        backup_ids = [back.id for back in unique_backups]
        try:
            autograde_backups(assignment, current_user.id, backup_ids, logger)
        except ValueError:
            logger.info(
                'Could not autograde backups - Please add an autograding key.')
    else:
        for back in unique_backups:
            new_score = Score(score=score,
                              kind=kind,
                              message=message,
                              user_id=back.submitter_id,
                              assignment=assignment,
                              backup=back,
                              grader=current_user)

            db.session.add(new_score)
            new_score.archive_duplicates()

            score_counter += 1
            if score_counter % 100 == 0:
                logger.info("Scored {} of {}".format(score_counter,
                                                     total_count))

        # only commit if all scores were successfully added
        db.session.commit()

    logger.info("Left {} '{}' scores of {}".format(score_counter, kind.title(),
                                                   score))
    return '/admin/course/{cid}/assignments/{aid}/scores'.format(
        cid=jobs.get_current_job().course_id, aid=assignment.id)
Example #9
0
def assign_scores(assign_id, score, kind, message, deadline,
                     include_backups=True, grade_backups=False):
    logger = jobs.get_job_logger()
    current_user = jobs.get_current_job().user

    assignment = Assignment.query.get(assign_id)
    students = [e.user_id for e in assignment.course.get_students()]
    submission_time = server_time_obj(deadline, assignment.course)

    # Find all submissions (or backups) before the deadline
    backups = Backup.query.filter(
        Backup.assignment_id == assign_id,
        or_(Backup.created <= deadline, Backup.custom_submission_time <= deadline)
    ).group_by(Backup.submitter_id).order_by(Backup.created.desc())

    if not include_backups:
        backups = backups.filter(Backup.submit == True)

    all_backups =  backups.all()

    if not all_backups:
        logger.info("No submissions were found with a deadline of {}."
                    .format(deadline))
        return "No Scores Created"

    score_counter, seen = 0, set()

    unique_backups = []

    for back in all_backups:
        if back.creator not in seen:
            unique_backups.append(back)
            seen |= back.owners()

    total_count = len(unique_backups)
    logger.info("Found {} unique and eligible submissions...".format(total_count))

    if grade_backups:
        logger.info('\nAutograding {} backups'.format(total_count))
        backup_ids = [back.id for back in unique_backups]
        try:
            autograde_backups(assignment, current_user.id, backup_ids, logger)
        except ValueError:
            logger.info('Could not autograde backups - Please add an autograding key.')
    else:
        for back in unique_backups:
            new_score = Score(score=score, kind=kind, message=message,
                              user_id=back.submitter_id,
                              assignment=assignment, backup=back,
                              grader=current_user)

            db.session.add(new_score)
            new_score.archive_duplicates()

            score_counter += 1
            if score_counter % 100 == 0:
                logger.info("Scored {} of {}".format(score_counter, total_count))

        # only commit if all scores were successfully added
        db.session.commit()

    logger.info("Left {} '{}' scores of {}".format(score_counter, kind.title(), score))
    return '/admin/course/{cid}/assignments/{aid}/scores'.format(
                cid=jobs.get_current_job().course_id, aid=assignment.id)