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