forked from mrlan/EnglishPal
Compare commits
23 Commits
Bug476-LiM
...
Bug546-Lix
Author | SHA1 | Date |
---|---|---|
|
e3db7c30b0 | |
|
9f03cc49fa | |
|
eed852cd66 | |
|
c6f8a3448d | |
|
d8af2a7e54 | |
|
a0c9b82ee7 | |
|
4a42c5c22c | |
|
101c359596 | |
|
64a82bee22 | |
|
9537024339 | |
|
85a3a9ce6a | |
|
f3b9fd8790 | |
|
624426b6cf | |
|
d1589f6062 | |
|
fcd2c83904 | |
|
29a673cd92 | |
|
1bec0bd107 | |
|
630cb6befa | |
|
5dbdf60a2c | |
|
101506a511 | |
|
9b3551bbc8 | |
|
90ac789bb4 | |
|
8575a0dc33 |
|
@ -1,4 +1,3 @@
|
|||
|
||||
from WordFreq import WordFreq
|
||||
from wordfreqCMD import youdao_link, sort_in_descending_order
|
||||
import pickle_idea, pickle_idea2
|
||||
|
@ -11,7 +10,6 @@ from difficulty import get_difficulty_level_for_user, text_difficulty_level, use
|
|||
from model.article import get_all_articles, get_article_by_id, get_number_of_articles
|
||||
import logging
|
||||
|
||||
|
||||
path_prefix = './'
|
||||
db_path_prefix = './db/' # comment this line in deployment
|
||||
|
||||
|
@ -30,8 +28,7 @@ def get_article_body(s):
|
|||
return '\n'.join(lst)
|
||||
|
||||
|
||||
#user_articlesWithoutNewWords_record 保存前端传来的用户阅读时长超过15秒且不含高亮生词的文章索引
|
||||
def get_today_article(user_word_list, visited_articles,user_articlesWithoutNewWords_record):
|
||||
def get_today_article(user_word_list, visited_articles):
|
||||
if visited_articles is None:
|
||||
visited_articles = {
|
||||
"index" : 0, # 为 article_ids 的索引
|
||||
|
@ -60,12 +57,7 @@ def get_today_article(user_word_list, visited_articles,user_articlesWithoutNewWo
|
|||
|
||||
d_user = load_freq_history(user_word_list)
|
||||
logging.debug('* get_today_article(): user_difficulty_level() start')
|
||||
|
||||
articles_id_list=None
|
||||
if os.path.exists(user_articlesWithoutNewWords_record) != False:
|
||||
articles_id_list = pickle_idea.load_record(user_articlesWithoutNewWords_record)
|
||||
#将 用户阅读时长超过15秒且不含高亮生词的文章记录 传入user_difficulty_level并据此 提高用户level
|
||||
user_level = user_difficulty_level(d_user, d3,articles_id_list) # more consideration as user's behaviour is dynamic. Time factor should be considered.
|
||||
user_level = user_difficulty_level(d_user, d3) # more consideration as user's behaviour is dynamic. Time factor should be considered.
|
||||
logging.debug('* get_today_article(): done')
|
||||
text_level = 0
|
||||
if visited_articles["index"] > len(visited_articles["article_ids"])-1: # 生成新的文章
|
||||
|
@ -98,7 +90,6 @@ def get_today_article(user_word_list, visited_articles,user_articlesWithoutNewWo
|
|||
"user_level": '%4.1f' % user_level,
|
||||
"text_level": '%4.1f' % text_level,
|
||||
"date": d['date'],
|
||||
"article_id":d['article_id'],#该变量存储 用户阅读时长超过15秒且不含高亮生词的文章索引
|
||||
"article_title": get_article_title(d['text']),
|
||||
"article_body": get_article_body(d['text']),
|
||||
"source": d["source"],
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
import pickle
|
||||
import math
|
||||
|
||||
from wordfreqCMD import remove_punctuation, freq, sort_in_descending_order, sort_in_ascending_order
|
||||
import snowballstemmer
|
||||
|
||||
|
@ -95,21 +94,10 @@ def revert_dict(d):
|
|||
return d2
|
||||
|
||||
|
||||
#articlesWithoutNewWords 存储用户阅读时长超过15秒且不含高亮生词的文章索引信息(用户阅读完后没有添加生词的文章)
|
||||
def user_difficulty_level(d_user, d,articlesWithoutNewWords):
|
||||
def user_difficulty_level(d_user, d):
|
||||
d_user2 = revert_dict(d_user) # key is date, and value is a list of words added in that date
|
||||
count = 0
|
||||
geometric = 1
|
||||
#传入根据用户生词计算出的用户level
|
||||
def get_level_sum(level):
|
||||
if articlesWithoutNewWords!=None:#若用户阅读完后没有添加生词的文章索引不为空,则根据这些文章的等级适度提高用户的level
|
||||
for article in articlesWithoutNewWords:
|
||||
if(level<float(article.get('text_level'))):
|
||||
level+=(float(article.get('text_level'))-level)/20 #根据文章等级提高用户level,用户level与用户阅读完后没有添加生词的文章level 差距越大,分数提高程度越大
|
||||
print(f"用户等级{level}")
|
||||
print("-----------------------------------")
|
||||
return level
|
||||
|
||||
for date in sorted(d_user2.keys(),
|
||||
reverse=True): # most recently added words are more important while determining user's level
|
||||
lst = d_user2[date] # a list of words
|
||||
|
@ -127,9 +115,10 @@ def user_difficulty_level(d_user, d,articlesWithoutNewWords):
|
|||
geometric = geometric * (hard)
|
||||
count += 1
|
||||
if count >= 10:
|
||||
return get_level_sum(geometric ** (1 / count))
|
||||
return geometric ** (1 / count)
|
||||
|
||||
return geometric ** (1 / max(count, 1))
|
||||
|
||||
return get_level_sum(geometric ** (1 / max(count, 1)))
|
||||
|
||||
def text_difficulty_level(s, d):
|
||||
s = remove_punctuation(s)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
// initialize from localStorage
|
||||
let isRead = localStorage.getItem('readChecked') !== 'false'; // default to true
|
||||
let isChoose = localStorage.getItem('chooseChecked') !== 'false';
|
||||
|
||||
|
@ -9,8 +8,15 @@ function getWord() {
|
|||
function fillInWord() {
|
||||
let word = getWord();
|
||||
if (isRead) Reader.read(word, inputSlider.value);
|
||||
if (!isChoose) return;
|
||||
if (!isChoose) {
|
||||
if(isHighlight){
|
||||
const element = document.getElementById("selected-words3");
|
||||
element.value = element.value + " " + word;
|
||||
}
|
||||
return;
|
||||
}
|
||||
const element = document.getElementById("selected-words");
|
||||
localStorage.setItem('nowWords', element.value);
|
||||
element.value = element.value + " " + word;
|
||||
localStorage.setItem('selectedWords', element.value);
|
||||
}
|
||||
|
@ -38,3 +44,4 @@ function onChooseClick() {
|
|||
if (performance.getEntriesByType("navigation")[0].type == "reload") {
|
||||
Reader.stopRead();
|
||||
}
|
||||
|
||||
|
|
|
@ -22,39 +22,48 @@ function getWord() {
|
|||
|
||||
function highLight() {
|
||||
if (!isHighlight) return;
|
||||
let word = (getWord() + "").trim();
|
||||
let articleContent = document.getElementById("article").innerHTML; // innerHTML保留HTML标签来保持部分格式,且适配不同的浏览器
|
||||
let pickedWords = document.getElementById("selected-words"); // words picked to the text area
|
||||
let dictionaryWords = document.getElementById("selected-words2"); // words appearing in the user's new words list
|
||||
let allWords = dictionaryWords === null ? pickedWords.value + " " : pickedWords.value + " " + dictionaryWords.value;
|
||||
highlightWords = document.getElementById("selected-words3");
|
||||
allWords = highlightWords == null ? allWords : allWords + " " + highlightWords.value;
|
||||
const list = allWords.split(" "); // 将所有的生词放入一个list中
|
||||
if(word !== null && word !== "" && word !== " "){
|
||||
let articleContent_fb2 = articleContent;
|
||||
if(localStorage.getItem("nowWords").indexOf(word) !== -1 || localStorage.getItem("nowWords").indexOf(word.toLowerCase()) !== -1){
|
||||
articleContent = articleContent.replace(new RegExp('<span class="highlighted">' + word + '</span>', "gi"), word);
|
||||
pickedWords.value = localStorage.getItem("nowWords").replace(word,"");
|
||||
document.getElementById("article").innerHTML = articleContent;
|
||||
return;
|
||||
}
|
||||
}
|
||||
let totalSet = new Set();
|
||||
for (let i = 0; i < list.length; ++i) {
|
||||
list[i] = list[i].replace(/(^\W*)|(\W*$)/g, ""); // 消除单词两边的非单词字符
|
||||
list[i] = list[i].replace('|', "");
|
||||
list[i] = list[i].replace('?', "");
|
||||
if (list[i] != "" && !totalSet.has(list[i])) {
|
||||
// 返回所有匹配单词的集合, 正则表达式RegExp()中, "\b"匹配一个单词的边界, g 表示全局匹配, i 表示对大小写不敏感。
|
||||
let matches = new Set(articleContent.match(new RegExp("\\b" + list[i] + "\\b", "gi")));
|
||||
if (matches.has("mark")) {
|
||||
// 优先处理单词为 "mark" 的情况
|
||||
totalSet = new Set(["mark", ...totalSet]);
|
||||
}
|
||||
totalSet = new Set([...totalSet, ...matches]);
|
||||
}
|
||||
}
|
||||
// 删除所有的mark标签,防止标签发生嵌套
|
||||
articleContent = articleContent.replace(/<(mark)[^>]*>/gi, "");
|
||||
articleContent = articleContent.replace(/<(\/mark)[^>]*>/gi, "");
|
||||
// 删除所有的"<span class='highlighted'>"标签,防止标签发生嵌套
|
||||
articleContent = articleContent.replace(new RegExp('<span class="highlighted">',"gi"), "")
|
||||
articleContent = articleContent.replace(new RegExp("</span>","gi"), "");
|
||||
// 将文章中所有出现该单词word的地方改为:"<span class='highlighted'>" + word + "</span>"。
|
||||
for (let word of totalSet) {
|
||||
articleContent = articleContent.replace(new RegExp("\\b" + word + "\\b", "g"), "<span class='highlighted'>" + word + "</span>");
|
||||
}
|
||||
document.getElementById("article").innerHTML = articleContent;
|
||||
|
||||
}
|
||||
|
||||
function cancelHighlighting() {
|
||||
let articleContent = document.getElementById("article").innerHTML;
|
||||
articleContent = articleContent.replace(/<(mark)[^>]*>/gi, "");
|
||||
articleContent = articleContent.replace(/<(\/mark)[^>]*>/gi, "");
|
||||
articleContent = articleContent.replace(new RegExp('<span class="highlighted">',"gi"), "")
|
||||
articleContent = articleContent.replace(new RegExp("</span>","gi"), "");
|
||||
document.getElementById("article").innerHTML = articleContent;
|
||||
}
|
||||
|
||||
|
|
|
@ -166,6 +166,7 @@
|
|||
<input id="selected-words2" type="hidden" value="{{ words }}">
|
||||
{% endif %}
|
||||
</div>
|
||||
<label id="selected-words3" type="hidden"></label>
|
||||
{{ yml['footer'] | safe }}
|
||||
{% if yml['js']['bottom'] %}
|
||||
{% for js in yml['js']['bottom'] %}
|
||||
|
@ -214,12 +215,6 @@
|
|||
elements.rangeValueDisplay.textContent = `${rangeValue}x`;
|
||||
localStorage.setItem('rangeValue', rangeValue);
|
||||
});
|
||||
|
||||
startTime=Date.now();//记录用户页面的初始时间
|
||||
if(window.performance.navigation.type!=1){//将第一次加载页面时的文章id,level保存到本地
|
||||
sessionStorage.setItem('article_id','{{today_article['article_id']}}');
|
||||
sessionStorage.setItem('text_level','{{today_article['text_level']}}');
|
||||
}
|
||||
};
|
||||
|
||||
function clearSelectedWords() {
|
||||
|
@ -229,18 +224,6 @@
|
|||
|
||||
|
||||
function load_next_article(){
|
||||
//在进入下一篇之前处理
|
||||
endTime=Date.now();//记录用户点击下一篇文章时的时间
|
||||
spendtime=endTime-startTime;//计算出用户浏览该页面的时长,单位毫秒
|
||||
if(spendtime/1000>15){//若浏览时长大于15,说明用户认真阅读了该篇文章(时长小于15代表用户不感兴趣,跳过,不做任何处理)
|
||||
if(!checkMarkedWords()){//检查该篇文章是否有生词高亮,若没有将文章id,level发送到后台,保存至文件中,在计算用户level时根据文件中保存的文章等级计算
|
||||
$.ajax({
|
||||
url: '/submit_article_id_without_new_words/{{username}}/'+sessionStorage.getItem('article_id')+'/'+sessionStorage.getItem('text_level'),
|
||||
dataType: 'json',
|
||||
success: function(data) {}
|
||||
});
|
||||
}
|
||||
}
|
||||
$.ajax({
|
||||
url: '/get_next_article/{{username}}',
|
||||
dataType: 'json',
|
||||
|
@ -253,21 +236,8 @@
|
|||
}
|
||||
}
|
||||
});
|
||||
startTime=Date.now();//在页面加载完下一篇文章,记录起始时间
|
||||
}
|
||||
function load_pre_article(){
|
||||
//在进入上一篇之前处理
|
||||
endTime=Date.now();//记录用户点击上一篇文章时的时间
|
||||
spendtime=endTime-startTime;//计算出用户浏览该文章的时长,单位毫秒
|
||||
if(spendtime/1000>15){
|
||||
if(!checkMarkedWords()){
|
||||
$.ajax({
|
||||
url: '/submit_article_id_without_new_words/{{username}}/'+sessionStorage.getItem('article_id')+'/'+sessionStorage.getItem('text_level'),
|
||||
dataType: 'json',
|
||||
success: function(data) {}
|
||||
});
|
||||
}
|
||||
}
|
||||
$.ajax({
|
||||
url: '/get_pre_article/{{username}}',
|
||||
dataType: 'json',
|
||||
|
@ -279,7 +249,6 @@
|
|||
}
|
||||
}
|
||||
});
|
||||
startTime=Date.now();//在页面加载完下一篇文章,记录起始时间
|
||||
}
|
||||
function update(today_article){
|
||||
$('#user_level').html(today_article['user_level']);
|
||||
|
@ -294,27 +263,6 @@
|
|||
setTimeout(() => {document.querySelector('#text_level').classList.remove('mark');}, 2000);
|
||||
document.querySelector('#user_level').classList.add('mark'); // do the same thing for user difficulty level
|
||||
setTimeout(() => {document.querySelector('#user_level').classList.remove('mark');}, 2000);
|
||||
|
||||
sessionStorage.setItem('article_id',today_article["article_id"]);//将更新后的文章id,level保存到本地
|
||||
sessionStorage.setItem('text_level',today_article['text_level']);
|
||||
}
|
||||
function checkMarkedWords(){//检查文章中是否有高亮生词
|
||||
let article_title= document.getElementById("article_title").innerHTML;//从页面中获取文章名和内容
|
||||
let article_body=document.getElementById("article").innerHTML;
|
||||
let article=article_title+" "+article_body;
|
||||
let pickedWords = document.getElementById("selected-words"); // words picked to the text area
|
||||
let dictionaryWords = document.getElementById("selected-words2"); // words appearing in the user's new words list
|
||||
let allWords = dictionaryWords === null ? pickedWords.value + " " : pickedWords.value + " " + dictionaryWords.value;
|
||||
const list = allWords.split(" "); // 将所有的生词放入一个list中
|
||||
for (let i = 0; i < list.length; ++i) {
|
||||
list[i] = list[i].replace(/(^\W*)|(\W*$)/g, "");
|
||||
}
|
||||
for (let i=1;i<list.length-1;i++){//对list中的每个生词进行查找,判断文章中是否有该生词
|
||||
if(article.search(list[i])!==-1){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
<!-- 检查是否存在上一篇或下一篇,不存在则对应按钮隐藏-->
|
||||
function check_pre(visited_articles){
|
||||
|
@ -344,7 +292,7 @@
|
|||
</body>
|
||||
<style>
|
||||
mark {
|
||||
color: #{{ yml['highlight']['color'] }};
|
||||
color: red;
|
||||
background-color: rgba(0, 0, 0, 0);
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -1,119 +0,0 @@
|
|||
import time
|
||||
|
||||
import pytest
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.common.exceptions import UnexpectedAlertPresentException, NoAlertPresentException, \
|
||||
ElementClickInterceptedException, NoSuchElementException, TimeoutException
|
||||
from helper import signup
|
||||
|
||||
|
||||
def is_textarea_empty(driver):
|
||||
# 获取<textarea>元素的内容,判断是否加入了生词
|
||||
textarea_element = driver.find_element(By.ID, 'selected-words')
|
||||
content = textarea_element.get_attribute("value")
|
||||
|
||||
return content is None or content.strip() == ""
|
||||
|
||||
|
||||
def get_user_level(driver):
|
||||
return float(driver.find_element(By.ID, 'user_level').text)
|
||||
|
||||
|
||||
def scroll(total_time, driver):
|
||||
try:
|
||||
half_time = (total_time - 2) / 2 # 分成两半,一半时间滚到底,一半时间滚回顶,模拟阅读时间
|
||||
|
||||
# 滚动到底部
|
||||
start_time = time.time()
|
||||
end_time = start_time + half_time
|
||||
while time.time() < end_time:
|
||||
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
|
||||
# 确保滚动更平滑
|
||||
time.sleep(1)
|
||||
|
||||
# 滚动回顶部
|
||||
start_time = time.time()
|
||||
end_time = start_time + half_time
|
||||
while time.time() < end_time:
|
||||
driver.execute_script("window.scrollTo(0, -document.body.scrollHeight);")
|
||||
time.sleep(1)
|
||||
|
||||
except ElementClickInterceptedException:
|
||||
print("加载出错")
|
||||
|
||||
|
||||
def read_test_with_time(driver, total_time):
|
||||
# 获取点击前的user_level和text_level
|
||||
before_user_level = get_user_level(driver)
|
||||
before_text_level = float(driver.find_element(By.ID, 'text_level').text)
|
||||
|
||||
# 检查是否加入了生词簿
|
||||
check = is_textarea_empty(driver)
|
||||
|
||||
scroll(total_time, driver)
|
||||
# 定位“下一页”按钮
|
||||
next_button = driver.find_element(By.ID, 'load_next_article')
|
||||
# 模拟点击
|
||||
next_button.click()
|
||||
|
||||
# 关闭弹窗
|
||||
try:
|
||||
WebDriverWait(driver, 1).until(EC.alert_is_present())
|
||||
driver.switch_to.alert.accept()
|
||||
except (UnexpectedAlertPresentException, NoAlertPresentException):
|
||||
pass
|
||||
|
||||
# 等待页面加载完毕,正确地获取更新后的值
|
||||
time.sleep(2)
|
||||
|
||||
# 获取点击后的user_level
|
||||
after_user_level = get_user_level(driver)
|
||||
|
||||
# 等待3秒方便观察测试
|
||||
time.sleep(3)
|
||||
|
||||
return before_user_level, after_user_level, before_text_level, check
|
||||
|
||||
|
||||
def test_score_with_enough_time(driver, URL):
|
||||
try:
|
||||
# 登录并跳转到测试主页面
|
||||
signup(URL, driver)
|
||||
# 测试阅读到足够时间的等级变化
|
||||
before_user_level, after_user_level, before_text_level, check = read_test_with_time(driver, 18)
|
||||
|
||||
# print(check, before_user_level, after_user_level, before_text_level)
|
||||
|
||||
if before_user_level < before_text_level and check:
|
||||
assert before_user_level < after_user_level, 'The user level dose not increase after reading an article with a high level and clicking to navigate away without adding any new vocabulary. '
|
||||
|
||||
|
||||
except (NoSuchElementException, TimeoutException) as e:
|
||||
print("Error occurs: " + str(e))
|
||||
|
||||
finally:
|
||||
driver.quit()
|
||||
|
||||
|
||||
def test_score_without_enough_time(driver, URL):
|
||||
try:
|
||||
# 登录并跳转到测试主页面
|
||||
signup(URL, driver)
|
||||
# 测试阅读时间不足够的等级变化
|
||||
before_user_level, after_user_level, before_text_level, check = read_test_with_time(driver, 6)
|
||||
|
||||
# print(check, before_user_level, after_user_level, before_text_level)
|
||||
|
||||
if before_user_level < before_text_level and check:
|
||||
assert before_user_level == after_user_level, 'After the user quickly skipped through the article, the user level does not remain unchanged. '
|
||||
|
||||
except (NoSuchElementException, TimeoutException) as e:
|
||||
print("Error occurs: " + str(e))
|
||||
|
||||
finally:
|
||||
driver.quit()
|
||||
|
||||
if __name__ == '__main__':
|
||||
pytest.main(["--html=report.html"])
|
|
@ -1,5 +1,7 @@
|
|||
import random
|
||||
import string
|
||||
import time
|
||||
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
import random
|
||||
import string
|
||||
import time
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.webdriver.common.action_chains import ActionChains
|
||||
|
||||
from helper import signup
|
||||
|
||||
def has_punctuation(s):
|
||||
return any(c in string.punctuation for c in s)
|
||||
|
||||
def select_one(driver):
|
||||
elem = driver.find_element(By.ID, 'article')
|
||||
essay_content = elem.text
|
||||
valid_word = random.choice([word for word in essay_content.split() if len(word) >= 6 and not has_punctuation(
|
||||
word) and 'font>' not in word and 'br>' not in word and 'p>' not in word])
|
||||
driver.find_element(By.ID, 'selected-words').send_keys(valid_word)
|
||||
driver.find_element(By.ID, 'article').click()
|
||||
return valid_word
|
||||
|
||||
def select_two(driver):
|
||||
word = driver.find_element(By.CLASS_NAME, 'highlighted')
|
||||
|
||||
# 创建ActionChains对象
|
||||
actions = ActionChains(driver)
|
||||
actions.move_to_element(word)
|
||||
|
||||
# 模拟鼠标按下并拖动以选择文本
|
||||
actions.double_click()
|
||||
actions.perform()
|
||||
|
||||
|
||||
def test_selected_second_word(driver, URL):
|
||||
try:
|
||||
signup(URL, driver)
|
||||
selected_words = select_one(driver);
|
||||
assert selected_words.strip() != "", "选中的单词被放置框中"
|
||||
select_two(driver)
|
||||
selected_second_words = driver.find_element(By.ID, 'selected-words').get_attribute('value')
|
||||
assert selected_second_words.strip() == "", "选中的单词被删除"
|
||||
finally:
|
||||
driver.quit()
|
|
@ -0,0 +1,39 @@
|
|||
from selenium.webdriver.common.action_chains import ActionChains
|
||||
from helper import signup
|
||||
|
||||
|
||||
def test_highlight(driver, URL):
|
||||
try:
|
||||
# 打开网页
|
||||
driver.get(URL)
|
||||
driver.maximize_window()
|
||||
|
||||
# 注册
|
||||
signup(URL, driver)
|
||||
|
||||
# 取消勾选“划词入库按钮”
|
||||
highlight_checkbox = driver.find_element_by_id("chooseCheckbox")
|
||||
driver.execute_script("arguments[0].click();", highlight_checkbox)
|
||||
|
||||
article = driver.find_element_by_id("article")
|
||||
|
||||
# 创建 ActionChains 对象
|
||||
actions = ActionChains(driver)
|
||||
|
||||
# 移动鼠标到起点位置
|
||||
actions.move_to_element(article)
|
||||
# actions.move_to_element_with_offset(article, 50, 100)
|
||||
# 按下鼠标左键
|
||||
actions.click_and_hold()
|
||||
# 拖动鼠标到结束位置
|
||||
actions.move_by_offset(400,50)
|
||||
# 释放鼠标左键
|
||||
actions.release()
|
||||
# 执行操作链
|
||||
actions.perform()
|
||||
# time.sleep(10)
|
||||
|
||||
assert driver.find_elements_by_class_name("highlighted") is not None
|
||||
finally:
|
||||
# 测试结束后关闭浏览器
|
||||
driver.quit()
|
|
@ -1,5 +1,3 @@
|
|||
import pickle
|
||||
import os.path
|
||||
from datetime import datetime
|
||||
from admin_service import ADMIN_NAME
|
||||
from flask import *
|
||||
|
@ -28,8 +26,6 @@ path_prefix = './' # comment this line in deployment
|
|||
|
||||
@userService.route("/get_next_article/<username>",methods=['GET','POST'])
|
||||
def get_next_article(username):
|
||||
user_articlesWithoutNewWords_record = path_prefix + 'static/frequency/' + 'ArticlesWithoutNewWords_%s.pickle' % (username)
|
||||
|
||||
user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (username)
|
||||
session['old_articleID'] = session.get('articleID')
|
||||
if request.method == 'GET':
|
||||
|
@ -40,7 +36,7 @@ def get_next_article(username):
|
|||
visited_articles["index"] += 1
|
||||
session["visited_articles"] = visited_articles
|
||||
logging.debug('/get_next_article: start calling get_today_arcile()')
|
||||
visited_articles, today_article, result_of_generate_article = get_today_article(user_freq_record, session.get('visited_articles'),user_articlesWithoutNewWords_record)
|
||||
visited_articles, today_article, result_of_generate_article = get_today_article(user_freq_record, session.get('visited_articles'))
|
||||
logging.debug('/get_next_arcile: done.')
|
||||
data = {
|
||||
'visited_articles': visited_articles,
|
||||
|
@ -51,37 +47,8 @@ def get_next_article(username):
|
|||
return 'Under construction'
|
||||
return json.dumps(data)
|
||||
|
||||
#保存前端传来 用户阅读时长超过15秒且不含高亮生词的文章(用户阅读完后没有添加生词的文章)的id,level
|
||||
@userService.route("/submit_article_id_without_new_words/<username>/<article_id>/<text_level>",methods=['GET'])
|
||||
def set_article_id_without_new_words(username,article_id,text_level):
|
||||
user_articles_without_new_words_record_path = path_prefix + 'static/frequency/' + 'ArticlesWithoutNewWords_%s.pickle' % (username)
|
||||
if os.path.exists(user_articles_without_new_words_record_path)==False: #若不存在 存储用户阅读时长超过15秒且不含高亮生词的文章索引信息的文件 则新建
|
||||
f = open(user_articles_without_new_words_record_path, 'wb')
|
||||
list=[]
|
||||
pickle.dump(list,f)
|
||||
f.close()
|
||||
|
||||
fp=open(user_articles_without_new_words_record_path,'rb')
|
||||
user_article_id_record=pickle.load(fp)
|
||||
fp.close()
|
||||
|
||||
dic = {}
|
||||
dic['article_id'] = article_id
|
||||
dic['text_level'] = text_level
|
||||
|
||||
if dic not in user_article_id_record: #若已存在记录(即这篇文章之前被阅读过且没有添加生词,且已加入索引信息记录文件中),则不再重复加入,避免重复刷分
|
||||
user_article_id_record.append(dic)
|
||||
print(f"编号为{article_id}的文章,阅读时间大于15秒且未有生词,记录于ArticlesWithoutNewWords_<username>.pickle")
|
||||
print(user_article_id_record)
|
||||
f=open(user_articles_without_new_words_record_path,'wb')
|
||||
pickle.dump(user_article_id_record,f)
|
||||
f.close()
|
||||
return "success"
|
||||
|
||||
@userService.route("/get_pre_article/<username>",methods=['GET'])
|
||||
def get_pre_article(username):
|
||||
user_articlesWithoutNewWords_record = path_prefix + 'static/frequency/' + 'ArticlesWithoutNewWords_%s.pickle' % (
|
||||
username)
|
||||
user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (username)
|
||||
if request.method == 'GET':
|
||||
visited_articles = session.get("visited_articles")
|
||||
|
@ -92,7 +59,7 @@ def get_pre_article(username):
|
|||
if visited_articles['article_ids'][-1] == "null": # 如果当前还是“null”,则将“null”pop出来
|
||||
visited_articles['article_ids'].pop()
|
||||
session["visited_articles"] = visited_articles
|
||||
visited_articles, today_article, result_of_generate_article = get_today_article(user_freq_record, session.get('visited_articles'),user_articlesWithoutNewWords_record)
|
||||
visited_articles, today_article, result_of_generate_article = get_today_article(user_freq_record, session.get('visited_articles'))
|
||||
data = {
|
||||
'visited_articles': visited_articles,
|
||||
'today_article': today_article,
|
||||
|
@ -163,8 +130,7 @@ def userpage(username):
|
|||
|
||||
# 获取session里的用户名
|
||||
username = session.get('username')
|
||||
user_articlesWithoutNewWords_record = path_prefix + 'static/frequency/' + 'ArticlesWithoutNewWords_%s.pickle' % (
|
||||
username)
|
||||
|
||||
user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (username)
|
||||
|
||||
if request.method == 'POST': # when we submit a form
|
||||
|
@ -183,7 +149,7 @@ def userpage(username):
|
|||
words = ''
|
||||
for x in lst3:
|
||||
words += x[0] + ' '
|
||||
visited_articles, today_article, result_of_generate_article = get_today_article(user_freq_record, session.get('visited_articles'),user_articlesWithoutNewWords_record)
|
||||
visited_articles, today_article, result_of_generate_article = get_today_article(user_freq_record, session.get('visited_articles'))
|
||||
session['visited_articles'] = visited_articles
|
||||
# 通过 today_article,加载前端的显示页面
|
||||
return render_template('userpage_get.html',
|
||||
|
|
Loading…
Reference in New Issue