Exemplo n.º 1
0
    def gen_rows(self, uid=None, aid=None, atid=None):

        title_hints = self.create_label(self, "You have "+str(self.hints_left)+" hints",
                                      APP_HIGHLIGHT_FONT, NICE_BLUE)
        self.labels.append(title_hints)
        # get a list of all the problem ids for the user for that assignment
        ids = db.get_user_nth_attempt(self.aid, self.uid, -1, conn)[2]
        # set iterator for grid rows
        ids = ast.literal_eval(ids)
        # for each id create a row
        self.i = 0
        for qid in ids:
            # create new entries
            self.problem_ids.append(qid)
            hint_button = self.create_button(self, "Hint!")
            #question_label = self.create_label(self, "", REGULAR_FONT)
            answer_entry = ttk.Entry(self, font=REGULAR_FONT)
            hint_label = self.create_label(self, "", REGULAR_FONT, NICE_BLUE)
            self.labels.append(hint_label)
            self.entries.append(answer_entry)
            self.hint_buttons[qid] = hint_button
            self.hints_labels[qid] = hint_label

            # set everything nicely on the grid using an iterator i
            answer_entry.grid(row=self.i+4, column=2)
            hint_button.grid(row=self.i+4, column=3)
            hint_label.grid(row=self.i+4, column=4)

            # set each label with the corresponding value from the problem object
            #question_label.config(text=db.get_problem_details(conn, qid)[0][2])

            # set each entry with the corresponding value from list of existing progress
            try:
                answer_entry.insert(0, self.existing_progress[self.i])
            except IndexError:
                print("no progress yet")

            # NEW (latex feature) create the canvas with the latex problem
            self.latex_row(db.get_problem_details(conn, qid)[0][2])

            self.i += 1

        title_hints.grid(row=1, column=2, pady=10)
        # create submit and save progress buttons
        self.update_progress_button = self.create_button(self, "Save")
        self.update_progress_button["command"] = lambda : self.update_progress()
        self.update_progress_button.grid(row=0, column=4, padx=5)

        self.submit_button = self.create_button(self,"Submit") 
        self.submit_button["command"] = lambda : self.submit_progress()
        self.submit_button.grid(row=0, column=5, padx=5)

        self.pdf_button = self.create_button(self, "Convert to PDF")
        self.pdf_button["command"]= lambda : self.conv.addOnLatex()
        self.pdf_button.grid(row=0, column=6, padx=5)
Exemplo n.º 2
0
    def addOnLatex(self):
        '''This method takes problems from the database and attaches them
        to the latex expression.
        '''
        # Fetch the user attempts for assignment
        ids = db.get_user_nth_attempt(self.aid, self.uid, -1, conn)[2]
        ids = ast.literal_eval(ids)

        # Loop through problems
        for qid in ids:

            # For each problem, append it to latex expression
            problem = db.get_problem_details(conn, qid)[0][2]

            self.content += problem + r'\newline\newline' + r'\begin{tikzpicture}' + r'\draw (0,0) -- (17,0) -- (17,3) -- (0,3) -- (0,0);' +r'\end{tikzpicture}' + r'\newline\newline\newline\newline'

        self.substitue_values()
Exemplo n.º 3
0
    def gen_rows(self):
        # get a list of all the problem ids for the user for that assignment
        ids = db.get_user_nth_attempt(self.aid, self.uid, -1, conn)[2]
        # set iterator for grid rows
        # print(db.get_user_nth_attempt(self.aid, self.uid, -1, conn)[2])
        ids = ast.literal_eval(ids)
        # for each id create a row
        i = 0
        for qid in ids:
            # create new entries
            question_label = self.create_label(self,
                                               text="",
                                               font=REGULAR_FONT)
            answer_entry = Entry(self, font=REGULAR_FONT)
            self.labels.append(question_label)
            self.entries.append(answer_entry)
            # add to corresponding dictonaries with problem ids as keys
            # self.subjects[qid] = subject_entry
            # self.questions[qid] = question_entry
            # self.answers[qid] = answer_entry

            # set everything nicely on the grid using an iterator i
            question_label.grid(row=i + 3, column=0)
            answer_entry.grid(row=i + 3, column=1)

            # set each label with the corresponding value from the problem object
            question_label.config(text=db.get_problem_details(conn, qid)[0][2])

            # set each entry with the corresponding value from list of existing progress
            try:
                answer_entry.insert(0, self.existing_progress[i])
            except IndexError:
                print("no progress yet")

            i += 1

        # create submit and save progress buttons
        self.update_progress_button = ttk.Button(
            text="Save", command=lambda: self.update_progress())
        self.update_progress_button.pack()

        self.submit_button = ttk.Button(text="Submit",
                                        command=lambda: self.submit_progress())
        self.submit_button.pack()
Exemplo n.º 4
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.º 5
0
    def set_uid(self, uid, aid=None, atid=None):
        self.uid = uid
        self.aid = aid
        self.atid = atid
        # label at top of the frame
        title = self.create_label(self, "A" + str(aid) + " Attempt",
                                  TITLE_FONT, "Red").grid(row=0,
                                                          column=1,
                                                          pady=10)

        # get the existing progress for the user for the assignment
        self.existing_progress = db.get_user_nth_attempt(
            self.aid, self.uid, (self.atid - 1), conn)[3]
        self.existing_progress = self.existing_progress.split(",")
        self.gen_rows()

        self.create_label(self, text="Problem",
                          font=REGULAR_FONT).grid(row=1, column=0, pady=10)
        self.create_label(self, text="Solution",
                          font=REGULAR_FONT).grid(row=1, column=1, pady=10)
Exemplo n.º 6
0
    def set_uid(self, uid, aid=None, atid=None):
        self.real_uid = uid
        self.uid = uid[0]
        self.aid = aid
        self.atid = atid
            # label at top of the frame
        title = self.create_label(self, "A"+str(aid)+" Attempt",
                                  TITLE_FONT,
                                  "Red").grid(row=0, column=1, pady=10)

         # get the existing progress for the user for the assignment
        self.existing_progress = db.get_user_nth_attempt(
            self.aid, self.uid, (self.atid-1), conn)[3]
        self.existing_progress = self.existing_progress.split(",")
        self.gen_rows()
        
        problem = self.create_label(self, "Problem", APP_HIGHLIGHT_FONT, NICE_BLUE)
        solution = self.create_label(self, "Solution", APP_HIGHLIGHT_FONT, NICE_BLUE)
        problems.grid(row=1,column=1, pady=10)
        solution.grid(row=1,column=2, pady=10)
Exemplo n.º 7
0
 def get_user_nth_attempt(self):
     db.get_user_nth_attempt(row + 1, 200, 1, conn)
Exemplo n.º 8
0
 def test_get_non_existant_nth_attempt(self):
     self.assertRaises(
         IndexError,
         lambda: db.get_user_nth_attempt(row + 1, 200, 10, conn))