From 16de0a7fd99a26d331e23eac7c1fd22594b7c50f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=B8=80=E9=97=AE=E4=B8=89=E4=B8=8D=E7=9F=A5?=
<178428409@qq.com>
Date: Thu, 20 Apr 2023 15:40:11 +0800
Subject: [PATCH] =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E5=8F=98=E9=87=8F?=
=?UTF-8?q?=E5=91=BD=E5=90=8D=EF=BC=9Aexisting=5Farticles=20=E2=86=92=20ha?=
=?UTF-8?q?d=5Fread=5Farticles?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Article.py | 20 ++++++++++----------
app/account_service.py | 4 ++--
app/templates/userpage_get.html | 2 +-
app/user_service.py | 16 ++++++++--------
4 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/app/Article.py b/app/Article.py
index e0f006a..b4df54c 100644
--- a/app/Article.py
+++ b/app/Article.py
@@ -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):
diff --git a/app/account_service.py b/app/account_service.py
index c1bd64c..8de9a03 100644
--- a/app/account_service.py
+++ b/app/account_service.py
@@ -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'})
diff --git a/app/templates/userpage_get.html b/app/templates/userpage_get.html
index 298b559..428bb3b 100644
--- a/app/templates/userpage_get.html
+++ b/app/templates/userpage_get.html
@@ -45,7 +45,7 @@
{# {% endfor %}#}
下一篇 Next Article
- {% 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 %}
上一篇 Previous Article
{% endif %}
diff --git a/app/user_service.py b/app/user_service.py
index 8d1dbfc..61b129d 100644
--- a/app/user_service.py
+++ b/app/user_service.py
@@ -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,