From cb224fe3abf0e729770abfa7861dd34aa1c9c69b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A7=9C=E9=9B=AA=E8=99=B9?= <2496758638@qq.com>
Date: Wed, 15 Jun 2022 12:04:43 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20'app/difficulty.py'?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/difficulty.py | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/app/difficulty.py b/app/difficulty.py
index 50aa179..1c576ad 100644
--- a/app/difficulty.py
+++ b/app/difficulty.py
@@ -21,12 +21,11 @@ def difficulty_level_from_frequency(word, d):
     level = 1
     if not word in d:
         return level
-    
-    if 'what' in d:
-        ratio = (d['what']+1)/(d[word]+1) # what is a frequent word
-        level = math.log( max(ratio, 1), 2)
-
-    level = min(level, 8) 
+    else:
+        if(len(word)<5): #calculate the difficulty level based on length
+        level = math.log(len(word),math.pow(d[word],2))
+        else:
+        level = math.log(len[word],d[word])
     return level
 
 
@@ -44,8 +43,8 @@ def get_difficulty_level(d1, d2):
                 d[k] = 6
             elif 'BBC' in d2[k]:
                 d[k] = 8
-                if k in d1: # BBC could contain easy words that are not in CET4 or CET6.  So 4 is not reasonable.  Recompute difficulty level.
-                    d[k] = min(difficulty_level_from_frequency(k, d1), d[k])
+                if k in d1: 
+                    d[k] = difficulty_level_from_frequency(k, d1)# BBC word rating 8 is too high,it is based on word fre
         elif k in d1:
             d[k] = difficulty_level_from_frequency(k, d1)
 
@@ -86,7 +85,7 @@ def user_difficulty_level(d_user, d):
             if word in d:
                 lst2.append((word, d[word]))
 
-        lst3 = sort_in_ascending_order(lst2) # easiest tuple first
+        lst3 = sort_in_descending_order(lst2) # easiest tuple first
         #print(lst3)
         for t in lst3:
             word = t[0]