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 %}