Compare commits

..

1 Commits

Author SHA1 Message Date
majiabin d72ab4fe3a BugFix257 2022-06-01 16:08:55 +08:00
5 changed files with 52 additions and 14 deletions

View File

@ -54,14 +54,56 @@ def get_today_article(user_word_list, articleID):
d = random.choice(result) d = random.choice(result)
text_level = text_difficulty_level(d['text'], d3) text_level = text_difficulty_level(d['text'], d3)
if articleID == None: if articleID == None:
# print('result = ', len(result), sep=' ')
p = False
for reading in result: for reading in result:
text_level = text_difficulty_level(reading['text'], d3) text_level = text_difficulty_level(reading['text'], d3)
factor = random.gauss(0.8, factor = random.gauss(0.8, 0.1) # a number drawn from Gaussian distribution with a mean of 0.8 and a stand deviation of 1
0.1) # a number drawn from Gaussian distribution with a mean of 0.8 and a stand deviation of 1
if within_range(text_level, user_level, (8.0 - user_level) * factor): if within_range(text_level, user_level, (8.0 - user_level) * factor):
list = session.get('articleIdList')
if list == None:
d = reading d = reading
list = [reading['article_id']]
session['articleIdList'] = list
p = True
break break
exist = False
for i in list:
if reading['article_id'] == i:
exist = True
break
if exist == False:
d = reading
list.append(reading['article_id'])
session['articleIdList']=list
p = True
break
if p == False:
session['articleIdList'] = None
p = True
while p:
for reading in result:
text_level = text_difficulty_level(reading['text'], d3)
factor = random.gauss(0.8, 0.1) # a number drawn from Gaussian distribution with a mean of 0.8 and a stand deviation of 1
if within_range(text_level, user_level, (8.0 - user_level) * factor):
if reading['article_id'] != session['prearticleID']:
d = reading
p = False
'''
测试代码
print(session['articleIdList'])
print(session['prearticleID'], d['article_id'], sep=' ')
问题描述选择下一篇文章时由于没有考虑选择文章时会重复选择当前文章可能会导致重复进入某一篇文章
解决方法选择下一篇文章时将选择的文章ID和当前文章ID比较若重复则换一个
进一步优化
问题描述利用上述方法可以满足不重复进入某一篇文章但是可能两篇文章会反复出现
解决方法记录一个队列用来保存出现过的文章ID
选择文章时若文章Id出现在队列中则放弃
若都出现过则清空队列随机选择一个不与当前文章重复的文章
'''
s = '<div class="alert alert-success" role="alert">According to your word list, your level is <span class="badge bg-success">%4.2f</span> and we have chosen an article with a difficulty level of <span class="badge bg-success">%4.2f</span> for you.</div>' % ( s = '<div class="alert alert-success" role="alert">According to your word list, your level is <span class="badge bg-success">%4.2f</span> and we have chosen an article with a difficulty level of <span class="badge bg-success">%4.2f</span> for you.</div>' % (
user_level, text_level) user_level, text_level)
s += '<p class="text-muted">Article added on: %s</p>' % (d['date']) s += '<p class="text-muted">Article added on: %s</p>' % (d['date'])

View File

@ -5,10 +5,6 @@ from UseSqlite import InsertQuery, RecordQuery
path_prefix = '/var/www/wordfreq/wordfreq/' path_prefix = '/var/www/wordfreq/wordfreq/'
path_prefix = './' # comment this line in deployment path_prefix = './' # comment this line in deployment
def verify_pass(newpass,oldpass):
if(newpass==oldpass):
return True
def verify_user(username, password): def verify_user(username, password):
rq = RecordQuery(path_prefix + 'static/wordfreqapp.db') rq = RecordQuery(path_prefix + 'static/wordfreqapp.db')
@ -51,8 +47,6 @@ def change_password(username, old_password, new_password):
if not verify_user(username, old_password): # 旧密码错误 if not verify_user(username, old_password): # 旧密码错误
return False return False
# 将用户名和密码一起加密,以免暴露不同用户的相同密码 # 将用户名和密码一起加密,以免暴露不同用户的相同密码
if verify_pass(new_password,old_password): #新旧密码一致
return False
password = md5(username + new_password) password = md5(username + new_password)
rq = InsertQuery(path_prefix + 'static/wordfreqapp.db') rq = InsertQuery(path_prefix + 'static/wordfreqapp.db')
rq.instructions_with_parameters("UPDATE user SET password=:password WHERE name=:username", dict( rq.instructions_with_parameters("UPDATE user SET password=:password WHERE name=:username", dict(

View File

@ -36,6 +36,8 @@ def signup():
session['username'] = username session['username'] = username
session['expiry_date'] = get_expiry_date(username) session['expiry_date'] = get_expiry_date(username)
session['articleID'] = None session['articleID'] = None
session['articleIdList'] = None
session['prearticleID'] = None
return '<p>恭喜,你已成功注册, 你的用户名是 <a href="%s">%s</a>。</p>\ return '<p>恭喜,你已成功注册, 你的用户名是 <a href="%s">%s</a>。</p>\
<p><a href="/%s">开始使用</a> <a href="/">返回首页</a><p/>' % (username, username, username) <p><a href="/%s">开始使用</a> <a href="/">返回首页</a><p/>' % (username, username, username)
else: else:

View File

@ -29,10 +29,9 @@ function highLight() {
if (sel_word1 != null) { if (sel_word1 != null) {
var list = sel_word1.value.split(" "); var list = sel_word1.value.split(" ");
for (var i = 0; i < list.length; ++i) { for (var i = 0; i < list.length; ++i) {
list[i] = list[i].replace(/(^\s*)|(\s*$)/g, "");//消除字符串两边空字符 list[i] = list[i].replace(/(^\s*)|(\s*$)/g, "");
if (list[i] != "" && "<mark>".indexOf(list[i]) == -1 && "</mark>".indexOf(list[i]) == -1) { if (list[i] != "" && "<mark>".indexOf(list[i]) == -1 && "</mark>".indexOf(list[i]) == -1) {
txt = txt.replace(new RegExp(list[i], "g"), "<mark>" + list[i] + "</mark>");
txt = txt.replace(new RegExp("\\s"+list[i]+"\\s", "g"), " <mark>" + list[i] + "</mark> ");
} }
} }
} }
@ -41,7 +40,7 @@ function highLight() {
for (var i = 0; i < list2.length; ++i) { for (var i = 0; i < list2.length; ++i) {
list2[i] = list2[i].replace(/(^\s*)|(\s*$)/g, ""); list2[i] = list2[i].replace(/(^\s*)|(\s*$)/g, "");
if (list2[i] != "" && "<mark>".indexOf(list2[i]) == -1 && "</mark>".indexOf(list2[i]) == -1) { if (list2[i] != "" && "<mark>".indexOf(list2[i]) == -1 && "</mark>".indexOf(list2[i]) == -1) {
txt = txt.replace(new RegExp("\\s"+list2[i]+"\\s", "g"), " <mark>" + list2[i] + "</mark> "); txt = txt.replace(new RegExp(list2[i], "g"), "<mark>" + list2[i] + "</mark>");
} }
} }
} }

View File

@ -30,6 +30,7 @@ def user_reset(username):
:return: 返回页面内容 :return: 返回页面内容
''' '''
if request.method == 'GET': if request.method == 'GET':
session['prearticleID'] = session['articleID']
session['articleID'] = None session['articleID'] = None
return redirect(url_for('user_bp.userpage', username=username)) return redirect(url_for('user_bp.userpage', username=username))
else: else: