def save(self,dictionary_file_path,option=None): ''' This function allows saving a dictionary and the modification associated ''' if option=="Quizlet": column=["Word","Definition/Translation/Association"] else: column=copy.copy(self.__column) self.__uploaded_dictionary_file_path=dictionary_file_path path=os.path.split(dictionary_file_path)[0] if not os.path.isdir(path): os.makedirs(path) file=open(dictionary_file_path,mode="w",encoding="iso-8859-1") if option=="Quizlet": pass else : file.write(";".join(column)) file.write("\n") for value in self.__content.values(): line=[] for col in column : if col=="Number of Days since the last interogation" and not value["Last Interogation Date"]==None: delta_time=datetime.datetime.now()-value["Last Interogation Date"] line.append(str(delta_time.days)) elif col=="Last Interogation Date" and not value["Last Interogation Date"]==None: line.append(str(value[col].isoformat())) elif col=="Number of Days before the next interogation" and not value["Number of Days since the last interogation"]==None: if fibonacci.fib(int(value["Group"]))-int(value["Number of Days since the last interogation"]) <=0: line.append("0") else: line.append(str(fibonacci.fib(int(value["Group"]))-int(value["Number of Days since the last interogation"]))) elif value[col]==None: line.append("") else: line.append(str(value[col])) if not value["Word"]=="": line.append("\n") file.write(";".join(line)) file.close()
def create_new_interogation (self,list,number_of_word_to_learn,day_in_advance,mode=""): ''' Create an interogation of words ''' total_point=0 number_of_word=0 vocabulary_list=list if len(list)==0 or mode=="marathon": for word,value in self.__content.items(): if len(vocabulary_list)<number_of_word_to_learn: if word in vocabulary_list: pass elif value["Group"]==0: vocabulary_list.append(word) elif fibonacci.fib(int(value["Group"]))-int(value["Number of Days since the last interogation"])-int(day_in_advance)<=0: vocabulary_list.append(word) else : break; unknown_vocabulary=[] known_vocabulary=[] random.shuffle(vocabulary_list) #pprint.pprint(vocabulary_list) for french_word in vocabulary_list: value=self.__content[french_word] number_of_word+=1 point=self.please_translate(french_word,mode) if point==None: return; elif point==0: unknown_vocabulary.append(french_word) else: known_vocabulary.append(french_word) total_point+=point self.save(self.__uploaded_dictionary_file_path) if len(unknown_vocabulary)==0 and len(known_vocabulary)==0: easygui.msgbox(msg="No new Vocabulary for today",title="Learn") return ; if not total_point==number_of_word: self.create_new_interogation(unknown_vocabulary,number_of_word_to_learn=number_of_word_to_learn,day_in_advance=day_in_advance,mode=mode)
def stat_display (self): number_total_of_word=len(self.__content.keys()) Group_stat={} Group_list=[] time_before_interogation={} time_before_interogation_list=[] average_group=0 text_to_display="########## STAT ##########\n" text_to_display+="Number of Word in the Dictionary: "+str(number_total_of_word)+"\n" for french_word, word_value in self.__content.items(): Group=int(word_value["Group"]) average_group+=Group if not int(word_value["Group"])==0: days_before_interogation=fibonacci.fib(int(word_value["Group"]))-int(word_value["Number of Days since the last interogation"]) else : days_before_interogation=0 if days_before_interogation<0: days_before_interogation=0 days_before_interogation_list=[] if not Group in Group_stat.keys(): Group_stat[Group]=1 Group_list.append(Group) else: Group_stat[Group]+=1 if not days_before_interogation in time_before_interogation.keys(): time_before_interogation[days_before_interogation]=1 time_before_interogation_list.append(days_before_interogation) else: time_before_interogation[days_before_interogation]+=1 if not number_total_of_word==0: average_group=average_group/number_total_of_word text_to_display+="Average Group: "+str(average_group)+"\n" text_to_display+="_____________________________________________\n" time_before_interogation_list.sort() Group_list.sort() for Group in Group_list: number_of_word=Group_stat[Group] text_to_display+="Per Cent of Word in Group "+str(Group)+": "+str(number_of_word*100/number_total_of_word)+"("+str(number_of_word)+" Words)"+"\n" text_to_display+="_____________________________________________\n" text_to_display+="_____________________________________________\n" for number_of_days in time_before_interogation_list: number_of_word=time_before_interogation[number_of_days] text_to_display+=str(number_of_word)+" more Words will be present in the interogation set in "+str(number_of_days)+" Days\n" text_to_display+="_____________________________________________\n" text_to_display+="########## END STAT ##########\n" easygui.textbox(title='Statistic', text=text_to_display, codebox=0)
def please_translate(self,french_word,mode=""): translation_in=easygui.enterbox(msg=french_word,title="Flash Card Recto") if translation_in==None or translation_in=="-q": return None substitution_list=[",","(",")"," ",";","ยจ"] correct_pattern_str=copy.copy(self.__content[french_word]["Definition/Translation/Association"]) for substitution in substitution_list: correct_pattern_str=correct_pattern_str.replace(substitution,".*") correct_pattern=re.compile(correct_pattern_str,re.IGNORECASE) if correct_pattern.search(translation_in) is not None: choices = ["Continue","Modify the word"] reply=easygui.buttonbox(msg="Good Answer",title="Good Answer",choices=choices) if reply=="Modify the word": self.modify_word(french_word) return None self.__content[french_word]["Group"]+=1 self.__content[french_word]["Last Interogation Date"]=datetime.datetime.now() self.__content[french_word]["Number of Days since the last interogation"]=0 value=copy.copy(self.__content[french_word]) self.__content[french_word]["Number of Days before the next interogation"]=fibonacci.fib(int(value["Group"])-int(value["Number of Days since the last interogation"])) self.save(self.__uploaded_dictionary_file_path) return 1 else: last_group=self.__content[french_word]["Group"] if self.__content[french_word]["Group"]==0: pass elif self.__content[french_word]["Group"]==1: self.__content[french_word]["Group"]=0 else: self.__content[french_word]["Group"]-=2 self.__content[french_word]["Last Interogation Date"]=datetime.datetime.now() self.save(self.__uploaded_dictionary_file_path) request_index=0 while correct_pattern.search(translation_in) is None: translation_in=easygui.enterbox( msg="Correct Anwswer for\n-->" +french_word+"\n is\n-->" +self.__content[french_word]["Definition/Translation/Association"]+ "\n------------------------------\nYour Anwswer was\n-->"+translation_in+ "\n------------------------------\nWrite the GOOD Answer or 'iwr' (I was right) or 'c' (continue)", title="Wrong Answer") request_index+=1 if translation_in==None or translation_in=="-q": return None if (translation_in=="I was right" or translation_in=="iwr") and request_index==1: self.__content[french_word]["Group"]==last_group+1 self.__content[french_word]["Last Interogation Date"]=datetime.datetime.now() self.__content[french_word]["Number of Days since the last interogation"]=0 value=copy.copy(self.__content[french_word]) self.__content[french_word]["Number of Days before the next interogation"]=fibonacci.fib(int(value["Group"])-int(value["Number of Days since the last interogation"])) self.save(self.__uploaded_dictionary_file_path) return 1 if translation_in=="c": translation_in=self.__content[french_word]["Definition/Translation/Association"] return 0 choices = ["Continue","Modify the word"] reply=easygui.buttonbox(msg="Good Answer",title="Flash Card Recto",choices=choices) if reply=="Modify the word": self.modify_word(french_word) return None return 0