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