Example #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)
Example #2
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
Example #3
0
 def done(self):
     '''the command that happens when the done button is pressed
     This will add the assignment to the database and remove
     the widgets for creating the assignment'''
     # start by getting the info from the entry boxes
     # this does not include the subject and number fields, because
     # those are stored in the listbox
     name = self.entry_fields["Assignment Name"].get()
     start_date = self.entry_fields["Start Date"].get()
     deadline = self.entry_fields["Due Date"].get()
     visible = self.entry_fields["Visible"].get()
     verified = self.verify_fields()
     # we want to make sure that none of the fields are empty
     if (verified):
         formula = ''
         # get the values from the listbox as a list
         lb = self.subject_box
         contents = lb.get(0, lb.size())
         # this returns a tuple that looks like this
         # ('1    1', '2    2') where the separator is the tab we created
         for i in range(len(contents)):
             # first we want to split the string
             sep = self.create_tab()
             items = contents[i].split(sep)
             formula += items[0] + ":" + items[1]
             formula += ","
         formula = formula[:-1]
         # update the database
         num = self.update_assignments_table(name, formula, start_date,
                                             deadline, visible)
         self.table_functions(num, formula)
         # check to make sure that the assignment is in the db
         aids = db.get_assignments_ids(conn)
         if num in aids:
             # add assignment to the listbox
             self.add_assign_to_lb(num)
             # want to destroy the widget after
             for frame in self.frames:
                 frame.destroy()
             # destroy labels
             for title in self.titles:
                 title.destroy()
             self.subj_pressed = False
             self.add_pressed = False
             # display message of success
             showinfo("Info", "Assignment successfully added")
         else:
             showinfo("Fail", "Could not add assignment")
     else:
         show_info("Failure", "Please fill out all the fields")
Example #4
0
    def __init__(self, parent, controller):
        '''initialises the window'''
        self.add_pressed = False
        self.subj_pressed = False
        self.controller = controller
        self.titles = []
        # name of the buttons for the first assignments box
        self.buttons = ["Add New", "Delete"]
        # the name of the buttons for the subject box if its created
        self.subject_buttons = ["Delete", "Done"]
        '''the names of the entry boxes these are stored as keys
        in the dictionary self.entry_fields which
        is inherited from GUISkeleton'''
        self.entries = [
            "Assignment Name", "Start Date", "Due Date", "Visible", "Subject",
            "Number of Questions"
        ]
        GUISkeleton.__init__(self, parent)
        # create the title label
        '''initiate the buttons on the screen'''
        new_frame = ttk.Frame(self)
        #back button
        self.create_label(new_frame, "Manage Assignments", TITLE_FONT,
                          "Red").pack(side="left", padx=40)
        back_button = self.create_button(new_frame, "Back")
        back_button["command"] = lambda: controller.show_frame('HomeScreen')
        back_button.pack(side="right", padx=10)
        new_frame.grid(row=0, column=0, pady=20, sticky="E")

        # we will fill this in with the listbox after
        self.subject_box = None
        self.list_box = None
        # the functions to initialise the buttons and the widgets
        # the numbers are the row and the column to place the widgets in
        self.mframe = ttk.Frame(self)
        self.create_frame(self.mframe, 1, 0)
        self.init_buttons(self.mframe, 2, 0)
        self.mframe.grid(row=1, column=0, columnspan=3)
        # add the assignments currently in the database to the list
        aids = db.get_assignments_ids(conn)  # this returns a list
        label_string = "{:>3}    {:>15}   {:>10}    {:>10}    {:>10}    {:>3}"
        label_string = label_string.format("Aid", "Assignment Name", "Formula",
                                           "Start Date", "Deadline", "Visible")
        self.add_to_list(self.list_box, label_string)
        for aid in aids:
            self.add_assign_to_lb(aid)
        # list that will hold all the frames of the widgets created
        self.frames = []
Example #5
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)
Example #6
0
    def __init__(self, parent, controller):
        '''initialises the window'''
        self.add_pressed = False
        self.subj_pressed = False
        self.controller = controller
        self.titles = []
        # name of the buttons for the first assignments box
        self.buttons = ["Add New", "Delete", "Back"]
        # the name of the buttons for the subject box if its created
        self.subject_buttons = ["Delete", "Done"]
        '''the names of the entry boxes these are stored as keys
        in the dictionary self.entry_fields which
        is inherited from GUISkeleton'''
        self.entries = [
            "Assignment Name", "Start Date", "Due Date", "Visible", "Subject",
            "Number of Questions"
        ]
        GUISkeleton.__init__(self, parent)
        # create the title label
        self.title = self.create_label(self, "View Assignments", TITLE_FONT,
                                       "red").grid(row=0,
                                                   column=1,
                                                   pady=10,
                                                   padx=20)

        # we will fill this in with the listbox after
        self.subject_box = None
        self.list_box = None
        # the functions to initialise the buttons and the widgets
        # the numbers are the row and the column to place the widgets in
        title = self.create_label(self, "Assignments", APP_HIGHLIGHT_FONT)
        title.grid(row=1, column=0)
        self.create_frame(2, 0)
        self.init_buttons(3, 0)
        # add the assignments currently in the database to the list
        aids = db.get_assignments_ids(conn)  # this returns a list
        for aid in aids:
            self.add_assign_to_lb(aid)
        # list that will hold all the frames of the widgets created
        self.frames = []
Example #7
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)
Example #8
0
 def gen_rows(self):
     ids = db.get_assignments_ids(conn)
Example #9
0
        back_button = self.create_button(new_frame, "Back")
        back_button["command"] = lambda: controller.show_frame('HomeScreen')
        back_button.pack(side="right", padx=10)
        new_frame.grid(row=0, column=0, pady=20, sticky="E")
        
        
        # we will fill this in with the listbox after
        self.subject_box = None
        self.list_box = None
        # the functions to initialise the buttons and the widgets
        # the numbers are the row and the column to place the widgets in
        self.create_frame(self.mframe, 1, 0)
        self.init_buttons(self.mframe, 2, 0)
        self.mframe.grid(row=1, column=0, columnspan=3)
        # add the assignments currently in the database to the list
        aids = db.get_assignments_ids(conn) # this returns a list
<<<<<<< HEAD
=======
        label_string = "{:>3}    {:>15}   {:>10}    {:>10}    {:>10}    {:>3}"
        label_string = label_string.format("Aid", "Assignment Name",
                                           "Formula", "Start Date",
                                           "Deadline", "Visible")
        self.add_to_list(self.list_box, label_string)        
>>>>>>> working_final
        for aid in aids:
            self.add_assign_to_lb(aid)
        # list that will hold all the frames of the widgets created 
        self.frames = []
        
    def create_tab(self, num=4):
        '''returns a string that is equivalent to the tab character