Mercurial > hg > webaudioevaluationtool
comparison python/timeline_view.py @ 2276:3004c6a5665c
timeline_view, timeline_view_movement: fix negative time issue (updated to new specification)
author | Brecht De Man <b.deman@qmul.ac.uk> |
---|---|
date | Wed, 20 Apr 2016 20:20:23 +0200 |
parents | 2b5990868aa7 |
children | 185232d01324 |
comparison
equal
deleted
inserted
replaced
2274:2b5990868aa7 | 2276:3004c6a5665c |
---|---|
40 plt.rc('font', **font) | 40 plt.rc('font', **font) |
41 | 41 |
42 # Colormap for to cycle through | 42 # Colormap for to cycle through |
43 colormap = ['b', 'r', 'g', 'c', 'm', 'y', 'k'] | 43 colormap = ['b', 'r', 'g', 'c', 'm', 'y', 'k'] |
44 | 44 |
45 # if enabled, x-axis shows time per audioholder, not total test time | |
46 show_audioholder_time = True | |
47 | |
48 # bar height (<1 to avoid overlapping) | 45 # bar height (<1 to avoid overlapping) |
49 bar_height = 0.6 | 46 bar_height = 0.6 |
50 | 47 |
51 # figure size | 48 # figure size |
52 fig_width = 25 | 49 fig_width = 25 |
63 for file in os.listdir(folder_name): | 60 for file in os.listdir(folder_name): |
64 if file.endswith(".xml"): | 61 if file.endswith(".xml"): |
65 tree = ET.parse(folder_name + '/' + file) | 62 tree = ET.parse(folder_name + '/' + file) |
66 root = tree.getroot() | 63 root = tree.getroot() |
67 subject_id = file[:-4] # drop '.xml' | 64 subject_id = file[:-4] # drop '.xml' |
68 | |
69 time_offset = 0 # test starts at zero | |
70 | 65 |
71 # ONE TIMELINE PER PAGE - make new plot per page | 66 # ONE TIMELINE PER PAGE - make new plot per page |
72 | 67 |
73 # get list of all page names | 68 # get list of all page names |
74 for audioholder in root.findall("./page"): # iterate over pages | 69 for audioholder in root.findall("./page"): # iterate over pages |
111 for event in listen_events: | 106 for event in listen_events: |
112 # mark this plot as not empty | 107 # mark this plot as not empty |
113 plot_empty = False | 108 plot_empty = False |
114 | 109 |
115 # get testtime: start and stop | 110 # get testtime: start and stop |
116 start_time = float(event.find('testtime').get('start'))-time_offset | 111 start_time = float(event.find('testtime').get('start')) |
117 stop_time = float(event.find('testtime').get('stop'))-time_offset | 112 stop_time = float(event.find('testtime').get('stop')) |
118 # event lines: | 113 # event lines: |
119 ax.plot([start_time, start_time], # x-values | 114 ax.plot([start_time, start_time], # x-values |
120 [0, N_audioelements+1], # y-values | 115 [0, N_audioelements+1], # y-values |
121 color='k' | 116 color='k' |
122 ) | 117 ) |
133 color=colormap[increment%len(colormap)] # colour | 128 color=colormap[increment%len(colormap)] # colour |
134 ) | 129 ) |
135 ) | 130 ) |
136 | 131 |
137 increment+=1 # to next audioelement | 132 increment+=1 # to next audioelement |
138 | |
139 # subtract total audioholder length from subsequent audioholder event times | |
140 audioholder_time = audioholder.find("./metric/metricresult/[@id='testTime']") | |
141 if audioholder_time is not None and show_audioholder_time: | |
142 time_offset = float(audioholder_time.text) | |
143 | 133 |
144 if not plot_empty: | 134 if not plot_empty: |
145 # set plot parameters | 135 # set plot parameters |
146 plt.title('Timeline ' + file + ": "+page_name) | 136 plt.title('Timeline ' + file + ": "+page_name) |
147 plt.xlabel('Time [seconds]') | 137 plt.xlabel('Time [seconds]') |
149 plt.ylim(0, N_audioelements+1) | 139 plt.ylim(0, N_audioelements+1) |
150 | 140 |
151 #y-ticks: fragment IDs, top to bottom | 141 #y-ticks: fragment IDs, top to bottom |
152 plt.yticks(range(N_audioelements, 0, -1), audioelements_names) # show fragment names | 142 plt.yticks(range(N_audioelements, 0, -1), audioelements_names) # show fragment names |
153 | 143 |
154 | |
155 #plt.show() # uncomment to show plot; comment when just saving | 144 #plt.show() # uncomment to show plot; comment when just saving |
156 #exit() | 145 #exit() |
157 | 146 |
158 plt.savefig(timeline_folder+subject_id+"-"+page_name+".pdf", bbox_inches='tight') | 147 plt.savefig(timeline_folder+subject_id+"-"+page_name+".pdf", bbox_inches='tight') |
159 plt.close() | 148 plt.close() |