Beispiel #1
0
def select_assignment() -> None:
    """Ask user to pick an assignment from their class/section (section is optional).

    Raises:
        ValueError: The course must be selected to pick assignment (sub-property)
    """
    global course, section, assignment
    if not course:
        raise ValueError("course has not been initialized")

    def key_for_sorting_section(a: Dict) -> int:
        """Get the number of ungraded submissions given an assignment (after matching section).

        Args:
            a (Dict): Dict with 'needs_grading_count_by_section' dict, which has 'section_id' and 'needs_grading_count'

        Returns:
            int: the number of ungraded submissions
        """
        global section
        for gcs in a["needs_grading_count_by_section"]:
            if gcs["section_id"] == section["id"]:
                return gcs["needs_grading_count"]
        return -1

    if not section:
        assignments: List[Dict[Any, Any]] = Assignments.get_all_assignments(
            course["id"], )
        assignments = sorted(
            assignments,
            key=lambda a: a["needs_grading_count"],
            reverse=True,
        )

        def add_ungraded_count(assignment: Dict) -> None:
            ungraded_count: str = assignment["needs_grading_count"]
            assignment["name"] += f" ({ungraded_count})"

        assignments = list(map(add_ungraded_count, assignments))

    else:
        assignments = Assignments.get_all_assignments(
            course["id"],
            section["id"],
        )
        assignments = sorted(
            assignments,
            key=key_for_sorting_section,
            reverse=True,
        )

        def add_ungraded_count(assignment: Dict) -> None:
            assignment["name"] += f" ({key_for_sorting_section(assignment)})"

        assignments = list(map(add_ungraded_count, assignments))
    assignment = Question.select_option(assignments, "assignment")
Beispiel #2
0
 def start(self):
     '''
     Starts the grading session.
     Checks if the assignment the user asks to grade actually exists.
     Loads the homeworkspec.xml from the database.
     Validates it.
     Uses it for grading.
     '''
     t.p('Grading assignment %s' % self.assigname)
     t.v('With compile timeout = %d' % self.cto)
     t.v('With run timeout = %d' % self.rto)
     t.p("")
     db = dbm.DAL(connect=True)
     if Assignments.assigexists(self.assigname, db):
         sql = 'SELECT {0} FROM {1} WHERE {2}=?'.format(Assignments.f_xml, Assignments.table_name, Assignments.f_assigname)
         result = db.query(sql, (self.assigname,), fetchone=True)
         resulttuple = XMLHelper.loadXMLandvalidate(result[0])
         if resulttuple[1] == False:
             # Bad hwspec.xml!
             t.e('HwSpec validation failed - ' + resulttuple[2], 1)
         else:
             t.p('Validation...Success!')
             self.specobj = resulttuple[0]
             self.__grade()
     else:
         t.e('Assignment %s does not exist!' % self.assigname, 1)
Beispiel #3
0
def getUserData(email, password):
    #Initializes a session object, which logs in to Aeries
    session = AeriesSession.Session(email, password)
    #Passes the session object to the Gradebooks class to
    #   read general gradebook information (in python format)
    #   from the home page
    gradebooks = Gradebooks.getGradebooks(session)
    #Passes the session object to the Assignments class to read
    #   the current month's (starting on the 1st ending on the
    #   last day) assignments (in python format) from the home page
    assignments = Assignments.getAssignments(session)
    return {'gradebooks': gradebooks, 'assignments': assignments}
Beispiel #4
0
def get(what, email, password, gradebook=None):
    try:
        session = AeriesSession.Session(email, password)
    except ValueError:
        raise
    if what == 'grades':
        data = Gradebooks.getGradebooks(session)
    if what == 'assignments':
        data = Assignments.getAssignments(session)
    if what == 'gradebook':
        #gradebook is treated as a regular expression
        data = GradebookDetails.getGradebook(gradebook, session)
    json = toJSON(data)
    return json
Beispiel #5
0
 def assignmentsClicked(self):
     self.assign = Assignments.Assignments(self.username)
     self.assign.show()
     self.close()