zypchn commited on
Commit
80dccab
·
verified ·
1 Parent(s): ebd335b

Update tools.py

Browse files

added 'self' keyword to access variables

Files changed (1) hide show
  1. tools.py +11 -11
tools.py CHANGED
@@ -34,18 +34,18 @@ class PokemonAdvisorTools():
34
 
35
  def list_card_names(self, name_query):
36
  """Retrieves a list of matching card names for the user's query."""
37
- prod_names_match = process.extract(name_query, ALL_PROD_NAMES, scorer=fuzz.WRatio, limit=5)
38
  return [name[0].replace("_", " ") for name in prod_names_match]
39
 
40
  def get_card_info(self, name_query):
41
  """Retrieves core financial and meta data for a single card."""
42
- prod_name = process.extractOne(name_query, ALL_PROD_NAMES, scorer=fuzz.WRatio)[0]
43
- card_df = knowledge_base_latest[knowledge_base_latest["prod_name"] == prod_name]
44
  return card_df.to_dict(orient="records")[0]
45
 
46
  def find_grading_opportunities(self, max_price=50, min_profit=20):
47
  """Scans the market for cards currently offering the highest raw-to-graded profit."""
48
- profitable_grades = knowledge_base_latest[knowledge_base_latest["is_grade_profitable"] == True]
49
  profitable_grades = profitable_grades[profitable_grades["used_price"] <= max_price]
50
  min_profit_grades = profitable_grades[profitable_grades["grade_profit"] >= min_profit]
51
  min_profit_grades = min_profit_grades.sort_values(
@@ -65,7 +65,7 @@ class PokemonAdvisorTools():
65
 
66
  def get_market_movers(self, sort_by="uptrend", interval=6):
67
  """Analyzes the current market and identifies the top 10 cards experiencing the largest positive (uptrend) or negative (downtrend) price movement over the last 6 months."""
68
- market_move_data = knowledge_base_latest.sort(by=f"trend_{interval}", ascending=(not sort_by=="uptrend")).head(10)
69
  output_columns = ["prod_name", "used_price", "graded_price"]
70
  market_move_data = market_move_data[output_columns]
71
  return market_move_data.to_dict(orient="records")
@@ -136,13 +136,13 @@ class PokemonAdvisorTools():
136
  """Scans the latest market snapshot to identify the top 20 cards that have experienced a sudden, significant price increase (jump-up) in either the used or graded market."""
137
  market_type = market_type.lower().strip()
138
  if market_type == "used":
139
- jump_data = knowledge_base_latest[knowledge_base_latest["used_jump_up"] == True]
140
  jump_data = jump_data.sort_values("used_price", ascending=False).head(20)
141
  output_columns = ["prod_name", "set_name", "used_price"]
142
  return jump_data[output_columns].to_dict(orient="records")
143
 
144
  elif market_type == "graded":
145
- jump_data = knowledge_base_latest[knowledge_base_latest["graded_jump_up"] == True]
146
  jump_data = jump_data.sort_values("graded_price", ascending=False).head(20)
147
  output_columns = ["prod_name", "set_name", "graded_price"]
148
  return jump_data[output_columns].to_dict(orient="records")
@@ -153,13 +153,13 @@ class PokemonAdvisorTools():
153
 
154
  def find_cards_by_artist(self, artist_name):
155
  """Identifies the top 20 cards drawn by a specified artist that currently present the highest raw-to-graded arbitrage profit opportunity."""
156
- artist_match = process.extractOne(artist_name, ALL_ARTIST_NAMES, scorer=fuzz.WRatio)
157
 
158
  if not artist_match or artist_match[1] < 75:
159
  return {"error": f"Artist '{artist_name}' not found or matched with low confidence."}
160
 
161
  artist_name_match = artist_match[0]
162
- artist_card_data = knowledge_base_latest[knowledge_base_latest["artist"] == artist_name_match]
163
  profitable_cards = artist_card_data[artist_card_data["is_grade_profitable"] == True]
164
  profitable_cards = profitable_cards.sort_values(by="grade_profit", ascending=False).head(20)
165
 
@@ -182,8 +182,8 @@ class PokemonAdvisorTools():
182
 
183
  def analyze_set_performance(self, set_name):
184
  """Provides a macro-level financial summary of a specific set, including its overall average 6-month trend, average grading profit, and the most expensive (chase) card."""
185
- set_name_match = process.extractOne(set_name.lower(), ALL_SET_NAMES, scorer=fuzz.WRatio)[0]
186
- set_card_data = knowledge_base_latest[knowledge_base_latest["set_name"] == set_name_match]
187
  total_cards = len(set_card_data)
188
  avg_trend_6 = set_card_data["used_trend_6"].mean()
189
  avg_grade_profit = set_card_data["grade_profit"].mean()
 
34
 
35
  def list_card_names(self, name_query):
36
  """Retrieves a list of matching card names for the user's query."""
37
+ prod_names_match = process.extract(name_query, self.ALL_PROD_NAMES, scorer=fuzz.WRatio, limit=5)
38
  return [name[0].replace("_", " ") for name in prod_names_match]
39
 
40
  def get_card_info(self, name_query):
41
  """Retrieves core financial and meta data for a single card."""
42
+ prod_name = process.extractOne(name_query, self.ALL_PROD_NAMES, scorer=fuzz.WRatio)[0]
43
+ card_df = self.knowledge_base_latest[self.knowledge_base_latest["prod_name"] == prod_name]
44
  return card_df.to_dict(orient="records")[0]
45
 
46
  def find_grading_opportunities(self, max_price=50, min_profit=20):
47
  """Scans the market for cards currently offering the highest raw-to-graded profit."""
48
+ profitable_grades = self.knowledge_base_latest[self.knowledge_base_latest["is_grade_profitable"] == True]
49
  profitable_grades = profitable_grades[profitable_grades["used_price"] <= max_price]
50
  min_profit_grades = profitable_grades[profitable_grades["grade_profit"] >= min_profit]
51
  min_profit_grades = min_profit_grades.sort_values(
 
65
 
66
  def get_market_movers(self, sort_by="uptrend", interval=6):
67
  """Analyzes the current market and identifies the top 10 cards experiencing the largest positive (uptrend) or negative (downtrend) price movement over the last 6 months."""
68
+ market_move_data = self.knowledge_base_latest.sort(by=f"trend_{interval}", ascending=(not sort_by=="uptrend")).head(10)
69
  output_columns = ["prod_name", "used_price", "graded_price"]
70
  market_move_data = market_move_data[output_columns]
71
  return market_move_data.to_dict(orient="records")
 
136
  """Scans the latest market snapshot to identify the top 20 cards that have experienced a sudden, significant price increase (jump-up) in either the used or graded market."""
137
  market_type = market_type.lower().strip()
138
  if market_type == "used":
139
+ jump_data = self.knowledge_base_latest[self.knowledge_base_latest["used_jump_up"] == True]
140
  jump_data = jump_data.sort_values("used_price", ascending=False).head(20)
141
  output_columns = ["prod_name", "set_name", "used_price"]
142
  return jump_data[output_columns].to_dict(orient="records")
143
 
144
  elif market_type == "graded":
145
+ jump_data = self.knowledge_base_latest[self.knowledge_base_latest["graded_jump_up"] == True]
146
  jump_data = jump_data.sort_values("graded_price", ascending=False).head(20)
147
  output_columns = ["prod_name", "set_name", "graded_price"]
148
  return jump_data[output_columns].to_dict(orient="records")
 
153
 
154
  def find_cards_by_artist(self, artist_name):
155
  """Identifies the top 20 cards drawn by a specified artist that currently present the highest raw-to-graded arbitrage profit opportunity."""
156
+ artist_match = process.extractOne(artist_name, self.ALL_ARTIST_NAMES, scorer=fuzz.WRatio)
157
 
158
  if not artist_match or artist_match[1] < 75:
159
  return {"error": f"Artist '{artist_name}' not found or matched with low confidence."}
160
 
161
  artist_name_match = artist_match[0]
162
+ artist_card_data = self.knowledge_base_latest[self.knowledge_base_latest["artist"] == artist_name_match]
163
  profitable_cards = artist_card_data[artist_card_data["is_grade_profitable"] == True]
164
  profitable_cards = profitable_cards.sort_values(by="grade_profit", ascending=False).head(20)
165
 
 
182
 
183
  def analyze_set_performance(self, set_name):
184
  """Provides a macro-level financial summary of a specific set, including its overall average 6-month trend, average grading profit, and the most expensive (chase) card."""
185
+ set_name_match = process.extractOne(set_name.lower(), self.ALL_SET_NAMES, scorer=fuzz.WRatio)[0]
186
+ set_card_data = self.knowledge_base_latest[self.knowledge_base_latest["set_name"] == set_name_match]
187
  total_cards = len(set_card_data)
188
  avg_trend_6 = set_card_data["used_trend_6"].mean()
189
  avg_grade_profit = set_card_data["grade_profit"].mean()