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