-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChairGamedataProcessing.py
118 lines (80 loc) · 3.43 KB
/
ChairGamedataProcessing.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 numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import os
import joblib
from utils import normalize_MPU9250_data, split_df
# from ChairAnalyzerOld import ChairAnalyser
from datetime import datetime
plt.interactive(True)
pd.options.display.max_columns = 15
pic_prefix = 'pic/'
data_path = 'Anonimised Data/Data'
processed_data_path = 'data/players_data_processed'
# data_dict = joblib.load('data/data_dict')
sessions_dict = joblib.load('data/sessions_dict')
gamedata_dict = joblib.load('data/gamedata_dict')
common_keys = set(sessions_dict.keys()) & set(gamedata_dict.keys())
game_events_features_dict = {}
for session_id in common_keys:
if 'schairlog' not in sessions_dict[session_id]:
continue
schairlog = sessions_dict[session_id]['schairlog'].copy()
times_is_killed = gamedata_dict[session_id]['times_is_killed']
times_kills = gamedata_dict[session_id]['times_kills']
# schairlog['time'] = pd.to_datetime(schairlog['time']).apply(lambda x: x.timestamp())
# times_is_killed = [x.timestamp() for x in pd.to_datetime(times_is_killed)]
# times_kills = [x.timestamp() for x in pd.to_datetime(times_kills)]
# time_start = 0
# time_end = 5
duration = 3
time_start_end_list = [(0, duration), (-duration, 0), (-duration, duration)]
sensors_list = ['acc_x', 'acc_y', 'acc_z', 'gyro_x', 'gyro_y', 'gyro_z']
# for time_kills in times_kills:
event_reactions_dict = {}
for times_list, times_name in zip([times_is_killed, times_kills], ['times_is_killed', 'times_kills']):
for time_start, time_end in time_start_end_list:
name = f"{times_name}_{time_start}_{time_end}"
std_list = []
for time_event in times_list:
timediff = schairlog['time'] - time_event
mask = (time_start <= timediff) & (timediff < time_end)
std = schairlog.loc[mask, sensors_list].std() # TODO: consider other sensors
std_list.append(std)
reaction_stats = pd.DataFrame(std_list).median() # It should be compared with mean std on the chair
event_reactions_dict[name] = reaction_stats
df_event_reactions = pd.DataFrame(event_reactions_dict) #.round(4).values
features_dict = {}
for sensor_name in df_event_reactions.index:
for column in df_event_reactions.columns:
feature_name = f"{sensor_name}__{column}"
features_dict[feature_name] = df_event_reactions.loc[sensor_name, column]
### KDA-like objectives
n_deaths = len(times_is_killed)
n_kills = len(times_kills)
n_deaths = max(n_deaths, 0.001) # bound
kill_death_ratio = min(n_kills / n_deaths, 10)
features_dict['Kill Death Ratio'] = kill_death_ratio
# features_dict['kill_death_ratio'] = kill_death_ratio
game_events_features_dict[session_id] = features_dict
df_game_events_features = pd.DataFrame(game_events_features_dict).T
df_game_events_features.reset_index(inplace=True)
df_game_events_features.rename(columns={'index': 'session_id'}, inplace=True)
df_game_events_features.to_csv('data/game_events_features.csv', index=False)
# schairlog['acc_x'].std()
#
#
# schairlog['time'] = pd.to_datetime(schairlog['time'])
# schairlog_ = schairlog.set_index(['time'])
#
#
# index_sample = schairlog_.index[5]
#
# schairlog_.loc[schairlog_.index < index_sample, :]
#
#
# schairlog['time'].iloc[0]
#
# data_dict.keys()
# gamedata_dict.keys()