forked from mrlan/EnglishPal
Compare commits
1 Commits
master
...
Bug257-MaJ
Author | SHA1 | Date |
---|---|---|
majiabin | d72ab4fe3a |
|
@ -54,13 +54,55 @@ 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):
|
||||||
d = reading
|
list = session.get('articleIdList')
|
||||||
break
|
if list == None:
|
||||||
|
d = reading
|
||||||
|
list = [reading['article_id']]
|
||||||
|
session['articleIdList'] = list
|
||||||
|
p = True
|
||||||
|
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)
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -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:
|
||||||
|
|
Loading…
Reference in New Issue