comparison scripts/evaluation_stats.py @ 2066:a13e5cf40feb

Scripts: evaluation_stats shows number of total fragments
author Brecht De Man <b.deman@qmul.ac.uk>
date Tue, 14 Jul 2015 19:40:58 +0100
parents 416fc71e0374
children edc386c86c86
comparison
equal deleted inserted replaced
2065:995391dc4dd2 2066:a13e5cf40feb
3 3
4 import xml.etree.ElementTree as ET 4 import xml.etree.ElementTree as ET
5 import os 5 import os
6 6
7 # XML results files location (modify as needed): 7 # XML results files location (modify as needed):
8 folder_name = "../saves" # Looks in 'saves/' folder from 'scripts/' folder 8 folder_name = "xml_with_statements" # Looks in 'saves/' folder from 'scripts/' folder
9 9
10 # Turn number of seconds (int) to '[minutes] min [seconds] s' (string) 10 # Turn number of seconds (int) to '[minutes] min [seconds] s' (string)
11 def seconds2timestr(time_in_seconds): 11 def seconds2timestr(time_in_seconds):
12 time_in_minutes = int(time_in_seconds/60) 12 time_in_minutes = int(time_in_seconds/60)
13 remaining_seconds = int(time_in_seconds%60) 13 remaining_seconds = int(time_in_seconds%60)
14 return str(time_in_minutes) + " min " + str(remaining_seconds) + " s" 14 return str(time_in_minutes) + " min " + str(remaining_seconds) + " s"
15 15
16 # stats initialisation 16 # stats initialisation
17 number_of_XML_files = 0 17 number_of_XML_files = 0
18 number_of_pages = 0 18 number_of_pages = 0
19 number_of_fragments = 0
19 time_per_page_accum = 0 20 time_per_page_accum = 0
20 21
21 # arrays initialisation 22 # arrays initialisation
22 page_names = [] 23 page_names = []
23 page_count = [] 24 page_count = []
44 page_name = audioholder.get('id') # get page name 45 page_name = audioholder.get('id') # get page name
45 46
46 if page_name is None: # ignore 'empty' audio_holders 47 if page_name is None: # ignore 'empty' audio_holders
47 print "WARNING: " + file + " contains empty audio holder. (evaluation_stats.py)" 48 print "WARNING: " + file + " contains empty audio holder. (evaluation_stats.py)"
48 break # move on to next 49 break # move on to next
49 50
50 # keep list of audioholder ids and count how many times each audioholder id was tested 51 # keep list of audioholder ids and count how many times each audioholder id was tested
51 if page_name in page_names: 52 if page_name in page_names:
52 page_index = page_names.index(page_name) # get index 53 page_index = page_names.index(page_name) # get index
53 page_count[page_index] += 1 54 page_count[page_index] += 1
54 else: 55 else:
55 page_names.append(page_name) 56 page_names.append(page_name)
56 page_count.append(1) 57 page_count.append(1)
57 58
58 # 'testTime' keeps total duration: subtract time so far for duration of this audioholder 59 # 'testTime' keeps total duration: subtract time so far for duration of this audioholder
59 duration = float(audioholder.find("./metric/metricresult[@id='testTime']").text) - total_duration 60 duration = float(audioholder.find("./metric/metricresult[@id='testTime']").text) - total_duration
67 # keep track of duration in function of page index 68 # keep track of duration in function of page index
68 if len(duration_order)>page_number: 69 if len(duration_order)>page_number:
69 duration_order[page_number].append(duration) 70 duration_order[page_number].append(duration)
70 else: 71 else:
71 duration_order.append([duration]) 72 duration_order.append([duration])
73
74 # number of audio elements
75 audioelements = audioholder.findall("./audioelement") # get audioelements
76 number_of_fragments += len(audioelements) # add length of this list to total
72 77
73 page_number += 1 # increase page count for this specific test 78 page_number += 1 # increase page count for this specific test
74 number_of_pages += 1 # increase total number of pages 79 number_of_pages += 1 # increase total number of pages
75 time_per_page_accum += duration # total duration (for average time spent per page) 80 time_per_page_accum += duration # total duration (for average time spent per page)
76 81
77 # print total duration of this test 82 # print total duration of this test
78 print " TOTAL: " + seconds2timestr(total_duration) 83 print " TOTAL: " + seconds2timestr(total_duration)
79 84
85
80 # PRINT EVERYTHING 86 # PRINT EVERYTHING
81 87
82 print "Number of XML files: " + str(number_of_XML_files) 88 print "Number of XML files: " + str(number_of_XML_files)
83 print "Number of pages: " + str(number_of_pages) 89 print "Number of pages: " + str(number_of_pages)
90 print "Number of fragments: " + str(number_of_fragments)
84 print "Average time per page: " + seconds2timestr(time_per_page_accum/number_of_pages) 91 print "Average time per page: " + seconds2timestr(time_per_page_accum/number_of_pages)
85 page_count_strings = list(str(x) for x in page_count) 92 page_count_strings = list(str(x) for x in page_count)
86 count_list = page_names + page_count_strings 93 count_list = page_names + page_count_strings
87 count_list[::2] = page_names 94 count_list[::2] = page_names
88 count_list[1::2] = page_count_strings 95 count_list[1::2] = page_count_strings
89 print "Pages tested: " + str(count_list) 96 print "Pages tested: " + str(count_list)
90 97
91 # Average duration for first, second, ... page 98 # Average duration for first, second, ... page
92 for page_number in range(len(duration_order)): #TODO make maximum page number automatic 99 for page_number in range(len(duration_order)): #TODO make maximum page number automatic
93 print "Average duration page " + str(page_number+1) + ": " +\ 100 print "Average duration page " + str(page_number+1) + ": " +\
94 seconds2timestr(sum(duration_order[page_number])/len(duration_order[page_number])) +\ 101 seconds2timestr(sum(duration_order[page_number])/len(duration_order[page_number])) +\
95 " ("+str(len(duration_order[page_number]))+" subjects)" 102 " ("+str(len(duration_order[page_number]))+" subjects)"
96 103
97 104
98 #TODO 105 #TODO
99 # time per page in function of number of fragments (plot) 106 # time per page in function of number of fragments (plot)
100 # time per participant in function of number of pages 107 # time per participant in function of number of pages
101 # plot total time for each participant 108 # plot total time for each participant
102 # plot total time 109 # plot total time
103 # show 'count' per page (in order) 110 # show 'count' per page (in order)
104 111
105 # clear up page_index <> page_count <> page_number confusion 112 # clear up page_index <> page_count <> page_number confusion