Spaces:
Running
Running
Merge pull request #55 from alecrem/feature/issue-54/search-text-type
Browse files- Middle_School_Card_Search.py +18 -10
- streamlit_common/lib.py +2 -0
- streamlit_common/locale.py +10 -2
Middle_School_Card_Search.py
CHANGED
@@ -4,7 +4,7 @@ import streamlit_common.footer
|
|
4 |
import streamlit_common.lib as lib
|
5 |
import streamlit_common.locale
|
6 |
|
7 |
-
mslist_path = "output/
|
8 |
number_shown_results = 20
|
9 |
_ = streamlit_common.locale.get_locale()
|
10 |
|
@@ -25,16 +25,24 @@ mslist_df = pd.read_csv(mslist_path)
|
|
25 |
mslist_df.fillna("", inplace=True)
|
26 |
st.write(f'**{mslist_df.shape[0]}**{_["search"]["cards_are_legal"][l]}')
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
]
|
36 |
results_df = results_en_df.merge(results_ja_df, how="outer")
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
if exact_match[0]:
|
39 |
cardname = exact_match[1]
|
40 |
if exact_match[2] is not None:
|
|
|
4 |
import streamlit_common.lib as lib
|
5 |
import streamlit_common.locale
|
6 |
|
7 |
+
mslist_path = "output/middleschool_extra_fields.csv"
|
8 |
number_shown_results = 20
|
9 |
_ = streamlit_common.locale.get_locale()
|
10 |
|
|
|
25 |
mslist_df.fillna("", inplace=True)
|
26 |
st.write(f'**{mslist_df.shape[0]}**{_["search"]["cards_are_legal"][l]}')
|
27 |
|
28 |
+
results_df = mslist_df
|
29 |
+
|
30 |
+
# Filter by card name
|
31 |
+
input_name = st.text_input(_["search"]["search_by_card_name"][l]).strip()
|
32 |
+
exact_match = lib.get_legal_cardnames(input_name, mslist_df)
|
33 |
+
results_en_df = results_df[results_df["name"].str.contains(input_name, case=False)]
|
34 |
+
results_ja_df = results_df[results_df["name_ja"].str.contains(input_name, case=False)]
|
|
|
35 |
results_df = results_en_df.merge(results_ja_df, how="outer")
|
36 |
+
|
37 |
+
# Filter by type
|
38 |
+
input_type = st.text_input(_["search"]["search_by_type"][l]).strip()
|
39 |
+
results_df = results_df[results_df["type"].str.contains(input_type, case=False)]
|
40 |
+
|
41 |
+
# Filter by text
|
42 |
+
input_text = st.text_input(_["search"]["search_by_text"][l]).strip()
|
43 |
+
results_df = results_df[results_df["text"].str.contains(input_text, case=False)]
|
44 |
+
|
45 |
+
if results_df.shape[0] < mslist_df.shape[0]:
|
46 |
if exact_match[0]:
|
47 |
cardname = exact_match[1]
|
48 |
if exact_match[2] is not None:
|
streamlit_common/lib.py
CHANGED
@@ -29,6 +29,8 @@ def get_legal_cardnames(cardname: str, mslist_df: pd.DataFrame) -> list:
|
|
29 |
"""Returns a list with legality (boolean) plus the English and Japanese
|
30 |
names for the card if there is an exact match, or the user's input if there is not.
|
31 |
"""
|
|
|
|
|
32 |
cardname_en_list = []
|
33 |
cardname_ja_list = []
|
34 |
legal = False
|
|
|
29 |
"""Returns a list with legality (boolean) plus the English and Japanese
|
30 |
names for the card if there is an exact match, or the user's input if there is not.
|
31 |
"""
|
32 |
+
if len(cardname) < 1:
|
33 |
+
return [False, [], []]
|
34 |
cardname_en_list = []
|
35 |
cardname_ja_list = []
|
36 |
legal = False
|
streamlit_common/locale.py
CHANGED
@@ -11,8 +11,16 @@ def get_locale():
|
|
11 |
"ja": "枚 のカードが使用可能です。",
|
12 |
},
|
13 |
"search_by_card_name": {
|
14 |
-
"en": "Search by card name:",
|
15 |
-
"ja": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
},
|
17 |
"exact_match": {
|
18 |
"en": "is an exact match.",
|
|
|
11 |
"ja": "枚 のカードが使用可能です。",
|
12 |
},
|
13 |
"search_by_card_name": {
|
14 |
+
"en": "Search by card name (or part of it):",
|
15 |
+
"ja": "カード名(もしくは一部)で検索してください:",
|
16 |
+
},
|
17 |
+
"search_by_text": {
|
18 |
+
"en": "Type a part of the rules text:",
|
19 |
+
"ja": "テキストの一部を入力してください:",
|
20 |
+
},
|
21 |
+
"search_by_type": {
|
22 |
+
"en": "Type a part of the card type line:",
|
23 |
+
"ja": "カードタイプの一部を入力してください:",
|
24 |
},
|
25 |
"exact_match": {
|
26 |
"en": "is an exact match.",
|