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