comparison scripts/evaluation_stats.py @ 1457:c8a9825aaa05

Merge from branch "WAC2016"
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Mon, 23 Nov 2015 09:13:12 +0000
parents 04e8a9c07c7e
children 1b6fa37d46a4
comparison
equal deleted inserted replaced
1456:cacd98e7e1ff 1457:c8a9825aaa05
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 import xml.etree.ElementTree as ET 4 import xml.etree.ElementTree as ET
5 import os # for getting files from directory 5 import os # for getting files from directory
6 import operator # for sorting data with multiple keys 6 import operator # for sorting data with multiple keys
7 7 import sys # for accessing command line arguments
8 # XML results files location (modify as needed): 8
9 folder_name = "../saves" # Looks in 'saves/' folder from 'scripts/' folder 9 # Command line arguments
10 assert len(sys.argv)<3, "evaluation_stats takes at most 1 command line argument\n"+\
11 "Use: python evaluation_stats.py [results_folder]"
12
13 # XML results files location
14 if len(sys.argv) == 1:
15 folder_name = "../saves" # Looks in 'saves/' folder from 'scripts/' folder
16 print "Use: python evaluation_stats.py [results_folder]"
17 print "Using default path: " + folder_name
18 elif len(sys.argv) == 2:
19 folder_name = sys.argv[1] # First command line argument is folder
10 20
11 # Turn number of seconds (int) to '[minutes] min [seconds] s' (string) 21 # Turn number of seconds (int) to '[minutes] min [seconds] s' (string)
12 def seconds2timestr(time_in_seconds): 22 def seconds2timestr(time_in_seconds):
13 time_in_minutes = int(time_in_seconds/60) 23 time_in_minutes = int(time_in_seconds/60)
14 remaining_seconds = int(time_in_seconds%60) 24 remaining_seconds = int(time_in_seconds%60)
17 # stats initialisation 27 # stats initialisation
18 number_of_XML_files = 0 28 number_of_XML_files = 0
19 number_of_pages = 0 29 number_of_pages = 0
20 number_of_fragments = 0 30 number_of_fragments = 0
21 total_empty_comments = 0 31 total_empty_comments = 0
32 total_not_played = 0
33 total_not_moved = 0
22 time_per_page_accum = 0 34 time_per_page_accum = 0
23 35
24 # arrays initialisation 36 # arrays initialisation
25 page_names = [] 37 page_names = []
26 page_count = [] 38 page_count = []
50 print "WARNING: " + file + " contains empty audio holder. (evaluation_stats.py)" 62 print "WARNING: " + file + " contains empty audio holder. (evaluation_stats.py)"
51 break # move on to next 63 break # move on to next
52 64
53 number_of_comments = 0 # for this page 65 number_of_comments = 0 # for this page
54 number_of_missing_comments = 0 # for this page 66 number_of_missing_comments = 0 # for this page
67 not_played = 0 # for this page
68 not_moved = 0 # for this page
69
70 # 'testTime' keeps total duration: subtract time so far for duration of this audioholder
71 duration = float(audioholder.find("./metric/metricresult[@id='testTime']").text) - total_duration
72
73 # total duration of test
74 total_duration += duration
55 75
56 # number of audio elements 76 # number of audio elements
57 audioelements = audioholder.findall("./audioelement") # get audioelements 77 audioelements = audioholder.findall("./audioelement") # get audioelements
58 number_of_fragments += len(audioelements) # add length of this list to total 78 number_of_fragments += len(audioelements) # add length of this list to total
59 79
60 # number of comments (interesting if comments not mandatory) 80 # number of comments (interesting if comments not mandatory)
61 for audioelement in audioelements: 81 for audioelement in audioelements:
62 response = audioelement.find("./comment/response") 82 response = audioelement.find("./comment/response")
83 was_played = audioelement.find("./metric/metricresult/[@name='elementFlagListenedTo']")
84 was_moved = audioelement.find("./metric/metricresult/[@name='elementFlagMoved']")
63 if response.text is not None and len(response.text) > 1: 85 if response.text is not None and len(response.text) > 1:
64 number_of_comments += 1 86 number_of_comments += 1
65 else: 87 else:
66 number_of_missing_comments += 1 88 number_of_missing_comments += 1
67 89 if was_played is not None and was_played.text == 'false':
90 not_played += 1
91 if was_moved is not None and was_moved.text == 'false':
92 not_moved += 1
93
94 # update global counters
68 total_empty_comments += number_of_missing_comments 95 total_empty_comments += number_of_missing_comments
69 96 total_not_played += not_played
70 # 'testTime' keeps total duration: subtract time so far for duration of this audioholder 97 total_not_moved += not_moved
71 duration = float(audioholder.find("./metric/metricresult[@id='testTime']").text) - total_duration
72
73 # total duration of test
74 total_duration += duration
75 98
76 # print audioholder id and duration 99 # print audioholder id and duration
77 print " " + page_name + ": " + seconds2timestr(duration) + ", "\ 100 print " " + page_name + ": " + seconds2timestr(duration) + ", "\
78 + str(number_of_comments)+"/"\ 101 + str(number_of_comments)+"/"\
79 +str(number_of_comments+number_of_missing_comments)+" comments" 102 +str(number_of_comments+number_of_missing_comments)+" comments"
103
104 # number of audio elements not played
105 if not_played > 1:
106 print 'ATTENTION: '+str(not_played)+' fragments were not listened to!'
107 if not_played == 1:
108 print 'ATTENTION: one fragment was not listened to!'
109
110 # number of audio element markers not moved
111 if not_moved > 1:
112 print 'ATTENTION: '+str(not_moved)+' markers were not moved!'
113 if not_moved == 1:
114 print 'ATTENTION: one marker was not moved!'
80 115
81 # keep track of duration in function of page index 116 # keep track of duration in function of page index
82 if len(duration_order)>page_number: 117 if len(duration_order)>page_number:
83 duration_order[page_number].append(duration) 118 duration_order[page_number].append(duration)
84 else: 119 else:
122 # PRINT EVERYTHING 157 # PRINT EVERYTHING
123 158
124 print "Number of XML files: " + str(number_of_XML_files) 159 print "Number of XML files: " + str(number_of_XML_files)
125 print "Number of pages: " + str(number_of_pages) 160 print "Number of pages: " + str(number_of_pages)
126 print "Number of fragments: " + str(number_of_fragments) 161 print "Number of fragments: " + str(number_of_fragments)
127 print "Number of empty comments: " + str(total_empty_comments) 162 print "Number of empty comments: " + str(total_empty_comments) +\
163 " (" + str(round(100.0*total_empty_comments/number_of_fragments,2)) + "%)"
164 print "Number of unplayed fragments: " + str(total_not_played) +\
165 " (" + str(round(100.0*total_not_played/number_of_fragments,2)) + "%)"
166 print "Number of unmoved markers: " + str(total_not_moved) +\
167 " (" + str(round(100.0*total_not_moved/number_of_fragments,2)) + "%)"
128 print "Average time per page: " + seconds2timestr(time_per_page_accum/number_of_pages) 168 print "Average time per page: " + seconds2timestr(time_per_page_accum/number_of_pages)
169
170 # Pages and number of times tested
129 page_count_strings = list(str(x) for x in page_count) 171 page_count_strings = list(str(x) for x in page_count)
130 count_list = page_names + page_count_strings 172 count_list = page_names + page_count_strings
131 count_list[::2] = page_names 173 count_list[::2] = page_names
132 count_list[1::2] = page_count_strings 174 count_list[1::2] = page_count_strings
133 print "Pages tested: " + str(count_list) 175 print "Pages tested: " + str(count_list)
134 176
135 # Average duration for first, second, ... page 177 # Average duration for first, second, ... page
178 print "Average duration per page:"
136 for page_number in range(len(duration_order)): 179 for page_number in range(len(duration_order)):
137 print "Average duration page " + str(page_number+1) + ": " +\ 180 print " page " + str(page_number+1) + ": " +\
138 seconds2timestr(sum(duration_order[page_number])/len(duration_order[page_number])) +\ 181 seconds2timestr(sum(duration_order[page_number])/len(duration_order[page_number])) +\
139 " ("+str(len(duration_order[page_number]))+" subjects)" 182 " ("+str(len(duration_order[page_number]))+" subjects)"
140 183
141 184
142 # Sort pages by number of audioelements, then by duration 185 # Sort pages by number of audioelements, then by duration
151 # combine and sort in function of number of audioelements and duration 194 # combine and sort in function of number of audioelements and duration
152 combined_list = [page_names, average_duration_page, fragments_per_page, number_of_subjects_page] 195 combined_list = [page_names, average_duration_page, fragments_per_page, number_of_subjects_page]
153 combined_list = sorted(zip(*combined_list), key=operator.itemgetter(1, 2)) # sort 196 combined_list = sorted(zip(*combined_list), key=operator.itemgetter(1, 2)) # sort
154 197
155 # Show average duration for all songs 198 # Show average duration for all songs
199 print "Average duration per audioholder:"
156 for page_index in range(len(page_names)): 200 for page_index in range(len(page_names)):
157 print "Average duration audioholder " + combined_list[page_index][0] + ": " \ 201 print " "+combined_list[page_index][0] + ": " \
158 + seconds2timestr(combined_list[page_index][1]) \ 202 + seconds2timestr(combined_list[page_index][1]) \
159 + " (" + str(combined_list[page_index][3]) + " subjects, " \ 203 + " (" + str(combined_list[page_index][3]) + " subjects, " \
160 + str(combined_list[page_index][2]) + " fragments)" 204 + str(combined_list[page_index][2]) + " fragments)"
161 205
162 206
166 # plot total time for each participant 210 # plot total time for each participant
167 # plot total time 211 # plot total time
168 # show 'count' per page (in order) 212 # show 'count' per page (in order)
169 213
170 # clear up page_index <> page_count <> page_number confusion 214 # clear up page_index <> page_count <> page_number confusion
215
216 # LaTeX -> PDF print out