Mercurial > hg > webaudioevaluationtool
comparison scripts/timeline_view_movement.py @ 1070:f1201566b54b
Scripts: modification to timeline plots: do not save (/show) plot if empty, e.g. legacy result files with no timing data
author | Brecht De Man <BrechtDeMan@users.noreply.github.com> |
---|---|
date | Mon, 17 Aug 2015 18:20:30 +0200 |
parents | 4dd1cb18b77c |
children | 7576a4957680 |
comparison
equal
deleted
inserted
replaced
1069:4dd1cb18b77c | 1070:f1201566b54b |
---|---|
67 # ONE TIMELINE PER PAGE - make new plot per page | 67 # ONE TIMELINE PER PAGE - make new plot per page |
68 | 68 |
69 # get list of all page names | 69 # get list of all page names |
70 for audioholder in root.findall("./audioholder"): # iterate over pages | 70 for audioholder in root.findall("./audioholder"): # iterate over pages |
71 page_name = audioholder.get('id') # get page name | 71 page_name = audioholder.get('id') # get page name |
72 plot_empty = True # check if any data is plotted | |
72 | 73 |
73 if page_name is None: # ignore 'empty' audio_holders | 74 if page_name is None: # ignore 'empty' audio_holders |
74 print "Skipping empty audioholder name from "+subject_id+"." | 75 print "Skipping empty audioholder name from "+subject_id+"." |
75 break | 76 break |
76 | 77 |
137 # assume not playing at start | 138 # assume not playing at start |
138 currently_playing = False # keep track of whether fragment is playing during move event | 139 currently_playing = False # keep track of whether fragment is playing during move event |
139 | 140 |
140 # draw all segments except final one | 141 # draw all segments except final one |
141 for event in move_events: | 142 for event in move_events: |
143 # mark this plot as not empty | |
144 plot_empty = False | |
145 | |
142 # get time and final position of move event | 146 # get time and final position of move event |
143 new_time = float(event.find("./time").text)-time_offset | 147 new_time = float(event.find("./time").text)-time_offset |
144 new_position = float(event.find("./position").text) | 148 new_position = float(event.find("./position").text) |
145 | 149 |
146 # get play/stop events since last move until current move event | 150 # get play/stop events since last move until current move event |
221 increment+=1 # to next audioelement | 225 increment+=1 # to next audioelement |
222 | 226 |
223 last_audioholder_duration = audioholder_time-time_offset | 227 last_audioholder_duration = audioholder_time-time_offset |
224 time_offset = audioholder_time | 228 time_offset = audioholder_time |
225 | 229 |
226 | 230 if not plot_empty: # if plot is not empty, show or store |
227 # set plot parameters | 231 # set plot parameters |
228 plt.title('Timeline ' + file + ": "+page_name) | 232 plt.title('Timeline ' + file + ": "+page_name) |
229 plt.xlabel('Time [seconds]') | 233 plt.xlabel('Time [seconds]') |
230 plt.xlim(0, last_audioholder_duration) | 234 plt.xlim(0, last_audioholder_duration) |
231 plt.ylabel('Rating') # default | 235 plt.ylabel('Rating') # default |
232 plt.ylim(0, 1) # rating between 0 and 1 | 236 plt.ylim(0, 1) # rating between 0 and 1 |
233 | 237 |
234 #y-ticks: labels on rating axis | 238 #y-ticks: labels on rating axis |
235 label_positions = [] | 239 label_positions = [] |
236 label_text = [] | 240 label_text = [] |
237 scale_tags = root.findall("./BrowserEvalProjectDocument/audioHolder/interface/scale") | 241 scale_tags = root.findall("./BrowserEvalProjectDocument/audioHolder/interface/scale") |
238 scale_title = root.find("./BrowserEvalProjectDocument/audioHolder/interface/title") | 242 scale_title = root.find("./BrowserEvalProjectDocument/audioHolder/interface/title") |
239 for tag in scale_tags: | 243 for tag in scale_tags: |
240 label_positions.append(float(tag.get('position'))/100) # on a scale from 0 to 100 | 244 label_positions.append(float(tag.get('position'))/100) # on a scale from 0 to 100 |
241 label_text.append(tag.text) | 245 label_text.append(tag.text) |
242 if len(label_positions) > 0: # if any labels available | 246 if len(label_positions) > 0: # if any labels available |
243 plt.yticks(label_positions, label_text) # show rating axis labels | 247 plt.yticks(label_positions, label_text) # show rating axis labels |
244 # set label Y-axis | 248 # set label Y-axis |
245 if scale_title is not None: | 249 if scale_title is not None: |
246 plt.ylabel(scale_title.text) | 250 plt.ylabel(scale_title.text) |
247 | 251 |
248 #plt.show() # uncomment to show plot; comment when just saving | 252 #plt.show() # uncomment to show plot; comment when just saving |
249 #exit() | 253 #exit() |
250 | 254 |
251 plt.savefig(timeline_folder+subject_id+"-"+page_name+".pdf", bbox_inches='tight') | 255 plt.savefig(timeline_folder+subject_id+"-"+page_name+".pdf", bbox_inches='tight') |
252 plt.close() | 256 plt.close() |
253 | 257 |