Mercurial > hg > webaudioevaluationtool
comparison scripts/timeline_view_movement.py @ 1069:4dd1cb18b77c
Scripts: timeline_view_movement with 'playing' areas highlighted
author | Brecht De Man <BrechtDeMan@users.noreply.github.com> |
---|---|
date | Wed, 12 Aug 2015 10:31:10 +0200 |
parents | 8eb0c24ea50a |
children | a00d0c8d5c74 |
comparison
equal
deleted
inserted
replaced
1068:8eb0c24ea50a | 1069:4dd1cb18b77c |
---|---|
111 initial_position_temp = audioelement.find("./metric/metricresult/[@name='elementInitialPosition']") | 111 initial_position_temp = audioelement.find("./metric/metricresult/[@name='elementInitialPosition']") |
112 if initial_position_temp is None: | 112 if initial_position_temp is None: |
113 print "Skipping "+page_name+" from "+subject_id+": does not have initial positions specified." | 113 print "Skipping "+page_name+" from "+subject_id+": does not have initial positions specified." |
114 break | 114 break |
115 | 115 |
116 # for this audioelement, loop over all move events | 116 # get move events, initial and eventual position |
117 initial_position = float(initial_position_temp.text) | 117 initial_position = float(initial_position_temp.text) |
118 move_events = audioelement.findall("./metric/metricresult/[@name='elementTrackerFull']/timepos") | 118 move_events = audioelement.findall("./metric/metricresult/[@name='elementTrackerFull']/timepos") |
119 final_position = float(audioelement.find("./value").text) | 119 final_position = float(audioelement.find("./value").text) |
120 | 120 |
121 # get listen events | |
122 start_times_global = [] | |
123 stop_times_global = [] | |
124 listen_events = audioelement.findall("./metric/metricresult/[@name='elementListenTracker']/event") | |
125 for event in listen_events: | |
126 # get testtime: start and stop | |
127 start_times_global.append(float(event.find('testtime').get('start'))-time_offset) | |
128 stop_times_global.append(float(event.find('testtime').get('stop'))-time_offset) | |
129 | |
121 # display fragment name at start | 130 # display fragment name at start |
122 plt.text(0,initial_position+0.02,audio_id,color=colormap[increment%len(colormap)]) #,rotation=45 | 131 plt.text(0,initial_position+0.02,audio_id,color=colormap[increment%len(colormap)]) #,rotation=45 |
123 | 132 |
124 # previous position and time | 133 # previous position and time |
125 previous_position = initial_position | 134 previous_position = initial_position |
126 previous_time = 0 | 135 previous_time = 0 |
127 | 136 |
137 # assume not playing at start | |
138 currently_playing = False # keep track of whether fragment is playing during move event | |
139 | |
128 # draw all segments except final one | 140 # draw all segments except final one |
129 for event in move_events: | 141 for event in move_events: |
142 # get time and final position of move event | |
130 new_time = float(event.find("./time").text)-time_offset | 143 new_time = float(event.find("./time").text)-time_offset |
131 new_position = float(event.find("./position").text) | 144 new_position = float(event.find("./position").text) |
132 # horizontal line from previous to current time | 145 |
133 plt.plot([previous_time, new_time], # x-values | 146 # get play/stop events since last move until current move event |
147 stop_times = [] | |
148 start_times = [] | |
149 # is there a play and/or stop event between previous_time and new_time? | |
150 for time in start_times_global: | |
151 if time>previous_time and time<new_time: | |
152 start_times.append(time) | |
153 for time in stop_times_global: | |
154 if time>previous_time and time<new_time: | |
155 stop_times.append(time) | |
156 # if no play/stop events between move events, find out whether playing | |
157 | |
158 segment_start = previous_time # first segment starts at previous move event | |
159 | |
160 # draw segments (horizontal line) | |
161 while len(start_times)+len(stop_times)>0: # while still play/stop events left | |
162 if len(stop_times)<1: # upcoming event is 'play' | |
163 # draw non-playing segment from segment_start to 'play' | |
164 currently_playing = False | |
165 segment_stop = start_times.pop(0) # remove and return first item | |
166 elif len(start_times)<1: # upcoming event is 'stop' | |
167 # draw playing segment (red) from segment_start to 'stop' | |
168 currently_playing = True | |
169 segment_stop = stop_times.pop(0) # remove and return first item | |
170 elif start_times[0]<stop_times[0]: # upcoming event is 'play' | |
171 # draw non-playing segment from segment_start to 'play' | |
172 currently_playing = False | |
173 segment_stop = start_times.pop(0) # remove and return first item | |
174 else: # stop_times[0]<start_times[0]: upcoming event is 'stop' | |
175 # draw playing segment (red) from segment_start to 'stop' | |
176 currently_playing = True | |
177 segment_stop = stop_times.pop(0) # remove and return first item | |
178 | |
179 # draw segment | |
180 plt.plot([segment_start, segment_stop], # x-values | |
181 [previous_position, previous_position], # y-values | |
182 color='r' if currently_playing else colormap[increment%len(colormap)], | |
183 linewidth=3 | |
184 ) | |
185 segment_start = segment_stop # move on to next segment | |
186 currently_playing = not currently_playing # toggle to draw final segment correctly | |
187 | |
188 # draw final segment (horizontal line) from last 'segment_start' to current move event time | |
189 plt.plot([segment_start, new_time], # x-values | |
134 [previous_position, previous_position], # y-values | 190 [previous_position, previous_position], # y-values |
135 color=colormap[increment%len(colormap)], | 191 # color depends on playing during move event or not: |
192 color='r' if currently_playing else colormap[increment%len(colormap)], | |
136 linewidth=3 | 193 linewidth=3 |
137 ) | 194 ) |
195 | |
138 # vertical line from previous to current position | 196 # vertical line from previous to current position |
197 #TODO red if currently playing, orig color if not | |
139 plt.plot([new_time, new_time], # x-values | 198 plt.plot([new_time, new_time], # x-values |
140 [previous_position, new_position], # y-values | 199 [previous_position, new_position], # y-values |
141 color=colormap[increment%len(colormap)], | 200 # color depends on playing during move event or not: |
201 color='r' if currently_playing else colormap[increment%len(colormap)], | |
142 linewidth=3 | 202 linewidth=3 |
143 ) | 203 ) |
144 | 204 |
145 # update previous_position value | 205 # update previous_position value |
146 previous_position = new_position | 206 previous_position = new_position |
155 ) | 215 ) |
156 | 216 |
157 # display fragment name at end | 217 # display fragment name at end |
158 plt.text(audioholder_time-time_offset,previous_position,\ | 218 plt.text(audioholder_time-time_offset,previous_position,\ |
159 audio_id,color=colormap[increment%len(colormap)]) #,rotation=45 | 219 audio_id,color=colormap[increment%len(colormap)]) #,rotation=45 |
160 | |
161 # for this audioelement, loop over all listen events | |
162 # listen_events = audioelement.findall("./metric/metricresult/[@name='elementListenTracker']/event") | |
163 # for event in listen_events: | |
164 # # get testtime: start and stop | |
165 # start_time = float(event.find('testtime').get('start')) | |
166 # stop_time = float(event.find('testtime').get('stop')) | |
167 | |
168 | 220 |
169 increment+=1 # to next audioelement | 221 increment+=1 # to next audioelement |
170 | 222 |
171 last_audioholder_duration = audioholder_time-time_offset | 223 last_audioholder_duration = audioholder_time-time_offset |
172 time_offset = audioholder_time | 224 time_offset = audioholder_time |
185 scale_tags = root.findall("./BrowserEvalProjectDocument/audioHolder/interface/scale") | 237 scale_tags = root.findall("./BrowserEvalProjectDocument/audioHolder/interface/scale") |
186 scale_title = root.find("./BrowserEvalProjectDocument/audioHolder/interface/title") | 238 scale_title = root.find("./BrowserEvalProjectDocument/audioHolder/interface/title") |
187 for tag in scale_tags: | 239 for tag in scale_tags: |
188 label_positions.append(float(tag.get('position'))/100) # on a scale from 0 to 100 | 240 label_positions.append(float(tag.get('position'))/100) # on a scale from 0 to 100 |
189 label_text.append(tag.text) | 241 label_text.append(tag.text) |
190 if len(label_positions) > 0: | 242 if len(label_positions) > 0: # if any labels available |
191 plt.yticks(label_positions, label_text) # show rating axis labels | 243 plt.yticks(label_positions, label_text) # show rating axis labels |
192 # set label Y-axis | 244 # set label Y-axis |
193 if scale_title is not None: | 245 if scale_title is not None: |
194 plt.ylabel(scale_title.text) | 246 plt.ylabel(scale_title.text) |
195 | 247 |