forked from mrlan/EnglishPal
修改变量命名:existing_articles → had_read_articles
parent
15bb925024
commit
16de0a7fd9
|
@ -32,17 +32,17 @@ def get_article_body(s):
|
|||
return '\n'.join(lst)
|
||||
|
||||
|
||||
def get_today_article(user_word_list, existing_articles):
|
||||
def get_today_article(user_word_list, had_read_articles):
|
||||
rq = RecordQuery(path_prefix + 'static/wordfreqapp.db')
|
||||
if existing_articles is None:
|
||||
existing_articles = {
|
||||
if had_read_articles is None:
|
||||
had_read_articles = {
|
||||
"index" : 0, # 为 article_ids 的索引
|
||||
"article_ids": [] # 之前显示文章的id列表,越后越新
|
||||
}
|
||||
if existing_articles["index"] > len(existing_articles["article_ids"])-1:
|
||||
if had_read_articles["index"] > len(had_read_articles["article_ids"])-1:
|
||||
rq.instructions("SELECT * FROM article")
|
||||
else:
|
||||
rq.instructions('SELECT * FROM article WHERE article_id=%d' % (existing_articles["article_ids"][existing_articles["index"]]))
|
||||
rq.instructions('SELECT * FROM article WHERE article_id=%d' % (had_read_articles["article_ids"][had_read_articles["index"]]))
|
||||
rq.do()
|
||||
result = rq.get_results()
|
||||
random.shuffle(result)
|
||||
|
@ -56,19 +56,19 @@ def get_today_article(user_word_list, existing_articles):
|
|||
d_user = load_freq_history(user_word_list)
|
||||
user_level = user_difficulty_level(d_user, d3) # more consideration as user's behaviour is dynamic. Time factor should be considered.
|
||||
text_level = 0
|
||||
if existing_articles["index"] > len(existing_articles["article_ids"])-1: # 下一篇
|
||||
if had_read_articles["index"] > len(had_read_articles["article_ids"])-1: # 下一篇
|
||||
flag_get_article = False
|
||||
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 reading['article_id'] not in existing_articles["article_ids"] and within_range(text_level, user_level, (8.0 - user_level) * factor): # 新的文章之前没有出现过且符合一定范围的水平
|
||||
if reading['article_id'] not in had_read_articles["article_ids"] and within_range(text_level, user_level, (8.0 - user_level) * factor): # 新的文章之前没有出现过且符合一定范围的水平
|
||||
d = reading
|
||||
existing_articles["article_ids"].append(d['article_id']) # 列表添加新的文章id;下面进行
|
||||
had_read_articles["article_ids"].append(d['article_id']) # 列表添加新的文章id;下面进行
|
||||
flag_get_article = True
|
||||
break
|
||||
if not flag_get_article:
|
||||
existing_articles["index"] -= 1
|
||||
had_read_articles["index"] -= 1
|
||||
else: # 上一篇
|
||||
d = random.choice(result)
|
||||
text_level = text_difficulty_level(d['text'], d3)
|
||||
|
@ -86,7 +86,7 @@ def get_today_article(user_word_list, existing_articles):
|
|||
"answer": get_answer_part(d['question'])
|
||||
}
|
||||
|
||||
return existing_articles, today_article
|
||||
return had_read_articles, today_article
|
||||
|
||||
|
||||
def load_freq_history(path):
|
||||
|
|
|
@ -37,7 +37,7 @@ def signup():
|
|||
session[username] = username
|
||||
session['username'] = username
|
||||
session['expiry_date'] = get_expiry_date(username)
|
||||
session['existing_articles'] = None
|
||||
session['had_read_articles'] = None
|
||||
return jsonify({'status': '2'})
|
||||
else:
|
||||
return jsonify({'status': '1'})
|
||||
|
@ -66,7 +66,7 @@ def login():
|
|||
session['username'] = username
|
||||
user_expiry_date = get_expiry_date(username)
|
||||
session['expiry_date'] = user_expiry_date
|
||||
session['existing_articles'] = None
|
||||
session['had_read_articles'] = None
|
||||
return jsonify({'status': '1'})
|
||||
else:
|
||||
return jsonify({'status': '0'})
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
{# {% endfor %}#}
|
||||
|
||||
<a class="btn btn-success" href="/{{ username }}/reset" role="button"> 下一篇 Next Article </a>
|
||||
{% if session.get('existing_articles') != None and session.get('existing_articles')["index"] !=0 %}
|
||||
{% if session.get('had_read_articles') != None and session.get('had_read_articles')["index"] !=0 %}
|
||||
<a class="btn btn-success" href="/{{ username }}/back" role="button"> 上一篇 Previous Article </a>
|
||||
{% endif %}
|
||||
|
||||
|
|
|
@ -30,9 +30,9 @@ def user_reset(username):
|
|||
:return: 返回页面内容
|
||||
'''
|
||||
if request.method == 'GET':
|
||||
existing_articles = session.get("existing_articles")
|
||||
existing_articles["index"] += 1
|
||||
session["existing_articles"] = existing_articles
|
||||
had_read_articles = session.get("had_read_articles")
|
||||
had_read_articles["index"] += 1
|
||||
session["had_read_articles"] = had_read_articles
|
||||
return redirect(url_for('user_bp.userpage', username=username))
|
||||
else:
|
||||
return 'Under construction'
|
||||
|
@ -45,9 +45,9 @@ def user_back(username):
|
|||
:return: 返回页面内容
|
||||
'''
|
||||
if request.method == 'GET':
|
||||
existing_articles = session.get("existing_articles")
|
||||
existing_articles["index"] -= 1
|
||||
session["existing_articles"] = existing_articles
|
||||
had_read_articles = session.get("had_read_articles")
|
||||
had_read_articles["index"] -= 1
|
||||
session["had_read_articles"] = had_read_articles
|
||||
return redirect(url_for('user_bp.userpage', username=username))
|
||||
|
||||
|
||||
|
@ -134,8 +134,8 @@ def userpage(username):
|
|||
words = ''
|
||||
for x in lst3:
|
||||
words += x[0] + ' '
|
||||
existing_articles, today_article = get_today_article(user_freq_record, session.get('existing_articles'))
|
||||
session['existing_articles'] = existing_articles
|
||||
had_read_articles, today_article = get_today_article(user_freq_record, session.get('had_read_articles'))
|
||||
session['had_read_articles'] = had_read_articles
|
||||
# 通过 today_article,加载前端的显示页面
|
||||
return render_template('userpage_get.html',
|
||||
username=username,
|
||||
|
|
Loading…
Reference in New Issue