Skip to content
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

add level and level_progress to stats api routes #648

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

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
Contributor

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
Contributor

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

app/constants/level.py Show resolved Hide resolved
@@ -108,6 +110,13 @@ async def get_player_mode_stats(
)

response = PlayerStats.from_mapping(data)
Copy link
Contributor

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
Contributor

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
Contributor

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

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.

5 participants