annotate scripts/evaluation_stats.py @ 2057:416fc71e0374

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