changeset 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 372a355779de df459c20946e
files python/timeline_view.py python/timeline_view_movement.py
diffstat 2 files changed, 13 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/python/timeline_view.py	Wed Apr 20 19:12:16 2016 +0200
+++ b/python/timeline_view.py	Wed Apr 20 20:20:23 2016 +0200
@@ -42,9 +42,6 @@
 # Colormap for to cycle through
 colormap = ['b', 'r', 'g', 'c', 'm', 'y', 'k']
 
-# if enabled, x-axis shows time per audioholder, not total test time
-show_audioholder_time = True
-
 # bar height (<1 to avoid overlapping)
 bar_height = 0.6
 
@@ -66,8 +63,6 @@
         root = tree.getroot()
         subject_id = file[:-4] # drop '.xml'
         
-        time_offset = 0 # test starts at zero
-        
         # ONE TIMELINE PER PAGE - make new plot per page
 
         # get list of all page names
@@ -113,8 +108,8 @@
                         plot_empty = False
                     
                         # get testtime: start and stop
-                        start_time = float(event.find('testtime').get('start'))-time_offset
-                        stop_time  = float(event.find('testtime').get('stop'))-time_offset
+                        start_time = float(event.find('testtime').get('start'))
+                        stop_time  = float(event.find('testtime').get('stop'))
                         # event lines:
                         ax.plot([start_time, start_time], # x-values
                             [0, N_audioelements+1], # y-values
@@ -135,11 +130,6 @@
                         )
                         
                 increment+=1 # to next audioelement
-                
-            # subtract total audioholder length from subsequent audioholder event times
-            audioholder_time = audioholder.find("./metric/metricresult/[@id='testTime']")
-            if audioholder_time is not None and show_audioholder_time: 
-                time_offset = float(audioholder_time.text)
             
             if not plot_empty:
                 # set plot parameters
@@ -151,7 +141,6 @@
                 #y-ticks: fragment IDs, top to bottom
                 plt.yticks(range(N_audioelements, 0, -1), audioelements_names) # show fragment names
 
-
                 #plt.show() # uncomment to show plot; comment when just saving
                 #exit()
             
--- a/python/timeline_view_movement.py	Wed Apr 20 19:12:16 2016 +0200
+++ b/python/timeline_view_movement.py	Wed Apr 20 20:20:23 2016 +0200
@@ -144,7 +144,7 @@
                         plot_empty = False
                     
                         # get time and final position of move event
-                        new_time = float(event.get("time"))-time_offset
+                        new_time = float(event.get("time")) #-time_offset # (legacy)
                         new_position = float(event.get("value"))
                         
                         # get play/stop events since last move until current move event
@@ -219,10 +219,10 @@
                     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 time<page_time-time_offset:
+                        if time>previous_time and time<page_time: #-time_offset:
                             start_times.append(time)
                     for time in stop_times_global:
-                        if time>previous_time and time<page_time-time_offset:
+                        if time>previous_time and time<page_time: #-time_offset:
                             stop_times.append(time)
                     # if no play/stop events between move events, find out whether playing
                     
@@ -259,7 +259,7 @@
                         currently_playing = not currently_playing # toggle to draw final segment correctly
                     
                     # draw final segment (horizontal line) from last 'segment_start' to current move event time
-                    plt.plot([segment_start, page_time-time_offset], # x-values
+                    plt.plot([segment_start, page_time], # x-values
                         [previous_position, previous_position], # y-values
                         # color depends on playing during move event or not:
                         color='r' if currently_playing else colormap[increment%len(colormap)], 
@@ -273,35 +273,25 @@
 #                     )
                     
                     # display fragment name at end
-                    plt.text(page_time-time_offset,previous_position,\
+                    plt.text(page_time,previous_position,\
                              audio_id,color=colormap[increment%len(colormap)]) #,rotation=45
                         
                 increment+=1 # to next audioelement
             
-            last_page_duration = page_time-time_offset
+            last_page_duration = page_time #-time_offset
             time_offset = page_time
             
-            if not plot_empty: # if plot is not empty, show or store
+            if not plot_empty: # if plot is not empty, show and/or store
                 # set plot parameters
                 plt.title('Timeline ' + file + ": "+page_name)
                 plt.xlabel('Time [seconds]')
                 plt.xlim(0, last_page_duration)
                 plt.ylabel('Rating') # default
                 plt.ylim(0, 1) # rating between 0 and 1
-            
-                #y-ticks: labels on rating axis
-                label_positions = []
-                label_text = []
-                scale_tags = root.findall("./BrowserEvalProjectDocument/audioHolder/interface/scale")
-                scale_title = root.find("./BrowserEvalProjectDocument/audioHolder/interface/title")
-                for tag in scale_tags:
-                    label_positions.append(float(tag.get('position'))/100) # on a scale from 0 to 100
-                    label_text.append(tag.text)
-                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: 
-                    plt.ylabel(scale_title.text)
+
+                # TO DO: 
+                # Y axis title and tick labels as specified in 'setup' for corresponding page
+                # Different plots for different axes
             
                 #plt.show() # uncomment to show plot; comment when just saving
                 #exit()