-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappWardObjectives.py
151 lines (107 loc) · 3.84 KB
/
appWardObjectives.py
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import streamlit as st
import requests
import io
from io import BytesIO
from PIL import Image
import matplotlib.pyplot as plt
#this line must come first
#st.set_page_config(layout="wide")
### DEFINE FUNCTIONS TO HELP WITH LOADING DATA ###
@st.cache(persist=True)
def load_invalid_combos():
"""
Loads invalid combos from public S3 bucket
"""
#get the response URL
response = requests.get('https://nadim-kawwa-dota-bucket.s3.us-west-2.amazonaws.com/invalid_cases.txt')
#store text
text = response.text
#separate by new line character
invalid_combos = text.split('\n')
return invalid_combos
@st.cache(persist=True)
def load_tower_image(combo):
"""
Loads the image associated with a tower combo
"""
img_url = ''.join(['https://nadim-kawwa-dota-bucket.s3.us-west-2.amazonaws.com/',
combo,
'.png'])
img_response = requests.get(img_url)
combo_img = Image.open(BytesIO(img_response.content))
return combo_img
@st.cache(persist=True)
def load_rosh_image(rosh_attempt):
"""
Loads the warding in the upper left quadrant
"""
img_url = ''.join(['https://nadim-kawwa-dota-bucket.s3.us-west-2.amazonaws.com/rosh_attempt_0',
str(rosh_attempt),
'.png'])
img_response = requests.get(img_url)
rosh_img = Image.open(BytesIO(img_response.content))
return rosh_img
### BEGIN CALLING FUNCTIONS HERE ###
st.title('DOTA2 Wards & Objectives')
st.subheader('An Interactive Tool To Explore Warding')
st.write('Select the most recently captured objective for each lane. A value of zero means that the tower is still alive.')
st.write('Scroll down to explore warding related to Roshan.')
#load invalid cases
invalid_combos = load_invalid_combos()
# ASK FOR USER INPUT #
rad_top = st.slider(label = 'Radiant Top',
min_value=0,
max_value=3,
value=1,
step=1)
rad_mid = st.slider(label = 'Radiant Mid',
min_value=0,
max_value=3,
value=1,
step=1)
rad_bot = st.slider(label = 'Radiant Bot',
min_value=0,
max_value=3,
value=1,
step=1)
dir_top = st.slider(label = 'Dire Top',
min_value=0,
max_value=3,
value=1,
step=1)
dir_mid = st.slider(label = 'Dire Mid',
min_value=0,
max_value=3,
value=1,
step=1)
dir_bot = st.slider(label = 'Dire Bot',
min_value=0,
max_value=3,
value=1,
step=1)
#make tuple from user input
user_input_tuple = (rad_top,
rad_mid,
rad_bot,
dir_top,
dir_mid,
dir_bot)
#convert each element to string
combo_string_tuple = tuple((str(x) for x in user_input_tuple))
#convert to combo
combo = '_'.join([a+b for a,b in zip('ABCDEF', combo_string_tuple)])
if st.button('Show Wards for Towers'):
if combo in invalid_combos:
st.write("Not enough data and/or invalid combo! Try again.")
else:
#st.write(combo)
combo_img = load_tower_image(combo)
st.image(combo_img)
rosh_attempt = st.slider(label = 'Roshan Attempt Number',
min_value=1,
max_value=3,
value=1,
step=1)
if st.button('Show Wards for Roshan'):
rosh_img = load_rosh_image(rosh_attempt)
st.image(rosh_img)