comparison scripts/evaluation_stats.py @ 2068:e943dc4d3d6e

Scripts: evaluation statistics: show average duration per song in order of number of fragments and average total duration; count empty comments; fragments per song; distinguish between same audioholder ids with different number of audioelements.
author Brecht De Man <b.deman@qmul.ac.uk>
date Wed, 15 Jul 2015 15:52:56 +0100
parents e0cf19024f91
children 4345ba8a1b6e
comparison
equal deleted inserted replaced
2067:e0cf19024f91 2068:e943dc4d3d6e
1 #!/usr/bin/python 1 #!/usr/bin/python
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 5 import os # for getting files from directory
6 import operator # for sorting data with multiple keys
6 7
7 # XML results files location (modify as needed): 8 # XML results files location (modify as needed):
8 folder_name = "../saves" # Looks in 'saves/' folder from 'scripts/' folder 9 folder_name = "../saves" # Looks in 'saves/' folder from 'scripts/' folder
9 10
10 # Turn number of seconds (int) to '[minutes] min [seconds] s' (string) 11 # Turn number of seconds (int) to '[minutes] min [seconds] s' (string)
12 time_in_minutes = int(time_in_seconds/60) 13 time_in_minutes = int(time_in_seconds/60)
13 remaining_seconds = int(time_in_seconds%60) 14 remaining_seconds = int(time_in_seconds%60)
14 return str(time_in_minutes) + " min " + str(remaining_seconds) + " s" 15 return str(time_in_minutes) + " min " + str(remaining_seconds) + " s"
15 16
16 # stats initialisation 17 # stats initialisation
17 number_of_XML_files = 0 18 number_of_XML_files = 0
18 number_of_pages = 0 19 number_of_pages = 0
19 number_of_fragments = 0 20 number_of_fragments = 0
20 time_per_page_accum = 0 21 total_empty_comments = 0
22 time_per_page_accum = 0
21 23
22 # arrays initialisation 24 # arrays initialisation
23 page_names = [] 25 page_names = []
24 page_count = [] 26 page_count = []
25 duration_page = [] # duration of experiment in function of page 27 duration_page = [] # duration of experiment in function of page content
26 duration_subject = [] 28 duration_order = [] # duration of experiment in function of page number
27 duration_order = [] 29 fragments_per_page = [] # number of fragments for corresponding page
28 30
29 # get every XML file in folder 31 # get every XML file in folder
30 files_list = os.listdir(folder_name) 32 files_list = os.listdir(folder_name)
31 for file in files_list: # iterate over all files in files_list 33 for file in files_list: # iterate over all files in files_list
32 if file.endswith(".xml"): # check if XML file 34 if file.endswith(".xml"): # check if XML file
46 48
47 if page_name is None: # ignore 'empty' audio_holders 49 if page_name is None: # ignore 'empty' audio_holders
48 print "WARNING: " + file + " contains empty audio holder. (evaluation_stats.py)" 50 print "WARNING: " + file + " contains empty audio holder. (evaluation_stats.py)"
49 break # move on to next 51 break # move on to next
50 52
51 # keep list of audioholder ids and count how many times each audioholder id was tested 53 number_of_comments = 0 # for this page
52 if page_name in page_names: 54 number_of_missing_comments = 0 # for this page
53 page_index = page_names.index(page_name) # get index 55
54 page_count[page_index] += 1 56 # number of audio elements
55 else: 57 audioelements = audioholder.findall("./audioelement") # get audioelements
56 page_names.append(page_name) 58 number_of_fragments += len(audioelements) # add length of this list to total
57 page_count.append(1) 59
60 # number of comments (interesting if comments not mandatory)
61 for audioelement in audioelements:
62 response = audioelement.find("./comment/response")
63 if response.text is not None and len(response.text) > 1:
64 number_of_comments += 1
65 else:
66 number_of_missing_comments += 1
67
68 total_empty_comments += number_of_missing_comments
58 69
59 # 'testTime' keeps total duration: subtract time so far for duration of this audioholder 70 # 'testTime' keeps total duration: subtract time so far for duration of this audioholder
60 duration = float(audioholder.find("./metric/metricresult[@id='testTime']").text) - total_duration 71 duration = float(audioholder.find("./metric/metricresult[@id='testTime']").text) - total_duration
61 72
62 # total duration of test 73 # total duration of test
63 total_duration += duration 74 total_duration += duration
64 75
65 # print audioholder id and duration 76 # print audioholder id and duration
66 print " " + page_name + ": " + seconds2timestr(duration) 77 print " " + page_name + ": " + seconds2timestr(duration) + ", "\
78 + str(number_of_comments)+"/"\
79 +str(number_of_comments+number_of_missing_comments)+" comments"
67 80
68 # keep track of duration in function of page index 81 # keep track of duration in function of page index
69 if len(duration_order)>page_number: 82 if len(duration_order)>page_number:
70 duration_order[page_number].append(duration) 83 duration_order[page_number].append(duration)
71 else: 84 else:
72 duration_order.append([duration]) 85 duration_order.append([duration])
73 86
74 # number of audio elements 87 # keep list of audioholder ids and count how many times each audioholder id
75 audioelements = audioholder.findall("./audioelement") # get audioelements 88 # was tested, how long it took, and how many fragments there were (if number of
76 number_of_fragments += len(audioelements) # add length of this list to total 89 # fragments is different, store as different audioholder id)
77 90 if page_name in page_names:
91 page_index = page_names.index(page_name) # get index
92 # check if number of audioelements the same
93 if len(audioelements) == fragments_per_page[page_index]:
94 page_count[page_index] += 1
95 duration_page[page_index].append(duration)
96 else: # make new entry
97 alt_page_name = page_name+"("+str(len(audioelements))+")"
98 if alt_page_name in page_names: # if already there
99 alt_page_index = page_names.index(alt_page_name) # get index
100 page_count[alt_page_index] += 1
101 duration_page[alt_page_index].append(duration)
102 else:
103 page_names.append(alt_page_name)
104 page_count.append(1)
105 duration_page.append([duration])
106 fragments_per_page.append(len(audioelements))
107 else:
108 page_names.append(page_name)
109 page_count.append(1)
110 duration_page.append([duration])
111 fragments_per_page.append(len(audioelements))
112
113 # bookkeeping
78 page_number += 1 # increase page count for this specific test 114 page_number += 1 # increase page count for this specific test
79 number_of_pages += 1 # increase total number of pages 115 number_of_pages += 1 # increase total number of pages
80 time_per_page_accum += duration # total duration (for average time spent per page) 116 time_per_page_accum += duration # total duration (for average time spent per page)
81 117
82 # print total duration of this test 118 # print total duration of this test
86 # PRINT EVERYTHING 122 # PRINT EVERYTHING
87 123
88 print "Number of XML files: " + str(number_of_XML_files) 124 print "Number of XML files: " + str(number_of_XML_files)
89 print "Number of pages: " + str(number_of_pages) 125 print "Number of pages: " + str(number_of_pages)
90 print "Number of fragments: " + str(number_of_fragments) 126 print "Number of fragments: " + str(number_of_fragments)
127 print "Number of empty comments: " + str(total_empty_comments)
91 print "Average time per page: " + seconds2timestr(time_per_page_accum/number_of_pages) 128 print "Average time per page: " + seconds2timestr(time_per_page_accum/number_of_pages)
92 page_count_strings = list(str(x) for x in page_count) 129 page_count_strings = list(str(x) for x in page_count)
93 count_list = page_names + page_count_strings 130 count_list = page_names + page_count_strings
94 count_list[::2] = page_names 131 count_list[::2] = page_names
95 count_list[1::2] = page_count_strings 132 count_list[1::2] = page_count_strings
96 print "Pages tested: " + str(count_list) 133 print "Pages tested: " + str(count_list)
97 134
98 # Average duration for first, second, ... page 135 # Average duration for first, second, ... page
99 for page_number in range(len(duration_order)): #TODO make maximum page number automatic 136 for page_number in range(len(duration_order)):
100 print "Average duration page " + str(page_number+1) + ": " +\ 137 print "Average duration page " + str(page_number+1) + ": " +\
101 seconds2timestr(sum(duration_order[page_number])/len(duration_order[page_number])) +\ 138 seconds2timestr(sum(duration_order[page_number])/len(duration_order[page_number])) +\
102 " ("+str(len(duration_order[page_number]))+" subjects)" 139 " ("+str(len(duration_order[page_number]))+" subjects)"
140
141
142 # Sort pages by number of audioelements, then by duration
143
144 # average duration and number of subjects per page
145 average_duration_page = []
146 number_of_subjects_page = []
147 for line in duration_page:
148 number_of_subjects_page.append(len(line))
149 average_duration_page.append(sum(line)/len(line))
150
151 # 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]
153 combined_list = sorted(zip(*combined_list), key=operator.itemgetter(1, 2)) # sort
154
155 # Show average duration for all songs
156 for page_index in range(len(page_names)):
157 print "Average duration audioholder " + combined_list[page_index][0] + ": " \
158 + seconds2timestr(combined_list[page_index][1]) \
159 + " (" + str(combined_list[page_index][3]) + " subjects, " \
160 + str(combined_list[page_index][2]) + " fragments)"
103 161
104 162
105 #TODO 163 #TODO
106 # time per page in function of number of fragments (plot) 164 # time per page in function of number of fragments (plot)
107 # time per participant in function of number of pages 165 # time per participant in function of number of pages