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

77 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-01 10:28 +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 Foil, edition_mapping 

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_mapping.keys(): 

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

17 collection = get_collection(temp_df, list_prices_df, market_prices_df) 

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

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

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

21 return_df[str(edition) + '_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'] in [10, 13]: # Soulbound and Soulbound rebellion 

42 # determine total unbound bcx to calculate value. 

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

44 if not is_fully_unbound(collection_card): 

45 bcx = 0 

46 

47 if (collection_card['edition'] == 18 and 

48 collection_card['foil'] == 0): # Conclave Reward only regulare are soulbound 

49 # determine total unbound bcx to calculate value. 

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

51 if not is_fully_unbound(collection_card): 

52 bcx = 0 

53 

54 if collection_card['edition'] == 6: # gladius 

55 pass # Has no value, not relevant for now 

56 else: 

57 list_price = get_list_price(collection_card, list_prices_df) 

58 if list_price: 

59 total_list_value += bcx * list_price 

60 

61 market_price = get_market_price(collection_card, market_prices_df, list_price) 

62 if market_price: 

63 total_market_value += bcx * market_price 

64 

65 if not list_price and not market_price: 

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

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

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

69 "ignored in collection value.") 

70 

71 return {'list_value': total_list_value, 

72 'market_value': total_market_value, 

73 'bcx': total_bcx, 

74 'number_of_cards': number_of_cards 

75 } 

76 

77 

78def get_list_price(collection_card, list_prices_df): 

79 list_price_filtered = find_card(collection_card, list_prices_df) 

80 if not list_price_filtered.empty: 

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

82 return None 

83 

84 

85def get_market_price(collection_card, market_prices_df, list_price): 

86 market_prices_filtered = find_card(collection_card, market_prices_df) 

87 if not market_prices_filtered.empty: 

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

89 if list_price: 

90 return min(market_price, list_price) 

91 else: 

92 return market_price 

93 return None 

94 

95 

96def find_card(collection_card, market_df): 

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

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

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

100 filtered_df = market_df.loc[mask] 

101 return filtered_df 

102 

103 

104def get_bcx(collection_card): 

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

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

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

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

109 

110 if edition == 0: 

111 if collection_card["gold"]: 

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

113 else: 

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

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

116 bcx = xp 

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

118 if collection_card["gold"]: 

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

120 else: 

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

122 else: 

123 bcx = xp 

124 

125 return bcx