From 4e1e19d71d2cfd82ee0e6fa91750db978bd90ea2 Mon Sep 17 00:00:00 2001
From: PlutoCtx <chentingxian195467@163.com>
Date: Sun, 18 Jun 2023 21:43:00 +0800
Subject: [PATCH] =?UTF-8?q?=E4=B8=BA=E7=B3=BB=E7=BB=9F=E6=B7=BB=E5=8A=A0?=
 =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=85=A8=E5=B1=80=E5=8F=98=E9=87=8F=E8=AE=B0?=
 =?UTF-8?q?=E5=BD=95=E6=95=B0=E6=8D=AE=E5=BA=93=E7=9A=84=E5=8D=95=E8=AF=8D?=
 =?UTF-8?q?=E5=8F=8A=E5=85=B6=E7=AD=89=E7=BA=A7=EF=BC=8C=E4=BD=BF=E5=BE=97?=
 =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E5=8D=95=E8=AF=8D=E7=AD=89=E7=BA=A7?=
 =?UTF-8?q?=E5=8F=AA=E9=9C=80=E5=9C=A8=E7=99=BB=E5=BD=95=E6=97=B6=E8=BF=9B?=
 =?UTF-8?q?=E8=A1=8C=E4=B8=80=E6=AC=A1=E8=AF=84=E7=BA=A7=EF=BC=8C=E5=A4=A7?=
 =?UTF-8?q?=E8=87=B4=E8=83=BD=E5=B0=86=E7=82=B9=E5=87=BB=E4=B8=8B=E4=B8=80?=
 =?UTF-8?q?=E7=AF=87=E7=9A=84=E6=97=B6=E9=97=B4=E7=BC=A9=E5=87=8F=E4=B8=BA?=
 =?UTF-8?q?=E5=8E=9F=E6=9D=A5=E7=9A=8410^-15=E6=AC=A1=E4=BB=A5=E4=B8=8B?=
 =?UTF-8?q?=EF=BC=8C=E6=84=9F=E8=B0=A2=E7=AB=A0=E7=BF=8A=E3=80=81=E8=B5=B5?=
 =?UTF-8?q?=E7=85=9C=E6=B6=B5=E3=80=81=E5=94=90=E4=BC=9F=E3=80=81=E5=AE=8B?=
 =?UTF-8?q?=E6=B1=9F=E6=B6=9B=E5=90=8C=E5=AD=A6=E7=9A=84=E5=BB=BA=E8=AE=AE?=
 =?UTF-8?q?=EF=BC=8C=E6=B2=A1=E6=9C=89=E4=BB=96=E4=BB=AC=E6=88=91=E6=87=92?=
 =?UTF-8?q?=E5=BE=97=E6=94=B9=E7=9A=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/difficulty.py | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/app/difficulty.py b/app/difficulty.py
index 20f947d..ad4c890 100644
--- a/app/difficulty.py
+++ b/app/difficulty.py
@@ -6,12 +6,14 @@
 # Purpose: compute difficulty level of a English text
 
 import pickle
-import math
 import time
 
-from wordfreqCMD import remove_punctuation, freq, sort_in_descending_order, sort_in_ascending_order
 import snowballstemmer
 
+from wordfreqCMD import remove_punctuation, freq, sort_in_descending_order, sort_in_ascending_order
+
+# 定义一个全局的res_d, 记录数据库单词评级之后的单词及其等级
+res_d = {}
 
 def load_record(pickle_fname):
     f = open(pickle_fname, 'rb')
@@ -43,7 +45,8 @@ def convert_test_type_to_difficulty_level(d):
             result[k] = 8
     time_end = time.time()
     print('convert_test_type_to_difficulty_level totally cost', time_end - time_start)
-
+    global res_d
+    res_d = result
     return result  # {'apple': 4, ...}
 
 
@@ -55,7 +58,10 @@ def get_difficulty_level_for_user(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, ...}
+    if res_d == {}:
+        d2 = convert_test_type_to_difficulty_level(d2)  # 根据d2的标记评级{'apple': 4, 'abandon': 4, ...}
+    else:
+        d2 = res_d
     stemmer = snowballstemmer.stemmer('english')
 
     for k in d1:  # 用户的词