Exemplo n.º 1
0
    def update_submission_time(self):
        '''
        gets the current time upon submission and calls a db function to update
        the user's attempt row with the new submission time
        '''
        now = time.strftime("%d/%m/%Y\n%H:%M:%S")
        db.update_assignment_submission_for_user_for_nth_attempt(
            self.aid, self.uid,
            len(db.get_user_attempts(self.aid, self.uid, conn)), now, conn)

        # LEADERBOARD
        # Update user's time
        user_attempts = db.get_user_attempts(self.aid, self.uid, conn)
        assignment_start = db.get_assignment_details(self.aid, conn)[3]

        # Update user's overall grade and time from recalculating all latest
        # submissions they made for all assignments
        ##num_of_assignments = len(db.get_assignments_ids(conn))
        all_assignments = db.get_assignments_ids(conn)
        user_total_grade = 0
        user_total_time = 0

        i = 1
        for assignment in all_assignments:
            ##print(db.get_latest_user_attempts(i, self.uid, conn)[1]) # Index problem with latest a#?
            print("====================")
            print("|||", db.get_latest_user_attempts(i, self.uid, conn)[0])
            assignment_start = db.get_assignment_details(i, conn)[3]
            print("CONDITIONAL",
                  db.get_latest_user_attempts(i, self.uid, conn)[0][5])
            print("CONDITIONAL",
                  type(db.get_latest_user_attempts(i, self.uid, conn)[0][5]))

            # Ensure current user's attempt is not one that has 0 attempt.
            if (db.get_latest_user_attempts(i, self.uid, conn)[0][5] != '0'):
                # Ensure data from latest submission is retrieved
                if (db.get_latest_user_attempts(i, self.uid, conn)[0][5] !=
                        ''):
                    latest_id = 0
                else:
                    latest_id = 1
                print("LATEST ID", latest_id)
                curr_aid_time = self.start_to_end_sec(
                    assignment_start,
                    db.get_latest_user_attempts(i, self.uid,
                                                conn)[latest_id][5])
                print("CURR_AID_TIME:", curr_aid_time)
                user_total_grade += int(
                    db.get_latest_user_attempts(i, self.uid,
                                                conn)[latest_id][4])
                user_total_time += int(curr_aid_time)
                i += 1

        average_grade = user_total_grade / len(all_assignments)

        db.update_user_grade(self.uid, average_grade, conn)
        db.update_user_time(self.uid, user_total_time, conn)
Exemplo n.º 2
0
 def add_assign_to_lb(self, aid):
     '''adds an assignment to the listbox to be able to be viewed
     @param aid-> the assignment id of the assignment to be added'''
     # update the other listbox that displays assignments
     # get the info by AID
     assignment = db.get_assignment_details(aid, conn)
     assign_string = "{:>3}    {:<15}   {:>10}    {:>10}    {:>10}    {:>3}"
     assign_string = assign_string.format(*assignment)
     # add the assignment to the list box
     self.add_to_list(self.list_box, assign_string)
Exemplo n.º 3
0
    def gen_rows(self):
        ids = db.get_assignments_ids(conn)
        # set iterator for grid rows
        i = 1

        # for each id create a row
        for aid in ids:
            # get the attempts for the user
            attempts = db.get_user_attempts(str(aid), self.uid, conn)
            # get the assignment details
            dets = db.get_assignment_details(aid, conn)
            # create new entries

            name_label = self.create_label(self,
                                           text=dets[1],
                                           font=REGULAR_FONT)
            deadline_label = self.create_label(self,
                                               text=dets[4],
                                               font=REGULAR_FONT)
            try:
                grade_label = self.create_label(self,
                                                text=attempts[-2][4],
                                                font=REGULAR_FONT)
            except IndexError:
                grade_label = self.create_label(self,
                                                text=attempts[-1][4],
                                                font=REGULAR_FONT)

            # add to corresponding dictonaries with user ids as keys
            self.names[aid] = name_label
            self.deadlines[aid] = deadline_label
            self.grades[aid] = grade_label

            # create new buttons
            past_attempt_button = self.create_button(self, "Past Attempts")
            new_attempt_button = self.create_button(self, "Current Attempt")
            new_attempt_button.config(
                command=lambda j=[aid, self.atid]: self.cont.show_frame(
                    "Attempt", self.real_uid, j[0], j[1]))
            past_attempt_button.config(
                command=lambda j=[aid, self.atid]: self.cont.show_frame(
                    "ViewPastAttempt", self.real_uid, j[0], j[1]))

            # add to corresponding dictonaries with user ids as keys
            self.past_attempts[aid] = past_attempt_button
            self.new_attempts[aid] = new_attempt_button

            # set everything nicely on the grid using an iterator i
            name_label.grid(row=i + 3, column=0)
            deadline_label.grid(row=i + 3, column=1)
            grade_label.grid(row=i + 3, column=2)
            new_attempt_button.grid(row=i + 3, column=3)
            past_attempt_button.grid(row=i + 3, column=4)

            i += 1
Exemplo n.º 4
0
 def add_assign_to_lb(self, aid):
     '''adds an assignment to the listbox to be able to be viewed
     @param aid-> the assignment id of the assignment to be added'''
     # update the other listbox that displays assignments
     # get the info by AID
     assignment = db.get_assignment_details(aid, conn)
     assign_string = ''
     tab = self.create_tab()
     for col in assignment:
         assign_string += str(col) + tab
     # add the assignment to the list box
     self.add_to_list(self.list_box, assign_string)
Exemplo n.º 5
0
 def __init__(self, aid):
     '''
     aid is the assignment id of the assignment we want to create
     '''
     # get user details from database
     assignment = db.get_assignment_details(conn, aid)[0]
     # assign corresponding values to variables
     self.aid = assignment[0]
     self.topic = assignment[1]
     self.deadline = assignment[2]
     self.visible = assignment[3]
     self.questions = assignment[4]
     self.length = assignment[5]
Exemplo n.º 6
0
    def substitue_values(self):
        ''' This method substitutes values such as course, assign #, deadline,
        and name into the latex expression and ends it. Then it proceeds to
        create the '.tex' file.
        '''

        # Substitues values into latex expression
        parser = argparse.ArgumentParser()
        parser.add_argument('-c', '--course', default='STAB22')
        parser.add_argument('-t', '--title', default='Assignment: ' + str(self.aid))
        parser.add_argument('-n', '--name', default = db.get_user_details(conn, self.uid)[0][2])
        parser.add_argument('-d', '--deadline', default=db.get_assignment_details(self.aid, conn)[3])

        args = parser.parse_args()

        # End the document
        self.content += r'\end{document}'
        self.createTexFile(args)
Exemplo n.º 7
0
    def submit_progress(self):
        # update progress
        answers = self.get_entries()
        progress = ""
        for ans in answers:
            progress += (str(ans) + ',')
        progress = progress[:-1]
        db.update_assignment_progress_for_user_for_nth_attempt(
            self.aid, self.uid,
            len(db.get_user_attempts(self.aid, self.uid, conn)), progress,
            conn)

        # get problem set
        # get a list of all the problem ids for the user for that assignment
        problem_set = db.get_user_nth_attempt(self.aid, self.uid, -1, conn)[2]

        # get stored solutions according to the problem set
        solution_set = db.get_solution_set(problem_set, conn)

        # get and update grade according to solution set
        try:
            grade = self.calc_grade(solution_set, progress)
            db.update_attempt_grade_for_user_for_nth_attempt(
                self.aid, self.uid,
                len(db.get_user_attempts(self.aid, self.uid, conn)), grade,
                conn)
        except (IndexError, SyntaxError):
            print("not complete")

        # create the new attempt
        # create a problem set with same formula
        quests = self.create_problem_set(
            db.get_assignment_details(self.aid, conn)[2])
        new_problem_set = []
        # add all ids to the list
        for quest in quests:
            new_problem_set.append(quest[0])

        self.update_submission_time()

        db.add_attempt('a' + str(self.aid), self.uid, new_problem_set, '', '',
                       '', conn)

        self.refresh()
Exemplo n.º 8
0
    def create_dropdown(self):
        '''create  a drop down menu with the assignment options currently in database'''
        self.counter = 0
        self.tkvar = StringVar()
        self.choices = []
        # Dictionary with options
        aids = db.get_assignments_ids(conn)  # this returns a list
        for aid in aids:
            assignment = db.get_assignment_details(aid, conn)
            assign_str = "Assignment " + str(assignment[0])
            self.choices.append(assign_str)

        self.title = self.create_label(
            self, "Please select the Assignment to view Grades", REGULAR_FONT,
            NICE_BLUE).grid(row=1, column=1, pady=10, padx=20)

        self.dropdown = ttk.Combobox(self, textvariable=self.tkvar)
        self.dropdown['values'] = self.choices
        self.dropdown.bind('<<ComboboxSelected>>', self.create_listbox)
        self.dropdown.grid(row=2, column=1)
Exemplo n.º 9
0
    def create_assignments_dropdown(self):
        '''Create  a drop down menu for the assignments 
		current in the database table
		
		NOTE: The Filter by ID ONLY works
		if the assignment has been selected from dropdown 
		already, need to add a popup or somethiing
		'''
        self.tkvar = StringVar()
        self.choices = []
        frame = ttk.Frame(self)
        # Dictionary with options
        aids = db.get_assignments_ids(conn)  # this returns a list
        for aid in aids:
            assignment = db.get_assignment_details(aid, conn)
            assign_str = "Assignment " + str(assignment[0])
            self.choices.append(assign_str)

        self.dropdown = ttk.Combobox(frame, textvariable=self.tkvar)
        self.dropdown['values'] = self.choices
        # set the command that is invoked when the value of the box is
        # switched
        self.dropdown.bind('<<ComboboxSelected>>', self.create_listbox)
        self.dropdown.pack(side="left", fill="both")
        # create the sort and filter buttons
        filter_button = self.create_button(frame, "Filter")
        sort_button = self.create_button(frame, "Sort")
        filter_button["command"] = lambda: self.filter_options()
        sort_button["command"] = lambda: self.sort_options()
        # create a clear filters button
        clear_button = self.create_button(frame, "Clear Filters")
        clear_button["command"] = lambda: self.clear_filters()
        # pack the buttosn into the frame
        filter_button.pack(side="left", padx=10)
        sort_button.pack(side="left")
        clear_button.pack(side="left", padx=10)
        frame.grid(row=1, column=1, padx=5, columnspan=3)
Exemplo n.º 10
0
 def test_view_assign_visibility_type(self):
     test = db.get_assignment_details(row + 1, conn)
     self.assertEqual(type(test[4]), int)
Exemplo n.º 11
0
 def test_view_assign_name_type(self):
     test = db.get_assignment_details(conn, row+1)
     self.assertEqual(type(test[1]), str)
Exemplo n.º 12
0
    def gen_rows(self):
        ids = db.get_assignments_ids(conn)
        # set iterator for grid rows
<<<<<<< HEAD
        i = 0
=======
        i = 1
>>>>>>> working_final

        # for each id create a row
        for aid in ids:
            # get the attempts for the user
            attempts = db.get_user_attempts(str(aid), self.uid, conn)
            # get the assignment details
            dets = db.get_assignment_details(aid, conn)
            # create new entries

            name_label = self.create_label(self, text=dets[1], font=REGULAR_FONT)
            deadline_label = self.create_label(self, text=dets[4], font=REGULAR_FONT)
            try :
                grade_label = self.create_label(self, text=attempts[-2][4], font=REGULAR_FONT)
            except IndexError:
                grade_label = self.create_label(self, text=attempts[-1][4], font=REGULAR_FONT)

            # add to corresponding dictonaries with user ids as keys
            self.names[aid] = name_label
            self.deadlines[aid] = deadline_label
            self.grades[aid] = grade_label

            # create new buttons
Exemplo n.º 13
0
 def test_view_assign_details(self):
     test = db.get_assignment_details(row + 1, conn)
     self.assertEqual(test, (row + 1, "a5", "subj1: 1+60", "2017/15/08", 0))
Exemplo n.º 14
0
 def test_view_assign_formula_type(self):
     test = db.get_assignment_details(row + 1, conn)
     self.assertEqual(type(test[2]), str)
Exemplo n.º 15
0
 def test_view_assign_deadline_type(self):
     test = db.get_assignment_details(row + 1, conn)
     self.assertEqual(type(test[3]), str)
Exemplo n.º 16
0
 def add_assign_to_lb(self, aid):
     '''adds an assignment to the listbox to be able to be viewed
     @param aid-> the assignment id of the assignment to be added'''
     # update the other listbox that displays assignments
     # get the info by AID
     assignment = db.get_assignment_details(aid, conn)
Exemplo n.º 17
0
 def test_view_non_existant_assign(self):
     self.assertRaises(sqlite3.OperationalError,
                       lambda: db.get_assignment_details("hello", conn))