-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_process_function.py
134 lines (114 loc) · 6.08 KB
/
data_process_function.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
# 1. 这一部分主要计算区间的fixation总数、duration的总和,平均duration
import numpy as np
def calculate_fixation_count(df):
result = (df[df['Eye movement type'] == 'Fixation'].groupby(['Presented Stimulus name', 'Participant name'])
['Eye movement type index'].agg(lambda x: x.max() - x.min() + 1)
.astype(int)
.reset_index())
result.columns = ['Presented Stimulus name',
'Participant name', 'Fixation count']
result.set_index(['Presented Stimulus name',
'Participant name'], inplace=True)
return result
def calculate_duration_count(df):
result = (df[df['Eye movement type'] == 'Fixation'].groupby(['Presented Stimulus name', 'Participant name', 'Eye movement type index'])['Gaze event duration'].unique()
.apply(lambda x: np.sum(x))
.groupby(['Presented Stimulus name', 'Participant name'])
.sum()
.astype(int)
.reset_index())
result.columns = ['Presented Stimulus name',
'Participant name', 'Count duration']
result.set_index(['Presented Stimulus name',
'Participant name'], inplace=True)
return result
def calculate_duration_mean(df):
result = (df[df['Eye movement type'] == 'Fixation'].groupby(['Presented Stimulus name', 'Participant name', 'Eye movement type index'])['Gaze event duration'].unique()
.apply(lambda x: np.sum(x))
.groupby(['Presented Stimulus name', 'Participant name'])
.mean()
.round(3) # 保留三位小数
.astype(float)
.reset_index())
result.columns = ['Presented Stimulus name',
'Participant name', 'Mean duration']
result.set_index(['Presented Stimulus name',
'Participant name'], inplace=True)
return result
def calculate_pupil_diameter_mean(df):
result = (df.groupby(['Presented Stimulus name', 'Participant name'])[['Pupil diameter left', 'Pupil diameter right']]
.mean()
.astype(float)
.reset_index())
result['pupil diameter mean'] = result[['Pupil diameter left',
'Pupil diameter right']].mean(axis=1).round(3) # 新增一个计算平均值的步骤
result.drop(['Pupil diameter left', 'Pupil diameter right'],
axis=1, inplace=True) # 删除原有的字段
result.set_index(['Presented Stimulus name',
'Participant name'], inplace=True)
return result
def calculate_pupil_diameter_max(df):
result = (df.groupby(['Presented Stimulus name', 'Participant name'])[['Pupil diameter left', 'Pupil diameter right']]
.max()
.astype(float)
.reset_index())
result['pupil diameter max'] = result[['Pupil diameter left',
'Pupil diameter right']].max(axis=1).round(3) # 新增一个计算平均值的步骤
result.drop(['Pupil diameter left', 'Pupil diameter right'],
axis=1, inplace=True) # 删除原有的字段
result.set_index(['Presented Stimulus name',
'Participant name'], inplace=True)
return result
def calculate_pupil_diameter_min(df):
result = (df.groupby(['Presented Stimulus name', 'Participant name'])[['Pupil diameter left', 'Pupil diameter right']]
.min()
.astype(float)
.reset_index())
result['pupil diameter min'] = result[['Pupil diameter left',
'Pupil diameter right']].min(axis=1).round(3) # 新增一个计算平均值的步骤
result.drop(['Pupil diameter left', 'Pupil diameter right'],
axis=1, inplace=True) # 删除原有的字段
result.set_index(['Presented Stimulus name',
'Participant name'], inplace=True)
return result
def calculate_fixation_count_aoi(df):
result = (df[df['Eye movement type'] == 'Fixation'].groupby(['Presented Stimulus name', 'Participant name', 'Ungrouped'])
['Eye movement type index'].agg(lambda x: x.max() - x.min() + 1)
.astype(int)
.reset_index())
result.columns = ['Presented Stimulus name',
'Participant name', 'Aoi type', 'Aoi fixation count']
result.set_index(['Presented Stimulus name',
'Participant name'], inplace=True)
return result
def calculate_duration_count_aoi(df):
result = (df[df['Eye movement type'] == 'Fixation']
.groupby(['Presented Stimulus name', 'Participant name', 'Ungrouped', 'Eye movement type index'])['Gaze event duration']
.unique()
.apply(lambda x: x[0])
.reset_index()
.groupby(['Presented Stimulus name', 'Participant name', 'Ungrouped'])['Gaze event duration']
.sum()
.astype(int)
.reset_index())
result.columns = ['Presented Stimulus name',
'Participant name', 'Ungrouped', 'Aoi duration sum']
result.set_index(['Presented Stimulus name',
'Participant name'], inplace=True)
return result
def calculate_duration_mean_aoi(df):
result = (df[df['Eye movement type'] == 'Fixation']
.groupby(['Presented Stimulus name', 'Participant name', 'Ungrouped', 'Eye movement type index'])['Gaze event duration']
.unique()
.apply(lambda x: x[0])
.reset_index()
.groupby(['Presented Stimulus name', 'Participant name', 'Ungrouped'])['Gaze event duration']
.mean()
.round(3)
.astype(float)
.reset_index())
result.columns = ['Presented Stimulus name',
'Participant name', 'Ungrouped', 'Aoi duration mean']
result.set_index(['Presented Stimulus name',
'Participant name'], inplace=True)
return result