示例#1
0
 def EnterResults(self, Answers, correctness, user, path):
     db = Database(path)
     logger.info('Saving Answer to Database..')
     answer_datetime = dt.now().strftime("%Y-%m-%d %H:%M:%S")
     db.add_answer(user, self.content['vocID'], ', '.join(Answers),
                   answer_datetime, correctness)
     return answer_datetime
 def Buttonfunc_EndSession(self):
     """ This exists the questionare and shows result statistics in the GUI
     The function is either called when all due vocables have been answered or prematurely as the corresponding
         button gets pressed during questionare"""
     logger.info('Finishing the session')
     self.user_answers_NumVocables, corrects, falses, self.user_answers_total = \
         functions.EndSession(self.user_answers, self.user_answers_NumVocables, self.user_answers_total)
     for frame in self.frame:
         for widget in frame.winfo_children():
             widget.destroy()
     tk.Label(self.frame[0],
              text=str(self.user) + ",",
              font=("Helvetica", 30)).pack()
     tk.Label(self.frame[0],
              text="du hast in dieser Session insgesamt ").pack()
     tk.Label(self.frame[0],
              text=str(self.user_answers_NumVocables),
              font=("Helvetica", 30)).pack()
     tk.Label(self.frame[0], text=" Vokabeln beantwortet!").pack()
     tk.Label(self.frame[0], text="Im letzten Durchgang waren:").pack()
     tk.Label(self.frame[0],
              text=corrects + " richtig und",
              justify="left",
              anchor="w").pack()
     tk.Label(self.frame[0],
              text=falses + " falsch",
              justify="left",
              anchor="w").pack()
     tk.Label(self.frame[0],
              text="Das hier war der " +
              str(len(self.Selector.Entities) - 1) + ". Durchgang.").pack()
     tk.Label(self.frame[0],
              text="Insgesamt hast du " + str(self.user_answers_total) +
              " Fragen beantwortet.").pack()
     self.Create_Buttons("EndSession")
 def Buttonfunc_Tippfehler(self):
     """ Button function after answered a vocable during questionare. After Checking the answer, even wrong answers
         will be saved as correct to the user's answer table in the DB if this button is pressed. """
     logger.info("Pressed Tippfehler for vocID " + str(self.Selector.idx))
     db = Database(self.path)
     db.set_answer_Tippfehler(self.user, self.answer_datetime)
     self.btn_Tippfehler.destroy()
示例#4
0
 def convert_JSON(self, vocables):
     logger.info("Converting from JSON to MySQL DB")
     for user in vocables[0].content["answers"]:
         logger.debug("Creating Data for user: "******"Alles", range(1, 1 + len(vocables)),
                         vocables[0].content[user]["last_stop"])
     logger.debug("finished creation of user tables")
     user_answers = {}
     for vocable in vocables:
         logger.debug("Adding Vocable: " +
                      ", ".join(vocable.content["deutsch"]))
         self.add_vocable(", ".join(vocable.content["deutsch"]),
                          ", ".join(vocable.content["spanisch"]),
                          vocable.content["kommentar"])
         logger.debug("Finding vocID of the vocable")
         vocID = self.find_vocable(", ".join(vocable.content["deutsch"]),
                                   ", ".join(vocable.content["spanisch"]),
                                   vocable.content["kommentar"])
         logger.debug("Found! VocID: " + str(vocID))
         for user in vocable.content["answers"]:
             if "NextTime" in vocable.content["answers"][user]:
                 for idx in range(
                         len(vocable.content["answers"][user]["delay"])):
                     index = -1 - idx  # start checking for delay > 0 in reverse order
                     if vocable.content["answers"][user]["delay"][index] > 0:
                         logger.debug("updating table of " + user +
                                      " at vocID " + str(vocID) +
                                      " to show a delay of " +
                                      str(vocable.content["answers"][user]
                                          ["delay"][index]))
                         self.set_lesson_delay(
                             user, "Alles", vocID[0][0],
                             vocable.content["answers"][user]["delay"]
                             [index],
                             vocable.content["answers"][user]["NextTime"])
                         break
                     logger.debug("Did not find a delay > 0 on vocID " +
                                  str(vocID[0][0]) + " for user " + user)
             # logger.debug("Adding previous answers to the DB")
             for idx in range(len(
                     vocable.content["answers"][user]["delay"])):
                 if user not in user_answers:
                     user_answers[user] = []
                 try:
                     user_answers[user].append(
                         (vocID[0][0], ", ".join(vocable.content["answers"]
                                                 [user]["answer"][idx]),
                          vocable.content["answers"][user]["datetime"][idx],
                          vocable.content["answers"][user]["correctness"]
                          [idx]))
                 except:
                     logger.warning("corrupted data on Answer: " +
                                    ", ".join(vocable.content["deutsch"]) +
                                    ", " + user)
     for user in vocables[0].content["answers"]:
         self._check_user(user)
         self.c.executemany(
             "INSERT INTO {}_answertable "
             "VALUES (?, ?, ?, ?)".format(user), user_answers[user])
 def Buttonfunc_LoadData(self):
     """ selects and loads the desired database when pressing the button at the start of the program """
     if self.path == "" and not self.testmode:
         self.path = filedialog.askopenfilename()
     elif self.testmode:
         self.path = os.path.dirname(
             os.path.abspath(__file__)) + "\Testdata.json"
     logger.info('Loading File: ' + self.path)
     self.Create_Buttons("MainScreen2")
 def Buttonfunc_AddVocables(self):
     """ Used to add additional vocables from a tsv to a DB file """
     logger.info("Adding vocables from tsv file")
     self.path, self.vocables, self.Selector = functions.LoadData(
         self.path, self.Selector)
     self.vocables = functions.AddVocables(self.vocables,
                                           self.path_AddVocables, self.path)
     self.path, self.vocables, self.Selector = functions.LoadData(
         self.path, C_selection.C_selection)
示例#7
0
 def ChangedEntries(self, deutsch, spanisch, kommentar, path):
     db = Database(path)
     logger.info("Saving changed on vocID: " +
                 str(self.OrigEntires[self.idx]["vocID"]))
     logger.debug("New contents are:")
     logger.debug("german: " + deutsch + ", spanisch: " + spanisch +
                  ", comment: " + kommentar)
     db.set_vocable(self.OrigEntires[self.idx]["vocID"], deutsch, spanisch,
                    kommentar)
示例#8
0
 def AddDelay(self, user, delay, mode, path):
     db = Database(path)
     TimeToAskAgain = dt.today() + dtt.timedelta(days=delay)
     if mode == "nach Fälligkeit":
         db.set_lesson_delay(user, 'Alles', self.content['vocID'], delay,
                             TimeToAskAgain.strftime("%Y-%m-%d"))
         self.content['NextTime'] = TimeToAskAgain.strftime("%Y-%m-%d")
         logger.info('Setting the new NextTime to ' +
                     TimeToAskAgain.strftime("%Y-%m-%d"))
 def Buttonfunc_saveTSV(self):
     """ Button function available after selection a DB to export the vocables table as TSV-file """
     logger.info("Exporting file " + self.path + " as TSV file")
     self.path, self.vocables, self.Selector = functions.LoadData(
         self.path, self.Selector)
     [file_no_extension, waste] = self.path.split(".")
     if os.path.isfile(file_no_extension + "_export.tsv"):
         logger.warning("TSV Export to file that already exists (" +
                        file_no_extension +
                        ") no action taken to not override current file!")
     else:
         functions.saveTSV(self.vocables, file_no_extension + "_export.tsv")
示例#10
0
 def Buttonfunc_Repeat_Wrong_Answers(self):
     """ After finishing a session of questionare, this function can be called by the corresponding button to
         start another questinare only asking those vocables, that have been answered incorrectly during the last
         session """
     logger.info('Repeating wrong answers')
     self.path, self.vocables, unnecessary = functions.LoadData(
         self.path, C_selection.C_selection(), user=self.user)
     self.user_answers, self.user_answers_idx, self.Selector, self.MaxNumVocables = \
         functions.Repeat_Wrong_Answers(self.user_answers,
                                        self.user_answers_idx,
                                        self.Selector)
     self.Buttonfunc_NextVocable()
     self.Create_Buttons("AskVocable")
示例#11
0
 def Search(self, deutsch, spanisch, kommentar, path):
     self.OrigEntires = []
     self.idx = 0
     logger.info("Searching for " + deutsch + "; " + spanisch + "; " +
                 kommentar)
     db = Database(path)
     results = db.find_vocable(deutsch, spanisch, kommentar)
     for result in results:
         self.OrigEntires.append({
             'vocID': result[0],
             'deutsch': result[1],
             'spanisch': result[2],
             'kommentar': result[3],
         })
     self.IDs = range(len(self.OrigEntires))
示例#12
0
 def Buttonfunc_CheckEntry(self):
     """ During Questionare of vocables, this button functions checks answers of the user for correctness """
     logger.info("Checking vocable with vocID: " +
                 str(self.current_vocable.content['vocID']))
     label_colors, correctness, self.answer_datetime = functions.CheckEntry(
         self.ET_Answer, self.current_vocable, self.requested, self.user,
         self.Selector, self.path, self.mode)
     self.user_answers.append(correctness)
     self.user_answers_idx.append(self.Selector.idx)
     # show correct answers as label in green, wrong answers show the correct word in red:
     for request, color in zip(self.requested, label_colors):
         tk.Label(self.frame[1],
                  text=request,
                  font=self.fontLayout,
                  fg=color).pack()
     self.Create_Buttons("CheckedVocable")
示例#13
0
 def Buttonfunc_NextVocable(self):
     """ After checking an answer and at the beginning of the questionare, this button function prepares vocable
         information to be displayed in the GUI --> german, spanish and comment contents """
     logger.info("Continuing to Questionare of Vocables")
     self.presented, self.requested, self.kommentar, self.MaxNumVocables, self.current_vocable = \
         functions.NextVocable(self.Selector,
                               self.mode,
                               self.path,
                               self.user,
                               self.languagemode,
                               self.vocables,
                               self.MaxNumVocables)
     for frame in self.frame:
         for widget in frame.winfo_children():
             widget.destroy()
     self.ET_Answer = []  #delete old information
     for id in range(len(self.requested)):
         self.ET_Answer.append(tk.Entry(self.frame[1],
                                        font=self.fontLayout))
         self.ET_Answer[-1].pack()
     self.ET_Answer[0].focus()  #set cursor to first Entry field
     self.label_presented = []
     for word in self.presented:
         self.label_presented.append(
             tk.Label(self.frame[0], font=self.fontLayout, text=word))
         self.label_presented[-1].pack()
     tk.Label(self.frame[0], font=self.fontLayout,
              text="").pack()  #just leave an empty line
     if self.kommentar != "":
         tk.Label(self.frame[0],
                  font=self.fontLayout + (" bold", ),
                  text="Kommentar: " + self.kommentar).pack()
     tk.Label(self.frame[0],
              font=self.fontLayout,
              text="Dies ist Vokabel " + str(1 + len(self.user_answers)) +
              "/" + str(self.MaxNumVocables) + " der Session").pack()
     if self.Selector.listID == 0:  # Abfragen nach Reihenfolge
         tk.Label(self.frame[0],
                  font=self.fontLayout,
                  text="bzw. " +
                  str(self.current_vocable.content["vocID"]) + "/" +
                  str(len(self.Selector.Entities[self.Selector.listID])) +
                  " der Datenbank").pack()
     self.Create_Buttons("AskVocable")
示例#14
0
    def CM_refreshResults(self, ResultFields):
        """ Manages the display of search results on the right side of the GUI during ChangeManagement """
        if len(self.SearchResults.IDs) > 0:
            logger.info(
                "Refreshing Results in Change Management, showing vocID: " +
                str(self.SearchResults.OrigEntires[self.SearchResults.idx]
                    ["vocID"]))
            for field in ResultFields:
                field.delete(0, "end")

            ResultFields[0].insert(
                0, self.SearchResults.OrigEntires[self.SearchResults.idx]
                ["deutsch"])
            ResultFields[1].insert(
                0, self.SearchResults.OrigEntires[self.SearchResults.idx]
                ["spanisch"])
            ResultFields[2].insert(
                0, self.SearchResults.OrigEntires[self.SearchResults.idx]
                ["kommentar"])
示例#15
0
 def NextEntity(self, mode):
     #initiate correctly depending on mode
     if self.IDs == -1 and mode == "nach Reihenfolge" and len(
             self.Entities) == 2:
         self.listID = 0
         self.IDs = self.Entities[0].index(self.last_stop)
         logger.debug("knowing that last_stop was " + str(self.last_stop))
     elif self.IDs == -1 and mode == "nach Fälligkeit" and len(
             self.Entities) == 2:
         self.listID = 1
         self.IDs = -1
     self.IDs += 1
     #restart if end of list is reached
     if self.IDs >= len(self.Entities[0]) and mode == "nach Reihenfolge":
         self.IDs = 0
     elif self.IDs >= len(self.Entities[-1]) and mode == "nach Fälligkeit":
         print("Trying to call more Entries than exist?!")
     self.idx = self.Entities[self.listID][self.IDs]
     logger.info("Trying to show the vocID: " + str(self.idx))
示例#16
0
    def Buttonfunc_Continue(self):
        """ At the main screen, after selection all radio buttons, this button function will start the questionare """
        for error in self.RadioBtns["errors"]:
            error.pack_forget()
        errors = 0
        if self.RadioBtns["user selection"].get() == "x":
            self.RadioBtns["errors"].append(
                tk.Label(self.frame[1],
                         text="Bitte Benutzer auswählen!",
                         fg="RED"))
            self.RadioBtns["errors"][-1].pack(anchor="w")
            errors = 1
        else:
            self.user = self.RadioBtns["user selection"].get()
            self.path, self.vocables, self.Selector = functions.LoadData(
                self.path, C_selection.C_selection(), user=self.user)

        if self.RadioBtns["language"].get() == "x":
            self.RadioBtns["errors"].append(
                tk.Label(self.frame[1],
                         text="Bitte Sprache auswählen!",
                         fg="RED"))
            self.RadioBtns["errors"][-1].pack(anchor="w")
            errors = 1
        elif self.RadioBtns["language"].get() == "deutsch":
            self.languagemode = 0
        elif self.RadioBtns["language"].get() == "spanisch":
            self.languagemode = 1

        if self.RadioBtns["mode"].get() == "x":
            self.RadioBtns["errors"].append(
                tk.Label(self.frame[1],
                         text="Bitte Modus auswählen!",
                         fg="RED"))
            self.RadioBtns["errors"][-1].pack(anchor="w")
            errors = 1
        elif (self.RadioBtns["mode"].get()
              == "nach Reihenfolge") and (self.ET_MaxNumVocables.get() == ""):
            self.RadioBtns["errors"].append(
                tk.Label(self.frame[1],
                         text="Bitte Maximal Anzahl eingeben!",
                         fg="RED"))
            self.RadioBtns["errors"][-1].pack(anchor="w")
            errors = 1
        elif self.RadioBtns["mode"].get() == "nach Reihenfolge":
            self.MaxNumVocables = int(self.ET_MaxNumVocables.get())
        self.mode = self.RadioBtns["mode"].get()

        if (self.RadioBtns["user selection"].get() != "x"):
            if (len(self.Selector.Entities[1])
                    == 0) and (self.RadioBtns["mode"].get()
                               == "nach Fälligkeit"):
                self.RadioBtns["errors"].append(
                    tk.Label(self.frame[1],
                             text="Keine Vokabeln für heute fällig!",
                             fg="RED"))
                self.RadioBtns["errors"][-1].pack(anchor="w")
                errors = 1
        if errors == 0:
            logger.info("Running user: "******" in languagemode " +
                        str(self.languagemode) + " in mode " + self.mode)
            self.Buttonfunc_NextVocable()
        else:
            logger.warning(
                "At least on Selection in Startscreen was not done properly")
示例#17
0
 def Buttonfunc_ChangeManagement(self):
     """ Starts the ChangeManagement, hence allowing to search and change vocable entries within current DB """
     logger.info("Entering ChangeManagement")
     self.path, self.vocables, self.Selector = functions.LoadData(
         self.path, self.Selector)
     self.SearchResults = CM()
     for widget in self.frameButtons.winfo_children():
         widget.destroy()
     for widget in self.frame[0].winfo_children():
         widget.destroy()
     for widget in self.frame[1].winfo_children():
         widget.destroy()
     # building labels and entry fields for the left side of the GUI:
     tk.Label(self.frame[0], text="SUCHE:",
              font=self.fontLayout).grid(row=1, column=1)
     i = 0
     SearchEntries = []
     Attributes = ["Deutsch:", "Spanisch:", "Kommentar:"]
     for item in Attributes:
         i += 1
         tk.Label(self.frame[0],
                  text=item,
                  font=self.fontLayout,
                  anchor="w").grid(row=i + 1, column=1, sticky="W")
         SearchEntries.append(tk.Entry(self.frame[0], font=self.fontLayout))
         SearchEntries[-1].grid(row=i + 1, column=2)
     tk.Label(self.frame[1], text="Gefunden:").grid(row=1, column=1)
     # building labels and entry fields for the right side of the GUI:
     i = 0
     self.FoundEntries = []
     for item in Attributes:
         i += 1
         tk.Label(self.frame[1],
                  text=item,
                  font=self.fontLayout,
                  anchor="w").grid(row=i * 2, column=1, sticky="W")
         self.FoundEntries.append(
             tk.Entry(self.frame[1], font=self.fontLayout, width=30))
         self.FoundEntries[-1].grid(row=2 * i + 1, column=1, columnspan=2)
     tk.Button(
         self.frame[1],
         text="Nächstes",
         font=self.fontLayout,
         command=lambda: self.Buttonfunc_CM_next(self.FoundEntries)).grid(
             row=8, column=2, sticky="W")
     tk.Button(self.frame[1],
               text="Vorheriges",
               font=self.fontLayout,
               command=lambda: self.Buttonfunc_CM_previous(
                   self.FoundEntries)).grid(row=8, column=1, sticky="E")
     tk.Button(
         self.frame[1],
         text="Speichern",
         font=self.fontLayout,
         command=lambda: self.Buttonfunc_CM_save(self.FoundEntries)).grid(
             row=9, column=1, columnspan=2)
     self.btn_search = tk.Button(
         self.frame[0],
         text="Suchen",
         font=self.fontLayout,
         command=lambda: self.
         Buttonfunc_CM_search(SearchEntries[0].get(), SearchEntries[1].get(
         ), SearchEntries[2].get(), self.FoundEntries))
     self.btn_search.grid(row=5, column=1, columnspan=2)
     self.btn_delete = []
     self.btn_delete.append(
         tk.Button(self.frame[1],
                   text="Vokabel löschen",
                   font=self.fontLayout,
                   command=self.Buttonfunc_CM_delete1))
     self.btn_delete.append(
         tk.Button(
             self.frame[1],
             text="Wirklich löschen",
             font=self.fontLayout,
             command=lambda: self.Buttonfunc_CM_delete2(self.FoundEntries)))
     self.btn_delete.append(
         tk.Label(self.frame[1], text=" ", font=self.fontLayout))
     self.btn_delete[0].grid(row=10, column=1, columnspan=2)
     self.ButtonLayout = "MainScreen"
     tk.Button(self.frameButtons,
               text="Zurück zum Hauptmenü",
               font=self.fontLayout,
               command=self.Create_Buttons).pack()