# HG changeset patch # User Brecht De Man # Date 1439368270 -7200 # Node ID 4dd1cb18b77cb100618e2fe867f8754718a79294 # Parent 8eb0c24ea50abf1a2e7b38c5591e8bce907ee1d0 Scripts: timeline_view_movement with 'playing' areas highlighted diff -r 8eb0c24ea50a -r 4dd1cb18b77c scripts/timeline_view.py --- a/scripts/timeline_view.py Tue Aug 11 20:49:34 2015 +0200 +++ b/scripts/timeline_view.py Wed Aug 12 10:31:10 2015 +0200 @@ -105,21 +105,21 @@ listen_events = audioelement.findall("./metric/metricresult/[@name='elementListenTracker']/event") for event in listen_events: # get testtime: start and stop - start_time = float(event.find('testtime').get('start')) - stop_time = float(event.find('testtime').get('stop')) + start_time = float(event.find('testtime').get('start'))-time_offset + stop_time = float(event.find('testtime').get('stop'))-time_offset # event lines: - ax.plot([start_time-time_offset, start_time-time_offset], # x-values + ax.plot([start_time, start_time], # x-values [0, N_audioelements+1], # y-values color='k' ) - ax.plot([stop_time-time_offset, stop_time-time_offset], # x-values + ax.plot([stop_time, stop_time], # x-values [0, N_audioelements+1], # y-values color='k' ) # plot time: ax.add_patch( patches.Rectangle( - (start_time-time_offset, N_audioelements-increment-bar_height/2), # (x, y) + (start_time, N_audioelements-increment-bar_height/2), # (x, y) stop_time - start_time, # width bar_height, # height color=colormap[increment%len(colormap)] # colour diff -r 8eb0c24ea50a -r 4dd1cb18b77c scripts/timeline_view_movement.py --- a/scripts/timeline_view_movement.py Tue Aug 11 20:49:34 2015 +0200 +++ b/scripts/timeline_view_movement.py Wed Aug 12 10:31:10 2015 +0200 @@ -113,11 +113,20 @@ print "Skipping "+page_name+" from "+subject_id+": does not have initial positions specified." break - # for this audioelement, loop over all move events + # get move events, initial and eventual position initial_position = float(initial_position_temp.text) move_events = audioelement.findall("./metric/metricresult/[@name='elementTrackerFull']/timepos") final_position = float(audioelement.find("./value").text) + # get listen events + start_times_global = [] + stop_times_global = [] + listen_events = audioelement.findall("./metric/metricresult/[@name='elementListenTracker']/event") + for event in listen_events: + # get testtime: start and stop + start_times_global.append(float(event.find('testtime').get('start'))-time_offset) + stop_times_global.append(float(event.find('testtime').get('stop'))-time_offset) + # display fragment name at start plt.text(0,initial_position+0.02,audio_id,color=colormap[increment%len(colormap)]) #,rotation=45 @@ -125,20 +134,71 @@ previous_position = initial_position previous_time = 0 + # assume not playing at start + currently_playing = False # keep track of whether fragment is playing during move event + # draw all segments except final one for event in move_events: + # get time and final position of move event new_time = float(event.find("./time").text)-time_offset new_position = float(event.find("./position").text) - # horizontal line from previous to current time - plt.plot([previous_time, new_time], # x-values + + # get play/stop events since last move until current move event + stop_times = [] + start_times = [] + # is there a play and/or stop event between previous_time and new_time? + for time in start_times_global: + if time>previous_time and timeprevious_time and time0: # while still play/stop events left + if len(stop_times)<1: # upcoming event is 'play' + # draw non-playing segment from segment_start to 'play' + currently_playing = False + segment_stop = start_times.pop(0) # remove and return first item + elif len(start_times)<1: # upcoming event is 'stop' + # draw playing segment (red) from segment_start to 'stop' + currently_playing = True + segment_stop = stop_times.pop(0) # remove and return first item + elif start_times[0] 0: + if len(label_positions) > 0: # if any labels available plt.yticks(label_positions, label_text) # show rating axis labels # set label Y-axis if scale_title is not None: