-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat/refactor: clean-up !with parameter parsing & add more param support #640
Open
minisbett
wants to merge
8
commits into
osuAkatsuki:master
Choose a base branch
from
minisbett:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9210fe9
rework with command
minisbett cc1d09a
Remove n300 from ScoreParams
minisbett 5e9bf19
Add tests
minisbett a65bbc7
Fix tests
minisbett 1a8f159
Merge branch 'master' into master
minisbett d9f6a0c
Merge branch 'osuAkatsuki:master' into master
minisbett bd9328d
Fix error with n300 leftover
minisbett 1af0b36
add first place scores table
minisbett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TypedDict | ||
from typing import cast | ||
|
||
from sqlalchemy import Column | ||
from sqlalchemy import Index | ||
from sqlalchemy import BigInteger | ||
from sqlalchemy import SmallInteger | ||
from sqlalchemy import String | ||
from sqlalchemy.dialects.mysql import insert as mysql_insert | ||
from sqlalchemy import select | ||
from sqlalchemy import and_ | ||
from sqlalchemy import PrimaryKeyConstraint | ||
|
||
import app.state.services | ||
from app.repositories import Base | ||
from app.constants.gamemodes import GameMode | ||
|
||
|
||
class FirstPlaceScoresTable(Base): | ||
__tablename__ = "first_place_scores" | ||
|
||
map_md5 = Column("map_md5", String(32), nullable=False) | ||
mode = Column("mode", SmallInteger, nullable=False) | ||
score_id = Column("score_id", BigInteger, nullable=False) | ||
|
||
__table_args__ = ( | ||
Index("first_place_scores_map_md5_mode_index", map_md5, mode), | ||
PrimaryKeyConstraint(map_md5, mode) | ||
) | ||
|
||
|
||
READ_PARAMS = ( | ||
FirstPlaceScoresTable.map_md5, | ||
FirstPlaceScoresTable.mode, | ||
FirstPlaceScoresTable.score_id | ||
) | ||
|
||
|
||
class FirstPlaceScore(TypedDict): | ||
map_md5: str | ||
mode: int | ||
score_id: int | ||
|
||
|
||
async def create_or_update( | ||
map_md5: str, | ||
mode: int, | ||
score_id: int | ||
) -> None: | ||
insert_stmt = mysql_insert(FirstPlaceScoresTable).values( | ||
map_md5=map_md5, | ||
mode=mode, | ||
score_id=score_id | ||
).on_duplicate_key_update( | ||
score_id=score_id | ||
) | ||
print(insert_stmt) | ||
await app.state.services.database.execute(insert_stmt) | ||
|
||
|
||
async def fetch_one(map_md5: str, mode: GameMode) -> FirstPlaceScore | None: | ||
select_stmt = select(*READ_PARAMS).where(and_(FirstPlaceScoresTable.map_md5 == map_md5, FirstPlaceScoresTable.mode == mode)) | ||
score = await app.state.services.database.fetch_one(select_stmt) | ||
return cast(FirstPlaceScore | None, score) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import pytest | ||
|
||
import app.commands | ||
from app.usecases.performance import ScoreParams | ||
|
||
@pytest.mark.parametrize( | ||
("test_input", "expected"), | ||
[ | ||
( | ||
# covers all parameters | ||
{"mode": 0, "args": "+hddtezfl 600x 99.37% 5x100 4x50 3xgeki 1xkatu 7m "}, | ||
ScoreParams(mode=0, mods=4206, combo=600, acc=99.37, n100=5, n50=4, ngeki=3, nkatu=1, nmiss=7) | ||
), | ||
|
||
( | ||
# specifically covers different mode & mods without "+" prefix | ||
{"mode": 1, "args": "hdhr"}, | ||
ScoreParams(mode=1, mods=30) | ||
), | ||
( | ||
# accuracy out of range | ||
{"mode": 0, "args": "100.0001%"}, | ||
app.commands.ParsingError("Invalid accuracy.") | ||
) | ||
] | ||
) | ||
def test_parse__with__args(test_input, expected): | ||
assert app.commands.parse__with__args(**test_input) == expected |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep the
msg
here is nice in the sense that from in-game, it's easy to tell whether or not the server correctly parsed the params you sendIt'll be quite nice now that the parsing is split into a function -- we can have a
format__with__args(score_args) -> str
and test that similarly