Mercurial > hg > webaudioevaluationtool
comparison python/evaluation_stats.py @ 2280:334b11f2b418
Merge branch 'master' of https://github.com/BrechtDeMan/WebAudioEvaluationTool
author | www-data <www-data@sucuk.dcs.qmul.ac.uk> |
---|---|
date | Wed, 20 Apr 2016 20:20:54 +0100 |
parents | df459c20946e |
children | 370a82784c71 |
comparison
equal
deleted
inserted
replaced
2277:372a355779de | 2280:334b11f2b418 |
---|---|
11 "Use: python evaluation_stats.py [results_folder]" | 11 "Use: python evaluation_stats.py [results_folder]" |
12 | 12 |
13 # XML results files location | 13 # XML results files location |
14 if len(sys.argv) == 1: | 14 if len(sys.argv) == 1: |
15 folder_name = "../saves" # Looks in 'saves/' folder from 'scripts/' folder | 15 folder_name = "../saves" # Looks in 'saves/' folder from 'scripts/' folder |
16 print "Use: python evaluation_stats.py [results_folder]" | 16 print("Use: python evaluation_stats.py [results_folder]") |
17 print "Using default path: " + folder_name | 17 print("Using default path: " + folder_name) |
18 elif len(sys.argv) == 2: | 18 elif len(sys.argv) == 2: |
19 folder_name = sys.argv[1] # First command line argument is folder | 19 folder_name = sys.argv[1] # First command line argument is folder |
20 | 20 |
21 # Turn number of seconds (int) to '[minutes] min [seconds] s' (string) | 21 # Turn number of seconds (int) to '[minutes] min [seconds] s' (string) |
22 def seconds2timestr(time_in_seconds): | 22 def seconds2timestr(time_in_seconds): |
46 if file.endswith(".xml"): # check if XML file | 46 if file.endswith(".xml"): # check if XML file |
47 number_of_XML_files += 1 | 47 number_of_XML_files += 1 |
48 tree = ET.parse(folder_name + '/' + file) | 48 tree = ET.parse(folder_name + '/' + file) |
49 root = tree.getroot() | 49 root = tree.getroot() |
50 | 50 |
51 print file # print file name (subject name) | 51 print(file) # print file name (subject name) |
52 | 52 |
53 # reset for new subject | 53 # reset for new subject |
54 total_duration = 0 | 54 total_duration = 0 |
55 page_number = 0 | 55 page_number = 0 |
56 | 56 |
57 # get list of all page names | 57 # get list of all page names |
58 for audioholder in root.findall("./page"): # iterate over pages | 58 for page in root.findall("./page"): # iterate over pages |
59 page_name = audioholder.get('ref') # get page name | 59 page_name = page.get('ref') # get page name |
60 | 60 |
61 if page_name is None: # ignore 'empty' audio_holders | 61 if page_name is None: # ignore 'empty' audio_holders |
62 print "WARNING: " + file + " contains empty audio holder. (evaluation_stats.py)" | 62 print("\tWARNING: " + file + " contains empty audio holder. (evaluation_stats.py)") |
63 break # move on to next | 63 break # move on to next |
64 if audioholder.get("state") != "complete": | 64 if page.get("state") != "complete": |
65 print "WARNING" + file + " contains incomplete audio holder." | 65 print("\tWARNING: " + file + " contains incomplete audio holder.") |
66 break | 66 break |
67 number_of_comments = 0 # for this page | 67 number_of_comments = 0 # for this page |
68 number_of_missing_comments = 0 # for this page | 68 number_of_missing_comments = 0 # for this page |
69 not_played = 0 # for this page | 69 not_played = 0 # for this page |
70 not_moved = 0 # for this page | 70 not_moved = 0 # for this page |
71 | 71 |
72 # 'testTime' keeps total duration: subtract time so far for duration of this audioholder | 72 # 'testTime' keeps total duration: subtract time so far for duration of this page |
73 duration = float(audioholder.find("./metric/metricresult[@id='testTime']").text) - total_duration | 73 duration = float(page.find("./metric/metricresult[@id='testTime']").text) - total_duration |
74 | 74 |
75 # total duration of test | 75 # total duration of test |
76 total_duration += duration | 76 total_duration += duration |
77 | 77 |
78 # number of audio elements | 78 # number of audio elements |
79 audioelements = audioholder.findall("./audioelement") # get audioelements | 79 audioelements = page.findall("./audioelement") # get audioelements |
80 number_of_fragments += len(audioelements) # add length of this list to total | 80 number_of_fragments += len(audioelements) # add length of this list to total |
81 | 81 |
82 # number of comments (interesting if comments not mandatory) | 82 # number of comments (interesting if comments not mandatory) |
83 for audioelement in audioelements: | 83 for audioelement in audioelements: |
84 if audioelement.get("type") != "outside-reference": | 84 if audioelement.get("type") != "outside-reference": |
97 # update global counters | 97 # update global counters |
98 total_empty_comments += number_of_missing_comments | 98 total_empty_comments += number_of_missing_comments |
99 total_not_played += not_played | 99 total_not_played += not_played |
100 total_not_moved += not_moved | 100 total_not_moved += not_moved |
101 | 101 |
102 # print audioholder id and duration | 102 # print page id and duration |
103 print " " + page_name + ": " + seconds2timestr(duration) + ", "\ | 103 print(" " + page_name + ": " + seconds2timestr(duration) + ", "\ |
104 + str(number_of_comments)+"/"\ | 104 + str(number_of_comments)+"/"\ |
105 +str(number_of_comments+number_of_missing_comments)+" comments" | 105 +str(number_of_comments+number_of_missing_comments)+" comments") |
106 | 106 |
107 # number of audio elements not played | 107 # number of audio elements not played |
108 if not_played > 1: | 108 if not_played > 1: |
109 print 'ATTENTION: '+str(not_played)+' fragments were not listened to!' | 109 print('ATTENTION: '+str(not_played)+' fragments were not listened to!') |
110 if not_played == 1: | 110 if not_played == 1: |
111 print 'ATTENTION: one fragment was not listened to!' | 111 print('ATTENTION: one fragment was not listened to!') |
112 | 112 |
113 # number of audio element markers not moved | 113 # number of audio element markers not moved |
114 if not_moved > 1: | 114 if not_moved > 1: |
115 print 'ATTENTION: '+str(not_moved)+' markers were not moved!' | 115 print('ATTENTION: '+str(not_moved)+' markers were not moved!') |
116 if not_moved == 1: | 116 if not_moved == 1: |
117 print 'ATTENTION: one marker was not moved!' | 117 print('ATTENTION: one marker was not moved!') |
118 | 118 |
119 # keep track of duration in function of page index | 119 # keep track of duration in function of page index |
120 if len(duration_order)>page_number: | 120 if len(duration_order)>page_number: |
121 duration_order[page_number].append(duration) | 121 duration_order[page_number].append(duration) |
122 else: | 122 else: |
123 duration_order.append([duration]) | 123 duration_order.append([duration]) |
124 | 124 |
125 # keep list of audioholder ids and count how many times each audioholder id | 125 # keep list of page ids and count how many times each page id |
126 # was tested, how long it took, and how many fragments there were (if number of | 126 # was tested, how long it took, and how many fragments there were (if number of |
127 # fragments is different, store as different audioholder id) | 127 # fragments is different, store as different page id) |
128 if page_name in page_names: | 128 if page_name in page_names: |
129 page_index = page_names.index(page_name) # get index | 129 page_index = page_names.index(page_name) # get index |
130 # check if number of audioelements the same | 130 # check if number of audioelements the same |
131 if len(audioelements) == fragments_per_page[page_index]: | 131 if len(audioelements) == fragments_per_page[page_index]: |
132 page_count[page_index] += 1 | 132 page_count[page_index] += 1 |
152 page_number += 1 # increase page count for this specific test | 152 page_number += 1 # increase page count for this specific test |
153 number_of_pages += 1 # increase total number of pages | 153 number_of_pages += 1 # increase total number of pages |
154 time_per_page_accum += duration # total duration (for average time spent per page) | 154 time_per_page_accum += duration # total duration (for average time spent per page) |
155 | 155 |
156 # print total duration of this test | 156 # print total duration of this test |
157 print " TOTAL: " + seconds2timestr(total_duration) | 157 print(" TOTAL: " + seconds2timestr(total_duration)) |
158 | 158 |
159 | 159 |
160 # PRINT EVERYTHING | 160 # PRINT EVERYTHING |
161 | 161 |
162 print "Number of XML files: " + str(number_of_XML_files) | 162 print("Number of XML files: " + str(number_of_XML_files)) |
163 print "Number of pages: " + str(number_of_pages) | 163 print("Number of pages: " + str(number_of_pages)) |
164 print "Number of fragments: " + str(number_of_fragments) | 164 print("Number of fragments: " + str(number_of_fragments)) |
165 print "Number of empty comments: " + str(total_empty_comments) +\ | 165 print("Number of empty comments: " + str(total_empty_comments) +\ |
166 " (" + str(round(100.0*total_empty_comments/number_of_fragments,2)) + "%)" | 166 " (" + str(round(100.0*total_empty_comments/number_of_fragments,2)) + "%)") |
167 print "Number of unplayed fragments: " + str(total_not_played) +\ | 167 print("Number of unplayed fragments: " + str(total_not_played) +\ |
168 " (" + str(round(100.0*total_not_played/number_of_fragments,2)) + "%)" | 168 " (" + str(round(100.0*total_not_played/number_of_fragments,2)) + "%)") |
169 print "Number of unmoved markers: " + str(total_not_moved) +\ | 169 print("Number of unmoved markers: " + str(total_not_moved) +\ |
170 " (" + str(round(100.0*total_not_moved/number_of_fragments,2)) + "%)" | 170 " (" + str(round(100.0*total_not_moved/number_of_fragments,2)) + "%)") |
171 print "Average time per page: " + seconds2timestr(time_per_page_accum/number_of_pages) | 171 print("Average time per page: " + seconds2timestr(time_per_page_accum/number_of_pages)) |
172 | |
173 # Pages and number of times tested | |
174 page_count_strings = list(str(x) for x in page_count) | |
175 count_list = page_names + page_count_strings | |
176 count_list[::2] = page_names | |
177 count_list[1::2] = page_count_strings | |
178 print "Pages tested: " + str(count_list) | |
179 | 172 |
180 # Average duration for first, second, ... page | 173 # Average duration for first, second, ... page |
181 print "Average duration per page:" | 174 print("Average duration per ordered page:") |
182 for page_number in range(len(duration_order)): | 175 for page_number in range(len(duration_order)): |
183 print " page " + str(page_number+1) + ": " +\ | 176 print(" page " + str(page_number+1) + ": " +\ |
184 seconds2timestr(sum(duration_order[page_number])/len(duration_order[page_number])) +\ | 177 seconds2timestr(sum(duration_order[page_number])/len(duration_order[page_number])) +\ |
185 " ("+str(len(duration_order[page_number]))+" subjects)" | 178 " ("+str(len(duration_order[page_number]))+" subjects)") |
186 | 179 |
187 | 180 |
188 # Sort pages by number of audioelements, then by duration | 181 # Sort pages by number of audioelements, then by duration |
189 | 182 |
190 # average duration and number of subjects per page | 183 # average duration and number of subjects per page |
197 # combine and sort in function of number of audioelements and duration | 190 # combine and sort in function of number of audioelements and duration |
198 combined_list = [page_names, average_duration_page, fragments_per_page, number_of_subjects_page] | 191 combined_list = [page_names, average_duration_page, fragments_per_page, number_of_subjects_page] |
199 combined_list = sorted(zip(*combined_list), key=operator.itemgetter(1, 2)) # sort | 192 combined_list = sorted(zip(*combined_list), key=operator.itemgetter(1, 2)) # sort |
200 | 193 |
201 # Show average duration for all songs | 194 # Show average duration for all songs |
202 print "Average duration per audioholder:" | 195 print("Average duration per page ID:") |
203 for page_index in range(len(page_names)): | 196 for page_index in range(len(page_names)): |
204 print " "+combined_list[page_index][0] + ": " \ | 197 print(" "+combined_list[page_index][0] + ": " \ |
205 + seconds2timestr(combined_list[page_index][1]) \ | 198 + seconds2timestr(combined_list[page_index][1]) \ |
206 + " (" + str(combined_list[page_index][3]) + " subjects, " \ | 199 + " (" + str(combined_list[page_index][3]) + " subjects, " \ |
207 + str(combined_list[page_index][2]) + " fragments)" | 200 + str(combined_list[page_index][2]) + " fragments)") |
208 | 201 |
209 | 202 |
210 #TODO | 203 #TODO |
211 # time per page in function of number of fragments (plot) | 204 # time per page in function of number of fragments (plot) |
212 # time per participant in function of number of pages | 205 # time per participant in function of number of pages |