-
Notifications
You must be signed in to change notification settings - Fork 152
add level and level_progress to stats api routes #648
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
base: master
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
I'm not sure whether this is a concern for bpy or whether a frontend should implement this itself |
level is a statistic so i don't have an issue with this being provided via API |
tbh would be cooler if level and level progress would be combined |
for more information, see https://pre-commit.ci
i'm not convinced we need all 3. level being a float with the decimals being the progress should be enough i don't particularly care which we pick, but either have level and progress separated or have them combined into one float. but not both |
then i would say keep level and level progress, bc for frotend dev its easier to use the values |
for more information, see https://pre-commit.ci
] | ||
|
||
|
||
def get_required_score_for_level(level: int) -> int: |
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 am ..not sure how i feel about functions living in constants?
|
||
|
||
def get_level_precise(score: int) -> float: | ||
baseLevel = get_level(score) |
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.
baseLevel = get_level(score) | |
base_level = get_level(score) |
etc, use pep8 naming please
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.
we should lint/autofix this if possible, maybe there's a pre-commit hook for it
status_code=status.HTTP_404_NOT_FOUND, | ||
) | ||
|
||
response = PlayerStats.from_mapping(data) |
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.
add level and level_progress to data instead. this will cause issues when instantiated otherwise as pydantic will not be happy about these values missing
# NOTE: kinda cursed, but that should do it | ||
response.level = get_level(int(data["tscore"])) | ||
response.level_progress = int( | ||
(get_level_precise(data["tscore"]) - get_level(data["tscore"])) * 100, |
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.
this specific pattern seems to repeat itself quite a lot. could we have a function that returns a tuple of level and level_progress instead and use that where needed?
if score >= LEVEL_GRAPH[99]: | ||
return 100 + int((score - LEVEL_GRAPH[99]) / 100000000000) | ||
|
||
for idx, v in enumerate(LEVEL_GRAPH, start=0): |
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.
you probably want bisect.bisect_left(LEVEL_GRAPH, score)
instead
|
||
import math | ||
|
||
LEVEL_GRAPH = [ |
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.
LEVEL_GRAPH = [ | |
LEVEL_GRAPH: list[int] = [ |
return 0 | ||
if level <= 100: | ||
return LEVEL_GRAPH[level - 1] | ||
return LEVEL_GRAPH[99] + 100000000000 * int(level - 100) |
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.
return LEVEL_GRAPH[99] + 100000000000 * int(level - 100) | |
return LEVEL_GRAPH[99] + 100_000_000_000 * int(level - 100) |
return 1 | ||
|
||
if score >= LEVEL_GRAPH[99]: | ||
return 100 + int((score - LEVEL_GRAPH[99]) / 100000000000) |
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.
return 100 + int((score - LEVEL_GRAPH[99]) / 100000000000) | |
return 100 + int((score - LEVEL_GRAPH[99]) / 100_000_000_000) |
|
||
|
||
def get_level_precise(score: int) -> float: | ||
baseLevel = get_level(score) |
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.
we should lint/autofix this if possible, maybe there's a pre-commit hook for it
left some feedback and can review more deeply later, but provided the comments are addressed i think this is good |
would anyone be interested in adding this functionality to the v2 api as well in a future pr? i'd like to get it into a better place so web implementations begin to switch over. eventually would be good to deprecate v1 once v2 has surpassed it's capabilities, get us into a much better state for maintainability of b.py |
Describe your changes
Checklist