diff options
author | Hui Lan <lanhui@zjnu.edu.cn> | 2021-02-11 18:47:34 +0800 |
---|---|---|
committer | Hui Lan <lanhui@zjnu.edu.cn> | 2021-02-11 18:47:34 +0800 |
commit | 878468fe34c65fc02959e267bc66f81718366662 (patch) | |
tree | 47435ac7df04cd9d7c15d82c3f007cdbe0c71574 | |
parent | ccb7bce2da5efaace604a7b80c18ca9dcc9bb4dc (diff) |
app/main.py: choose an article only when articleID is None.
-rw-r--r-- | app/main.py | 17 | ||||
-rw-r--r-- | app/test/test_add_word_and_essay_does_not_change.py | 7 |
2 files changed, 13 insertions, 11 deletions
diff --git a/app/main.py b/app/main.py index 3556d83..2bd903a 100644 --- a/app/main.py +++ b/app/main.py @@ -94,14 +94,15 @@ def get_today_article(user_word_list, articleID): user_level = user_difficulty_level(d_user, d3) # more consideration as user's behaviour is dynamic. Time factor should be considered.
random.shuffle(result) # shuffle list
d = random.choice(result)
- text_level = text_difficulty_level(d['text'], d3)
- for reading in result:
- text_level = text_difficulty_level(reading['text'], d3)
- #print('TEXT_LEVEL %4.2f' % (text_level))
- if within_range(text_level, user_level, 0.1):
- d = reading
- break
-
+ if articleID == None:
+ text_level = text_difficulty_level(d['text'], d3)
+ for reading in result:
+ text_level = text_difficulty_level(reading['text'], d3)
+ #print('TEXT_LEVEL %4.2f' % (text_level))
+ if within_range(text_level, user_level, 0.1):
+ d = reading
+ break
+
s = '<p><i>According to your word list, your level is <b>%4.2f</b> and we have chosen an article with a difficulty level of <b>%4.2f</b> for you.</i></p>' % (user_level, text_level)
s += '<p><b>%s</b></p>' % (d['date'])
s += '<p><font size=+2>%s</font></p>' % (d['text'])
diff --git a/app/test/test_add_word_and_essay_does_not_change.py b/app/test/test_add_word_and_essay_does_not_change.py index 576e432..ff7b90b 100644 --- a/app/test/test_add_word_and_essay_does_not_change.py +++ b/app/test/test_add_word_and_essay_does_not_change.py @@ -63,8 +63,9 @@ def test_add_word_and_essay_does_not_change(): driver.save_screenshot('./app/test/test_add_word_and_essay_does_not_change_pic1.png') elem = driver.find_element_by_id('text-content') current_essay_content = elem.text - - assert current_essay_content == essay_content + + index = current_essay_content.find('for you.') + assert current_essay_content[index:] == essay_content[index:] # click the Next button. Now the essay should change. elem = driver.find_element_by_xpath('//form[1]//input[1]') # 找到get所有词频按钮 @@ -75,6 +76,6 @@ def test_add_word_and_essay_does_not_change(): elem = driver.find_element_by_id('text-content') next_essay_content = elem.text - assert current_essay_content != next_essay_content + assert current_essay_content[index:] != next_essay_content[index:] finally: driver.quit() |