-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer_info.py
87 lines (68 loc) · 3.67 KB
/
player_info.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
import attr
import numpy as np
import pandas as pd
import queries
# NOTE This is currently deprecated due to table format being changed, but something similar will be needed in the future
@attr.s
class player:
# Holds player data
# Attributes:
# name: name of the player
# games_id: a pandas dataframe that contains the games that the player is involved in as well as their in game id
# snapshots: a pandas dataframe that contains the snapshots of the current player, i.e. location, angle, HP, armor
# ticks: a pandas dataframe that contains all ticks that involve the current player, i.e. shot, got shot, etc
name = attr.ib(default = attr.Factory(str))
games_id = attr.ib(default = attr.Factory(pd.DataFrame))
snapshots = attr.ib(default = attr.Factory(pd.DataFrame))
ticks = attr.ib(default = attr.Factory(pd.DataFrame))
### functions for populating player attributes
# populate the games_id attribute
def populate_games_id(self):
player_query = queries.queries()
player_query.entities_player_query(self.name)
self.games_id = player_query.execute_query()
# populate the snapshots attribute with all games that the player is involved in
def populate_snapshots(self):
snapshots_query = queries.queries()
for index, row in self.games_id.iterrows(): # this loop goes through all the games the player is involved in
snapshots_query.snapshots_game_player_query(row["id"], row["player_id"])
cur_game_snapshots = snapshots_query.execute_query()
if index == 0:
self.snapshots = cur_game_snapshots
else:
self.snapshots.append(cur_game_snapshots)
# populate the ticks attribute with all games that the player is involed in
def populate_ticks(self):
ticks_query = queries.queries()
for index, row in self.games_id.iterrows(): # this loop goes through all the games the player is involved in
ticks_query.ticks_game_player_query(row["id"], row["player_id"])
cur_game_ticks = ticks_query.execute_query()
if index == 0:
self.ticks = cur_game_ticks
else:
self.ticks.append(cur_game_ticks)
### player statistics, only call these if the populate functions have been ran
# propotion of times that the player was the fire_entity where the hurt_entity was non-empty
def shoot_accuracy(self):
per_game_accuracy = []
for _, row in self.games_id.iterrows(): # this loop goes through all the games the player is involved in
cur_fire_ticks = (self.ticks).loc[(self.ticks['id'].astype(str) == str(row['id'])) &
(self.ticks['fire_entity'].astype(str) == str(row['player_id']))]
miss_prop = np.mean(cur_fire_ticks['hurt_entity'] == '') # empty hurt_entity means shot missed
per_game_accuracy.append(1 - miss_prop)
return np.array(per_game_accuracy)
# conditioning:
# role
# combat stats when playing down/up in terms of team equipment values
# sub-idea, stats when engaging 1v1 against opponent with superior/inferior equipment
# combat stats at different distances
# shooting, clear line of sight, through smoke, through obstacle
# location/scenario specific, e.g. entering/defending A site
# defending vs entering equal or unequal numbers
# stats:
# accuracy
# add something smoke related, the number opponent vision obscured (meh)
# incendiary/molotov, path blocked, damage done
# net +/-
# some measure of "value" given value of equipment
# success probability under certain scenarios