Skip to content

Conversation

shoucandanghehe
Copy link
Member

No description provided.

@shoucandanghehe shoucandanghehe requested a review from Copilot July 19, 2025 14:36
Copy link

codecov bot commented Jul 19, 2025

Codecov Report

Attention: Patch coverage is 20.00000% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...nebot_plugin_tetris_stats/games/tetrio/rank/all.py 20.00% 4 Missing ⚠️
...ot_plugin_tetris_stats/games/tetrio/rank/detail.py 20.00% 4 Missing ⚠️
Files with missing lines Coverage Δ
...nebot_plugin_tetris_stats/games/tetrio/rank/all.py 64.44% <20.00%> (-4.61%) ⬇️
...ot_plugin_tetris_stats/games/tetrio/rank/detail.py 59.57% <20.00%> (-4.07%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR removes the use of SQLite-specific julianday function and replaces it with database-agnostic date comparison logic to improve compatibility across different database systems. The change affects how the system finds comparison data points that are closest to 24 hours before the latest record.

  • Replaced SQLite julianday function with standard datetime comparison using <= and >= operators
  • Implemented a two-query approach to find records before and after the target time, then select the closest one
  • Added comprehensive Chinese comments explaining the logic flow

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
nonebot_plugin_tetris_stats/games/tetrio/rank/detail.py Updated comparison data query logic to use database-agnostic datetime operations
nonebot_plugin_tetris_stats/games/tetrio/rank/all.py Applied the same database-agnostic datetime comparison logic

.options(selectinload(TETRIOLeagueStats.fields))
)
).one()
or latest_data # 回退到最新记录
Copy link
Preview

Copilot AI Jul 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback logic using or latest_data will always evaluate to latest_data when the query returns None, but this could lead to incorrect comparison calculations. Consider checking if valid comparison data exists before proceeding, or handle the case where no historical data is available more explicitly.

Suggested change
or latest_data # 回退到最新记录
if before is None else before # Explicitly check for None

Copilot uses AI. Check for mistakes.

.options(selectinload(TETRIOLeagueStats.fields))
)
).one()
or latest_data
Copy link
Preview

Copilot AI Jul 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback logic using or latest_data will always evaluate to latest_data when the query returns None, but this could lead to incorrect comparison calculations. Consider checking if valid comparison data exists before proceeding, or handle the case where no historical data is available more explicitly.

Copilot uses AI. Check for mistakes.

Comment on lines +80 to +85
compare_data = (
before
if abs((target_time - before.update_time).total_seconds())
< abs((target_time - after.update_time).total_seconds())
else after
)
Copy link
Preview

Copilot AI Jul 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When before or after fallback to latest_data, the time difference calculation may not work as expected. If both queries return None and fallback to latest_data, both before and after will reference the same object, making the comparison meaningless.

Suggested change
compare_data = (
before
if abs((target_time - before.update_time).total_seconds())
< abs((target_time - after.update_time).total_seconds())
else after
)
if before is latest_data and after is latest_data:
compare_data = latest_data
else:
compare_data = (
before
if abs((target_time - before.update_time).total_seconds())
< abs((target_time - after.update_time).total_seconds())
else after
)

Copilot uses AI. Check for mistakes.

Comment on lines +82 to +87
compare_data = (
before
if abs((target_time - before.update_time).total_seconds())
< abs((target_time - after.update_time).total_seconds())
else after
)
Copy link
Preview

Copilot AI Jul 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When before or after fallback to latest_data, the time difference calculation may not work as expected. If both queries return None and fallback to latest_data, both before and after will reference the same object, making the comparison meaningless.

Suggested change
compare_data = (
before
if abs((target_time - before.update_time).total_seconds())
< abs((target_time - after.update_time).total_seconds())
else after
)
if before is latest_data and after is latest_data:
compare_data = latest_data
else:
compare_data = (
before
if abs((target_time - before.update_time).total_seconds())
< abs((target_time - after.update_time).total_seconds())
else after
)

Copilot uses AI. Check for mistakes.

@shoucandanghehe shoucandanghehe merged commit 52a6d95 into main Jul 19, 2025
14 of 15 checks passed
@shoucandanghehe shoucandanghehe deleted the fix/julianday branch July 19, 2025 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant