comparison scripts/timeline_view.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 235594325b84
comparison
equal deleted inserted replaced
1069:4dd1cb18b77c 1070:f1201566b54b
71 # ONE TIMELINE PER PAGE - make new plot per page 71 # ONE TIMELINE PER PAGE - make new plot per page
72 72
73 # get list of all page names 73 # get list of all page names
74 for audioholder in root.findall("./audioholder"): # iterate over pages 74 for audioholder in root.findall("./audioholder"): # iterate over pages
75 page_name = audioholder.get('id') # get page name 75 page_name = audioholder.get('id') # get page name
76 plot_empty = True # check if any data is plotted
76 77
77 if page_name is None: # ignore 'empty' audio_holders 78 if page_name is None: # ignore 'empty' audio_holders
78 break 79 break
79 80
80 # SORT AUDIO ELEMENTS ALPHABETICALLY 81 # SORT AUDIO ELEMENTS ALPHABETICALLY
94 fig = plt.figure(figsize=(fig_width, fig_height)) 95 fig = plt.figure(figsize=(fig_width, fig_height))
95 ax = fig.add_subplot(111) #, aspect='equal' 96 ax = fig.add_subplot(111) #, aspect='equal'
96 97
97 # for page [page_name], print comments related to fragment [id] 98 # for page [page_name], print comments related to fragment [id]
98 for tuple in data: 99 for tuple in data:
99 audioelement = tuple[1] 100 audioelement = tuple[1]
100 if audioelement is not None: # Check it exists 101 if audioelement is not None: # Check it exists
101 audio_id = str(audioelement.get('id')) 102 audio_id = str(audioelement.get('id'))
102 audioelements_names.append(audio_id) 103 audioelements_names.append(audio_id)
103 104
104 # for this audioelement, loop over all listen events 105 # for this audioelement, loop over all listen events
105 listen_events = audioelement.findall("./metric/metricresult/[@name='elementListenTracker']/event") 106 listen_events = audioelement.findall("./metric/metricresult/[@name='elementListenTracker']/event")
106 for event in listen_events: 107 for event in listen_events:
108 # mark this plot as not empty
109 plot_empty = False
110
107 # get testtime: start and stop 111 # get testtime: start and stop
108 start_time = float(event.find('testtime').get('start'))-time_offset 112 start_time = float(event.find('testtime').get('start'))-time_offset
109 stop_time = float(event.find('testtime').get('stop'))-time_offset 113 stop_time = float(event.find('testtime').get('stop'))-time_offset
110 # event lines: 114 # event lines:
111 ax.plot([start_time, start_time], # x-values 115 ax.plot([start_time, start_time], # x-values
131 # subtract total audioholder length from subsequent audioholder event times 135 # subtract total audioholder length from subsequent audioholder event times
132 audioholder_time = audioholder.find("./metric/metricresult/[@id='testTime']") 136 audioholder_time = audioholder.find("./metric/metricresult/[@id='testTime']")
133 if audioholder_time is not None and show_audioholder_time: 137 if audioholder_time is not None and show_audioholder_time:
134 time_offset = float(audioholder_time.text) 138 time_offset = float(audioholder_time.text)
135 139
136 # set plot parameters 140 if not plot_empty:
137 plt.title('Timeline ' + file + ": "+page_name) 141 # set plot parameters
138 plt.xlabel('Time [seconds]') 142 plt.title('Timeline ' + file + ": "+page_name)
139 plt.ylabel('Fragment') 143 plt.xlabel('Time [seconds]')
140 plt.ylim(0, N_audioelements+1) 144 plt.ylabel('Fragment')
145 plt.ylim(0, N_audioelements+1)
141 146
142 #y-ticks: fragment IDs, top to bottom 147 #y-ticks: fragment IDs, top to bottom
143 plt.yticks(range(N_audioelements, 0, -1), audioelements_names) # show fragment names 148 plt.yticks(range(N_audioelements, 0, -1), audioelements_names) # show fragment names
144 149
145 150
146 #plt.show() # uncomment to show plot; comment when just saving 151 #plt.show() # uncomment to show plot; comment when just saving
147 #exit() 152 #exit()
148 153
149 plt.savefig(timeline_folder+subject_id+"-"+page_name+".pdf", bbox_inches='tight') 154 plt.savefig(timeline_folder+subject_id+"-"+page_name+".pdf", bbox_inches='tight')
150 plt.close() 155 plt.close()
151 156
152 #TODO: if 'nonsensical' or unknown: dashed line until next event 157 #TODO: if 'nonsensical' or unknown: dashed line until next event
153 #TODO: Vertical lines for fragment looping point 158 #TODO: Vertical lines for fragment looping point
154 159