forked from mrlan/EnglishPal
[BUGFIX] Article.py: modified get_today_article to fix bug 209
parent
3d6a61c113
commit
3ccaad00f2
|
@ -32,36 +32,40 @@ def get_article_body(s):
|
||||||
return '\n'.join(lst)
|
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')
|
rq = RecordQuery(path_prefix + 'static/wordfreqapp.db')
|
||||||
if articleID == None:
|
articleID = session['articleID']
|
||||||
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)
|
|
||||||
|
|
||||||
# Choose article according to reader's level
|
# Choose article according to reader's level
|
||||||
d1 = load_freq_history(path_prefix + 'static/frequency/frequency.p')
|
d1 = load_freq_history(path_prefix + 'static/frequency/frequency.p')
|
||||||
d2 = load_freq_history(path_prefix + 'static/words_and_tests.p')
|
d2 = load_freq_history(path_prefix + 'static/words_and_tests.p')
|
||||||
d3 = get_difficulty_level(d1, d2)
|
d3 = get_difficulty_level(d1, d2)
|
||||||
|
|
||||||
d = {}
|
|
||||||
d_user = load_freq_history(user_word_list)
|
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.
|
# more consideration as user's behaviour is dynamic. Time factor should be considered.
|
||||||
random.shuffle(result) # shuffle list
|
user_level = user_difficulty_level(d_user, d3)
|
||||||
d = random.choice(result)
|
|
||||||
text_level = text_difficulty_level(d['text'], d3)
|
|
||||||
if articleID == None:
|
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:
|
for reading in result:
|
||||||
text_level = text_difficulty_level(reading['text'], d3)
|
text_level = text_difficulty_level(reading['text'], d3)
|
||||||
factor = random.gauss(0.8,
|
# a number drawn from Gaussian distribution with a mean of 0.8 and a stand deviation of 1
|
||||||
0.1) # 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):
|
if within_range(text_level, user_level, (8.0 - user_level) * factor):
|
||||||
d = reading
|
lst.append(reading['article_id'])
|
||||||
break
|
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 = '<div class="alert alert-success" role="alert">According to your word list, your level is <span class="badge bg-success">%4.2f</span> and we have chosen an article with a difficulty level of <span class="badge bg-success">%4.2f</span> for you.</div>' % (
|
s = '<div class="alert alert-success" role="alert">According to your word list, your level is <span class="badge bg-success">%4.2f</span> and we have chosen an article with a difficulty level of <span class="badge bg-success">%4.2f</span> for you.</div>' % (
|
||||||
user_level, text_level)
|
user_level, text_level)
|
||||||
s += '<p class="text-muted">Article added on: %s</p>' % (d['date'])
|
s += '<p class="text-muted">Article added on: %s</p>' % (d['date'])
|
||||||
|
|
|
@ -92,6 +92,7 @@ def mainpage():
|
||||||
return render_template('mainpage_post.html', lst=lst, yml=Yaml.yml)
|
return render_template('mainpage_post.html', lst=lst, yml=Yaml.yml)
|
||||||
|
|
||||||
elif request.method == 'GET': # when we load a html page
|
elif request.method == 'GET': # when we load a html page
|
||||||
|
session['article_id_lst'] = None
|
||||||
random_ads = get_random_ads()
|
random_ads = get_random_ads()
|
||||||
number_of_essays = total_number_of_essays()
|
number_of_essays = total_number_of_essays()
|
||||||
d = load_freq_history(path_prefix + 'static/frequency/frequency.p')
|
d = load_freq_history(path_prefix + 'static/frequency/frequency.p')
|
||||||
|
|
|
@ -121,7 +121,7 @@ def userpage(username):
|
||||||
username=username,
|
username=username,
|
||||||
session=session,
|
session=session,
|
||||||
flashed_messages=get_flashed_messages_if_any(),
|
flashed_messages=get_flashed_messages_if_any(),
|
||||||
today_article=get_today_article(user_freq_record, session['articleID']),
|
today_article=get_today_article(user_freq_record),
|
||||||
d_len=len(d),
|
d_len=len(d),
|
||||||
lst3=lst3,
|
lst3=lst3,
|
||||||
yml=Yaml.yml,
|
yml=Yaml.yml,
|
||||||
|
|
Loading…
Reference in New Issue