Spaces:
Running
Running
Merge pull request #61 from alecrem/feature/issue-60/add-search-fields
Browse files- Middle_School_Card_Search.py +44 -7
- streamlit_common/locale.py +105 -13
Middle_School_Card_Search.py
CHANGED
@@ -39,28 +39,65 @@ st.write(f'**{mslist_df.shape[0]}**{_["search"]["cards_are_legal"][l]}')
|
|
39 |
results_df = mslist_df
|
40 |
|
41 |
# Filter by card name
|
42 |
-
input_name = st.text_input(
|
|
|
|
|
|
|
43 |
exact_match = lib.get_legal_cardnames(input_name, mslist_df)
|
44 |
results_en_df = results_df[results_df["name"].str.contains(input_name, case=False)]
|
45 |
results_ja_df = results_df[results_df["name_ja"].str.contains(input_name, case=False)]
|
46 |
results_df = results_en_df.merge(results_ja_df, how="outer")
|
47 |
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
|
|
50 |
# Filter by type (select)
|
|
|
51 |
select_types = col1.multiselect(
|
52 |
-
_["search"]["select_type"][l],
|
53 |
-
[
|
|
|
54 |
)
|
55 |
for cardtype in select_types:
|
56 |
-
|
|
|
|
|
|
|
57 |
|
58 |
# Filter by type (text input)
|
59 |
-
input_type = col2.text_input(
|
|
|
|
|
|
|
60 |
results_df = results_df[results_df["type"].str.contains(input_type, case=False)]
|
61 |
|
62 |
# Filter by text
|
63 |
-
input_text = st.text_input(
|
|
|
|
|
|
|
64 |
results_df = results_df[results_df["text"].str.contains(input_text, case=False)]
|
65 |
|
66 |
if results_df.shape[0] < mslist_df.shape[0]:
|
|
|
39 |
results_df = mslist_df
|
40 |
|
41 |
# Filter by card name
|
42 |
+
input_name = st.text_input(
|
43 |
+
f'**{_["search"]["search_by_card_name"][l]}**',
|
44 |
+
placeholder=_["search"]["search_by_card_name_placeholder"][l],
|
45 |
+
).strip()
|
46 |
exact_match = lib.get_legal_cardnames(input_name, mslist_df)
|
47 |
results_en_df = results_df[results_df["name"].str.contains(input_name, case=False)]
|
48 |
results_ja_df = results_df[results_df["name_ja"].str.contains(input_name, case=False)]
|
49 |
results_df = results_en_df.merge(results_ja_df, how="outer")
|
50 |
|
51 |
+
# Filter by color
|
52 |
+
(
|
53 |
+
colorcol0,
|
54 |
+
colorcol1,
|
55 |
+
colorcol2,
|
56 |
+
colorcol3,
|
57 |
+
colorcol4,
|
58 |
+
colorcol5,
|
59 |
+
colorcol6,
|
60 |
+
) = st.columns(7)
|
61 |
+
colorcol0.write(f'**{_["search"]["search_by_color"][l]}**')
|
62 |
+
if colorcol1.checkbox(_["basic"]["color_w"][l]):
|
63 |
+
results_df = results_df[results_df["w"] == True]
|
64 |
+
if colorcol2.checkbox(_["basic"]["color_u"][l]):
|
65 |
+
results_df = results_df[results_df["u"] == True]
|
66 |
+
if colorcol3.checkbox(_["basic"]["color_b"][l]):
|
67 |
+
results_df = results_df[results_df["b"] == True]
|
68 |
+
if colorcol4.checkbox(_["basic"]["color_r"][l]):
|
69 |
+
results_df = results_df[results_df["r"] == True]
|
70 |
+
if colorcol5.checkbox(_["basic"]["color_g"][l]):
|
71 |
+
results_df = results_df[results_df["g"] == True]
|
72 |
+
if colorcol6.checkbox(_["basic"]["color_c"][l]):
|
73 |
+
results_df = results_df[results_df["c"] == True]
|
74 |
|
75 |
+
col1, col2 = st.columns(2)
|
76 |
# Filter by type (select)
|
77 |
+
type_list = streamlit_common.locale.get_type_options()
|
78 |
select_types = col1.multiselect(
|
79 |
+
f'**{_["search"]["select_type"][l]}**',
|
80 |
+
type_list[l],
|
81 |
+
placeholder=_["search"]["select_type_placeholder"][l],
|
82 |
)
|
83 |
for cardtype in select_types:
|
84 |
+
type_to_search = cardtype
|
85 |
+
if l == "ja":
|
86 |
+
type_to_search = type_list["en"][type_list["ja"].index(cardtype)]
|
87 |
+
results_df = results_df[results_df["type"].str.contains(type_to_search, case=False)]
|
88 |
|
89 |
# Filter by type (text input)
|
90 |
+
input_type = col2.text_input(
|
91 |
+
f'**{_["search"]["search_by_type"][l]}**',
|
92 |
+
placeholder=_["search"]["search_by_type_placeholder"][l],
|
93 |
+
).strip()
|
94 |
results_df = results_df[results_df["type"].str.contains(input_type, case=False)]
|
95 |
|
96 |
# Filter by text
|
97 |
+
input_text = st.text_input(
|
98 |
+
f'**{_["search"]["search_by_text"][l]}**',
|
99 |
+
placeholder=_["search"]["search_by_text_placeholder"][l],
|
100 |
+
).strip()
|
101 |
results_df = results_df[results_df["text"].str.contains(input_text, case=False)]
|
102 |
|
103 |
if results_df.shape[0] < mslist_df.shape[0]:
|
streamlit_common/locale.py
CHANGED
@@ -11,25 +11,45 @@ def get_locale():
|
|
11 |
"ja": "枚 のカードが使用可能です。",
|
12 |
},
|
13 |
"search_by_card_name": {
|
14 |
-
"en": "Search by card name
|
15 |
-
"ja": "
|
16 |
},
|
17 |
-
"
|
18 |
-
"en": "Type a part of
|
19 |
-
"ja": "
|
20 |
-
},
|
21 |
-
"search_by_type": {
|
22 |
-
"en": "Search by types, cardtypes and supertypes:",
|
23 |
-
"ja": "タイプ、サブタイプ、スーパータイプで検索:",
|
24 |
},
|
25 |
"select_type": {
|
26 |
"en": "Select card types:",
|
27 |
"ja": "タイプを選択してください:",
|
28 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
"exact_match": {
|
30 |
"en": "is an exact match.",
|
31 |
"ja": "が完全一致します。",
|
32 |
},
|
|
|
|
|
|
|
|
|
33 |
"cards_found": {
|
34 |
"en": " cards were found.",
|
35 |
"ja": "枚 のカードが見つかりました。",
|
@@ -39,12 +59,12 @@ def get_locale():
|
|
39 |
"ja": "上位の検索結果:",
|
40 |
},
|
41 |
"see_more": {
|
42 |
-
"en": "See more",
|
43 |
-
"ja": "
|
44 |
},
|
45 |
"see_20": {
|
46 |
-
"en": "
|
47 |
-
"ja": "20
|
48 |
},
|
49 |
},
|
50 |
"check": {
|
@@ -69,4 +89,76 @@ def get_locale():
|
|
69 |
"ja": "**枚",
|
70 |
},
|
71 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
}
|
|
|
11 |
"ja": "枚 のカードが使用可能です。",
|
12 |
},
|
13 |
"search_by_card_name": {
|
14 |
+
"en": "Search by card name:",
|
15 |
+
"ja": "カード名で検索:",
|
16 |
},
|
17 |
+
"search_by_card_name_placeholder": {
|
18 |
+
"en": "Type a card name or part of it",
|
19 |
+
"ja": "カード名もしくはその一部を入力してください",
|
|
|
|
|
|
|
|
|
20 |
},
|
21 |
"select_type": {
|
22 |
"en": "Select card types:",
|
23 |
"ja": "タイプを選択してください:",
|
24 |
},
|
25 |
+
"search_by_type": {
|
26 |
+
"en": "Search by card types:",
|
27 |
+
"ja": "カードタイプで検索:",
|
28 |
+
},
|
29 |
+
"search_by_type_placeholder": {
|
30 |
+
"en": "Type a types, subtypes or supertypes",
|
31 |
+
"ja": "タイプ、サブタイプ、スーパータイプを入力",
|
32 |
+
},
|
33 |
+
"select_type_placeholder": {
|
34 |
+
"en": "Select card types",
|
35 |
+
"ja": "カードタイプ選択",
|
36 |
+
},
|
37 |
+
"search_by_text": {
|
38 |
+
"en": "Search by rules text:",
|
39 |
+
"ja": "テキストで検索:",
|
40 |
+
},
|
41 |
+
"search_by_text_placeholder": {
|
42 |
+
"en": "Type a part of the rules text",
|
43 |
+
"ja": "テキストの一部を入力してください",
|
44 |
+
},
|
45 |
"exact_match": {
|
46 |
"en": "is an exact match.",
|
47 |
"ja": "が完全一致します。",
|
48 |
},
|
49 |
+
"search_by_color": {
|
50 |
+
"en": "Color:",
|
51 |
+
"ja": "色:",
|
52 |
+
},
|
53 |
"cards_found": {
|
54 |
"en": " cards were found.",
|
55 |
"ja": "枚 のカードが見つかりました。",
|
|
|
59 |
"ja": "上位の検索結果:",
|
60 |
},
|
61 |
"see_more": {
|
62 |
+
"en": "See more results",
|
63 |
+
"ja": "さらに表示する",
|
64 |
},
|
65 |
"see_20": {
|
66 |
+
"en": "Reset to 20 results",
|
67 |
+
"ja": "上位20枚表示に戻す",
|
68 |
},
|
69 |
},
|
70 |
"check": {
|
|
|
89 |
"ja": "**枚",
|
90 |
},
|
91 |
},
|
92 |
+
"basic": {
|
93 |
+
"color_w": {
|
94 |
+
"en": "W",
|
95 |
+
"ja": "白",
|
96 |
+
},
|
97 |
+
"color_u": {
|
98 |
+
"en": "U",
|
99 |
+
"ja": "青",
|
100 |
+
},
|
101 |
+
"color_b": {
|
102 |
+
"en": "B",
|
103 |
+
"ja": "黒",
|
104 |
+
},
|
105 |
+
"color_r": {
|
106 |
+
"en": "R",
|
107 |
+
"ja": "赤",
|
108 |
+
},
|
109 |
+
"color_g": {
|
110 |
+
"en": "G",
|
111 |
+
"ja": "緑",
|
112 |
+
},
|
113 |
+
"color_c": {
|
114 |
+
"en": "C",
|
115 |
+
"ja": "無/茶",
|
116 |
+
},
|
117 |
+
"type_artifact": {
|
118 |
+
"en": "Artifact",
|
119 |
+
"ja": "アーティファクト",
|
120 |
+
},
|
121 |
+
"type_creature": {
|
122 |
+
"en": "Creature",
|
123 |
+
"ja": "クリーチャー",
|
124 |
+
},
|
125 |
+
"type_enchantment": {
|
126 |
+
"en": "Enchantment",
|
127 |
+
"ja": "エンチャント",
|
128 |
+
},
|
129 |
+
"type_instant": {
|
130 |
+
"en": "Instant",
|
131 |
+
"ja": "インスタント",
|
132 |
+
},
|
133 |
+
"type_land": {
|
134 |
+
"en": "Land",
|
135 |
+
"ja": "土地",
|
136 |
+
},
|
137 |
+
"type_sorcery": {
|
138 |
+
"en": "Sorcery",
|
139 |
+
"ja": "ソーサリー",
|
140 |
+
},
|
141 |
+
},
|
142 |
+
}
|
143 |
+
|
144 |
+
|
145 |
+
def get_type_options():
|
146 |
+
_ = get_locale()
|
147 |
+
return {
|
148 |
+
"en": [
|
149 |
+
_["basic"]["type_artifact"]["en"],
|
150 |
+
_["basic"]["type_creature"]["en"],
|
151 |
+
_["basic"]["type_enchantment"]["en"],
|
152 |
+
_["basic"]["type_instant"]["en"],
|
153 |
+
_["basic"]["type_land"]["en"],
|
154 |
+
_["basic"]["type_sorcery"]["en"],
|
155 |
+
],
|
156 |
+
"ja": [
|
157 |
+
_["basic"]["type_artifact"]["ja"],
|
158 |
+
_["basic"]["type_creature"]["ja"],
|
159 |
+
_["basic"]["type_enchantment"]["ja"],
|
160 |
+
_["basic"]["type_instant"]["ja"],
|
161 |
+
_["basic"]["type_land"]["ja"],
|
162 |
+
_["basic"]["type_sorcery"]["ja"],
|
163 |
+
],
|
164 |
}
|