From 3361e4ba79cf861fa2b624feefe626b87cb05f38 Mon Sep 17 00:00:00 2001 From: PlutoCtx Date: Sun, 18 Jun 2023 13:21:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95convert=5Ft?= =?UTF-8?q?est=5Ftype=5Fto=5Fdifficulty=5Flevel=E5=92=8Cget=5Fdifficulty?= =?UTF-8?q?=5Flevel=5Ffor=5Fuser=E5=87=BD=E6=95=B0=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=E6=89=80=E9=9C=80=E6=97=B6=E9=97=B4=E7=9A=84=E5=87=A0=E8=A1=8C?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/difficulty.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/difficulty.py b/app/difficulty.py index cb93768..20f947d 100644 --- a/app/difficulty.py +++ b/app/difficulty.py @@ -7,6 +7,8 @@ import pickle import math +import time + from wordfreqCMD import remove_punctuation, freq, sort_in_descending_order, sort_in_ascending_order import snowballstemmer @@ -24,6 +26,7 @@ def convert_test_type_to_difficulty_level(d): :param d: 存储了单词库pickle文件中的单词的字典 :return: """ + time_start = time.time() result = {} L = list(d.keys()) # in d, we have test types (e.g., CET4,CET6,BBC) for each word @@ -38,6 +41,8 @@ def convert_test_type_to_difficulty_level(d): result[k] = 7 elif 'BBC' in d[k]: result[k] = 8 + time_end = time.time() + print('convert_test_type_to_difficulty_level totally cost', time_end - time_start) return result # {'apple': 4, ...} @@ -48,6 +53,7 @@ def get_difficulty_level_for_user(d1, d2): d1 用户不会的词 在d2的后面添加单词,没有新建一个新的字典 """ + time_start = time.time() # TODO: convert_test_type_to_difficulty_level() should not be called every time. Each word's difficulty level should be pre-computed. d2 = convert_test_type_to_difficulty_level(d2) # 根据d2的标记评级{'apple': 4, 'abandon': 4, ...} stemmer = snowballstemmer.stemmer('english') @@ -61,6 +67,8 @@ def get_difficulty_level_for_user(d1, d2): d2[k] = d2[stem] # 按照词根进行评级 else: d2[k] = 3 # 如果k的词根都不在,那么就当认为是3级 + time_end = time.time() + print('get_difficulty_level_for_user totally cost', time_end - time_start) return d2