File size: 2,296 Bytes
7d13043
 
4393140
7d13043
d200e3d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1764877
 
 
 
 
 
 
d200e3d
 
 
 
 
767d8ff
 
 
d200e3d
 
 
 
7d13043
d200e3d
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import pandas as pd
import numpy as np
import streamlit as st

# import glob
# import yaml
from pathlib import Path
from collections import defaultdict

#########################################
# Helpers Functions

def filter_by_1col(df, col_name, query, exact_flag=False):

    def check_valid_value(query, string, exact_flag=False):
        if exact_flag:
            if query.lower() == string.lower():
                return True

        elif query.lower() in string.lower():
            return True
        
        return False

    ok_flag_list = []
    assert col_name in df.columns, "col_name must be valid"

    for i, s in enumerate(df[col_name]):

        if isinstance(s, list):
            for s2 in s:
                flag = check_valid_value(query, s2, exact_flag=exact_flag)
                if flag: break
        else:
            flag = check_valid_value(query, s, exact_flag=exact_flag)

        
        ok_flag_list.append(flag)
    
    assert len(ok_flag_list) == len(df)
    return np.array(ok_flag_list)

def display_image(url, scale=0.5):
    from urllib.request import urlopen
    from PIL import Image

    image = Image.open(urlopen(url))
    st.image(image.resize(( int(image.width * scale), int(image.height * scale))))

def display_heroes_from_df(df):
    display_cols = ['image','name', 'color', 'star', 'class', 'speed', 'power', 'attack', 'defense', 'health', 'types', 'source', 'family']
    df[display_cols]
    st.dataframe(df[display_cols],
                 column_config={
                         "image": st.column_config.ImageColumn("Avatar", help="")},
                 use_container_width=True,
                 hide_index=True)

    for i in range(len(df)):
        url = df['image'].values[i]
        display_image(url)
        st.write(df['skill'].values[i])
        st.write(df['effects'].values[i])
        # for sp in df['effects'].values[i]:
        #     st.write(sp)

#########################################


df = pd.read_csv('heroes_ep.csv')

idx_all = []
idx_all.append(filter_by_1col(df, 'types', 'hit 3'))
idx_all.append(filter_by_1col(df, 'effects', 'dispel'))
idx_all.append(filter_by_1col(df, 'speed', 'fast', exact_flag=False))

df2 = df[np.all(idx_all,axis=0)]

display_heroes_from_df(df2.sort_values("power", ascending=False))