annotate scripts/generate_report.py @ 1811:520da128f47a

Scripts: comment_parser and score_parser start new CSV files each time; various plots added to generated PDF report
author Brecht De Man <b.deman@qmul.ac.uk>
date Thu, 20 Aug 2015 11:29:29 +0200
parents 7020aed2f8c6
children a76081548018
rev   line source
b@1810 1 #!/usr/bin/python
b@1810 2 # -*- coding: utf-8 -*-
b@1810 3
b@1810 4 import xml.etree.ElementTree as ET
b@1810 5 import os # for getting files from directory
b@1810 6 import operator # for sorting data with multiple keys
b@1810 7 import sys # for accessing command line arguments
b@1810 8 import subprocess # for calling pdflatex
b@1810 9 import shlex # for calling pdflatex
b@1810 10 import matplotlib.pyplot as plt # plots
b@1810 11 import numpy as np # numbers
b@1810 12
b@1810 13 # Command line arguments
b@1811 14 assert len(sys.argv)<4, "evaluation_stats takes at most 2 command line argument\n"+\
b@1811 15 "Use: python generate_report.py [results_folder] [no_render | -nr]"
b@1811 16
b@1811 17 render_figures = True
b@1810 18
b@1810 19 # XML results files location
b@1810 20 if len(sys.argv) == 1:
b@1810 21 folder_name = "../saves" # Looks in 'saves/' folder from 'scripts/' folder
b@1811 22 print "Use: python generate_report.py [results_folder] [no_render | -nr]"
b@1810 23 print "Using default path: " + folder_name
b@1810 24 elif len(sys.argv) == 2:
b@1810 25 folder_name = sys.argv[1] # First command line argument is folder
b@1811 26 elif len(sys.argv) == 3:
b@1811 27 folder_name = sys.argv[1] # First command line argument is folder
b@1811 28 assert sys.argv[2] in ('no_render','-nr'), "Second argument not recognised. \n" +\
b@1811 29 "Use: python generate_report.py [results_folder] [no_render | -nr]"
b@1811 30 # Second command line argument is [no_render | -nr]
b@1811 31 render_figures = False
b@1811 32
b@1811 33
b@1811 34 #TODO add 'skip regenerating figures'
b@1810 35
b@1810 36 # Turn number of seconds (int) to '[minutes] min [seconds] s' (string)
b@1810 37 def seconds2timestr(time_in_seconds):
b@1810 38 time_in_minutes = int(time_in_seconds/60)
b@1810 39 remaining_seconds = int(time_in_seconds%60)
b@1810 40 return str(time_in_minutes) + " min " + str(remaining_seconds) + " s"
b@1810 41
b@1810 42 # stats initialisation
b@1810 43 number_of_XML_files = 0
b@1810 44 number_of_pages = 0
b@1810 45 number_of_fragments = 0
b@1810 46 total_empty_comments = 0
b@1810 47 total_not_played = 0
b@1810 48 total_not_moved = 0
b@1810 49 time_per_page_accum = 0
b@1810 50
b@1810 51 # arrays initialisation
b@1810 52 page_names = []
b@1811 53 real_page_names = [] # regardless of differing numbers of fragments
b@1811 54 subject_count = [] # subjects per audioholder name
b@1810 55 page_count = []
b@1810 56 duration_page = [] # duration of experiment in function of page content
b@1810 57 duration_order = [] # duration of experiment in function of page number
b@1810 58 fragments_per_page = [] # number of fragments for corresponding page
b@1810 59
b@1811 60 # survey stats
b@1811 61 gender = []
b@1811 62 age = []
b@1811 63
b@1810 64 # get username if available
b@1810 65 for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
b@1810 66 user = os.environ.get(name)
b@1810 67 if user:
b@1810 68 break
b@1810 69 else:
b@1810 70 user = ''
b@1810 71
b@1810 72
b@1810 73 # begin LaTeX document
b@1810 74 header = r'''\documentclass[11pt, oneside]{article}
b@1810 75 \usepackage{geometry}
b@1811 76 \geometry{a4paper}
b@1811 77 \usepackage[parfill]{parskip} % empty line instead of indent
b@1811 78 \usepackage{graphicx} % figures
b@1811 79 \usepackage{hyperref}
b@1811 80 \usepackage{tikz} % pie charts
b@1810 81 \title{Report}
b@1810 82 \author{'''+\
b@1810 83 user+\
b@1810 84 r'''}
b@1810 85 \graphicspath{{'''+\
b@1810 86 folder_name+\
b@1810 87 r'''/}}
b@1811 88 %\setcounter{section}{-1} % Summary section 0 so number of sections equals number of files
b@1810 89 \begin{document}
b@1810 90 \maketitle
b@1811 91 This is an automatically generated report using the `generate\_report.py' Python script
b@1811 92 included with the Web Audio Evaluation Tool \cite{WAET} distribution which can be found
b@1811 93 at \texttt{code.soundsoftware.ac.uk/projects/webaudioevaluationtool}.
b@1810 94 \tableofcontents
b@1811 95
b@1810 96 '''
b@1810 97
b@1811 98 footer = r'''\begin{thebibliography}{9}
b@1811 99 \bibitem{WAET} % reference to accompanying publication
b@1811 100 Nicholas Jillings, Brecht De Man, David Moffat and Joshua D. Reiss,
b@1811 101 ``Web Audio Evaluation Tool: A browser-based listening test environment,''
b@1811 102 presented at the 12th Sound and Music Computing Conference, July 2015.
b@1811 103 \end{thebibliography}
b@1811 104 \end{document}'''
b@1810 105
b@1810 106 body = ''
b@1810 107
b@1810 108 # generate images for later use
b@1811 109 if render_figures:
b@1811 110 subprocess.call("python timeline_view_movement.py", shell=True)
b@1811 111 subprocess.call("python score_parser.py", shell=True)
b@1811 112 subprocess.call("python score_plot.py", shell=True)
b@1810 113
b@1810 114 # get every XML file in folder
b@1810 115 files_list = os.listdir(folder_name)
b@1810 116 for file in files_list: # iterate over all files in files_list
b@1810 117 if file.endswith(".xml"): # check if XML file
b@1810 118 number_of_XML_files += 1
b@1810 119 tree = ET.parse(folder_name + '/' + file)
b@1810 120 root = tree.getroot()
b@1810 121
b@1810 122 # PRINT name as section
b@1810 123 body+= '\section{'+file[:-4].capitalize()+'}\n' # make section header from name without extension
b@1810 124
b@1810 125 # reset for new subject
b@1810 126 total_duration = 0
b@1810 127 page_number = 0
b@1810 128
b@1810 129 individual_table = '' # table with stats for this individual test file
b@1811 130 timeline_plots = '' # plots of timeline (movements and plays)
b@1811 131
b@1811 132 # DEMO survey stats
b@1811 133 # get gender
b@1811 134 this_subjects_gender = root.find("./posttest/radio/[@id='gender']")
b@1811 135 if this_subjects_gender is not None:
b@1811 136 gender.append(this_subjects_gender.get("name"))
b@1811 137 else:
b@1811 138 gender.append('UNAVAILABLE')
b@1811 139 # get age
b@1811 140 this_subjects_age = root.find("./posttest/number/[@id='age']")
b@1811 141 if this_subjects_age is not None:
b@1811 142 age.append(this_subjects_age.text)
b@1810 143
b@1810 144 # get list of all page names
b@1810 145 for audioholder in root.findall("./audioholder"): # iterate over pages
b@1810 146 page_name = audioholder.get('id') # get page name
b@1810 147
b@1810 148 if page_name is None: # ignore 'empty' audio_holders
b@1810 149 print "WARNING: " + file + " contains empty audio holder. (evaluation_stats.py)"
b@1810 150 break # move on to next
b@1810 151
b@1810 152 number_of_comments = 0 # for this page
b@1810 153 number_of_missing_comments = 0 # for this page
b@1810 154 not_played = 0 # for this page
b@1810 155 not_moved = 0 # for this page
b@1810 156
b@1810 157 # 'testTime' keeps total duration: subtract time so far for duration of this audioholder
b@1810 158 duration = float(audioholder.find("./metric/metricresult[@id='testTime']").text) - total_duration
b@1810 159
b@1810 160 # total duration of test
b@1810 161 total_duration += duration
b@1810 162
b@1810 163 # number of audio elements
b@1810 164 audioelements = audioholder.findall("./audioelement") # get audioelements
b@1810 165 number_of_fragments += len(audioelements) # add length of this list to total
b@1810 166
b@1810 167 # number of comments (interesting if comments not mandatory)
b@1810 168 for audioelement in audioelements:
b@1810 169 response = audioelement.find("./comment/response")
b@1810 170 was_played = audioelement.find("./metric/metricresult/[@name='elementFlagListenedTo']")
b@1810 171 was_moved = audioelement.find("./metric/metricresult/[@name='elementFlagMoved']")
b@1810 172 if response.text is not None and len(response.text) > 1:
b@1810 173 number_of_comments += 1
b@1810 174 else:
b@1810 175 number_of_missing_comments += 1
b@1810 176 if was_played is not None and was_played.text == 'false':
b@1810 177 not_played += 1
b@1810 178 if was_moved is not None and was_moved.text == 'false':
b@1810 179 not_moved += 1
b@1810 180
b@1810 181 # update global counters
b@1810 182 total_empty_comments += number_of_missing_comments
b@1810 183 total_not_played += not_played
b@1810 184 total_not_moved += not_moved
b@1810 185
b@1810 186 # PRINT alerts when elements not played or markers not moved
b@1810 187 # number of audio elements not played
b@1810 188 if not_played > 1:
b@1810 189 body += '\\emph{\\textbf{ATTENTION: '+str(not_played)+' fragments were not listened to in '+page_name+'!}} \\\\ \n'
b@1810 190 if not_played == 1:
b@1810 191 body += '\\emph{\\textbf{ATTENTION: one fragment was not listened to in '+page_name+'!}} \\\\ \n '
b@1810 192
b@1810 193 # number of audio element markers not moved
b@1810 194 if not_moved > 1:
b@1810 195 body += '\\emph{\\textbf{ATTENTION: '+str(not_moved)+' markers were not moved in '+page_name+'!}} \\\\ \n'
b@1810 196 if not_moved == 1:
b@1810 197 body += '\\emph{\\textbf{ATTENTION: one marker was not moved in '+page_name+'!}} \\\\ \n'
b@1810 198 #TODO which one not moved/listened to?
b@1810 199
b@1810 200 # PRINT song-specific statistic
b@1810 201 individual_table += page_name+'&'+\
b@1810 202 str(number_of_comments) + '/' +\
b@1810 203 str(number_of_comments+number_of_missing_comments)+'&'+\
b@1810 204 seconds2timestr(duration)+'\\\\'
b@1810 205
b@1810 206 # get timeline for this audioholder
b@1810 207 img_path = 'timelines_movement/'+file[:-4]+'-'+page_name+'.pdf'
b@1810 208
b@1810 209 # check if available
b@1810 210 if os.path.isfile(folder_name+'/'+img_path):
b@1810 211 # SHOW timeline image
b@1811 212 timeline_plots += '\\includegraphics[width=\\textwidth]{'+\
b@1811 213 folder_name+'/'+img_path+'}\n\n'
b@1810 214
b@1810 215 # keep track of duration in function of page index
b@1810 216 if len(duration_order)>page_number:
b@1810 217 duration_order[page_number].append(duration)
b@1810 218 else:
b@1810 219 duration_order.append([duration])
b@1811 220
b@1810 221 # keep list of audioholder ids and count how many times each audioholder id
b@1811 222 # was tested, how long it took, and how many fragments there were
b@1811 223 # (if number of fragments is different, store as different audioholder id)
b@1810 224 if page_name in page_names:
b@1810 225 page_index = page_names.index(page_name) # get index
b@1810 226 # check if number of audioelements the same
b@1810 227 if len(audioelements) == fragments_per_page[page_index]:
b@1810 228 page_count[page_index] += 1
b@1810 229 duration_page[page_index].append(duration)
b@1810 230 else: # make new entry
b@1810 231 alt_page_name = page_name+"("+str(len(audioelements))+")"
b@1810 232 if alt_page_name in page_names: # if already there
b@1810 233 alt_page_index = page_names.index(alt_page_name) # get index
b@1810 234 page_count[alt_page_index] += 1
b@1810 235 duration_page[alt_page_index].append(duration)
b@1810 236 else:
b@1810 237 page_names.append(alt_page_name)
b@1810 238 page_count.append(1)
b@1810 239 duration_page.append([duration])
b@1810 240 fragments_per_page.append(len(audioelements))
b@1810 241 else:
b@1810 242 page_names.append(page_name)
b@1810 243 page_count.append(1)
b@1810 244 duration_page.append([duration])
b@1810 245 fragments_per_page.append(len(audioelements))
b@1811 246
b@1811 247 # number of subjects per audioholder regardless of differing numbers of
b@1811 248 # fragments (for inclusion in box plots)
b@1811 249 if page_name in real_page_names:
b@1811 250 page_index = real_page_names.index(page_name) # get index
b@1811 251 subject_count[page_index] += 1
b@1811 252 else:
b@1811 253 real_page_names.append(page_name)
b@1811 254 subject_count.append(1)
b@1811 255
b@1810 256 # bookkeeping
b@1810 257 page_number += 1 # increase page count for this specific test
b@1810 258 number_of_pages += 1 # increase total number of pages
b@1810 259 time_per_page_accum += duration # total duration (for average time spent per page)
b@1810 260
b@1810 261 # PRINT table with statistics about this test
b@1810 262 body += r'''\begin{tabular}{|p{3.5cm}|c|p{2.5cm}|}
b@1810 263 \hline
b@1810 264 \textbf{Song name} & \textbf{Comments} & \textbf{Duration} \\ \hline '''+\
b@1810 265 individual_table+\
b@1810 266 r'''\hline
b@1810 267 \textbf{TOTAL} & & \textbf{'''+\
b@1810 268 seconds2timestr(total_duration)+\
b@1810 269 r'''}\\
b@1810 270 \hline
b@1811 271 \end{tabular}
b@1811 272
b@1811 273 '''
b@1811 274 # PRINT timeline plots
b@1811 275 body += timeline_plots
b@1810 276
b@1810 277 # join to footer
b@1810 278 footer = body + footer
b@1810 279
b@1810 280 # empty body again
b@1810 281 body = ''
b@1810 282
b@1811 283 # PRINT summary of everything (at start)
b@1811 284 # unnumbered so that number of sections equals number of files
b@1811 285 body += '\section*{Summary}\n\\addcontentsline{toc}{section}{Summary}'
b@1810 286
b@1810 287 # PRINT table with statistics
b@1810 288 body += '\\begin{tabular}{ll}'
b@1810 289 body += r'Number of XML files: &' + str(number_of_XML_files) + r'\\'
b@1810 290 body += r'Number of pages: &' + str(number_of_pages) + r'\\'
b@1810 291 body += r'Number of fragments: &' + str(number_of_fragments) + r'\\'
b@1810 292 body += r'Number of empty comments: &' + str(total_empty_comments) +\
b@1810 293 " (" + str(round(100.0*total_empty_comments/number_of_fragments,2)) + r"\%)\\"
b@1810 294 body += r'Number of unplayed fragments: &' + str(total_not_played) +\
b@1810 295 " (" + str(round(100.0*total_not_played/number_of_fragments,2)) + r"\%)\\"
b@1810 296 body += r'Number of unmoved markers: &' + str(total_not_moved) +\
b@1810 297 " (" + str(round(100.0*total_not_moved/number_of_fragments,2)) + r"\%)\\"
b@1810 298 body += r'Average time per page: &' + seconds2timestr(time_per_page_accum/number_of_pages) + r"\\"
b@1810 299 body += '\\end{tabular} \\vspace{1.5cm} \\\\ \n'
b@1810 300
b@1810 301 # Average duration for first, second, ... page
b@1810 302 body += " \\vspace{.5cm} Average duration per page (see also Figure \\ref{fig:avgtimeperpage}): \\\\ \n"
b@1810 303 body += r'''\begin{tabular}{lll}
b@1810 304 \textbf{Page} & \textbf{Duration} & \textbf{\# subjects}\\
b@1810 305 '''
b@1810 306 tpp_averages = [] # store average time per page
b@1810 307 for page_number in range(len(duration_order)):
b@1810 308 body += str(page_number+1) + "&" +\
b@1810 309 seconds2timestr(sum(duration_order[page_number])/len(duration_order[page_number])) +\
b@1810 310 "&"+str(len(duration_order[page_number]))+r"\\"
b@1810 311 tpp_averages.append(sum(duration_order[page_number])/len(duration_order[page_number]))
b@1810 312
b@1810 313 body += '\\end{tabular} \\vspace{1.5cm} \\\\ \n'
b@1810 314
b@1810 315 # SHOW bar plot of average time per page
b@1811 316 plt.bar(range(1,len(duration_order)+1), np.array(tpp_averages)/60)
b@1811 317 plt.xlabel('Page order')
b@1810 318 plt.xlim(.8, len(duration_order)+1)
b@1810 319 plt.xticks(np.arange(1,len(duration_order)+1)+.4, range(1,len(duration_order)+1))
b@1811 320 plt.ylabel('Average time [minutes]')
b@1810 321 plt.savefig(folder_name+"/time_per_page.pdf", bbox_inches='tight')
b@1810 322 plt.close()
b@1810 323 #TODO add error bars
b@1810 324
b@1810 325
b@1810 326 # Sort pages by number of audioelements, then by duration
b@1810 327
b@1810 328 # average duration and number of subjects per page
b@1810 329 average_duration_page = []
b@1810 330 number_of_subjects_page = []
b@1810 331 for line in duration_page:
b@1810 332 number_of_subjects_page.append(len(line))
b@1810 333 average_duration_page.append(sum(line)/len(line))
b@1810 334
b@1810 335 # combine and sort in function of number of audioelements and duration
b@1810 336 combined_list = [page_names, average_duration_page, fragments_per_page, number_of_subjects_page]
b@1810 337 combined_list = sorted(zip(*combined_list), key=operator.itemgetter(1, 2)) # sort
b@1810 338
b@1810 339 # Show average duration for all songs
b@1811 340 body += r'''\vspace{.5cm} Average duration per audioholder (see also Figure \ref{fig:avgtimeperaudioholder}): \\
b@1810 341 \begin{tabular}{llll}
b@1810 342 \textbf{Audioholder} & \textbf{Duration} & \textbf{\# subjects} & \textbf{\# fragments} \\
b@1810 343 '''
b@1811 344 audioholder_names_ordered = []
b@1811 345 average_duration_audioholder_ordered = []
b@1811 346 number_of_subjects = []
b@1810 347 for page_index in range(len(page_names)):
b@1811 348 audioholder_names_ordered.append(combined_list[page_index][0])
b@1811 349 average_duration_audioholder_ordered.append(combined_list[page_index][1])
b@1811 350 number_of_subjects.append(combined_list[page_index][3])
b@1810 351 body += combined_list[page_index][0] + "&" +\
b@1810 352 seconds2timestr(combined_list[page_index][1]) + "&" +\
b@1810 353 str(combined_list[page_index][3]) + "&" +\
b@1810 354 str(combined_list[page_index][2]) + r"\\"
b@1810 355 body += '\\end{tabular}\n'
b@1810 356
b@1811 357 # SHOW bar plot of average time per page
b@1811 358 plt.bar(range(1,len(audioholder_names_ordered)+1), np.array(average_duration_audioholder_ordered)/60)
b@1811 359 plt.xlabel('Audioholder')
b@1811 360 plt.xlim(.8, len(audioholder_names_ordered)+1)
b@1811 361 plt.xticks(np.arange(1,len(audioholder_names_ordered)+1)+.4, audioholder_names_ordered, rotation=90)
b@1811 362 plt.ylabel('Average time [minutes]')
b@1811 363 plt.savefig(folder_name+"/time_per_audioholder.pdf", bbox_inches='tight')
b@1811 364 plt.close()
b@1811 365
b@1811 366 # SHOW bar plot of average time per page
b@1811 367 plt.bar(range(1,len(audioholder_names_ordered)+1), number_of_subjects)
b@1811 368 plt.xlabel('Audioholder')
b@1811 369 plt.xlim(.8, len(audioholder_names_ordered)+1)
b@1811 370 plt.xticks(np.arange(1,len(audioholder_names_ordered)+1)+.4, audioholder_names_ordered, rotation=90)
b@1811 371 plt.ylabel('Number of subjects')
b@1811 372 ax = plt.gca()
b@1811 373 ylims = ax.get_ylim()
b@1811 374 yint = np.arange(int(np.floor(ylims[0])), int(np.ceil(ylims[1]))+1)
b@1811 375 plt.yticks(yint)
b@1811 376 plt.savefig(folder_name+"/subjects_per_audioholder.pdf", bbox_inches='tight')
b@1811 377 plt.close()
b@1811 378
b@1811 379 # SHOW both figures
b@1811 380 body += r'''\begin{figure}[htbp]
b@1811 381 \begin{center}
b@1811 382 \includegraphics[width=.65\textwidth]{'''+\
b@1811 383 folder_name+"/time_per_page.pdf"+\
b@1811 384 r'''}
b@1811 385 \caption{Average time spent per page.}
b@1811 386 \label{fig:avgtimeperpage}
b@1811 387 \end{center}
b@1811 388 \end{figure}
b@1811 389 '''
b@1811 390 body += r'''\begin{figure}[htbp]
b@1811 391 \begin{center}
b@1811 392 \includegraphics[width=.65\textwidth]{'''+\
b@1811 393 folder_name+"/time_per_audioholder.pdf"+\
b@1811 394 r'''}
b@1811 395 \caption{Average time spent per audioholder.}
b@1811 396 \label{fig:avgtimeperaudioholder}
b@1811 397 \end{center}
b@1811 398 \end{figure}
b@1811 399 '''
b@1811 400 body += r'''\begin{figure}[htbp]
b@1811 401 \begin{center}
b@1811 402 \includegraphics[width=.65\textwidth]{'''+\
b@1811 403 folder_name+"/subjects_per_audioholder.pdf"+\
b@1811 404 r'''}
b@1811 405 \caption{Number of subjects per audioholder.}
b@1811 406 \label{fig:avgtimeperaudioholder}
b@1811 407 \end{center}
b@1811 408 \end{figure}
b@1811 409 '''
b@1811 410 #TODO add error bars
b@1811 411 #TODO layout of figures
b@1811 412
b@1811 413 # SHOW boxplot per audioholder
b@1811 414 #TODO order in decreasing order of participants
b@1811 415 for audioholder_name in page_names: # get each name
b@1811 416 # plot boxplot if exists (not so for the 'alt' names)
b@1811 417 if os.path.isfile(folder_name+'/ratings/'+audioholder_name+'-ratings-box.pdf'):
b@1811 418 body += r'''\begin{figure}[htbp]
b@1811 419 \begin{center}
b@1811 420 \includegraphics[width=.65\textwidth]{'''+\
b@1811 421 folder_name+"/ratings/"+audioholder_name+'-ratings-box.pdf'+\
b@1811 422 r'''}
b@1811 423 \caption{Box plot of ratings for audioholder '''+\
b@1811 424 audioholder_name+' ('+str(subject_count[real_page_names.index(audioholder_name)])+\
b@1811 425 ''' participants).}
b@1811 426 \label{fig:avgtimeperpage}
b@1811 427 \end{center}
b@1811 428 \end{figure}
b@1811 429 '''
b@1811 430
b@1811 431 # DEMO pie chart of gender distribution among subjects
b@1811 432 genders = ['male', 'female', 'other', 'preferNotToSay', 'UNAVAILABLE']
b@1811 433 # TODO: get the above automatically
b@1811 434 gender_distribution = ''
b@1811 435 for item in genders:
b@1811 436 number = gender.count(item)
b@1811 437 if number>0:
b@1811 438 gender_distribution += str("{:.2f}".format((100.0*number)/len(gender)))+\
b@1811 439 '/'+item.capitalize()+' ('+str(number)+'),\n'
b@1811 440
b@1811 441 body += r'''
b@1811 442 \def\angle{0}
b@1811 443 \def\radius{3}
b@1811 444 \def\cyclelist{{"orange","blue","red","green"}}
b@1811 445 \newcount\cyclecount \cyclecount=-1
b@1811 446 \newcount\ind \ind=-1
b@1811 447 \begin{figure}[htbp]
b@1811 448 \begin{center}\begin{tikzpicture}[nodes = {font=\sffamily}]
b@1811 449 \foreach \percent/\name in {'''+\
b@1811 450 gender_distribution+\
b@1811 451 r'''} {\ifx\percent\empty\else % If \percent is empty, do nothing
b@1811 452 \global\advance\cyclecount by 1 % Advance cyclecount
b@1811 453 \global\advance\ind by 1 % Advance list index
b@1811 454 \ifnum6<\cyclecount % If cyclecount is larger than list
b@1811 455 \global\cyclecount=0 % reset cyclecount and
b@1811 456 \global\ind=0 % reset list index
b@1811 457 \fi
b@1811 458 \pgfmathparse{\cyclelist[\the\ind]} % Get color from cycle list
b@1811 459 \edef\color{\pgfmathresult} % and store as \color
b@1811 460 % Draw angle and set labels
b@1811 461 \draw[fill={\color!50},draw={\color}] (0,0) -- (\angle:\radius)
b@1811 462 arc (\angle:\angle+\percent*3.6:\radius) -- cycle;
b@1811 463 \node at (\angle+0.5*\percent*3.6:0.7*\radius) {\percent\,\%};
b@1811 464 \node[pin=\angle+0.5*\percent*3.6:\name]
b@1811 465 at (\angle+0.5*\percent*3.6:\radius) {};
b@1811 466 \pgfmathparse{\angle+\percent*3.6} % Advance angle
b@1811 467 \xdef\angle{\pgfmathresult} % and store in \angle
b@1811 468 \fi
b@1811 469 };
b@1811 470 \end{tikzpicture}
b@1811 471 \caption{Representation of gender across subjects}
b@1811 472 \label{default}
b@1811 473 \end{center}
b@1811 474 \end{figure}
b@1811 475 '''
b@1811 476 # problem: some people entered twice?
b@1811 477
b@1810 478 #TODO
b@1810 479 # time per page in function of number of fragments (plot)
b@1810 480 # time per participant in function of number of pages
b@1810 481 # plot total time for each participant
b@1810 482 # show 'count' per page (in order)
b@1810 483
b@1810 484 # clear up page_index <> page_count <> page_number confusion
b@1810 485
b@1810 486
b@1811 487 texfile = header+body+footer # add bits together
b@1810 488
b@1810 489 # write TeX file
b@1811 490 with open(folder_name + '/' + 'Report.tex','w') as f:
b@1810 491 f.write(texfile)
b@1811 492 proc=subprocess.Popen(shlex.split('pdflatex -output-directory='+folder_name+' '+ folder_name + '/Report.tex'))
b@1810 493 proc.communicate()
b@1810 494 # run again
b@1811 495 proc=subprocess.Popen(shlex.split('pdflatex -output-directory='+folder_name+' '+ folder_name + '/Report.tex'))
b@1810 496 proc.communicate()
b@1810 497
b@1811 498 #TODO remove auxiliary LaTeX files
b@1811 499 try:
b@1811 500 os.remove(folder_name + '/' + 'Report.aux')
b@1811 501 os.remove(folder_name + '/' + 'Report.log')
b@1811 502 os.remove(folder_name + '/' + 'Report.out')
b@1811 503 os.remove(folder_name + '/' + 'Report.toc')
b@1811 504 except OSError:
b@1811 505 pass
b@1811 506