diff --git a/app/Article.py b/app/Article.py index 774d25a..b847837 100644 --- a/app/Article.py +++ b/app/Article.py @@ -32,36 +32,40 @@ def get_article_body(s): return '\n'.join(lst) -def get_today_article(user_word_list, articleID): +def get_today_article(user_word_list): rq = RecordQuery(path_prefix + 'static/wordfreqapp.db') - if articleID == None: - rq.instructions("SELECT * FROM article") - else: - rq.instructions('SELECT * FROM article WHERE article_id=%d' % (articleID)) - rq.do() - result = rq.get_results() - random.shuffle(result) + articleID = session['articleID'] # Choose article according to reader's level d1 = load_freq_history(path_prefix + 'static/frequency/frequency.p') d2 = load_freq_history(path_prefix + 'static/words_and_tests.p') d3 = get_difficulty_level(d1, d2) - - d = {} 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. - random.shuffle(result) # shuffle list - d = random.choice(result) - text_level = text_difficulty_level(d['text'], d3) - if articleID == None: - 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): - d = reading - break + # more consideration as user's behaviour is dynamic. Time factor should be considered. + user_level = user_difficulty_level(d_user, d3) + if articleID == None: + if not session['article_id_lst']: + rq.instructions("SELECT * FROM article") + rq.do() + result = rq.get_results() + random.shuffle(result) + + lst = [] + for reading in result: + text_level = text_difficulty_level(reading['text'], d3) + # a number drawn from Gaussian distribution with a mean of 0.8 and a stand deviation of 1 + factor = random.gauss(0.8,0.1) + if within_range(text_level, user_level, (8.0 - user_level) * factor): + lst.append(reading['article_id']) + session['article_id_lst'] = lst + articleID = session['article_id_lst'].pop(0) + + rq.instructions('SELECT * FROM article WHERE article_id=%d' % (articleID)) + rq.do() + result = rq.get_results() + d = result[0] + text_level = text_difficulty_level(d['text'], d3) s = '' % ( user_level, text_level) s += '

Article added on: %s

' % (d['date']) diff --git a/app/main.py b/app/main.py index d903bf4..74e9e13 100644 --- a/app/main.py +++ b/app/main.py @@ -92,6 +92,7 @@ def mainpage(): return render_template('mainpage_post.html', lst=lst, yml=Yaml.yml) elif request.method == 'GET': # when we load a html page + session['article_id_lst'] = None random_ads = get_random_ads() number_of_essays = total_number_of_essays() d = load_freq_history(path_prefix + 'static/frequency/frequency.p') diff --git a/app/templates/userpage_get.html b/app/templates/userpage_get.html index 19542c1..0dde12f 100644 --- a/app/templates/userpage_get.html +++ b/app/templates/userpage_get.html @@ -69,10 +69,9 @@ ( {{ freq }} ) - - 熟悉 - 不熟悉 - 删除 + 熟悉 + 不熟悉 + 删除

{% else %}

@@ -81,9 +80,9 @@ ( {{ freq }} ) - 熟悉 - 不熟悉 - 删除 + 熟悉 + 不熟悉 + 删除

{% endif %} {% else %} @@ -98,6 +97,49 @@ {% endfor %} {% endif %} + + +