BrechtDeMan@1071: #!/usr/bin/python BrechtDeMan@1071: # -*- coding: utf-8 -*- BrechtDeMan@1071: BrechtDeMan@1071: import xml.etree.ElementTree as ET BrechtDeMan@1071: import os # for getting files from directory BrechtDeMan@1071: import operator # for sorting data with multiple keys BrechtDeMan@1071: import sys # for accessing command line arguments BrechtDeMan@1071: import subprocess # for calling pdflatex BrechtDeMan@1071: import shlex # for calling pdflatex BrechtDeMan@1071: import matplotlib.pyplot as plt # plots BrechtDeMan@1071: import numpy as np # numbers BrechtDeMan@1071: BrechtDeMan@1071: # Command line arguments BrechtDeMan@798: assert len(sys.argv)<4, "generate_report takes at most 2 command line arguments\n"+\ BrechtDeMan@1072: "Use: python generate_report.py [results_folder] [no_render | -nr]" BrechtDeMan@1072: BrechtDeMan@1072: render_figures = True BrechtDeMan@1071: BrechtDeMan@1071: # XML results files location BrechtDeMan@1071: if len(sys.argv) == 1: BrechtDeMan@780: folder_name = "../saves/" # Looks in 'saves/' folder from 'scripts/' folder BrechtDeMan@1072: print "Use: python generate_report.py [results_folder] [no_render | -nr]" BrechtDeMan@1071: print "Using default path: " + folder_name BrechtDeMan@1071: elif len(sys.argv) == 2: BrechtDeMan@1071: folder_name = sys.argv[1] # First command line argument is folder BrechtDeMan@1072: elif len(sys.argv) == 3: BrechtDeMan@1072: folder_name = sys.argv[1] # First command line argument is folder BrechtDeMan@1072: assert sys.argv[2] in ('no_render','-nr'), "Second argument not recognised. \n" +\ BrechtDeMan@1072: "Use: python generate_report.py [results_folder] [no_render | -nr]" BrechtDeMan@1072: # Second command line argument is [no_render | -nr] BrechtDeMan@1072: render_figures = False BrechtDeMan@1071: BrechtDeMan@1076: def isNaN(num): BrechtDeMan@1076: return num != num BrechtDeMan@1076: BrechtDeMan@1071: # Turn number of seconds (int) to '[minutes] min [seconds] s' (string) BrechtDeMan@1071: def seconds2timestr(time_in_seconds): BrechtDeMan@1076: if time_in_seconds is not None and not isNaN(time_in_seconds): BrechtDeMan@1076: time_in_minutes = int(time_in_seconds/60) BrechtDeMan@1076: remaining_seconds = int(time_in_seconds%60) BrechtDeMan@1076: return str(time_in_minutes) + " min " + str(remaining_seconds) + " s" BrechtDeMan@1076: else: BrechtDeMan@1076: return 'N/A' BrechtDeMan@1071: BrechtDeMan@1071: # stats initialisation BrechtDeMan@1071: number_of_XML_files = 0 BrechtDeMan@1071: number_of_pages = 0 BrechtDeMan@1071: number_of_fragments = 0 BrechtDeMan@1071: total_empty_comments = 0 BrechtDeMan@1071: total_not_played = 0 BrechtDeMan@1071: total_not_moved = 0 BrechtDeMan@1071: time_per_page_accum = 0 BrechtDeMan@1071: BrechtDeMan@1071: # arrays initialisation BrechtDeMan@1071: page_names = [] BrechtDeMan@1072: real_page_names = [] # regardless of differing numbers of fragments BrechtDeMan@1072: subject_count = [] # subjects per audioholder name BrechtDeMan@1071: page_count = [] BrechtDeMan@1071: duration_page = [] # duration of experiment in function of page content BrechtDeMan@1071: duration_order = [] # duration of experiment in function of page number BrechtDeMan@1071: fragments_per_page = [] # number of fragments for corresponding page BrechtDeMan@1071: BrechtDeMan@1072: # survey stats BrechtDeMan@1072: gender = [] BrechtDeMan@1072: age = [] BrechtDeMan@1072: BrechtDeMan@1071: # get username if available BrechtDeMan@1071: for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'): BrechtDeMan@1071: user = os.environ.get(name) BrechtDeMan@1071: if user: BrechtDeMan@1071: break BrechtDeMan@1071: else: BrechtDeMan@1071: user = '' BrechtDeMan@1071: BrechtDeMan@1071: BrechtDeMan@1071: # begin LaTeX document BrechtDeMan@1071: header = r'''\documentclass[11pt, oneside]{article} BrechtDeMan@1071: \usepackage{geometry} BrechtDeMan@1072: \geometry{a4paper} BrechtDeMan@1072: \usepackage[parfill]{parskip} % empty line instead of indent BrechtDeMan@1072: \usepackage{graphicx} % figures BrechtDeMan@780: \usepackage[space]{grffile} % include figures with spaces in paths BrechtDeMan@1072: \usepackage{hyperref} BrechtDeMan@1076: \usepackage{tikz} % pie charts BrechtDeMan@1071: \title{Report} BrechtDeMan@1071: \author{'''+\ BrechtDeMan@1071: user+\ BrechtDeMan@1071: r'''} BrechtDeMan@1071: \graphicspath{{'''+\ BrechtDeMan@1071: folder_name+\ BrechtDeMan@780: r'''}} BrechtDeMan@1072: %\setcounter{section}{-1} % Summary section 0 so number of sections equals number of files BrechtDeMan@1071: \begin{document} BrechtDeMan@1071: \maketitle BrechtDeMan@1072: This is an automatically generated report using the `generate\_report.py' Python script BrechtDeMan@1072: included with the Web Audio Evaluation Tool \cite{WAET} distribution which can be found BrechtDeMan@1072: at \texttt{code.soundsoftware.ac.uk/projects/webaudioevaluationtool}. BrechtDeMan@1071: \tableofcontents BrechtDeMan@1072: BrechtDeMan@1071: ''' BrechtDeMan@1071: BrechtDeMan@1075: footer = '\n\t\t'+r'''\begin{thebibliography}{9} BrechtDeMan@1072: \bibitem{WAET} % reference to accompanying publication BrechtDeMan@1072: Nicholas Jillings, Brecht De Man, David Moffat and Joshua D. Reiss, BrechtDeMan@1072: ``Web Audio Evaluation Tool: A browser-based listening test environment,'' BrechtDeMan@1072: presented at the 12th Sound and Music Computing Conference, July 2015. BrechtDeMan@1072: \end{thebibliography} BrechtDeMan@1072: \end{document}''' BrechtDeMan@1071: BrechtDeMan@1071: body = '' BrechtDeMan@1071: BrechtDeMan@780: # make sure folder_name ends in '/' BrechtDeMan@780: folder_name = os.path.join(folder_name, '') BrechtDeMan@780: BrechtDeMan@1071: # generate images for later use BrechtDeMan@1072: if render_figures: BrechtDeMan@780: subprocess.call("python timeline_view_movement.py '"+folder_name+"'", shell=True) BrechtDeMan@780: subprocess.call("python score_parser.py '"+folder_name+"'", shell=True) BrechtDeMan@781: subprocess.call("python score_plot.py '"+folder_name+"ratings/'", shell=True) BrechtDeMan@1071: BrechtDeMan@1071: # get every XML file in folder BrechtDeMan@1071: files_list = os.listdir(folder_name) BrechtDeMan@1071: for file in files_list: # iterate over all files in files_list BrechtDeMan@1071: if file.endswith(".xml"): # check if XML file BrechtDeMan@1071: number_of_XML_files += 1 BrechtDeMan@780: tree = ET.parse(folder_name + file) BrechtDeMan@1071: root = tree.getroot() BrechtDeMan@1071: BrechtDeMan@1071: # PRINT name as section BrechtDeMan@1075: body+= '\n\section{'+file[:-4].capitalize()+'}\n' # make section header from name without extension BrechtDeMan@1071: BrechtDeMan@1071: # reset for new subject BrechtDeMan@1071: total_duration = 0 BrechtDeMan@1071: page_number = 0 BrechtDeMan@1071: BrechtDeMan@1075: individual_table = '\n' # table with stats for this individual test file BrechtDeMan@1072: timeline_plots = '' # plots of timeline (movements and plays) BrechtDeMan@1072: BrechtDeMan@1072: # DEMO survey stats BrechtDeMan@1072: # get gender BrechtDeMan@1072: this_subjects_gender = root.find("./posttest/radio/[@id='gender']") BrechtDeMan@1072: if this_subjects_gender is not None: BrechtDeMan@1072: gender.append(this_subjects_gender.get("name")) BrechtDeMan@1072: else: BrechtDeMan@1072: gender.append('UNAVAILABLE') BrechtDeMan@1072: # get age BrechtDeMan@1072: this_subjects_age = root.find("./posttest/number/[@id='age']") BrechtDeMan@1072: if this_subjects_age is not None: BrechtDeMan@1072: age.append(this_subjects_age.text) BrechtDeMan@1076: #TODO add plot of age BrechtDeMan@1076: BrechtDeMan@1071: # get list of all page names giuliomoro@1208: for audioholder in root.findall("./page"): # iterate over pages BrechtDeMan@1071: page_name = audioholder.get('id') # get page name BrechtDeMan@1071: BrechtDeMan@1071: if page_name is None: # ignore 'empty' audio_holders BrechtDeMan@1071: print "WARNING: " + file + " contains empty audio holder. (evaluation_stats.py)" BrechtDeMan@1071: break # move on to next BrechtDeMan@1071: BrechtDeMan@1071: number_of_comments = 0 # for this page BrechtDeMan@1071: number_of_missing_comments = 0 # for this page BrechtDeMan@1073: not_played = [] # for this page BrechtDeMan@1073: not_moved = [] # for this page BrechtDeMan@1071: BrechtDeMan@1076: if audioholder.find("./metric/metricresult[@id='testTime']") is not None: # check if time is included BrechtDeMan@1076: # 'testTime' keeps total duration: subtract time so far for duration of this audioholder BrechtDeMan@1076: duration = float(audioholder.find("./metric/metricresult[@id='testTime']").text) - total_duration BrechtDeMan@1071: BrechtDeMan@1076: # total duration of test BrechtDeMan@1076: total_duration += duration BrechtDeMan@1076: else: BrechtDeMan@1076: duration = float('nan') BrechtDeMan@1076: total_duration = float('nan') BrechtDeMan@1071: BrechtDeMan@1071: # number of audio elements BrechtDeMan@1071: audioelements = audioholder.findall("./audioelement") # get audioelements BrechtDeMan@1071: number_of_fragments += len(audioelements) # add length of this list to total BrechtDeMan@1071: BrechtDeMan@1071: # number of comments (interesting if comments not mandatory) BrechtDeMan@1071: for audioelement in audioelements: BrechtDeMan@1071: response = audioelement.find("./comment/response") BrechtDeMan@1071: was_played = audioelement.find("./metric/metricresult/[@name='elementFlagListenedTo']") BrechtDeMan@1071: was_moved = audioelement.find("./metric/metricresult/[@name='elementFlagMoved']") BrechtDeMan@1071: if response.text is not None and len(response.text) > 1: BrechtDeMan@1071: number_of_comments += 1 BrechtDeMan@1071: else: BrechtDeMan@1071: number_of_missing_comments += 1 BrechtDeMan@1071: if was_played is not None and was_played.text == 'false': BrechtDeMan@1073: not_played.append(audioelement.get('id')) BrechtDeMan@1071: if was_moved is not None and was_moved.text == 'false': BrechtDeMan@1073: not_moved.append(audioelement.get('id')) BrechtDeMan@1071: BrechtDeMan@1071: # update global counters BrechtDeMan@1071: total_empty_comments += number_of_missing_comments BrechtDeMan@1073: total_not_played += len(not_played) BrechtDeMan@1073: total_not_moved += len(not_moved) BrechtDeMan@1071: BrechtDeMan@1071: # PRINT alerts when elements not played or markers not moved BrechtDeMan@1071: # number of audio elements not played BrechtDeMan@1073: if len(not_played) > 1: BrechtDeMan@1075: body += '\t\t\\emph{\\textbf{ATTENTION: '+str(len(not_played))+\ BrechtDeMan@1073: ' fragments were not listened to in '+page_name+'! }}'+\ BrechtDeMan@1073: ', '.join(not_played)+'\\\\ \n' BrechtDeMan@1073: if len(not_played) == 1: BrechtDeMan@1075: body += '\t\t\\emph{\\textbf{ATTENTION: one fragment was not listened to in '+page_name+'! }}'+\ BrechtDeMan@1073: not_played[0]+'\\\\ \n' BrechtDeMan@1071: BrechtDeMan@1071: # number of audio element markers not moved BrechtDeMan@1073: if len(not_moved) > 1: BrechtDeMan@1075: body += '\t\t\\emph{\\textbf{ATTENTION: '+str(len(not_moved))+\ BrechtDeMan@1073: ' markers were not moved in '+page_name+'! }}'+\ BrechtDeMan@1073: ', '.join(not_moved)+'\\\\ \n' BrechtDeMan@1073: if len(not_moved) == 1: BrechtDeMan@1075: body += '\t\t\\emph{\\textbf{ATTENTION: one marker was not moved in '+page_name+'! }}'+\ BrechtDeMan@1073: not_moved[0]+'\\\\ \n' BrechtDeMan@1071: BrechtDeMan@1071: # PRINT song-specific statistic BrechtDeMan@1075: individual_table += '\t\t'+page_name+'&'+\ BrechtDeMan@1071: str(number_of_comments) + '/' +\ BrechtDeMan@1071: str(number_of_comments+number_of_missing_comments)+'&'+\ BrechtDeMan@1075: seconds2timestr(duration)+'\\\\\n' BrechtDeMan@1071: BrechtDeMan@1071: # get timeline for this audioholder BrechtDeMan@1071: img_path = 'timelines_movement/'+file[:-4]+'-'+page_name+'.pdf' BrechtDeMan@1071: BrechtDeMan@1071: # check if available BrechtDeMan@780: if os.path.isfile(folder_name+img_path): BrechtDeMan@1071: # SHOW timeline image BrechtDeMan@1072: timeline_plots += '\\includegraphics[width=\\textwidth]{'+\ BrechtDeMan@780: folder_name+img_path+'}\n\t\t' BrechtDeMan@1071: BrechtDeMan@1071: # keep track of duration in function of page index BrechtDeMan@1071: if len(duration_order)>page_number: BrechtDeMan@1071: duration_order[page_number].append(duration) BrechtDeMan@1071: else: BrechtDeMan@1071: duration_order.append([duration]) BrechtDeMan@1072: BrechtDeMan@1071: # keep list of audioholder ids and count how many times each audioholder id BrechtDeMan@1072: # was tested, how long it took, and how many fragments there were BrechtDeMan@1072: # (if number of fragments is different, store as different audioholder id) BrechtDeMan@1071: if page_name in page_names: BrechtDeMan@1071: page_index = page_names.index(page_name) # get index BrechtDeMan@1071: # check if number of audioelements the same BrechtDeMan@1071: if len(audioelements) == fragments_per_page[page_index]: BrechtDeMan@1071: page_count[page_index] += 1 BrechtDeMan@1071: duration_page[page_index].append(duration) BrechtDeMan@1071: else: # make new entry BrechtDeMan@1071: alt_page_name = page_name+"("+str(len(audioelements))+")" BrechtDeMan@1071: if alt_page_name in page_names: # if already there BrechtDeMan@1071: alt_page_index = page_names.index(alt_page_name) # get index BrechtDeMan@1071: page_count[alt_page_index] += 1 BrechtDeMan@1071: duration_page[alt_page_index].append(duration) BrechtDeMan@1071: else: BrechtDeMan@1071: page_names.append(alt_page_name) BrechtDeMan@1071: page_count.append(1) BrechtDeMan@1071: duration_page.append([duration]) BrechtDeMan@1071: fragments_per_page.append(len(audioelements)) BrechtDeMan@1071: else: BrechtDeMan@1071: page_names.append(page_name) BrechtDeMan@1071: page_count.append(1) BrechtDeMan@1071: duration_page.append([duration]) BrechtDeMan@1071: fragments_per_page.append(len(audioelements)) BrechtDeMan@1072: BrechtDeMan@1072: # number of subjects per audioholder regardless of differing numbers of BrechtDeMan@1072: # fragments (for inclusion in box plots) BrechtDeMan@1072: if page_name in real_page_names: BrechtDeMan@1072: page_index = real_page_names.index(page_name) # get index BrechtDeMan@1072: subject_count[page_index] += 1 BrechtDeMan@1072: else: BrechtDeMan@1072: real_page_names.append(page_name) BrechtDeMan@1072: subject_count.append(1) BrechtDeMan@1072: BrechtDeMan@1071: # bookkeeping BrechtDeMan@1071: page_number += 1 # increase page count for this specific test BrechtDeMan@1071: number_of_pages += 1 # increase total number of pages BrechtDeMan@1071: time_per_page_accum += duration # total duration (for average time spent per page) BrechtDeMan@1071: BrechtDeMan@1071: # PRINT table with statistics about this test BrechtDeMan@1075: body += '\t\t'+r'''\begin{tabular}{|p{3.5cm}|c|p{2.5cm}|} BrechtDeMan@1071: \hline BrechtDeMan@1071: \textbf{Song name} & \textbf{Comments} & \textbf{Duration} \\ \hline '''+\ BrechtDeMan@1075: individual_table+'\t\t'+\ BrechtDeMan@1071: r'''\hline BrechtDeMan@1071: \textbf{TOTAL} & & \textbf{'''+\ BrechtDeMan@1071: seconds2timestr(total_duration)+\ BrechtDeMan@1071: r'''}\\ BrechtDeMan@1071: \hline BrechtDeMan@1072: \end{tabular} BrechtDeMan@1072: BrechtDeMan@1072: ''' BrechtDeMan@1072: # PRINT timeline plots BrechtDeMan@1072: body += timeline_plots BrechtDeMan@1071: BrechtDeMan@1071: # join to footer BrechtDeMan@1071: footer = body + footer BrechtDeMan@1071: BrechtDeMan@1071: # empty body again BrechtDeMan@1071: body = '' BrechtDeMan@1071: BrechtDeMan@1072: # PRINT summary of everything (at start) BrechtDeMan@1072: # unnumbered so that number of sections equals number of files BrechtDeMan@1075: body += '\section*{Summary}\n\t\t\\addcontentsline{toc}{section}{Summary}\n' BrechtDeMan@1071: BrechtDeMan@1071: # PRINT table with statistics BrechtDeMan@1075: body += '\t\t\\begin{tabular}{ll}\n\t\t\t' BrechtDeMan@1075: body += r'Number of XML files: &' + str(number_of_XML_files) + r'\\'+'\n\t\t\t' BrechtDeMan@1075: body += r'Number of pages: &' + str(number_of_pages) + r'\\'+'\n\t\t\t' BrechtDeMan@1075: body += r'Number of fragments: &' + str(number_of_fragments) + r'\\'+'\n\t\t\t' BrechtDeMan@1071: body += r'Number of empty comments: &' + str(total_empty_comments) +\ BrechtDeMan@1075: " (" + str(round(100.0*total_empty_comments/number_of_fragments,2)) + r"\%)\\"+'\n\t\t\t' BrechtDeMan@1071: body += r'Number of unplayed fragments: &' + str(total_not_played) +\ BrechtDeMan@1075: " (" + str(round(100.0*total_not_played/number_of_fragments,2)) + r"\%)\\"+'\n\t\t\t' BrechtDeMan@1071: body += r'Number of unmoved markers: &' + str(total_not_moved) +\ BrechtDeMan@1075: " (" + str(round(100.0*total_not_moved/number_of_fragments,2)) + r"\%)\\"+'\n\t\t\t' BrechtDeMan@1075: body += r'Average time per page: &' + seconds2timestr(time_per_page_accum/number_of_pages) + r"\\"+'\n\t\t' BrechtDeMan@1071: body += '\\end{tabular} \\vspace{1.5cm} \\\\ \n' BrechtDeMan@1071: BrechtDeMan@1071: # Average duration for first, second, ... page BrechtDeMan@1075: body += "\t\t\\vspace{.5cm} \n\n\t\tAverage duration per page (see also Figure \\ref{fig:avgtimeperpage}): \\\\ \n\t\t" BrechtDeMan@1071: body += r'''\begin{tabular}{lll} BrechtDeMan@1075: \textbf{Page} & \textbf{Duration} & \textbf{\# subjects}\\''' BrechtDeMan@1071: tpp_averages = [] # store average time per page BrechtDeMan@1071: for page_number in range(len(duration_order)): BrechtDeMan@1075: body += '\n\t\t\t'+str(page_number+1) + "&" +\ BrechtDeMan@1071: seconds2timestr(sum(duration_order[page_number])/len(duration_order[page_number])) +\ BrechtDeMan@1071: "&"+str(len(duration_order[page_number]))+r"\\" BrechtDeMan@1071: tpp_averages.append(sum(duration_order[page_number])/len(duration_order[page_number])) BrechtDeMan@1071: BrechtDeMan@1075: body += '\n\t\t\\end{tabular} \\vspace{1.5cm} \\\\ \n\n\t\t' BrechtDeMan@1071: BrechtDeMan@1071: # SHOW bar plot of average time per page BrechtDeMan@1072: plt.bar(range(1,len(duration_order)+1), np.array(tpp_averages)/60) BrechtDeMan@1072: plt.xlabel('Page order') BrechtDeMan@1071: plt.xlim(.8, len(duration_order)+1) BrechtDeMan@1071: plt.xticks(np.arange(1,len(duration_order)+1)+.4, range(1,len(duration_order)+1)) BrechtDeMan@1072: plt.ylabel('Average time [minutes]') BrechtDeMan@780: plt.savefig(folder_name+"time_per_page.pdf", bbox_inches='tight') BrechtDeMan@1071: plt.close() BrechtDeMan@1071: #TODO add error bars BrechtDeMan@1071: BrechtDeMan@1071: BrechtDeMan@1071: # Sort pages by number of audioelements, then by duration BrechtDeMan@1071: BrechtDeMan@1071: # average duration and number of subjects per page BrechtDeMan@1071: average_duration_page = [] BrechtDeMan@1071: number_of_subjects_page = [] BrechtDeMan@1071: for line in duration_page: BrechtDeMan@1071: number_of_subjects_page.append(len(line)) BrechtDeMan@1071: average_duration_page.append(sum(line)/len(line)) BrechtDeMan@1071: BrechtDeMan@1071: # combine and sort in function of number of audioelements and duration BrechtDeMan@1071: combined_list = [page_names, average_duration_page, fragments_per_page, number_of_subjects_page] BrechtDeMan@1071: combined_list = sorted(zip(*combined_list), key=operator.itemgetter(1, 2)) # sort BrechtDeMan@1071: BrechtDeMan@1071: # Show average duration for all songs BrechtDeMan@1075: body += r'''\vspace{.5cm} BrechtDeMan@1075: Average duration per audioholder (see also Figure \ref{fig:avgtimeperaudioholder}): \\ BrechtDeMan@1075: \begin{tabular}{llll} BrechtDeMan@1075: \textbf{Audioholder} & \textbf{Duration} & \textbf{\# subjects} & \textbf{\# fragments} \\''' BrechtDeMan@1072: audioholder_names_ordered = [] BrechtDeMan@1072: average_duration_audioholder_ordered = [] BrechtDeMan@1072: number_of_subjects = [] BrechtDeMan@1071: for page_index in range(len(page_names)): BrechtDeMan@1072: audioholder_names_ordered.append(combined_list[page_index][0]) BrechtDeMan@1072: average_duration_audioholder_ordered.append(combined_list[page_index][1]) BrechtDeMan@1072: number_of_subjects.append(combined_list[page_index][3]) BrechtDeMan@1075: body += '\n\t\t\t'+combined_list[page_index][0] + "&" +\ BrechtDeMan@1071: seconds2timestr(combined_list[page_index][1]) + "&" +\ BrechtDeMan@1071: str(combined_list[page_index][3]) + "&" +\ BrechtDeMan@1071: str(combined_list[page_index][2]) + r"\\" BrechtDeMan@1075: body += '\n\t\t\\end{tabular}\n' BrechtDeMan@1071: BrechtDeMan@1072: # SHOW bar plot of average time per page BrechtDeMan@1072: plt.bar(range(1,len(audioholder_names_ordered)+1), np.array(average_duration_audioholder_ordered)/60) BrechtDeMan@1072: plt.xlabel('Audioholder') BrechtDeMan@1072: plt.xlim(.8, len(audioholder_names_ordered)+1) BrechtDeMan@1072: plt.xticks(np.arange(1,len(audioholder_names_ordered)+1)+.4, audioholder_names_ordered, rotation=90) BrechtDeMan@1072: plt.ylabel('Average time [minutes]') BrechtDeMan@780: plt.savefig(folder_name+"time_per_audioholder.pdf", bbox_inches='tight') BrechtDeMan@1072: plt.close() BrechtDeMan@1072: BrechtDeMan@1072: # SHOW bar plot of average time per page BrechtDeMan@1072: plt.bar(range(1,len(audioholder_names_ordered)+1), number_of_subjects) BrechtDeMan@1072: plt.xlabel('Audioholder') BrechtDeMan@1072: plt.xlim(.8, len(audioholder_names_ordered)+1) BrechtDeMan@1072: plt.xticks(np.arange(1,len(audioholder_names_ordered)+1)+.4, audioholder_names_ordered, rotation=90) BrechtDeMan@1072: plt.ylabel('Number of subjects') BrechtDeMan@1072: ax = plt.gca() BrechtDeMan@1072: ylims = ax.get_ylim() BrechtDeMan@1072: yint = np.arange(int(np.floor(ylims[0])), int(np.ceil(ylims[1]))+1) BrechtDeMan@1072: plt.yticks(yint) BrechtDeMan@780: plt.savefig(folder_name+"subjects_per_audioholder.pdf", bbox_inches='tight') BrechtDeMan@1072: plt.close() BrechtDeMan@1072: BrechtDeMan@1072: # SHOW both figures BrechtDeMan@1075: body += r''' BrechtDeMan@1075: \begin{figure}[htbp] BrechtDeMan@1072: \begin{center} BrechtDeMan@1072: \includegraphics[width=.65\textwidth]{'''+\ BrechtDeMan@780: folder_name+'time_per_page.pdf'+\ BrechtDeMan@1072: r'''} BrechtDeMan@1072: \caption{Average time spent per page.} BrechtDeMan@1072: \label{fig:avgtimeperpage} BrechtDeMan@1072: \end{center} BrechtDeMan@1072: \end{figure} BrechtDeMan@1075: BrechtDeMan@1072: ''' BrechtDeMan@1072: body += r'''\begin{figure}[htbp] BrechtDeMan@1072: \begin{center} BrechtDeMan@1072: \includegraphics[width=.65\textwidth]{'''+\ BrechtDeMan@780: folder_name+'time_per_audioholder.pdf'+\ BrechtDeMan@1072: r'''} BrechtDeMan@1072: \caption{Average time spent per audioholder.} BrechtDeMan@1072: \label{fig:avgtimeperaudioholder} BrechtDeMan@1072: \end{center} BrechtDeMan@1072: \end{figure} BrechtDeMan@1075: BrechtDeMan@1072: ''' BrechtDeMan@1072: body += r'''\begin{figure}[htbp] BrechtDeMan@1072: \begin{center} BrechtDeMan@1072: \includegraphics[width=.65\textwidth]{'''+\ BrechtDeMan@780: folder_name+'subjects_per_audioholder.pdf'+\ BrechtDeMan@1072: r'''} BrechtDeMan@1072: \caption{Number of subjects per audioholder.} BrechtDeMan@1076: \label{fig:subjectsperaudioholder} BrechtDeMan@1072: \end{center} BrechtDeMan@1072: \end{figure} BrechtDeMan@1075: BrechtDeMan@1072: ''' BrechtDeMan@1072: #TODO add error bars BrechtDeMan@1072: #TODO layout of figures BrechtDeMan@1072: BrechtDeMan@1072: # SHOW boxplot per audioholder BrechtDeMan@1072: #TODO order in decreasing order of participants BrechtDeMan@1072: for audioholder_name in page_names: # get each name BrechtDeMan@1072: # plot boxplot if exists (not so for the 'alt' names) BrechtDeMan@780: if os.path.isfile(folder_name+'ratings/'+audioholder_name+'-ratings-box.pdf'): BrechtDeMan@1072: body += r'''\begin{figure}[htbp] BrechtDeMan@1072: \begin{center} BrechtDeMan@1072: \includegraphics[width=.65\textwidth]{'''+\ BrechtDeMan@780: folder_name+"ratings/"+audioholder_name+'-ratings-box.pdf'+\ BrechtDeMan@1072: r'''} BrechtDeMan@1072: \caption{Box plot of ratings for audioholder '''+\ BrechtDeMan@1072: audioholder_name+' ('+str(subject_count[real_page_names.index(audioholder_name)])+\ BrechtDeMan@1072: ''' participants).} BrechtDeMan@1076: \label{fig:boxplot'''+audioholder_name.replace(" ", "")+'''} BrechtDeMan@1072: \end{center} BrechtDeMan@1072: \end{figure} BrechtDeMan@1075: BrechtDeMan@1072: ''' BrechtDeMan@1072: BrechtDeMan@1072: # DEMO pie chart of gender distribution among subjects BrechtDeMan@1072: genders = ['male', 'female', 'other', 'preferNotToSay', 'UNAVAILABLE'] BrechtDeMan@1072: # TODO: get the above automatically BrechtDeMan@1072: gender_distribution = '' BrechtDeMan@1072: for item in genders: BrechtDeMan@1072: number = gender.count(item) BrechtDeMan@1072: if number>0: BrechtDeMan@1072: gender_distribution += str("{:.2f}".format((100.0*number)/len(gender)))+\ BrechtDeMan@1072: '/'+item.capitalize()+' ('+str(number)+'),\n' BrechtDeMan@1072: BrechtDeMan@1072: body += r''' BrechtDeMan@1075: % Pie chart of gender distribution BrechtDeMan@1072: \def\angle{0} BrechtDeMan@1072: \def\radius{3} BrechtDeMan@1072: \def\cyclelist{{"orange","blue","red","green"}} BrechtDeMan@1072: \newcount\cyclecount \cyclecount=-1 BrechtDeMan@1072: \newcount\ind \ind=-1 BrechtDeMan@1072: \begin{figure}[htbp] BrechtDeMan@1072: \begin{center}\begin{tikzpicture}[nodes = {font=\sffamily}] BrechtDeMan@1072: \foreach \percent/\name in {'''+\ BrechtDeMan@1072: gender_distribution+\ BrechtDeMan@1072: r'''} {\ifx\percent\empty\else % If \percent is empty, do nothing BrechtDeMan@1072: \global\advance\cyclecount by 1 % Advance cyclecount BrechtDeMan@1072: \global\advance\ind by 1 % Advance list index BrechtDeMan@1072: \ifnum6<\cyclecount % If cyclecount is larger than list BrechtDeMan@1072: \global\cyclecount=0 % reset cyclecount and BrechtDeMan@1072: \global\ind=0 % reset list index BrechtDeMan@1072: \fi BrechtDeMan@1072: \pgfmathparse{\cyclelist[\the\ind]} % Get color from cycle list BrechtDeMan@1072: \edef\color{\pgfmathresult} % and store as \color BrechtDeMan@1072: % Draw angle and set labels BrechtDeMan@1072: \draw[fill={\color!50},draw={\color}] (0,0) -- (\angle:\radius) BrechtDeMan@1072: arc (\angle:\angle+\percent*3.6:\radius) -- cycle; BrechtDeMan@1072: \node at (\angle+0.5*\percent*3.6:0.7*\radius) {\percent\,\%}; BrechtDeMan@1072: \node[pin=\angle+0.5*\percent*3.6:\name] BrechtDeMan@1072: at (\angle+0.5*\percent*3.6:\radius) {}; BrechtDeMan@1072: \pgfmathparse{\angle+\percent*3.6} % Advance angle BrechtDeMan@1072: \xdef\angle{\pgfmathresult} % and store in \angle BrechtDeMan@1072: \fi BrechtDeMan@1072: }; BrechtDeMan@1072: \end{tikzpicture} BrechtDeMan@1072: \caption{Representation of gender across subjects} BrechtDeMan@1072: \label{default} BrechtDeMan@1072: \end{center} BrechtDeMan@1072: \end{figure} BrechtDeMan@1075: BrechtDeMan@1072: ''' BrechtDeMan@1072: # problem: some people entered twice? BrechtDeMan@1072: BrechtDeMan@1071: #TODO BrechtDeMan@1071: # time per page in function of number of fragments (plot) BrechtDeMan@1071: # time per participant in function of number of pages BrechtDeMan@1071: # plot total time for each participant BrechtDeMan@1071: # show 'count' per page (in order) BrechtDeMan@1071: BrechtDeMan@1071: # clear up page_index <> page_count <> page_number confusion BrechtDeMan@1071: BrechtDeMan@1071: BrechtDeMan@1072: texfile = header+body+footer # add bits together BrechtDeMan@1071: BrechtDeMan@780: print 'pdflatex -output-directory="'+folder_name+'"" "'+ folder_name + 'Report.tex"' # DEBUG BrechtDeMan@780: BrechtDeMan@1071: # write TeX file BrechtDeMan@780: with open(folder_name + 'Report.tex','w') as f: BrechtDeMan@1071: f.write(texfile) BrechtDeMan@780: proc=subprocess.Popen(shlex.split('pdflatex -output-directory="'+folder_name+'" "'+ folder_name + 'Report.tex"')) BrechtDeMan@1071: proc.communicate() BrechtDeMan@1071: # run again BrechtDeMan@780: proc=subprocess.Popen(shlex.split('pdflatex -output-directory="'+folder_name+'" "'+ folder_name + 'Report.tex"')) BrechtDeMan@1071: proc.communicate() BrechtDeMan@1071: BrechtDeMan@1072: #TODO remove auxiliary LaTeX files BrechtDeMan@1072: try: BrechtDeMan@780: os.remove(folder_name + 'Report.aux') BrechtDeMan@780: os.remove(folder_name + 'Report.log') BrechtDeMan@780: os.remove(folder_name + 'Report.out') BrechtDeMan@780: os.remove(folder_name + 'Report.toc') BrechtDeMan@1072: except OSError: BrechtDeMan@1072: pass giuliomoro@1208: