Mercurial > hg > webaudioevaluationtool
comparison scripts/evaluation_stats.py @ 251:3c5689af726b
Scripts: evaluation_stats.py added to quickly show a report on tests done so far (to be expanded)
author | Brecht De Man <b.deman@qmul.ac.uk> |
---|---|
date | Wed, 01 Jul 2015 11:09:17 +0100 |
parents | |
children | 7bdc95a1fbd1 |
comparison
equal
deleted
inserted
replaced
250:f69f7957979b | 251:3c5689af726b |
---|---|
1 #!/usr/bin/python | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 import xml.etree.ElementTree as ET | |
5 import os | |
6 | |
7 # XML results files location (modify as needed): | |
8 folder_name = "../saves" # Looks in 'saves/' folder from 'scripts/' folder | |
9 | |
10 # Turn number of seconds (int) to '[minutes] min [seconds] s' (string) | |
11 def seconds2timestr(time_in_seconds): | |
12 time_in_minutes = int(time_in_seconds/60) | |
13 remaining_seconds = int(time_in_seconds%60) | |
14 return str(time_in_minutes) + " min " + str(remaining_seconds) + " s" | |
15 | |
16 # stats initialisation | |
17 number_of_XML_files = 0 | |
18 number_of_pages = 0 | |
19 time_per_page_accum = 0 | |
20 | |
21 # arrays initialisation | |
22 page_names = [] | |
23 page_count = [] | |
24 duration_page = [] # duration of experiment in function of page | |
25 duration_subject = [] | |
26 duration_order = [] | |
27 | |
28 # get every XML file in folder | |
29 files_list = os.listdir(folder_name) | |
30 for file in files_list: # iterate over all files in files_list | |
31 if file.endswith(".xml"): # check if XML file | |
32 number_of_XML_files += 1 | |
33 tree = ET.parse(folder_name + '/' + file) | |
34 root = tree.getroot() | |
35 | |
36 print file # print file name (subject name) | |
37 | |
38 # reset for new subject | |
39 total_duration = 0 | |
40 page_number = 0 | |
41 | |
42 # get list of all page names | |
43 for audioholder in root.findall("./audioholder"): # iterate over pages | |
44 page_name = audioholder.get('id') # get page name | |
45 | |
46 if page_name is None: # ignore 'empty' audio_holders | |
47 print "WARNING: " + file + " contains empty audio holder. (evaluation_stats.py)" | |
48 break # move on to next | |
49 | |
50 # keep list of audioholder ids and count how many times each audioholder id was tested | |
51 if page_name in page_names: | |
52 page_index = page_names.index(page_name) # get index | |
53 page_count[page_index] += 1 | |
54 else: | |
55 page_names.append(page_name) | |
56 page_count.append(1) | |
57 | |
58 # '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 | |
61 # total duration of test | |
62 total_duration += duration | |
63 | |
64 # print audioholder id and duration | |
65 print " " + page_name + ": " + seconds2timestr(duration) | |
66 | |
67 # keep track of duration in function of page index | |
68 if len(duration_order)>page_number: | |
69 duration_order[page_number].append(duration) | |
70 else: | |
71 duration_order.append([duration]) | |
72 | |
73 page_number += 1 # increase page count for this specific test | |
74 number_of_pages += 1 # increase total number of pages | |
75 time_per_page_accum += duration # total duration (for average time spent per page) | |
76 | |
77 # print total duration of this test | |
78 print " TOTAL: " + seconds2timestr(total_duration) | |
79 | |
80 # PRINT EVERYTHING | |
81 | |
82 print "Number of XML files: " + str(number_of_XML_files) | |
83 print "Number of pages: " + str(number_of_pages) | |
84 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) | |
86 count_list = page_names + page_count_strings | |
87 count_list[::2] = page_names | |
88 count_list[1::2] = page_count_strings | |
89 print "Pages tested: " + str(count_list) | |
90 | |
91 # Average duration for first, second, ... page | |
92 for page_number in range(len(duration_order)): #TODO make maximum page number automatic | |
93 print "Average duration page " + str(page_number+1) + ": " +\ | |
94 seconds2timestr(sum(duration_order[page_number])/len(duration_order[page_number])) +\ | |
95 " ("+str(len(duration_order[page_number]))+" subjects)" | |
96 | |
97 | |
98 #TODO | |
99 # time per page in function of number of fragments (plot) | |
100 # time per participant in function of number of pages | |
101 # plot total time for each participant | |
102 # plot total time | |
103 # show 'count' per page (in order) | |
104 | |
105 # clear up page_index <> page_count <> page_number confusion |