Skip to content

Conversation

HorizonCode
Copy link
Contributor

@HorizonCode HorizonCode commented Mar 13, 2024

Describe your changes

  • Adds level and level_progress to stats routes

Checklist

  • I've manually tested my code

@minisbett
Copy link
Contributor

I'm not sure whether this is a concern for bpy or whether a frontend should implement this itself

@tsunyoku
Copy link
Contributor

level is a statistic so i don't have an issue with this being provided via API

@7ez
Copy link
Contributor

7ez commented Mar 13, 2024

tbh would be cooler if level and level progress would be combined

@tsunyoku
Copy link
Contributor

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

@HorizonCode
Copy link
Contributor Author

then i would say keep level and level progress, bc for frotend dev its easier to use the values

]


def get_required_score_for_level(level: int) -> int:
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
baseLevel = get_level(score)
base_level = get_level(score)

etc, use pep8 naming please

Copy link
Member

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)
Copy link
Member

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,
Copy link
Member

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):
Copy link
Member

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

https://docs.python.org/3/library/bisect.html


import math

LEVEL_GRAPH = [
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
LEVEL_GRAPH = [
LEVEL_GRAPH: list[int] = [

return 0
if level <= 100:
return LEVEL_GRAPH[level - 1]
return LEVEL_GRAPH[99] + 100000000000 * int(level - 100)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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)
Copy link
Member

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

@cmyui
Copy link
Member

cmyui commented May 1, 2025

left some feedback and can review more deeply later, but provided the comments are addressed i think this is good

@cmyui
Copy link
Member

cmyui commented May 1, 2025

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

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.

6 participants