Alejandro Cremades commited on
Commit
2844b79
2 Parent(s): 2c2aaef 82116f7

Merge pull request #40 from alecrem/feature/issue-39/real-card-names-on-list-check

Browse files
pages/1_Check_Card_List.py CHANGED
@@ -35,11 +35,18 @@ for line in input_list.split("\n"):
35
  cardnames.append(lib.remove_number_of_copies(cardname))
36
 
37
  input_cards = pd.DataFrame(cardnames, columns=["cardname"])
38
- input_cards["legal"] = input_cards["cardname"].apply(
39
- lib.is_cardname_legal, args=[mslist_df]
40
  )
 
 
41
 
42
  col2.write("##### Middle School legality")
43
- col2.dataframe(input_cards[["legal", "cardname"]], use_container_width=True)
 
 
 
 
 
44
 
45
  streamlit_common.footer.write_footer()
 
35
  cardnames.append(lib.remove_number_of_copies(cardname))
36
 
37
  input_cards = pd.DataFrame(cardnames, columns=["cardname"])
38
+ input_cards["legalnames"] = input_cards["cardname"].apply(
39
+ lib.get_legal_cardnames, args=[mslist_df]
40
  )
41
+ input_cards = input_cards.apply(lib.split_names_list, axis=1)
42
+ input_cards = input_cards.apply(lib.legal_to_checkmark, axis=1)
43
 
44
  col2.write("##### Middle School legality")
45
+ if "English" in input_cards and "日本語" in input_cards:
46
+ col2.dataframe(
47
+ input_cards[["Legal", "English", "日本語"]],
48
+ use_container_width=True,
49
+ hide_index=True,
50
+ )
51
 
52
  streamlit_common.footer.write_footer()
streamlit_common/lib.py CHANGED
@@ -18,24 +18,35 @@ def row_to_link(row: pd.DataFrame) -> None:
18
 
19
 
20
  def get_legal_cardnames(cardname: str, mslist_df: pd.DataFrame) -> list:
21
- """Returns a list with the English and Japanese names for the card
22
- if there is an exact match, or `None` if there is not.
23
  """
 
 
 
24
  english_match = mslist_df[mslist_df["name"].str.lower() == cardname.lower()]
25
- cardname_en_list = None
26
  if english_match.shape[0] > 0:
 
27
  cardname_en_list = english_match["name"].to_list()
28
  cardname_ja_list = english_match["name_ja"].to_list()
29
  japanese_match = mslist_df[mslist_df["name_ja"] == cardname]
30
  if japanese_match.shape[0] > 0:
 
31
  cardname_en_list = japanese_match["name"].to_list()
32
  cardname_ja_list = japanese_match["name_ja"].to_list()
33
- if cardname_en_list is not None and len(cardname_en_list) > 0:
34
- return [
35
- cardname_en_list[0] or None,
36
- cardname_ja_list[0] or None,
37
- ]
38
- return None
 
 
 
 
 
 
 
39
 
40
 
41
  def remove_number_of_copies(line: str) -> str:
@@ -55,3 +66,22 @@ def is_cardname_legal(cardname: str, mslist_df: pd.DataFrame) -> bool:
55
  if mslist_df[mslist_df["name_ja"] == cardname].shape[0] > 0:
56
  return True
57
  return False
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
 
20
  def get_legal_cardnames(cardname: str, mslist_df: pd.DataFrame) -> list:
21
+ """Returns a list with legality (boolean) plus the English and Japanese
22
+ names for the card if there is an exact match, or the user's input if there is not.
23
  """
24
+ cardname_en_list = []
25
+ cardname_ja_list = []
26
+ legal = False
27
  english_match = mslist_df[mslist_df["name"].str.lower() == cardname.lower()]
 
28
  if english_match.shape[0] > 0:
29
+ legal = True
30
  cardname_en_list = english_match["name"].to_list()
31
  cardname_ja_list = english_match["name_ja"].to_list()
32
  japanese_match = mslist_df[mslist_df["name_ja"] == cardname]
33
  if japanese_match.shape[0] > 0:
34
+ legal = True
35
  cardname_en_list = japanese_match["name"].to_list()
36
  cardname_ja_list = japanese_match["name_ja"].to_list()
37
+ if len(cardname_en_list) > 0:
38
+ legalname_en = cardname_en_list[0]
39
+ else:
40
+ legalname_en = cardname
41
+ if len(cardname_ja_list) > 0:
42
+ legalname_ja = cardname_ja_list[0]
43
+ else:
44
+ legalname_ja = cardname
45
+ return [
46
+ legal,
47
+ legalname_en,
48
+ legalname_ja,
49
+ ]
50
 
51
 
52
  def remove_number_of_copies(line: str) -> str:
 
66
  if mslist_df[mslist_df["name_ja"] == cardname].shape[0] > 0:
67
  return True
68
  return False
69
+
70
+
71
+ def legal_to_checkmark(row: pd.DataFrame) -> pd.DataFrame:
72
+ if row["islegal"]:
73
+ row["Legal"] = "✅"
74
+ return row
75
+ row["Legal"] = "🚫"
76
+ return row
77
+
78
+
79
+ def split_names_list(row: pd.DataFrame):
80
+ """Splits the English and Japanese card names in a list into two different columns"""
81
+ if not isinstance(row["legalnames"], list):
82
+ return row
83
+ row["islegal"] = row["legalnames"][0]
84
+ row["English"] = row["legalnames"][1]
85
+ if row["legalnames"][1] is not None:
86
+ row["日本語"] = row["legalnames"][2]
87
+ return row