This repository has been archived by the owner on Sep 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web_visual.py
110 lines (92 loc) · 3.55 KB
/
web_visual.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
import streamlit as st
import pandas as pd
import numpy as np
import os
import matplotlib.pyplot as plt
from meta_data import map_names, maps_data, vehicle_types, vehicle_types_data
from matplotlib.colors import Normalize
import scipy.stats as stat
from scipy import interpolate
from PIL import Image
def density(data, bandwidth):
x = data['x']
y = data['z']
#TO-DO: getting size from data
xmin = -500.0
xmax = 500.0
ymin = -500.0
ymax = 500.0
X, Y = np.mgrid[xmin:xmax:25j, ymin:ymax:25j]
positions = np.vstack([X.ravel(), Y.ravel()])
values = np.vstack([x, y])
try:
kernel = stat.gaussian_kde(values)
kernel.set_bandwidth(bw_method=kernel.factor / bandwidth)
Z = np.reshape(kernel(positions).T, X.shape)
except:
return None
Z = np.rot90(Z)
vmax = np.abs(Z).max()
vmin = np.abs(Z).min()
cmap = plt.cm.jet
# Normalize the colors b/w 0 and 1
colors_norm = Normalize(vmin, vmax, clip=True)(Z)
colors = cmap(colors_norm)
# Now set the alpha channel
colors[..., -1] = colors_norm
return [colors,[xmin, xmax, ymin, ymax]]
@st.cache
def load_data(map_name):
try:
file_path = 'https://wothub-data.s3.amazonaws.com/' + map_name + '.csv'
df = pd.read_csv(file_path)
#df = df.loc[(df['map_name'] == map_name),:] # FLAG Create local division
except:
return pd.DataFrame([])
return df
@st.cache
def load_img(map_name):
dir_path = os.path.dirname(os.path.realpath(__file__))
img_dir = os.path.join(dir_path,'maps/images')
img_path = os.path.join(img_dir, map_name + '.png')
img = plt.imread(img_path)
return img
st.sidebar.title("WotHub")
st.sidebar.markdown('World of Tanks players position predictor')
# choose parameters
map_to_filter = st.sidebar.selectbox('Map', map_names, index = 0)
team_to_filter = st.sidebar.radio('Team', (1,2))
levels_to_filter = st.sidebar.slider('Levels', 1, 10, (6,8))
types_to_filter = st.sidebar.multiselect('Type', vehicle_types, vehicle_types[0])
time_input = st.sidebar.text_input("Time left: ", value = '13:30')
time = time_input.split(':')
time = int(time[0]) * 60 + int(time[1])
time = 900 - time
if time > 900 or time < 0:
time = 300
bandwidth_to_filter = st.sidebar.slider('Bandwidth', 1., 5., 2.)
st.sidebar.markdown('Made by [Pavel Tarashkevich](https://github.com/pashok3d)')
df = load_data(maps_data[map_to_filter])
img = load_img(maps_data[map_to_filter])
if not df.empty:
type_bit_map = np.full(np.shape(df['type']), False)
for type in types_to_filter:
type_bit_map = np.asarray((type_bit_map) | (df['type'] == vehicle_types_data[type]))
data_choice = df.loc[(df['team'] == team_to_filter) &
(df['clock'] == time) &
(type_bit_map) &
(df['tier'] >= levels_to_filter[0]) & (df['tier'] <= levels_to_filter[1])]
if not data_choice.empty:
color_map = density(data_choice, bandwidth_to_filter)
if color_map:
background = Image.fromarray(np.uint8(img*255))
density_map = Image.fromarray(np.uint8(color_map[0]*255))
density_map = density_map.resize((512,512))
background.paste(density_map, (0, 0), density_map)
st.image(background, use_column_width=True)
else:
st.text('Not enough data, try to change filter parameters.')
else:
st.text('No data, try to change filter parameters.')
else:
st.text('Failed to load data.')