<commit_before># coding=utf-8

from app import db
from werkzeug.security import generate_password_hash, check_password_hash
from mongoengine import NULLIFY, PULL

from app.helpers.filestorage import *

from app.structures.models.user import User

#Some constants for doing submission status stuff
SUBMISSION_UNGRADED = 0
SUBMISSION_TESTING = 1
SUBMISSION_TESTED = 2
SUBMISSION_GRADING = 3
SUBMISSION_GRADED = 4

class Submission(db.Document):
  '''
  A submission contains all the information about one attempt at a given problem
  by a student.
  '''
  #bookkeeping
  submitter = db.ReferenceField('User')
  problem = db.ReferenceField('Problem')
  isLatest = db.BooleanField(default=True)

  submissionTime = db.DateTimeField(required=True)
  isLate = db.BooleanField(default=False)
  grade = db.ReferenceField('GBGrade')
  status = db.IntField(default=0)
  gradedBy = db.ReferenceField('User')

  #Comment fields
  comments = db.StringField(default="")
  autoGraderComments = db.StringField(default="")

  #partnerinfo
  partner = db.ReferenceField('User')
  partnerSubmission = db.ReferenceField('Submission')

  meta = {"cascade": True}

  def cleanup(self):
    try:
      if self.partnerInfo:
        self.partnerInfo.delete()
      self.grade.delete()
    except:
      pass

  def getStatus(self):
    if self.status == SUBMISSION_UNGRADED:
      return "info", "Submitted (Ungraded)"
    elif self.status == SUBMISSION_TESTING:
      return "warning", "Autograde in progress"
    elif self.status == SUBMISSION_TESTED:
      return "info", "Submitted (Tested, Ungraded)"
    elif self.status == SUBMISSION_GRADING:
      return "warning", "Grading in progress"
    elif self.status == SUBMISSION_GRADED:
      return "success", "Graded"

class StudentSubmissionList(db.EmbeddedDocument):
  '''
  A list of all the submissions a student has made for a specific problem.
  '''
  submissions = db.ListField(db.ReferenceField('Submission'))

  meta = {"cascade": True}

  def cleanup(self):
    for s in self.submissions:
      s.cleanup()
      s.delete()
    self.submissions = []

  def addSubmission(self, sub):
    if len(self.submissions) > 0:
      self.submissions[-1].isLatest = False
      self.submissions[-1].save()
    self.submissions.append(sub)

class Problem(db.Document):
  '''
  One problem that a student can submit files to.
  '''
  name = db.StringField()
  gradeColumn = db.ReferenceField('GBColumn', reverse_delete_rule=NULLIFY)
  duedate = db.DateTimeField()

  #The problem rubric
  rubric = db.MapField(db.DecimalField())

  #List of the names of the files we test with
  testfiles = db.ListField(db.StringField())

  #Can students have partners
  allowPartners = db.BooleanField(default=True)

  #Which files must a student submit
  requiredFiles = db.StringField(default=None)
  strictFiles = db.StringField(default=None)
  bannedFiles = db.StringField(default=None)

  #URLs for grader notes and for problem specification
  gradeNotes = db.StringField()
  problemPage = db.StringField()

  #Settings for releasing grades
  releaseAutoComments = db.BooleanField(default=False)
  autoGradeOnly = db.BooleanField(default=False)


  #Map usernames to submission lists
  studentSubmissions = db.MapField(db.EmbeddedDocumentField('StudentSubmissionList'))

  meta = {"cascade": True}

  def __init__(self, name, **data):
    super(Problem, self).__init__(**data)
    self.name = name

  def getStatusCount(self):
    c,a = self.getParents()
    users = User.objects.filter(courseStudent=c)
    ungraded = 0
    ip = 0
    done = 0
    for u in users:
      sub = self.getLatestSubmission(u)
      if sub == None:
        continue
      if sub.status < 3:
        ungraded += 1<commit_msg>changed release to default true<commit_after># coding=utf-8

from app import db
from werkzeug.security import generate_password_hash, check_password_hash
from mongoengine import NULLIFY, PULL

from app.helpers.filestorage import *

from app.structures.models.user import User

#Some constants for doing submission status stuff
SUBMISSION_UNGRADED = 0
SUBMISSION_TESTING = 1
SUBMISSION_TESTED = 2
SUBMISSION_GRADING = 3
SUBMISSION_GRADED = 4

class Submission(db.Document):
  '''
  A submission contains all the information about one attempt at a given problem
  by a student.
  '''
  #bookkeeping
  submitter = db.ReferenceField('User')
  problem = db.ReferenceField('Problem')
  isLatest = db.BooleanField(default=True)

  submissionTime = db.DateTimeField(required=True)
  isLate = db.BooleanField(default=False)
  grade = db.ReferenceField('GBGrade')
  status = db.IntField(default=0)
  gradedBy = db.ReferenceField('User')

  #Comment fields
  comments = db.StringField(default="")
  autoGraderComments = db.StringField(default="")

  #partnerinfo
  partner = db.ReferenceField('User')
  partnerSubmission = db.ReferenceField('Submission')

  meta = {"cascade": True}

  def cleanup(self):
    try:
      if self.partnerInfo:
        self.partnerInfo.delete()
      self.grade.delete()
    except:
      pass

  def getStatus(self):
    if self.status == SUBMISSION_UNGRADED:
      return "info", "Submitted (Ungraded)"
    elif self.status == SUBMISSION_TESTING:
      return "warning", "Autograde in progress"
    elif self.status == SUBMISSION_TESTED:
      return "info", "Submitted (Tested, Ungraded)"
    elif self.status == SUBMISSION_GRADING:
      return "warning", "Grading in progress"
    elif self.status == SUBMISSION_GRADED:
      return "success", "Graded"

class StudentSubmissionList(db.EmbeddedDocument):
  '''
  A list of all the submissions a student has made for a specific problem.
  '''
  submissions = db.ListField(db.ReferenceField('Submission'))

  meta = {"cascade": True}

  def cleanup(self):
    for s in self.submissions:
      s.cleanup()
      s.delete()
    self.submissions = []

  def addSubmission(self, sub):
    if len(self.submissions) > 0:
      self.submissions[-1].isLatest = False
      self.submissions[-1].save()
    self.submissions.append(sub)

class Problem(db.Document):
  '''
  One problem that a student can submit files to.
  '''
  name = db.StringField()
  gradeColumn = db.ReferenceField('GBColumn', reverse_delete_rule=NULLIFY)
  duedate = db.DateTimeField()

  #The problem rubric
  rubric = db.MapField(db.DecimalField())

  #List of the names of the files we test with
  testfiles = db.ListField(db.StringField())

  #Can students have partners
  allowPartners = db.BooleanField(default=True)

  #Which files must a student submit
  requiredFiles = db.StringField(default=None)
  strictFiles = db.StringField(default=None)
  bannedFiles = db.StringField(default=None)

  #URLs for grader notes and for problem specification
  gradeNotes = db.StringField()
  problemPage = db.StringField()

  #Settings for releasing grades
  releaseAutoComments = db.BooleanField(default=True)
  autoGradeOnly = db.BooleanField(default=False)


  #Map usernames to submission lists
  studentSubmissions = db.MapField(db.EmbeddedDocumentField('StudentSubmissionList'))

  meta = {"cascade": True}

  def __init__(self, name, **data):
    super(Problem, self).__init__(**data)
    self.name = name

  def getStatusCount(self):
    c,a = self.getParents()
    users = User.objects.filter(courseStudent=c)
    ungraded = 0
    ip = 0
    done = 0
    for u in users:
      sub = self.getLatestSubmission(u)
      if sub == None:
        continue
      if sub.status < 3:
        ungraded += 1
{'fraction_non_alphanumeric': 0.10572923654904065, 'fraction_numerical': 0.004025224741714746, 'mean_word_length': 3.900723208415516, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2339058', 'n_tokens_mistral': 2397, 'n_tokens_neox': 2314, 'n_words': 593}