annotate scripts/evaluation_stats.py @ 261:7bdc95a1fbd1

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 3c5689af726b
children edc386c86c86
rev   line source
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@261 8 folder_name = "xml_with_statements" # 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@261 19 number_of_fragments = 0
b@251 20 time_per_page_accum = 0
b@251 21
b@251 22 # arrays initialisation
b@251 23 page_names = []
b@251 24 page_count = []
b@251 25 duration_page = [] # duration of experiment in function of page
b@251 26 duration_subject = []
b@251 27 duration_order = []
b@251 28
b@251 29 # get every XML file in folder
b@251 30 files_list = os.listdir(folder_name)
b@251 31 for file in files_list: # iterate over all files in files_list
b@251 32 if file.endswith(".xml"): # check if XML file
b@251 33 number_of_XML_files += 1
b@251 34 tree = ET.parse(folder_name + '/' + file)
b@251 35 root = tree.getroot()
b@251 36
b@251 37 print file # print file name (subject name)
b@251 38
b@251 39 # reset for new subject
b@251 40 total_duration = 0
b@251 41 page_number = 0
b@251 42
b@251 43 # get list of all page names
b@251 44 for audioholder in root.findall("./audioholder"): # iterate over pages
b@251 45 page_name = audioholder.get('id') # get page name
b@251 46
b@251 47 if page_name is None: # ignore 'empty' audio_holders
b@251 48 print "WARNING: " + file + " contains empty audio holder. (evaluation_stats.py)"
b@251 49 break # move on to next
b@261 50
b@251 51 # keep list of audioholder ids and count how many times each audioholder id was tested
b@251 52 if page_name in page_names:
b@251 53 page_index = page_names.index(page_name) # get index
b@251 54 page_count[page_index] += 1
b@261 55 else:
b@251 56 page_names.append(page_name)
b@251 57 page_count.append(1)
b@251 58
b@251 59 # 'testTime' keeps total duration: subtract time so far for duration of this audioholder
b@251 60 duration = float(audioholder.find("./metric/metricresult[@id='testTime']").text) - total_duration
b@251 61
b@251 62 # total duration of test
b@251 63 total_duration += duration
b@251 64
b@251 65 # print audioholder id and duration
b@251 66 print " " + page_name + ": " + seconds2timestr(duration)
b@251 67
b@251 68 # keep track of duration in function of page index
b@251 69 if len(duration_order)>page_number:
b@251 70 duration_order[page_number].append(duration)
b@251 71 else:
b@251 72 duration_order.append([duration])
b@261 73
b@261 74 # number of audio elements
b@261 75 audioelements = audioholder.findall("./audioelement") # get audioelements
b@261 76 number_of_fragments += len(audioelements) # add length of this list to total
b@251 77
b@251 78 page_number += 1 # increase page count for this specific test
b@251 79 number_of_pages += 1 # increase total number of pages
b@251 80 time_per_page_accum += duration # total duration (for average time spent per page)
b@261 81
b@261 82 # print total duration of this test
b@261 83 print " TOTAL: " + seconds2timestr(total_duration)
b@261 84
b@261 85
b@251 86 # PRINT EVERYTHING
b@251 87
b@251 88 print "Number of XML files: " + str(number_of_XML_files)
b@251 89 print "Number of pages: " + str(number_of_pages)
b@261 90 print "Number of fragments: " + str(number_of_fragments)
b@251 91 print "Average time per page: " + seconds2timestr(time_per_page_accum/number_of_pages)
b@251 92 page_count_strings = list(str(x) for x in page_count)
b@251 93 count_list = page_names + page_count_strings
b@251 94 count_list[::2] = page_names
b@251 95 count_list[1::2] = page_count_strings
b@251 96 print "Pages tested: " + str(count_list)
b@251 97
b@251 98 # Average duration for first, second, ... page
b@251 99 for page_number in range(len(duration_order)): #TODO make maximum page number automatic
b@251 100 print "Average duration page " + str(page_number+1) + ": " +\
b@261 101 seconds2timestr(sum(duration_order[page_number])/len(duration_order[page_number])) +\
b@261 102 " ("+str(len(duration_order[page_number]))+" subjects)"
b@261 103
b@251 104
b@251 105 #TODO
b@251 106 # time per page in function of number of fragments (plot)
b@251 107 # time per participant in function of number of pages
b@251 108 # plot total time for each participant
b@261 109 # plot total time
b@251 110 # show 'count' per page (in order)
b@251 111
b@251 112 # clear up page_index <> page_count <> page_number confusion