From 2f8dde4e4250f1b314e96d868e591eb22ee92f80 Mon Sep 17 00:00:00 2001 From: limengdie <2233601742@qq.com> Date: Mon, 22 Apr 2024 22:48:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E6=97=B6=E6=8F=90=E4=BA=A4=E4=B9=8B?= =?UTF-8?q?=E5=89=8D=E7=9A=84=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81,?= =?UTF-8?q?=E4=BD=86=E8=AF=A5=E4=BB=A3=E7=A0=81=E9=80=BB=E8=BE=91=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E7=BC=BA=E9=99=B7=EF=BC=8C=E5=BE=85=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Article.py | 13 +++- app/difficulty.py | 19 +++-- app/templates/userpage_get.html | 57 +++++++++++++++ app/test/test_bug476_LiMengdie.py | 114 ++++++++++++++++++++++++++++++ app/user_service.py | 42 +++++++++-- 5 files changed, 235 insertions(+), 10 deletions(-) create mode 100644 app/test/test_bug476_LiMengdie.py diff --git a/app/Article.py b/app/Article.py index 566ceb6..f19002e 100644 --- a/app/Article.py +++ b/app/Article.py @@ -1,3 +1,4 @@ + from WordFreq import WordFreq from wordfreqCMD import youdao_link, sort_in_descending_order import pickle_idea, pickle_idea2 @@ -10,6 +11,7 @@ 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 @@ -28,7 +30,8 @@ def get_article_body(s): return '\n'.join(lst) -def get_today_article(user_word_list, visited_articles): +#user_articlesWithoutNewWords_record 保存前端传来的用户阅读时长超过15秒且不含高亮生词的文章索引 +def get_today_article(user_word_list, visited_articles,user_articlesWithoutNewWords_record): if visited_articles is None: visited_articles = { "index" : 0, # 为 article_ids 的索引 @@ -57,7 +60,12 @@ def get_today_article(user_word_list, visited_articles): d_user = load_freq_history(user_word_list) logging.debug('* get_today_article(): user_difficulty_level() start') - user_level = user_difficulty_level(d_user, d3) # more consideration as user's behaviour is dynamic. Time factor should be considered. + + 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. logging.debug('* get_today_article(): done') text_level = 0 if visited_articles["index"] > len(visited_articles["article_ids"])-1: # 生成新的文章 @@ -90,6 +98,7 @@ def get_today_article(user_word_list, visited_articles): "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"], diff --git a/app/difficulty.py b/app/difficulty.py index 1bd8d68..b75db6b 100644 --- a/app/difficulty.py +++ b/app/difficulty.py @@ -7,6 +7,7 @@ import pickle import math + from wordfreqCMD import remove_punctuation, freq, sort_in_descending_order, sort_in_ascending_order import snowballstemmer @@ -94,10 +95,21 @@ def revert_dict(d): return d2 -def user_difficulty_level(d_user, d): +#articlesWithoutNewWords 存储用户阅读时长超过15秒且不含高亮生词的文章索引信息(用户阅读完后没有添加生词的文章) +def user_difficulty_level(d_user, d,articlesWithoutNewWords): 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= 10: - return geometric ** (1 / count) - - return geometric ** (1 / max(count, 1)) + return get_level_sum(geometric ** (1 / count)) + return get_level_sum(geometric ** (1 / max(count, 1))) def text_difficulty_level(s, d): s = remove_punctuation(s) diff --git a/app/templates/userpage_get.html b/app/templates/userpage_get.html index 8c684b6..4e25725 100644 --- a/app/templates/userpage_get.html +++ b/app/templates/userpage_get.html @@ -173,13 +173,33 @@ {% endfor %} {% endif %}