def __init__(self, WORD_DICT, parent): # Get todayList # self.today_list = ["test"] self.vocab = Vocab.Vocab(WORD_DICT) self.vocab.saveVocab() # 保存词库 self.today_list_obj = TodayList.TodayList(self.vocab) self.open = True if self.today_list_obj.new_user: value, ok = QInputDialog.getInt(parent, '学习计划设定', '请输入每天需要背诵的数量(5-700):', 50, 5, 700, 1) if ok: self.today_list_obj.plan_for_new_user(value, self.vocab) else: self.open = False return self.today_list_dict = self.today_list_obj.getTodayList() self.today_list = list(self.today_list_dict.keys()) self.finished = False self.ite = -1 self.review_list = [] # self.is_first_round = True if self.next_word(): print('开始背单词') if len(self.today_list) > 0: self.word_current = self.today_list[self.ite] else: print("Fail to get recite list for today") self.finished = True else: # 今天的任务已经背完了 QMessageBox.information(parent, '提醒', '你已经背完今天的单词了呢,注意劳逸结合哦~', QMessageBox.Yes) # parent.close() self.finished = True
def test_14_time_concept(self): vocab = Vocab.Vocab(word_dict) todaylist_obj = TodayList.TodayList(vocab) todaylist_obj.plan_for_new_user(50, vocab) todaylist_obj.save_todaylist() pre_todaylist = list(todaylist_obj.getTodayList().keys()) todaylist_obj = TodayList.TodayList(vocab) curr_todaylist = list(todaylist_obj.getTodayList().keys()) self.assertTrue(pre_todaylist == curr_todaylist) pre_todaylist = curr_todaylist todaylist_obj.change_date(datetime.date.today() + datetime.timedelta(days=1)) todaylist_obj.save_todaylist() todaylist_obj = TodayList.TodayList(vocab) curr_todaylist = list(todaylist_obj.getTodayList().keys()) self.assertFalse(pre_todaylist == curr_todaylist)
def test_13_get_n_word_from_todaylist(self): vocab = Vocab.Vocab(word_dict) todaylist_obj = TodayList.TodayList(vocab) todaylist_dict = todaylist_obj.getTodayList() get_list = todaylist_obj.get_n_word_from_todaylist(5) self.assertTrue(set(get_list).issubset(set(list(todaylist_dict.keys())))) get_list = todaylist_obj.get_n_word_from_todaylist(20) self.assertEqual(len(get_list), 0)
def test_12_add_word_to_todaylist(self): vocab = Vocab.Vocab(word_dict) todaylist_obj = TodayList.TodayList(vocab) todaylist_obj.plan_for_new_user(10, vocab) todaylist_dict = todaylist_obj.getTodayList() word = random.choice(list(todaylist_dict.keys())) self.assertFalse(todaylist_obj.add_word_to_todaylist(word, vocab)) while True: word = random.choice(list(vocab.getVocabDict().keys())) if word not in todaylist_dict.keys(): break self.assertTrue(todaylist_obj.add_word_to_todaylist(word, vocab)) self.assertEqual(len(todaylist_obj.getTodayList()), 11) todaylist_obj = TodayList.TodayList(vocab) self.assertEqual(len(todaylist_obj.getTodayList()), 11) self.assertFalse(todaylist_obj.add_word_to_todaylist('dsddsds', vocab))
from StudyPlan import TodayList from StudyPlan import Vocab import random # 先生成词汇表vocab vocab = Vocab.Vocab() # 根据词汇表生成今日计划todayList todayList = TodayList.TodayList(vocab).getTodayList() print(todayList) # 打印todayList检查是否符合要求 # 测试用代码,确认vocab中词汇的熟悉程度可以更新 familiarity = [0, 1, 2] for key in vocab.getVocabDict().keys(): vocab.updateFamiliarity(key, random.choice(familiarity)) # 给每个词随机赋予熟悉程度 vocab.display() vocab.saveVocab()
def __init__(self, WORD_DICT): super(SettingGUI, self).__init__() self.setupUi(self) # Init study setting self.vocab = Vocab.Vocab(WORD_DICT) self.vocab.saveVocab() # 保存词库 self.today_list_obj = TodayList.TodayList(self.vocab) self.open = True if self.today_list_obj.new_user: value, ok = QInputDialog.getInt(self, '学习计划设定', '请输入每天需要背诵的数量(5-700):', 50, 5, 700, 1) if ok: self.today_list_obj.plan_for_new_user(value, self.vocab) self.word_num_today = value self.today_list_obj.save_todaylist() else: self.word_num_today = 50 # 默认值为50 self.open = False return else: self.word_num_today = self.today_list_obj.get_stated_todaylist_length( ) self.textBrowser.setText(str(self.word_num_today)) # 显示今日词数 self.textBrowser.setAutoFillBackground(True) self.listWidget.setAutoFillBackground(True) # self.listWidget_2.setAutoFillBackground(True) self.vocab_dict = self.vocab.getVocabDict() _translate = QCoreApplication.translate ite = 0 # print(len(self.vocab_dict)) for word in self.vocab_dict: if self.vocab_dict[word] == 0: continue # print(word) # self.listWidget.addItem(word) if self.vocab_dict[word] == 1: self.listWidget.addItem(word + ' 未掌握') item = self.listWidget.item(ite) # item.setText(_translate("MainWindow", str(word))) item.setBackground(QtGui.QColor(0, 255, 0, 40)) item.setSizeHint(QSize(350, 30)) item.setTextAlignment(Qt.AlignCenter) # self.listWidget_2.addItem('未掌握') # item = self.listWidget_2.item(ite) # # item.setText(_translate("MainWindow", '未掌握')) # item.setBackground(QtGui.QColor(0, 255, 0, 40)) # item.setSizeHint(QSize(350, 30)) else: self.listWidget.addItem(word + ' 已掌握') item = self.listWidget.item(ite) # item.setText(_translate("MainWindow", str(word))) item.setBackground(QtGui.QColor(0, 255, 0, 127)) item.setSizeHint(QSize(350, 30)) item.setTextAlignment(Qt.AlignCenter) # self.listWidget_2.addItem('已掌握') # item = self.listWidget_2.item(ite) # # item.setText(_translate("MainWindow", '未掌握')) # item.setBackground(QtGui.QColor(0, 255, 0, 127)) # item.setSizeHint(QSize(350, 30)) ite += 1
def test_11_init_todaylist(self): if os.path.exists('StudyPlan/TodayList.pkl'): os.remove('StudyPlan/TodayList.pkl') vocab = Vocab.Vocab(word_dict) todaylist_obj = TodayList.TodayList(vocab) self.assertTrue(todaylist_obj.new_user) todaylist_obj.plan_for_new_user(20, vocab) todaylist_dict = todaylist_obj.getTodayList() self.assertEqual(len(todaylist_dict), 20) all_value_0_in_todaylist = True for k in todaylist_dict: if not (todaylist_dict[k] == 0): all_value_0_in_todaylist = False break self.assertTrue(all_value_0_in_todaylist) all_familiarity_0_in_todaylist = True for k in todaylist_dict: if not (vocab.getFamiliarity(k) == 0): all_familiarity_0_in_todaylist = False break self.assertTrue(all_familiarity_0_in_todaylist) for k in vocab.getVocabDict().keys(): vocab.updateFamiliarity(k, 1) todaylist_obj.plan_for_new_user(20, vocab) todaylist_dict = todaylist_obj.getTodayList() all_familiarity_1_in_todaylist = True for k in todaylist_dict: if not (vocab.getFamiliarity(k) == 1): all_familiarity_1_in_todaylist = False break self.assertTrue(all_familiarity_1_in_todaylist) for k in vocab.getVocabDict().keys(): vocab.updateFamiliarity(k, 2) todaylist_obj.plan_for_new_user(20, vocab) todaylist_dict = todaylist_obj.getTodayList() all_familiarity_2_in_todaylist = True for k in todaylist_dict: if not (vocab.getFamiliarity(k) == 2): all_familiarity_2_in_todaylist = False break self.assertTrue(all_familiarity_2_in_todaylist) new_num = unfamiliar_num = 0 for k in list(vocab.getVocabDict().keys())[:100]: vocab.updateFamiliarity(k, 0) for k in list(vocab.getVocabDict().keys())[200:400]: vocab.updateFamiliarity(k, 1) todaylist_obj.plan_for_new_user(20, vocab) todaylist_dict = todaylist_obj.getTodayList() for k in todaylist_dict: if vocab.getFamiliarity(k) == 0: new_num += 1 if vocab.getFamiliarity(k) == 1: unfamiliar_num += 1 self.assertEqual(new_num, 12) self.assertEqual(unfamiliar_num, 8)