WIP:Bug509-XieQiuHan-WangZiming #82

Closed
wangziming wants to merge 0 commits from Bug509-XieQiuHan-WangZiming into master

Bug509改进和项目重构(解决业务中的前端代码文本)

Bug509改进和项目重构(解决业务中的前端代码文本)
wangziming added 8 commits 2023-03-27 22:05:28 +08:00

@wangziming

Thanks

先不要合并,我看看。

@wangziming Thanks 先不要合并,我看看。
wangziming added 1 commit 2023-03-29 20:54:09 +08:00
mrlan added 1 commit 2023-03-30 16:10:46 +08:00
mrlan reviewed 2023-03-30 21:47:23 +08:00
app/Article.py Outdated
@ -36,2 +36,3 @@
rq = RecordQuery(path_prefix + 'static/wordfreqapp.db')
if articleID == None:
if existing_articles is None:
existing_articles = [0, []] # existing_articles[0]为existing_articles[1]的索引existing_articles[1]:之前显示文章的id列表越后越新

@wangziming

Thanks

看不懂 existing_articles 这个变量。

是指 visited_articles 吗?

其目的与用法需要多加解释。为什么第一个元素是索引?

@wangziming Thanks 看不懂 existing_articles 这个变量。 是指 visited_articles 吗? 其目的与用法需要多加解释。为什么第一个元素是索引?

是的,existing_articles[1]存储了之前看过的文章id.

增加索引是为了实现,在阅读上几篇后,可以点击“下一篇”返回到刚才新的文章;想要达成这样的效果,额外记录索引是一个更为简单的方法,因此将ids和index放在一起。

是的,existing_articles[1]存储了之前看过的文章id. 增加索引是为了实现,在阅读上几篇后,可以点击“下一篇”返回到刚才新的文章;想要达成这样的效果,额外记录索引是一个更为简单的方法,因此将ids和index放在一起。
wangziming marked this conversation as resolved
mrlan reviewed 2023-03-31 08:32:25 +08:00
app/Article.py Outdated
@ -64,0 +82,4 @@
"answer": get_answer_part(d['question'])
}
else:
existing_articles[0] -= 1

@wangziming

不断点击“上一篇”,existing_articles[0] 不断减1,会不会让 existing_articles[0] 变为负数? 比如 -100? 变为负数,程序还是可以正常运行吗?

@wangziming 不断点击“上一篇”,`existing_articles[0]` 不断减1,会不会让 `existing_articles[0]` 变为负数? 比如 -100? 变为负数,程序还是可以正常运行吗?

这里的减一不是因为上一篇而去减一,而是因为flag==False,即点击下一篇没有找到文章。

因为点击下一篇会先执行user_service.user_reset(),在这里我执行了existing_articles[0] += 1,所以到后来的Article.get_today_article()中如果没有找到文章,我会重新将existing_articles[0] -= 1,因为没有新的文章产生嘛。

这里的减一不是因为上一篇而去减一,而是因为flag==False,即点击下一篇没有找到文章。 因为点击下一篇会先执行user_service.user_reset(),在这里我执行了existing_articles[0] += 1,所以到后来的Article.get_today_article()中如果没有找到文章,我会重新将existing_articles[0] -= 1,因为没有新的文章产生嘛。

这里的逻辑确实和"上一篇"有点“杂糅”在一起。修改后,这里将d(存储确定返回的笔记信息)初始化为None,d的写入只有上一篇分支与下一篇分支中的有合适level文章时,这两个地方。所以后面就用d作为判断条件是否处理d中的数据。而原先的flag放到“下一篇”的分支中,这里还改了以下名称“flag_get_article”。

这里的逻辑确实和"上一篇"有点“杂糅”在一起。修改后,这里将d(存储确定返回的笔记信息)初始化为None,d的写入只有上一篇分支与下一篇分支中的有合适level文章时,这两个地方。所以后面就用d作为判断条件是否处理d中的数据。而原先的flag放到“下一篇”的分支中,这里还改了以下名称“flag_get_article”。
wangziming marked this conversation as resolved
wangziming added 3 commits 2023-04-04 22:34:06 +08:00
wangziming added 7 commits 2023-04-24 15:55:30 +08:00
mrlan reviewed 2023-04-25 11:27:30 +08:00
app/Article.py Outdated
@ -33,3 +33,3 @@
def get_today_article(user_word_list, articleID):
def get_today_article(user_word_list, had_read_articles):

@wangziming

请把 had_read_articles 改为 visited_articles

@wangziming 请把 `had_read_articles` 改为 `visited_articles`

收到

收到
wangziming marked this conversation as resolved
mrlan reviewed 2023-04-25 11:29:55 +08:00
app/Article.py Outdated
@ -39,2 +44,2 @@
else:
rq.instructions('SELECT * FROM article WHERE article_id=%d' % (articleID))
else: # 生成阅读过的文章,因此查询指定 article_id 的文章
rq.instructions('SELECT * FROM article WHERE article_id=%d' % (had_read_articles["article_ids"][had_read_articles["index"]]))

@wangziming

had_read_articles["article_ids"][had_read_articles["index"]]) 会出现 null 值?

  File "./Article.py", line 45, in get_today_article
    article_id = int(had_read_articles["article_ids"][had_read_articles["index"]])
ValueError: invalid literal for int() with base 10: 'null'
@wangziming `had_read_articles["article_ids"][had_read_articles["index"]])` 会出现 null 值? ``` File "./Article.py", line 45, in get_today_article article_id = int(had_read_articles["article_ids"][had_read_articles["index"]]) ValueError: invalid literal for int() with base 10: 'null' ```

没有考虑到刷新页面或者会话为关闭直接进入页面的情况,会存在bug,已改。

没有考虑到刷新页面或者会话为关闭直接进入页面的情况,会存在bug,已改。
wangziming marked this conversation as resolved
wangziming added 1 commit 2023-04-25 11:38:31 +08:00
wangziming added 1 commit 2023-04-25 17:48:30 +08:00
jinchengyu reviewed 2023-04-26 20:05:37 +08:00
@ -48,2 +47,2 @@
<a class="btn btn-success" href="/{{ username }}/back" role="button"> 上一篇 Previous Article </a>
{% endif%}
<a class="btn btn-success" href="/{{ username }}/reset" role="button"> 下一篇 Next Article </a>
{% if session.get('existing_articles') != None and session.get('existing_articles')["index"] !=0 %}

存在边界值问题:

当刚开始就没有找到文章或者就根本被没有文章的时候,会出现上一篇按钮。

@wangziming

存在边界值问题: 当刚开始就没有找到文章或者就根本被没有文章的时候,会出现上一篇按钮。 @wangziming
wangziming marked this conversation as resolved
@ -54,0 +73,4 @@
</div>
{% else %}
<div class="alert alert-success" role="alert">
<p class="text-muted"><span class="badge bg-success">Notes:</span><br>No article is currently available for you. You can try again a few times or mark new words in the passage to improve your level.</p>

找不到文章 和 看完所有的文章 需要区分:

看完所有的文章也是找不到文章,不能使用相同的提示信息。

@wangziming

找不到文章 和 看完所有的文章 需要区分: 看完所有的文章也是找不到文章,不能使用相同的提示信息。 @wangziming
wangziming marked this conversation as resolved
@ -47,1 +48,3 @@
session['articleID'] = session.get('old_articleID')
existing_articles = session.get("existing_articles")
existing_articles["index"] -= 1
session["existing_articles"] = existing_articles

存在逻辑错误:

表现:当出现找不到文章的时候,点击上一篇,出现的是上上一篇文章

原因:当出现找不到文章的时候,existing_articles 索引指向的就是上一篇文章,而点击上一篇文章时,有对索引进行了减一,导致查询了上上一篇文章。

@wangziming

存在逻辑错误: 表现:当出现找不到文章的时候,点击上一篇,出现的是上上一篇文章 原因:当出现找不到文章的时候,existing_articles 索引指向的就是上一篇文章,而点击上一篇文章时,有对索引进行了减一,导致查询了上上一篇文章。 @wangziming
wangziming marked this conversation as resolved
@ -130,11 +134,14 @@ 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'))

变量命名优化:

存储已经阅读过的文章的变量名称为 existing_articles 可能存在歧义,建议更换为 had_read_articles

@wangziming

变量命名优化: 存储已经阅读过的文章的变量名称为 existing_articles 可能存在歧义,建议更换为 had_read_articles @wangziming
wangziming marked this conversation as resolved

I have been following the convaservation and I could not find any issue yet as @mrlan already did most of the code review.

I have been following the convaservation and I could not find any issue yet as @mrlan already did most of the code review.

I have been following the convaservation and I could not find any issue yet as @mrlan already did most of the code review.

Thanks. Probably the regression error Bug 530 is due to this fix. Could you look into that?

Hui

> I have been following the convaservation and I could not find any issue yet as @mrlan already did most of the code review. Thanks. Probably the regression error Bug [530](http://118.25.96.118/bugzilla/show_bug.cgi?id=530) is due to this fix. Could you look into that? Hui
wangziming reviewed 2023-05-07 14:13:54 +08:00
mrlan closed this pull request 2024-09-05 09:25:14 +08:00

Pull request closed

Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: mrlan/EnglishPal#82
There is no content yet.