Coverage for src/utils/collection_util.py: 0%

74 statements  

« prev     ^ index     » next       coverage.py v7.8.2, created at 2025-06-03 19:06 +0000

1import logging 

2from datetime import datetime 

3 

4import pandas as pd 

5 

6from src.configuration import store, config 

7from src.static.static_values_enum import Edition, Foil 

8 

9 

10def get_card_edition_value(account, list_prices_df, market_prices_df): 

11 store_copy_df = store.collection.loc[(store.collection.player == account)].copy() 

12 return_df = pd.DataFrame({'date': datetime.today().strftime('%Y-%m-%d'), 

13 'account_name': account}, index=[0]) 

14 

15 for edition in Edition.__iter__(): 

16 temp_df = store_copy_df.loc[(store_copy_df.edition == edition.value)] 

17 collection = get_collection(temp_df, list_prices_df, market_prices_df) 

18 return_df[str(edition.name) + '_market_value'] = collection['market_value'] 

19 return_df[str(edition.name) + '_list_value'] = collection['list_value'] 

20 return_df[str(edition.name) + '_bcx'] = collection['bcx'] 

21 return_df[str(edition.name) + '_number_of_cards'] = collection['number_of_cards'] 

22 

23 return return_df 

24 

25 

26def is_fully_unbound(collection_card): 

27 return collection_card.bcx == collection_card.bcx_unbound 

28 

29 

30def get_collection(df, list_prices_df, market_prices_df): 

31 total_list_value = 0 

32 total_market_value = 0 

33 total_bcx = 0 

34 number_of_cards = 0 

35 

36 for index, collection_card in df.iterrows(): 

37 number_of_cards += 1 

38 bcx = collection_card.bcx 

39 total_bcx += bcx 

40 

41 if (collection_card['edition'] == Edition.soulbound.value or 

42 collection_card['edition'] == Edition.soulboundrb.value): 

43 # determine total unbound bcx to calculate value. 

44 # only fully unbound soulbound units will be used for value calculations 

45 if not is_fully_unbound(collection_card): 

46 bcx = 0 

47 

48 if collection_card['edition'] == Edition.gladius.value: 

49 pass # Has no value, not relevant for now 

50 else: 

51 list_price = get_list_price(collection_card, list_prices_df) 

52 if list_price: 

53 total_list_value += bcx * list_price 

54 

55 market_price = get_market_price(collection_card, market_prices_df, list_price) 

56 if market_price: 

57 total_market_value += bcx * market_price 

58 

59 if not list_price and not market_price: 

60 logging.warning(f"Card '{collection_card['card_name']}' - {collection_card['card_detail_id']} - " 

61 f"{Foil.get(collection_card['foil'])}. " 

62 "Not found with either a list price or market price on Peakmonsters.com — " 

63 "ignored in collection value.") 

64 

65 return {'list_value': total_list_value, 

66 'market_value': total_market_value, 

67 'bcx': total_bcx, 

68 'number_of_cards': number_of_cards 

69 } 

70 

71 

72def get_list_price(collection_card, list_prices_df): 

73 list_price_filtered = find_card(collection_card, list_prices_df) 

74 if not list_price_filtered.empty: 

75 return float(list_price_filtered.low_price_bcx.iloc[0]) 

76 return None 

77 

78 

79def get_market_price(collection_card, market_prices_df, list_price): 

80 market_prices_filtered = find_card(collection_card, market_prices_df) 

81 if not market_prices_filtered.empty: 

82 market_price = float(market_prices_filtered.last_bcx_price.iloc[0]) 

83 if list_price: 

84 return min(market_price, list_price) 

85 else: 

86 return market_price 

87 return None 

88 

89 

90def find_card(collection_card, market_df): 

91 mask = (market_df.card_detail_id == collection_card['card_detail_id']) \ 

92 & (market_df.foil == collection_card['foil']) \ 

93 & (market_df.edition == collection_card['edition']) 

94 filtered_df = market_df.loc[mask] 

95 return filtered_df 

96 

97 

98def get_bcx(collection_card): 

99 # rarity = self.card_details[int(collection_card["card_detail_id"]) - 1]["rarity"] 

100 rarity = config.card_details_df.loc[collection_card['card_detail_id']].rarity 

101 edition = int(collection_card["edition"]) 

102 xp = int(collection_card["xp"]) 

103 

104 if edition == 0: 

105 if collection_card["gold"]: 

106 bcx = xp / config.settings["gold_xp"][rarity - 1] 

107 else: 

108 bcx = xp / config.settings["alpha_xp"][rarity - 1] + 1 

109 elif edition == 2 and int(collection_card["card_detail_id"]) > 223: # all promo cards alpha/beta 

110 bcx = xp 

111 elif (edition < 3) or ((edition == 3) and (int(collection_card["card_detail_id"]) <= 223)): 

112 if collection_card["gold"]: 

113 bcx = xp / config.settings["beta_gold_xp"][rarity - 1] 

114 else: 

115 bcx = xp / config.settings["beta_xp"][rarity - 1] + 1 

116 else: 

117 bcx = xp 

118 

119 return bcx