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