-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_grp.py
126 lines (92 loc) · 3.02 KB
/
plot_grp.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
#!/usr/bin/python
from ruis import *
if __name__ == "__main__":
#
# sqlite grab file names
#
conn = sqlite3.connect("example.db")
c = conn.cursor()
c.execute("select * from example") # filenames
rows = c.fetchall()
ana_tokens=[]
ana_struct={}
#
# grab the first row, and interprete the ntuple
#
for i in range(len(rows)):
row = rows[i]
print row
token_name = row[0]
events_fname = row[1]
rui_fname = row[2]
expertise = int(row[3])
offset = float(row[5])
ana = Analysis(token_name,
rui_fname,
events_fname,
expertise,
offset,
debug=True)
##
## bail if bad data
##
if ana.data_is_good == False: continue
##
## add tags
##
ana.add_tags("Avatar not in play", "red")
ana.add_tags("PvE Combat", "blue")
ana.add_tags("Typed communication","green")
ana.add_point_tag("Join group","black")
##
## Make any cuts
##
## cut pre-play
ana.tags_times["Avatar not in play"] = [(0, ana.tags_times["Avatar not in play"][0][1])]
#ana.add_cut( (0, ana.tags_times["Avatar not in play"][0][1]) )
#ana.cut_by_tags("Typed communication")
#cut_by_tags("PvE Combat")
#ana.cut_all_but("PvE Combat")
ana.apply_cuts()
play_time = ana.calc_play_time()
##
## make data structs for 2D plot
##
keys = ana.make_keys_hist()
spaces = []
for e in ana.events:
if e.spt[1] == "KEY" and e.spt[2] == "SPACE" and e.cut==False:
spaces.append(float(e.time))
ana_tokens.append(token_name)
ana_struct[token_name] = (keys, play_time, get_colour(expertise), spaces, ana.tags_times, ana.tags_colours, ana.events[len(ana.events)-1].time)
##
## Plots
##
fig = plt.figure( figsize=(12,0.4*len(ana_tokens)))
fig_ax = fig.add_subplot(111)
X=[]
Y=[]
for index, t in enumerate(ana_tokens):
spaces = ana_struct[t][3]
for i in spaces:
X.append(i)
Y.append(index)
times = ana_struct[t][4]
colours = ana_struct[t][5]
for k, v in times.items():
print "Adding \'"+str(k)+"\' tags"
for i in v:
fig_ax.add_patch(mpatches.Rectangle((i[0],index-0.5),i[1]-i[0],1,fill=True, alpha=0.3,color=colours[k]))
N = len(ana_tokens)
ind = np.arange(N)
fig_ax.set_yticks(ind)
fig_ax.set_yticklabels(ana_tokens)
fig_ax.set_ylim([-0.5,0.5+len(ana_tokens)-1])
max_times = []
for t in ana_tokens:
max_times.append(ana_struct[t][6])
fig_ax.set_xlim([0,max(max_times)])
plt.subplots_adjust(left=0.1,right=0.98, top=0.90, bottom=0.3)
fig_ax.set_xlabel('Time (s)')
plt.scatter(X,Y, marker='.')
plt.show()