Spaces:
Runtime error
Runtime error
update app.py to include datavault
Browse files- app.py +154 -56
- heroes_ep_extra.csv +0 -0
app.py
CHANGED
@@ -66,7 +66,7 @@ def display_image(url, scale=0.5):
|
|
66 |
image = Image.open(urlopen(url))
|
67 |
st.image(image.resize(( int(image.width * scale), int(image.height * scale))))
|
68 |
|
69 |
-
def display_heroes_from_df(df):
|
70 |
st.dataframe(df[display_cols],
|
71 |
column_config={
|
72 |
"image": st.column_config.ImageColumn("Avatar", help="")},
|
@@ -76,17 +76,82 @@ def display_heroes_from_df(df):
|
|
76 |
for i in range(len(df)):
|
77 |
url = df['image'].values[i]
|
78 |
display_image(url)
|
79 |
-
st.write(f"{df['name'].values[i]} - {df['speed'].values[i]} - {df['class'].values[i]}")
|
80 |
st.write(f'Attack:{df["attack"].values[i]} -- Defence:{df["defense"].values[i]} -- Health:{df["health"].values[i]}')
|
81 |
-
st.write(df['skill'].values[i])
|
82 |
st.write(df['effects'].values[i])
|
83 |
# for sp in df['effects'].values[i]:
|
84 |
# st.write(sp)
|
85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
#########################################
|
87 |
## Load the main file (TODO: caching)=
|
88 |
st.set_page_config(layout="wide")
|
89 |
-
|
|
|
90 |
|
91 |
df = pd.read_csv('heroes_ep.csv')
|
92 |
class_values = ['None'] + list(df['class'].unique())
|
@@ -95,75 +160,108 @@ color_values = ['None'] + list(df['color'].unique())
|
|
95 |
speed_values = ['None'] + list(df['speed'].unique())
|
96 |
source_values = ['None'] + list(df['source'].unique())
|
97 |
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
#########################################
|
103 |
-
##
|
104 |
-
|
105 |
-
|
106 |
-
# with st.sidebar:
|
107 |
-
with st.expander("Filter Options"):
|
108 |
-
name_option = st.text_input(label="Name:", value="")
|
109 |
-
star_option = st.selectbox(label='Star:', options=star_values, index=0)
|
110 |
-
color_option = st.selectbox(label='Color:', options=color_values, index=0)
|
111 |
-
speed_option = st.selectbox(label='Speed:', options=speed_values, index=0)
|
112 |
-
class_option = st.selectbox(label='Class:', options=class_values, index=0)
|
113 |
-
source_option = st.selectbox(label='Origin:', options=source_values, index=0)
|
114 |
|
115 |
-
|
116 |
-
|
117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
|
125 |
-
idx_all = []
|
126 |
-
|
127 |
-
if name_option != '':
|
128 |
-
idx_all.append(filter_by_1col(df, 'name', name_option, exact_flag=False))
|
129 |
|
130 |
-
if
|
131 |
-
|
132 |
|
133 |
-
if
|
134 |
-
|
135 |
|
136 |
-
if
|
137 |
-
|
138 |
|
139 |
-
if
|
140 |
-
|
141 |
|
142 |
-
if
|
143 |
-
|
144 |
|
145 |
-
if
|
146 |
-
|
147 |
-
idx_all.append(filter_by_1col_num(df, 'defense', defense_option, oper_flag="ge"))
|
148 |
|
149 |
-
if
|
150 |
-
|
151 |
-
|
152 |
|
153 |
-
if
|
154 |
-
|
155 |
-
|
156 |
|
|
|
|
|
|
|
157 |
|
158 |
-
if special_type_option != '':
|
159 |
-
|
160 |
|
161 |
-
if special_text_option != '':
|
162 |
-
|
163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
#########################################
|
165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
|
167 |
-
|
|
|
168 |
|
169 |
-
|
|
|
|
66 |
image = Image.open(urlopen(url))
|
67 |
st.image(image.resize(( int(image.width * scale), int(image.height * scale))))
|
68 |
|
69 |
+
def display_heroes_from_df(df,display_cols=display_cols):
|
70 |
st.dataframe(df[display_cols],
|
71 |
column_config={
|
72 |
"image": st.column_config.ImageColumn("Avatar", help="")},
|
|
|
76 |
for i in range(len(df)):
|
77 |
url = df['image'].values[i]
|
78 |
display_image(url)
|
79 |
+
st.write(f"***{df['name'].values[i]}*** - {df['speed'].values[i]} - {df['class'].values[i]}")
|
80 |
st.write(f'Attack:{df["attack"].values[i]} -- Defence:{df["defense"].values[i]} -- Health:{df["health"].values[i]}')
|
81 |
+
st.write(f"***{df['skill'].values[i]}***" )
|
82 |
st.write(df['effects'].values[i])
|
83 |
# for sp in df['effects'].values[i]:
|
84 |
# st.write(sp)
|
85 |
|
86 |
+
#########################################
|
87 |
+
## Helper function for LB/CB stat analysis
|
88 |
+
def return_costume_list(df0, hero_name):
|
89 |
+
assert hero_name in df0.name.values
|
90 |
+
|
91 |
+
if hero_name[-2:] == "C2":
|
92 |
+
return ['None', 'CB1', 'CB2']
|
93 |
+
elif hero_name[-2:] == " C":
|
94 |
+
hero_name2 = hero_name + "2"
|
95 |
+
if hero_name2 in df0.name.values: # if this hero has C2
|
96 |
+
return ['None', 'CB1', 'CB2']
|
97 |
+
else:
|
98 |
+
return ['None', 'CB1']
|
99 |
+
else:
|
100 |
+
hero_name1 = hero_name + " C"
|
101 |
+
hero_name2 = hero_name + " C2"
|
102 |
+
if hero_name2 in df0.name.values: # if this hero has C2
|
103 |
+
return ['None', 'CB1', 'CB2']
|
104 |
+
elif hero_name1 in df0.name.values: # if this hero has C2
|
105 |
+
return ['None', 'CB1']
|
106 |
+
else:
|
107 |
+
return ['None']
|
108 |
+
|
109 |
+
def get_prefix(lb_choice="None", costume_choice="None"):
|
110 |
+
prefix_1 = "Max level"
|
111 |
+
|
112 |
+
if lb_choice != 'None':
|
113 |
+
prefix_1 = "Limit Break"
|
114 |
+
|
115 |
+
prefix_2 = ""
|
116 |
+
if costume_choice != "None":
|
117 |
+
prefix_2 = f" {costume_choice}" # CB1 or CB2
|
118 |
+
|
119 |
+
prefix_3 = ":"
|
120 |
+
if lb_choice == 'LB1':
|
121 |
+
prefix_3 = " #1:"
|
122 |
+
elif lb_choice == 'LB2':
|
123 |
+
prefix_3 = " #2:"
|
124 |
+
|
125 |
+
return prefix_1 + prefix_2 + prefix_3
|
126 |
+
|
127 |
+
def return_hero_stat(df0, hero_name, lb_choice="None", costume_choice="None"):
|
128 |
+
assert hero_name in df0.name.values
|
129 |
+
|
130 |
+
display_cols_0 = ['image', 'name', 'color', 'star', 'class', 'speed',]
|
131 |
+
display_cols_1 = [] # ['power', 'attack', 'defense', 'health', ] --> to be select base one LB/Costume choice
|
132 |
+
display_cols_2 = ['Aether Power', 'source', 'family', 'types', 'skill', 'effects']
|
133 |
+
|
134 |
+
prefix = get_prefix(lb_choice, costume_choice)
|
135 |
+
|
136 |
+
display_cols_1.append(f'{prefix} Power')
|
137 |
+
display_cols_1.append(f'{prefix} Attack')
|
138 |
+
display_cols_1.append(f'{prefix} Defense')
|
139 |
+
display_cols_1.append(f'{prefix} Health')
|
140 |
+
|
141 |
+
display_cols_all = display_cols_0 + display_cols_1 + display_cols_2
|
142 |
+
df_ret = df0[df0.name == hero_name][display_cols_all]
|
143 |
+
|
144 |
+
df_ret = df_ret.rename(columns={f'{prefix} Power':'power',
|
145 |
+
f'{prefix} Attack':'attack',
|
146 |
+
f'{prefix} Defense':'defense',
|
147 |
+
f'{prefix} Health':'health'})
|
148 |
+
return df_ret
|
149 |
+
|
150 |
#########################################
|
151 |
## Load the main file (TODO: caching)=
|
152 |
st.set_page_config(layout="wide")
|
153 |
+
st.header(f'HeroPlan Explorer')
|
154 |
+
st.write('Powered by Heroplan.io : Thanks E&P community for continually update hero data.')
|
155 |
|
156 |
df = pd.read_csv('heroes_ep.csv')
|
157 |
class_values = ['None'] + list(df['class'].unique())
|
|
|
160 |
speed_values = ['None'] + list(df['speed'].unique())
|
161 |
source_values = ['None'] + list(df['source'].unique())
|
162 |
|
163 |
+
#########################################
|
164 |
+
## Select Main Program
|
165 |
+
|
166 |
+
with st.sidebar:
|
167 |
+
genre = st.radio(
|
168 |
+
"Choose how to explore heroes",
|
169 |
+
[":rainbow[Heroes Explorer]", "***LB/CB Hero Stat*** :movie_camera:"],
|
170 |
+
captions = ["Filter only heroes with certain properties", "Co-powered by Elioty33's DataVault"])
|
171 |
|
172 |
#########################################
|
173 |
+
## Program 1
|
174 |
+
if genre == ':rainbow[Heroes Explorer]':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
|
176 |
+
col1, col2, col3 = st.columns(3)
|
177 |
+
with col1:
|
178 |
+
st.header("Standard Filters:")
|
179 |
+
st.write("Tips: filter costume by typing ' C' or 'C2' in the Name box")
|
180 |
+
with st.expander("Filter Options"):
|
181 |
+
name_option = st.text_input(label="Name:", value="")
|
182 |
+
star_option = st.selectbox(label='Star:', options=star_values, index=0)
|
183 |
+
color_option = st.selectbox(label='Color:', options=color_values, index=0)
|
184 |
+
speed_option = st.selectbox(label='Speed:', options=speed_values, index=0)
|
185 |
+
class_option = st.selectbox(label='Class:', options=class_values, index=0)
|
186 |
+
source_option = st.selectbox(label='Origin:', options=source_values, index=0)
|
187 |
|
188 |
+
special_type_option = st.text_input(label="SpecialSkill Category", value="Hit 3")
|
189 |
+
special_text_option = st.text_input(label="SpecialSkill Text", value="Dispel")
|
190 |
+
with col2:
|
191 |
+
st.header("Stat Filters")
|
192 |
+
with st.expander("Stat Options"):
|
193 |
+
defense_option = st.text_input(label="Defense:", value="0")
|
194 |
+
attack_option = st.text_input(label="Attack:", value="0")
|
195 |
+
health_option = st.text_input(label="Health:", value="0")
|
196 |
+
with col3:
|
197 |
+
st.header("Sorted By (or directly click at the column name)")
|
198 |
+
sort_option = st.selectbox(label='Sort by', options=display_cols[1:], index=5) # default is power
|
199 |
|
200 |
+
idx_all = []
|
|
|
|
|
|
|
201 |
|
202 |
+
if name_option != '':
|
203 |
+
idx_all.append(filter_by_1col(df, 'name', name_option, exact_flag=False))
|
204 |
|
205 |
+
if star_option != 'None':
|
206 |
+
idx_all.append(filter_by_1col_num(df, 'star', star_option, oper_flag="eq"))
|
207 |
|
208 |
+
if speed_option != 'None':
|
209 |
+
idx_all.append(filter_by_1col(df, 'speed', speed_option, exact_flag=True))
|
210 |
|
211 |
+
if color_option != 'None':
|
212 |
+
idx_all.append(filter_by_1col(df, 'color', color_option, exact_flag=False))
|
213 |
|
214 |
+
if class_option != 'None':
|
215 |
+
idx_all.append(filter_by_1col(df, 'class', class_option, exact_flag=False))
|
216 |
|
217 |
+
if source_option != 'None':
|
218 |
+
idx_all.append(filter_by_1col(df, 'source', source_option, exact_flag=False))
|
|
|
219 |
|
220 |
+
if defense_option != "0":
|
221 |
+
defense_option = int(defense_option)
|
222 |
+
idx_all.append(filter_by_1col_num(df, 'defense', defense_option, oper_flag="ge"))
|
223 |
|
224 |
+
if attack_option != "0":
|
225 |
+
attack_option = int(attack_option)
|
226 |
+
idx_all.append(filter_by_1col_num(df, 'attack', attack_option, oper_flag="ge"))
|
227 |
|
228 |
+
if health_option != "0":
|
229 |
+
health_option = int(health_option)
|
230 |
+
idx_all.append(filter_by_1col_num(df, 'health', health_option, oper_flag="ge"))
|
231 |
|
232 |
+
if special_type_option != '':
|
233 |
+
idx_all.append(filter_by_1col(df, 'types', special_type_option, exact_flag=False))
|
234 |
|
235 |
+
if special_text_option != '':
|
236 |
+
idx_all.append(filter_by_1col(df, 'effects', special_text_option, exact_flag=False))
|
237 |
|
238 |
+
#########################################
|
239 |
+
st.header(f'Updated: Oct 23, 2023 -- Total heroes = {len(df)}')
|
240 |
+
|
241 |
+
df2 = df[np.all(idx_all,axis=0)]
|
242 |
+
|
243 |
+
display_heroes_from_df(df2.sort_values(sort_option, ascending=False))
|
244 |
#########################################
|
245 |
+
## Program 2
|
246 |
+
else:
|
247 |
+
df_extra = pd.read_csv("heroes_ep_extra.csv")
|
248 |
+
|
249 |
+
st.header("Analyze Hero LB/CB Stat (without Emblem)")
|
250 |
+
st.write("HeroPlan and DataVault are combined here. Thanks ***@Elioty33*** for his DataVault contribution")
|
251 |
+
st.write(f"Currently, there are {len(df_extra)} heroes having both data on HeroPlan and DataVault.")
|
252 |
+
st.write(f"We don't have emblem calculator here, you can go heroplan.io to do the job.")
|
253 |
+
st.write(f"***Heuristically*** Choose Sword-path can increase att 100-150, def 50-100, hp ~100 (reverse att-def for shield path)")
|
254 |
+
st.write(f"Choose HP-path can increase att 50-100, def 50-100, hp ~200")
|
255 |
+
|
256 |
+
|
257 |
+
name_values = sorted(list(df_extra['name'].values))
|
258 |
+
name_choice = st.selectbox(label='Hero Name:', options=name_values, index=0)
|
259 |
+
|
260 |
+
lb_list = ['None', 'LB1', 'LB2']
|
261 |
+
costume_list = return_costume_list(df_extra, name_choice)
|
262 |
|
263 |
+
lb_choice = st.selectbox(label='Limit Break:', options=lb_list, index=0)
|
264 |
+
costume_choice = st.selectbox(label='Costume:', options=costume_list, index=0)
|
265 |
|
266 |
+
df_ret = return_hero_stat(df_extra, name_choice, lb_choice=lb_choice, costume_choice=costume_choice)
|
267 |
+
display_heroes_from_df(df_ret,display_cols=df_ret.columns[:-2]) # display all except special-skill text
|
heroes_ep_extra.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|