Skip to content

Commit

Permalink
fix: shinyLevels
Browse files Browse the repository at this point in the history
  • Loading branch information
MalikAza committed Dec 5, 2024
1 parent d1542f7 commit af6809c
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 80 deletions.
9 changes: 6 additions & 3 deletions pyZUnivers/api_responses/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

from .packs import Pack

ShinyLevels = TypedDict("ShinyLevels", {0: bool, 1: bool, 2: bool})
ShinyScores = TypedDict("ShinyScores", {0: int, 1: int, 2: int})

class Item(TypedDict):
id: str
name: str
Expand All @@ -13,8 +16,8 @@ class Item(TypedDict):
reference: None|str
pack: Pack
urls: List[str]
score: int
scoreGolden: int
scores: ShinyScores
shinyLevels: ShinyLevels
isRecyclable: bool
isTradable: bool
isCounting: bool
Expand All @@ -25,7 +28,7 @@ class Item(TypedDict):

class __ItemMoreInfos(TypedDict):
item: Item
isGolden: bool
shinyLevel: int
upgradeLevel: int

class ItemMetaData(__ItemMoreInfos):
Expand Down
2 changes: 1 addition & 1 deletion pyZUnivers/api_responses/towers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Reputation(TypedDict):
class DropRate(TypedDict):
id: str
rarity: int
isGolden: bool
shinyLevel: bool
rate: int

class TowerFloor(TypedDict):
Expand Down
3 changes: 2 additions & 1 deletion pyZUnivers/api_responses/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ class AscensionUser(TypedDict):

class CountByRarity(TypedDict):
rarity: int
isGolden: bool
shinyLevel: int
upgradeLevel: int
inventoryCount: int
inventoryUniqueCount: int
itemCount: int
upgradableItemCount: int
chromaItemCount: int

class Overview(TypedDict):
countByRarity: List[CountByRarity]
Expand Down
38 changes: 0 additions & 38 deletions pyZUnivers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,44 +216,6 @@ def get_advent_calendar(username: str):

return 'openedDate' in today_calendar

@staticmethod
def get_advent_score(username: str) -> int:
"""
Calculates the advent score for a given username by retrieving
calendar data and calculating the score based on various criteria.
Args:
username (str): The username of the user.
Returns:
int: The advent score for the user.
"""
username, parsed_username = parse_username(username)

try:
calendar_datas: AdventCalendarType = get_datas(f"{API_BASE_URL}/calendar/{parsed_username}")
except ResourceNotFoundError:
raise UserNotFound(username)
calendar = calendar_datas['calendars']
calendar.sort(key=lambda x: x["index"])

index_date = int(datetime.now(pytz.timezone('Europe/Paris')).strftime("%d"))
calendar_till_today = calendar[:index_date]

score = 0
for calendar in calendar_till_today:
if calendar['itemMetadata']:
rarity = f'{calendar["itemMetadata"]["item"]["rarity"]}*'
if calendar['itemMetadata']['isGolden']: rarity += '+'
score += ADVENT_INDEX[rarity]
if calendar['banner']: score += ADVENT_INDEX['banner']
if calendar['loreDust']: score += ADVENT_INDEX['dust']
if calendar['loreFragment']: score += ADVENT_INDEX['fragment']
if calendar['balance']: score += ADVENT_INDEX['balance']
if calendar['luckyType']: score += ADVENT_INDEX['ticket']

return score

@staticmethod
def get_journa(username: str) -> bool:
"""
Expand Down
4 changes: 2 additions & 2 deletions pyZUnivers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ def best_inventory(username: str, limit: int = 10) -> List[UserInventoryObject]:
inventory = get_inventory(username)

def sorted_callback(x: UserInventoryObject) -> int:
if x["isGolden"]: return x["item"]["scoreGolden"]
return x["item"]["score"]
shiny_level = x["shinyLevel"]
return x["item"]['scores'][str(shiny_level)]

inventory = sorted(inventory, key=sorted_callback, reverse=True)

Expand Down
103 changes: 68 additions & 35 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def test_get_inventory_without_search(self, mock_get_datas):
"id": 2,
"name": "Item 2",
"score": 20,
"isGolden": True
"shinyLevel": 1
},
"quantity": 3
}
Expand Down Expand Up @@ -248,32 +248,40 @@ def test_best_inventory_with_default_limit(self, mock_get_inventory):
"item": {
"id": 1,
"name": "Item 1",
"score": 10,
"scoreGolden": 20
"scores": {
"0": 10,
"1": 20,
"2": 30
}
},
"quantity": 5,
"isGolden": False

"shinyLevel": 0
},
{
"item": {
"id": 2,
"name": "Item 2",
"score": 20,
"scoreGolden": 40
"scores": {
"0": 20,
"1": 40,
"2": 60
},
},
"quantity": 3,
"isGolden": True
"shinyLevel": 1
},
{
"item": {
"id": 3,
"name": "Item 3",
"score": 15,
"scoreGolden": 30
"scores": {
"0": 15,
"1": 30,
"2": 45
}
},
"quantity": 2,
"isGolden": False
"shinyLevel": 0
}
]
mock_get_inventory.return_value = mock_response
Expand All @@ -286,31 +294,40 @@ def test_best_inventory_with_default_limit(self, mock_get_inventory):
"item": {
"id": 2,
"name": "Item 2",
"score": 20,
"scoreGolden": 40
"scores": {
"0": 20,
"1": 40,
"2": 60
},
},
"quantity": 3,
"isGolden": True
"shinyLevel": 1
},
{
"item": {
"id": 3,
"name": "Item 3",
"score": 15,
"scoreGolden": 30
"scores": {
"0": 15,
"1": 30,
"2": 45
}
},
"quantity": 2,
"isGolden": False
"shinyLevel": 0
},
{
"item": {
"id": 1,
"name": "Item 1",
"score": 10,
"scoreGolden": 20
"scores": {
"0": 10,
"1": 20,
"2": 30
}
},
"quantity": 5,
"isGolden": False
"shinyLevel": 0
}
]

Expand All @@ -323,30 +340,40 @@ def test_best_inventory_with_custom_limit(self, mock_get_inventory):
"item": {
"id": 1,
"name": "Item 1",
"score": 10,
"scores": {
"0": 10,
"1": 20,
"2": 30
},
},
"quantity": 5,
"isGolden": False
"shinyLevel": 0
},
{
"item": {
"id": 2,
"name": "Item 2",
"score": 20,
"scoreGolden": 40
"scores": {
"0": 20,
"1": 40,
"2": 60
},
},
"quantity": 3,
"isGolden": True
"shinyLevel": 1
},
{
"item": {
"id": 3,
"name": "Item 3",
"score": 15,
"scoreGolden": 30
"scores": {
"0": 15,
"1": 30,
"2": 45
},
},
"quantity": 2,
"isGolden": False
"shinyLevel": 0
}
]
mock_get_inventory.return_value = mock_response
Expand All @@ -360,21 +387,27 @@ def test_best_inventory_with_custom_limit(self, mock_get_inventory):
"item": {
"id": 2,
"name": "Item 2",
"score": 20,
"scoreGolden": 40
"scores": {
"0": 20,
"1": 40,
"2": 60
},
},
"quantity": 3,
"isGolden": True
"shinyLevel": 1
},
{
"item": {
"id": 3,
"name": "Item 3",
"score": 15,
"scoreGolden": 30
"scores": {
"0": 15,
"1": 30,
"2": 45
},
},
"isGolden": False,
"quantity": 2
"quantity": 2,
"shinyLevel": 0
}
]

Expand Down

0 comments on commit af6809c

Please sign in to comment.