b@2264
|
1 #!/usr/bin/python
|
b@2264
|
2 # -*- coding: utf-8 -*-
|
b@2264
|
3
|
b@2264
|
4 import xml.etree.ElementTree as ET
|
b@2264
|
5 import os # for getting files from directory
|
b@2264
|
6 import operator # for sorting data with multiple keys
|
b@2264
|
7 import sys # for accessing command line arguments
|
b@2264
|
8 import subprocess # for calling pdflatex
|
b@2264
|
9 import shlex # for calling pdflatex
|
b@2264
|
10 import matplotlib.pyplot as plt # plots
|
b@2264
|
11 import numpy as np # numbers
|
b@2264
|
12
|
b@2264
|
13 # Command line arguments
|
b@2264
|
14 assert len(sys.argv)<4, "generate_report takes at most 2 command line arguments\n"+\
|
b@2264
|
15 "Use: python generate_report.py [results_folder] [no_render | -nr]"
|
b@2264
|
16
|
b@2264
|
17 render_figures = True
|
b@2264
|
18
|
b@2264
|
19 # XML results files location
|
b@2264
|
20 if len(sys.argv) == 1:
|
b@2264
|
21 folder_name = "../saves/" # Looks in 'saves/' folder from 'scripts/' folder
|
b@2279
|
22 print("Use: python generate_report.py [results_folder] [no_render | -nr]")
|
b@2279
|
23 print("Using default path: " + folder_name)
|
b@2264
|
24 elif len(sys.argv) == 2:
|
b@2264
|
25 folder_name = sys.argv[1] # First command line argument is folder
|
b@2264
|
26 elif len(sys.argv) == 3:
|
b@2264
|
27 folder_name = sys.argv[1] # First command line argument is folder
|
b@2264
|
28 assert sys.argv[2] in ('no_render','-nr'), "Second argument not recognised. \n" +\
|
b@2264
|
29 "Use: python generate_report.py [results_folder] [no_render | -nr]"
|
b@2264
|
30 # Second command line argument is [no_render | -nr]
|
b@2264
|
31 render_figures = False
|
b@2264
|
32
|
b@2264
|
33 def isNaN(num):
|
b@2264
|
34 return num != num
|
b@2264
|
35
|
b@2264
|
36 # Turn number of seconds (int) to '[minutes] min [seconds] s' (string)
|
b@2264
|
37 def seconds2timestr(time_in_seconds):
|
b@2264
|
38 if time_in_seconds is not None and not isNaN(time_in_seconds):
|
b@2264
|
39 time_in_minutes = int(time_in_seconds/60)
|
b@2264
|
40 remaining_seconds = int(time_in_seconds%60)
|
b@2264
|
41 return str(time_in_minutes) + " min " + str(remaining_seconds) + " s"
|
b@2264
|
42 else:
|
b@2264
|
43 return 'N/A'
|
b@2264
|
44
|
b@2264
|
45 # stats initialisation
|
b@2264
|
46 number_of_XML_files = 0
|
b@2264
|
47 number_of_pages = 0
|
b@2264
|
48 number_of_fragments = 0
|
b@2264
|
49 total_empty_comments = 0
|
b@2264
|
50 total_not_played = 0
|
b@2264
|
51 total_not_moved = 0
|
b@2264
|
52 time_per_page_accum = 0
|
b@2264
|
53
|
b@2264
|
54 # arrays initialisation
|
b@2264
|
55 page_names = []
|
b@2264
|
56 real_page_names = [] # regardless of differing numbers of fragments
|
b@2279
|
57 subject_count = [] # subjects per page name
|
b@2264
|
58 page_count = []
|
b@2264
|
59 duration_page = [] # duration of experiment in function of page content
|
b@2264
|
60 duration_order = [] # duration of experiment in function of page number
|
b@2264
|
61 fragments_per_page = [] # number of fragments for corresponding page
|
b@2264
|
62
|
b@2264
|
63 # survey stats
|
b@2264
|
64 gender = []
|
b@2264
|
65 age = []
|
b@2264
|
66
|
b@2522
|
67 # diagnostics
|
b@2522
|
68 browser = []
|
b@2522
|
69 platform = []
|
b@2522
|
70
|
b@2264
|
71 # get username if available
|
b@2264
|
72 for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
|
b@2264
|
73 user = os.environ.get(name)
|
b@2264
|
74 if user:
|
b@2264
|
75 break
|
b@2264
|
76 else:
|
b@2264
|
77 user = ''
|
b@2264
|
78
|
b@2485
|
79 # Months
|
b@2485
|
80 month_array = ['January', 'February', 'March', 'April', 'May', 'June', \
|
b@2485
|
81 'July', 'August', 'September', 'October', 'November', 'December']
|
b@2264
|
82
|
b@2264
|
83 # begin LaTeX document
|
b@2264
|
84 header = r'''\documentclass[11pt, oneside]{article}
|
b@2264
|
85 \usepackage{geometry}
|
b@2264
|
86 \geometry{a4paper}
|
b@2264
|
87 \usepackage[parfill]{parskip} % empty line instead of indent
|
b@2486
|
88 \usepackage{graphicx} % figures
|
b@2486
|
89 \usepackage[space]{grffile} % include figures with spaces in paths
|
b@2487
|
90 \usepackage[pdfpagelabels]{hyperref}
|
b@2486
|
91 \usepackage{tikz} % pie charts
|
b@2486
|
92 \usepackage{float} % place figures 'here'
|
b@2264
|
93 \title{Report}
|
b@2264
|
94 \author{'''+\
|
b@2264
|
95 user+\
|
b@2264
|
96 r'''}
|
b@2264
|
97 \graphicspath{{'''+\
|
b@2264
|
98 folder_name+\
|
b@2264
|
99 r'''}}
|
b@2264
|
100 %\setcounter{section}{-1} % Summary section 0 so number of sections equals number of files
|
b@2264
|
101 \begin{document}
|
b@2264
|
102 \maketitle
|
b@2264
|
103 This is an automatically generated report using the `generate\_report.py' Python script
|
b@2264
|
104 included with the Web Audio Evaluation Tool \cite{WAET} distribution which can be found
|
b@2487
|
105 at \texttt{\href{https://github.com/BrechtDeMan/WebAudioEvaluationTool}{github.com/BrechtDeMan/WebAudioEvaluationTool}}.
|
b@2264
|
106 \tableofcontents
|
b@2264
|
107
|
b@2264
|
108 '''
|
b@2264
|
109
|
b@2486
|
110 footer = '\n\t\t'+r'''\begin{thebibliography}{1}
|
b@2264
|
111 \bibitem{WAET} % reference to accompanying publication
|
b@2264
|
112 Nicholas Jillings, Brecht De Man, David Moffat and Joshua D. Reiss,
|
b@2264
|
113 ``Web Audio Evaluation Tool: A browser-based listening test environment,''
|
b@2264
|
114 presented at the 12th Sound and Music Computing Conference, July 2015.
|
b@2264
|
115 \end{thebibliography}
|
b@2264
|
116 \end{document}'''
|
b@2264
|
117
|
b@2264
|
118 # make sure folder_name ends in '/'
|
b@2264
|
119 folder_name = os.path.join(folder_name, '')
|
b@2264
|
120
|
b@2264
|
121 # generate images for later use
|
b@2264
|
122 if render_figures:
|
b@2567
|
123 script_path = os.path.dirname(os.path.realpath(__file__)) # where is generate_report.py?
|
b@2567
|
124 subprocess.call("python " +script_path+"/timeline_view_movement.py '"+folder_name+"'", shell=True)
|
b@2567
|
125 subprocess.call("python " +script_path+"/score_parser.py '"+folder_name+"'", shell=True)
|
b@2567
|
126 subprocess.call("python " +script_path+"/score_plot.py '"+folder_name+"ratings/'", shell=True)
|
b@2264
|
127
|
b@2485
|
128 # make array of text and array of dates
|
b@2485
|
129 body_array = []
|
b@2485
|
130 date_array = []
|
b@2485
|
131
|
b@2264
|
132 # get every XML file in folder
|
b@2264
|
133 files_list = os.listdir(folder_name)
|
b@2264
|
134 for file in files_list: # iterate over all files in files_list
|
b@2264
|
135 if file.endswith(".xml"): # check if XML file
|
b@2264
|
136 number_of_XML_files += 1
|
b@2264
|
137 tree = ET.parse(folder_name + file)
|
b@2264
|
138 root = tree.getroot()
|
b@2264
|
139
|
b@2485
|
140 # get date
|
b@2485
|
141 # <datetime>
|
b@2485
|
142 # <date year="2016" month="7" day="12"/>
|
b@2485
|
143 # <time hour="14" minute="12" secs="6"/>
|
b@2485
|
144 # </datetime>
|
b@2485
|
145 date_node = root.find("./datetime/date")
|
b@2485
|
146 time_node = root.find("./datetime/time")
|
b@2485
|
147 year = date_node.get("year")
|
b@2485
|
148 month = date_node.get("month")
|
b@2485
|
149 day = date_node.get("day")
|
b@2485
|
150 hour = time_node.get("hour")
|
b@2485
|
151 minute = time_node.get("minute")
|
b@2485
|
152 second = time_node.get("secs")
|
b@2485
|
153 date_array.append((int(year),int(month),int(day),\
|
b@2485
|
154 int(hour),int(minute),int(second)))
|
b@2946
|
155
|
b@2946
|
156 # prepend zero if needed
|
b@2946
|
157 minute_string = str(minute) if int(minute)>9 else "0"+str(minute)
|
b@2946
|
158 second_string = str(second) if int(second)>9 else "0"+str(second)
|
b@2264
|
159
|
b@2485
|
160 # date as section title
|
b@2946
|
161 body = '\n\section{'+day+' '+month_array[int(month)-1]+' '+year+' '+hour+':'+\
|
b@2946
|
162 minute_string+':'+second_string+'}\n'
|
b@2485
|
163
|
b@2485
|
164 # file name
|
b@2487
|
165 body += '\t\tFile: '+file[:-4]+'\\\\ \n'
|
b@2485
|
166
|
b@2264
|
167 # reset for new subject
|
b@2264
|
168 total_duration = 0
|
b@2264
|
169 page_number = 0
|
b@2264
|
170
|
b@2264
|
171 individual_table = '\n' # table with stats for this individual test file
|
b@2264
|
172 timeline_plots = '' # plots of timeline (movements and plays)
|
b@2264
|
173
|
b@2522
|
174 # diagnostics: browser
|
b@2522
|
175 vendor = root.find("./navigator/vendor")
|
b@2522
|
176 if vendor is not None and vendor.text is not None:
|
b@2522
|
177 browser.append(vendor.text.replace(',',''))
|
b@2522
|
178 else:
|
b@2522
|
179 browser.append('UNAVAILABLE')
|
b@2522
|
180
|
b@2522
|
181 # diagnostics: platform
|
b@2522
|
182 platform_tag = root.find("./navigator/platform")
|
b@2522
|
183 if platform_tag is not None and platform_tag.text is not None:
|
b@2522
|
184 platform.append(platform_tag.text.replace('_','\_'))
|
b@2522
|
185 else:
|
b@2522
|
186 platform_tag.append('UNAVAILABLE')
|
b@2522
|
187
|
b@2264
|
188 # DEMO survey stats
|
b@2264
|
189 # get gender
|
b@2487
|
190 post_survey = root.find("./survey/[@location='post']")
|
b@2487
|
191 this_subjects_gender = post_survey.find("./surveyresult/[@ref='gender']/response")
|
b@2264
|
192 if this_subjects_gender is not None:
|
b@2264
|
193 gender.append(this_subjects_gender.get("name"))
|
b@2264
|
194 else:
|
b@2264
|
195 gender.append('UNAVAILABLE')
|
b@2264
|
196 # get age
|
b@2487
|
197 this_subjects_age = post_survey.find("./surveyresult/[@ref='age']/response")
|
b@2264
|
198 if this_subjects_age is not None:
|
b@2264
|
199 age.append(this_subjects_age.text)
|
b@2487
|
200 if this_subjects_gender is not None:
|
b@2487
|
201 body += 'Details: '+this_subjects_gender.get("name")
|
b@2487
|
202 if this_subjects_age is not None:
|
b@2487
|
203 body += ', ' + this_subjects_age.text
|
b@2487
|
204 body += '\\\\ \n'
|
b@2264
|
205
|
b@2264
|
206 # get list of all page names
|
b@2279
|
207 for page in root.findall("./page"): # iterate over pages
|
b@2279
|
208 page_name = page.get('ref') # get page name
|
b@2264
|
209
|
b@2264
|
210 if page_name is None: # ignore 'empty' audio_holders
|
b@2279
|
211 print("WARNING: " + file + " contains empty audio holder. (evaluation_stats.py)")
|
b@2264
|
212 break # move on to next
|
b@2264
|
213
|
b@2264
|
214 number_of_comments = 0 # for this page
|
b@2264
|
215 number_of_missing_comments = 0 # for this page
|
b@2264
|
216 not_played = [] # for this page
|
b@2264
|
217 not_moved = [] # for this page
|
b@2264
|
218
|
b@2279
|
219 if page.find("./metric/metricresult[@id='testTime']") is not None: # check if time is included
|
b@2279
|
220 # 'testTime' keeps total duration: subtract time so far for duration of this page
|
b@2279
|
221 duration = float(page.find("./metric/metricresult[@id='testTime']").text)# - total_duration
|
b@2264
|
222
|
b@2264
|
223 # total duration of test
|
b@2264
|
224 total_duration += duration
|
b@2264
|
225 else:
|
b@2264
|
226 duration = float('nan')
|
b@2264
|
227 total_duration = float('nan')
|
b@2264
|
228
|
b@2264
|
229 # number of audio elements
|
b@2279
|
230 audioelements = page.findall("./audioelement") # get audioelements
|
b@2264
|
231 number_of_fragments += len(audioelements) # add length of this list to total
|
b@2264
|
232
|
b@2264
|
233 # number of comments (interesting if comments not mandatory)
|
b@2264
|
234 for audioelement in audioelements:
|
n@2996
|
235 if audioelement.get("type") != "outside-reference":
|
n@2996
|
236 response = audioelement.find("./comment/response")
|
n@2996
|
237 was_played = audioelement.find("./metric/metricresult/[@name='elementFlagListenedTo']")
|
n@2996
|
238 was_moved = audioelement.find("./metric/metricresult/[@name='elementFlagMoved']")
|
n@2996
|
239 if response is not None and response.text is not None and len(response.text) > 1:
|
n@2996
|
240 number_of_comments += 1
|
n@2996
|
241 else:
|
n@2996
|
242 number_of_missing_comments += 1
|
n@2996
|
243 if was_played is not None and was_played.text == 'false':
|
n@2996
|
244 not_played.append(audioelement.get('name'))
|
n@2996
|
245 if was_moved is not None and was_moved.text == 'false':
|
n@2996
|
246 not_moved.append(audioelement.get('name'))
|
b@2264
|
247
|
b@2264
|
248 # update global counters
|
b@2264
|
249 total_empty_comments += number_of_missing_comments
|
b@2264
|
250 total_not_played += len(not_played)
|
b@2264
|
251 total_not_moved += len(not_moved)
|
b@2264
|
252
|
b@2264
|
253 # PRINT alerts when elements not played or markers not moved
|
b@2264
|
254 # number of audio elements not played
|
b@2264
|
255 if len(not_played) > 1:
|
b@2264
|
256 body += '\t\t\\emph{\\textbf{ATTENTION: '+str(len(not_played))+\
|
b@2264
|
257 ' fragments were not listened to in '+page_name+'! }}'+\
|
b@2264
|
258 ', '.join(not_played)+'\\\\ \n'
|
b@2264
|
259 if len(not_played) == 1:
|
b@2264
|
260 body += '\t\t\\emph{\\textbf{ATTENTION: one fragment was not listened to in '+page_name+'! }}'+\
|
b@2264
|
261 not_played[0]+'\\\\ \n'
|
b@2264
|
262
|
b@2264
|
263 # number of audio element markers not moved
|
b@2264
|
264 if len(not_moved) > 1:
|
b@2264
|
265 body += '\t\t\\emph{\\textbf{ATTENTION: '+str(len(not_moved))+\
|
b@2264
|
266 ' markers were not moved in '+page_name+'! }}'+\
|
b@2264
|
267 ', '.join(not_moved)+'\\\\ \n'
|
b@2264
|
268 if len(not_moved) == 1:
|
b@2264
|
269 body += '\t\t\\emph{\\textbf{ATTENTION: one marker was not moved in '+page_name+'! }}'+\
|
b@2264
|
270 not_moved[0]+'\\\\ \n'
|
b@2264
|
271
|
b@2264
|
272 # PRINT song-specific statistic
|
b@2264
|
273 individual_table += '\t\t'+page_name+'&'+\
|
b@2264
|
274 str(number_of_comments) + '/' +\
|
b@2264
|
275 str(number_of_comments+number_of_missing_comments)+'&'+\
|
b@2264
|
276 seconds2timestr(duration)+'\\\\\n'
|
b@2264
|
277
|
b@2279
|
278 # get timeline for this page
|
b@2264
|
279 img_path = 'timelines_movement/'+file[:-4]+'-'+page_name+'.pdf'
|
b@2264
|
280
|
b@2264
|
281 # check if available
|
b@2264
|
282 if os.path.isfile(folder_name+img_path):
|
b@2264
|
283 # SHOW timeline image
|
b@2264
|
284 timeline_plots += '\\includegraphics[width=\\textwidth]{'+\
|
b@2264
|
285 folder_name+img_path+'}\n\t\t'
|
b@2264
|
286
|
b@2264
|
287 # keep track of duration in function of page index
|
b@2264
|
288 if len(duration_order)>page_number:
|
b@2264
|
289 duration_order[page_number].append(duration)
|
b@2264
|
290 else:
|
b@2264
|
291 duration_order.append([duration])
|
b@2264
|
292
|
b@2279
|
293 # keep list of page ids and count how many times each page id
|
b@2264
|
294 # was tested, how long it took, and how many fragments there were
|
b@2279
|
295 # (if number of fragments is different, store as different page id)
|
b@2264
|
296 if page_name in page_names:
|
b@2264
|
297 page_index = page_names.index(page_name) # get index
|
b@2264
|
298 # check if number of audioelements the same
|
b@2264
|
299 if len(audioelements) == fragments_per_page[page_index]:
|
b@2264
|
300 page_count[page_index] += 1
|
b@2264
|
301 duration_page[page_index].append(duration)
|
b@2264
|
302 else: # make new entry
|
b@2264
|
303 alt_page_name = page_name+"("+str(len(audioelements))+")"
|
b@2264
|
304 if alt_page_name in page_names: # if already there
|
b@2264
|
305 alt_page_index = page_names.index(alt_page_name) # get index
|
b@2264
|
306 page_count[alt_page_index] += 1
|
b@2264
|
307 duration_page[alt_page_index].append(duration)
|
b@2264
|
308 else:
|
b@2264
|
309 page_names.append(alt_page_name)
|
b@2264
|
310 page_count.append(1)
|
b@2264
|
311 duration_page.append([duration])
|
b@2264
|
312 fragments_per_page.append(len(audioelements))
|
b@2264
|
313 else:
|
b@2264
|
314 page_names.append(page_name)
|
b@2264
|
315 page_count.append(1)
|
b@2264
|
316 duration_page.append([duration])
|
b@2264
|
317 fragments_per_page.append(len(audioelements))
|
b@2264
|
318
|
b@2279
|
319 # number of subjects per page regardless of differing numbers of
|
b@2264
|
320 # fragments (for inclusion in box plots)
|
b@2264
|
321 if page_name in real_page_names:
|
b@2264
|
322 page_index = real_page_names.index(page_name) # get index
|
b@2264
|
323 subject_count[page_index] += 1
|
b@2264
|
324 else:
|
b@2264
|
325 real_page_names.append(page_name)
|
b@2264
|
326 subject_count.append(1)
|
b@2264
|
327
|
b@2264
|
328 # bookkeeping
|
b@2264
|
329 page_number += 1 # increase page count for this specific test
|
b@2264
|
330 number_of_pages += 1 # increase total number of pages
|
b@2264
|
331 time_per_page_accum += duration # total duration (for average time spent per page)
|
b@2264
|
332
|
b@2264
|
333 # PRINT table with statistics about this test
|
b@2264
|
334 body += '\t\t'+r'''\begin{tabular}{|p{3.5cm}|c|p{2.5cm}|}
|
b@2264
|
335 \hline
|
b@2264
|
336 \textbf{Song name} & \textbf{Comments} & \textbf{Duration} \\ \hline '''+\
|
b@2264
|
337 individual_table+'\t\t'+\
|
b@2264
|
338 r'''\hline
|
b@2264
|
339 \textbf{TOTAL} & & \textbf{'''+\
|
b@2264
|
340 seconds2timestr(total_duration)+\
|
b@2264
|
341 r'''}\\
|
b@2264
|
342 \hline
|
b@2264
|
343 \end{tabular}
|
b@2264
|
344
|
b@2264
|
345 '''
|
b@2264
|
346 # PRINT timeline plots
|
b@2486
|
347 body += timeline_plots+'\n'
|
b@2264
|
348
|
b@2485
|
349 body_array.append(body)
|
b@2485
|
350
|
b@2485
|
351 # put sections in order according to date
|
b@2485
|
352 body_array_ordered = [b for d,b in sorted(zip(date_array,body_array))]
|
b@2485
|
353 body = ''.join(body_array_ordered)
|
b@2485
|
354
|
b@2264
|
355 # join to footer
|
b@2264
|
356 footer = body + footer
|
b@2264
|
357
|
b@2264
|
358 # empty body again
|
b@2264
|
359 body = ''
|
b@2264
|
360
|
b@2264
|
361 # PRINT summary of everything (at start)
|
b@2264
|
362 # unnumbered so that number of sections equals number of files
|
b@2264
|
363 body += '\section*{Summary}\n\t\t\\addcontentsline{toc}{section}{Summary}\n'
|
b@2264
|
364
|
b@2264
|
365 # PRINT table with statistics
|
b@2264
|
366 body += '\t\t\\begin{tabular}{ll}\n\t\t\t'
|
b@2264
|
367 body += r'Number of XML files: &' + str(number_of_XML_files) + r'\\'+'\n\t\t\t'
|
b@2264
|
368 body += r'Number of pages: &' + str(number_of_pages) + r'\\'+'\n\t\t\t'
|
b@2264
|
369 body += r'Number of fragments: &' + str(number_of_fragments) + r'\\'+'\n\t\t\t'
|
b@2264
|
370 body += r'Number of empty comments: &' + str(total_empty_comments) +\
|
b@2264
|
371 " (" + str(round(100.0*total_empty_comments/number_of_fragments,2)) + r"\%)\\"+'\n\t\t\t'
|
b@2264
|
372 body += r'Number of unplayed fragments: &' + str(total_not_played) +\
|
b@2264
|
373 " (" + str(round(100.0*total_not_played/number_of_fragments,2)) + r"\%)\\"+'\n\t\t\t'
|
b@2264
|
374 body += r'Number of unmoved markers: &' + str(total_not_moved) +\
|
b@2264
|
375 " (" + str(round(100.0*total_not_moved/number_of_fragments,2)) + r"\%)\\"+'\n\t\t\t'
|
b@2264
|
376 body += r'Average time per page: &' + seconds2timestr(time_per_page_accum/number_of_pages) + r"\\"+'\n\t\t'
|
b@2486
|
377 body += '\\end{tabular} \\\\ \n'
|
b@2264
|
378
|
b@2264
|
379 # Average duration for first, second, ... page
|
b@2486
|
380 body += "\n\n\t\t\\subsection*{Average duration per ordered page}\n See also Figure \\ref{fig:avgtimeperorder}. \\\\ \n\t\t"
|
b@2264
|
381 body += r'''\begin{tabular}{lll}
|
b@2264
|
382 \textbf{Page} & \textbf{Duration} & \textbf{\# subjects}\\'''
|
b@2264
|
383 tpp_averages = [] # store average time per page
|
b@2264
|
384 for page_number in range(len(duration_order)):
|
b@2264
|
385 body += '\n\t\t\t'+str(page_number+1) + "&" +\
|
b@2264
|
386 seconds2timestr(sum(duration_order[page_number])/len(duration_order[page_number])) +\
|
b@2264
|
387 "&"+str(len(duration_order[page_number]))+r"\\"
|
b@2264
|
388 tpp_averages.append(sum(duration_order[page_number])/len(duration_order[page_number]))
|
b@2264
|
389
|
b@2264
|
390 body += '\n\t\t\\end{tabular} \\vspace{1.5cm} \\\\ \n\n\t\t'
|
b@2264
|
391
|
b@2264
|
392 # SHOW bar plot of average time per page
|
b@2264
|
393 plt.bar(range(1,len(duration_order)+1), np.array(tpp_averages)/60)
|
b@2264
|
394 plt.xlabel('Page order')
|
b@2264
|
395 plt.xlim(.8, len(duration_order)+1)
|
b@2264
|
396 plt.xticks(np.arange(1,len(duration_order)+1)+.4, range(1,len(duration_order)+1))
|
b@2264
|
397 plt.ylabel('Average time [minutes]')
|
b@2486
|
398 plt.savefig(folder_name+"time_per_order.pdf", bbox_inches='tight')
|
b@2264
|
399 plt.close()
|
b@2264
|
400 #TODO add error bars
|
b@2264
|
401
|
b@2264
|
402
|
b@2264
|
403 # Sort pages by number of audioelements, then by duration
|
b@2264
|
404
|
b@2264
|
405 # average duration and number of subjects per page
|
b@2264
|
406 average_duration_page = []
|
b@2264
|
407 number_of_subjects_page = []
|
b@2264
|
408 for line in duration_page:
|
b@2264
|
409 number_of_subjects_page.append(len(line))
|
b@2264
|
410 average_duration_page.append(sum(line)/len(line))
|
b@2264
|
411
|
b@2264
|
412 # combine and sort in function of number of audioelements and duration
|
b@2264
|
413 combined_list = [page_names, average_duration_page, fragments_per_page, number_of_subjects_page]
|
b@2264
|
414 combined_list = sorted(zip(*combined_list), key=operator.itemgetter(1, 2)) # sort
|
b@2264
|
415
|
b@2264
|
416 # Show average duration for all songs
|
b@2486
|
417 body += '\n\n\t\t'+r'''\subsection*{Average duration per page}
|
b@2486
|
418 See also Figure \ref{fig:avgtimeperpage}. \\
|
b@2264
|
419 \begin{tabular}{llll}
|
b@2264
|
420 \textbf{Audioholder} & \textbf{Duration} & \textbf{\# subjects} & \textbf{\# fragments} \\'''
|
b@2279
|
421 page_names_ordered = []
|
b@2279
|
422 average_duration_page_ordered = []
|
b@2264
|
423 number_of_subjects = []
|
b@2264
|
424 for page_index in range(len(page_names)):
|
b@2279
|
425 page_names_ordered.append(combined_list[page_index][0])
|
b@2279
|
426 average_duration_page_ordered.append(combined_list[page_index][1])
|
b@2264
|
427 number_of_subjects.append(combined_list[page_index][3])
|
b@2264
|
428 body += '\n\t\t\t'+combined_list[page_index][0] + "&" +\
|
b@2264
|
429 seconds2timestr(combined_list[page_index][1]) + "&" +\
|
b@2264
|
430 str(combined_list[page_index][3]) + "&" +\
|
b@2264
|
431 str(combined_list[page_index][2]) + r"\\"
|
b@2264
|
432 body += '\n\t\t\\end{tabular}\n'
|
b@2264
|
433
|
b@2264
|
434 # SHOW bar plot of average time per page
|
b@2279
|
435 plt.bar(range(1,len(page_names_ordered)+1), np.array(average_duration_page_ordered)/60)
|
b@2264
|
436 plt.xlabel('Audioholder')
|
b@2279
|
437 plt.xlim(.8, len(page_names_ordered)+1)
|
b@2279
|
438 plt.xticks(np.arange(1,len(page_names_ordered)+1)+.4, page_names_ordered, rotation=90)
|
b@2264
|
439 plt.ylabel('Average time [minutes]')
|
b@2279
|
440 plt.savefig(folder_name+"time_per_page.pdf", bbox_inches='tight')
|
b@2264
|
441 plt.close()
|
b@2264
|
442
|
b@2264
|
443 # SHOW bar plot of average time per page
|
b@2279
|
444 plt.bar(range(1,len(page_names_ordered)+1), number_of_subjects)
|
b@2264
|
445 plt.xlabel('Audioholder')
|
b@2279
|
446 plt.xlim(.8, len(page_names_ordered)+1)
|
b@2279
|
447 plt.xticks(np.arange(1,len(page_names_ordered)+1)+.4, page_names_ordered, rotation=90)
|
b@2264
|
448 plt.ylabel('Number of subjects')
|
b@2264
|
449 ax = plt.gca()
|
b@2264
|
450 ylims = ax.get_ylim()
|
b@2264
|
451 yint = np.arange(int(np.floor(ylims[0])), int(np.ceil(ylims[1]))+1)
|
b@2264
|
452 plt.yticks(yint)
|
b@2279
|
453 plt.savefig(folder_name+"subjects_per_page.pdf", bbox_inches='tight')
|
b@2264
|
454 plt.close()
|
b@2264
|
455
|
b@2946
|
456 # SHOW these figures
|
b@2264
|
457 body += r'''
|
b@2486
|
458 \begin{figure}[htbp]
|
b@2486
|
459 \begin{center}
|
b@2486
|
460 \includegraphics[width=.65\textwidth]{'''+\
|
b@2486
|
461 folder_name+'time_per_order.pdf'+\
|
b@2264
|
462 r'''}
|
b@2486
|
463 \caption{Average time spent per page (order).}
|
b@2486
|
464 \label{fig:avgtimeperorder}
|
b@2486
|
465 \end{center}
|
b@2486
|
466 \end{figure}
|
b@2264
|
467
|
b@2264
|
468 '''
|
b@2264
|
469 body += r'''\begin{figure}[htbp]
|
b@2486
|
470 \begin{center}
|
b@2486
|
471 \includegraphics[width=.65\textwidth]{'''+\
|
b@2279
|
472 folder_name+'time_per_page.pdf'+\
|
b@2264
|
473 r'''}
|
b@2486
|
474 \caption{Average time spent per page (content).}
|
b@2279
|
475 \label{fig:avgtimeperpage}
|
b@2486
|
476 \end{center}
|
b@2486
|
477 \end{figure}
|
b@2264
|
478
|
b@2264
|
479 '''
|
b@2264
|
480 body += r'''\begin{figure}[htbp]
|
b@2486
|
481 \begin{center}
|
b@2486
|
482 \includegraphics[width=.65\textwidth]{'''+\
|
b@2279
|
483 folder_name+'subjects_per_page.pdf'+\
|
b@2264
|
484 r'''}
|
b@2279
|
485 \caption{Number of subjects per page.}
|
b@2279
|
486 \label{fig:subjectsperpage}
|
b@2486
|
487 \end{center}
|
b@2486
|
488 \end{figure}
|
b@2485
|
489
|
b@2264
|
490 '''
|
b@2264
|
491 #TODO add error bars
|
b@2264
|
492 #TODO layout of figures
|
b@2264
|
493
|
b@2486
|
494 # SHOW boxplot per page (in alphabetical order of page name)
|
b@2946
|
495 #TODO get scale names (now hardcoded 'preference' automatically)
|
b@2486
|
496 body += '\t\t\\clearpage \n\t\\subsection*{Ratings per page}\n'
|
b@2486
|
497 for page_name in sorted(page_names): # get each name
|
b@2264
|
498 # plot boxplot if exists (not so for the 'alt' names)
|
b@2946
|
499 if os.path.isfile(folder_name+'ratings/'+page_name+'-preference-ratings-box.pdf'):
|
b@2486
|
500 body += r'''\begin{figure}[H]
|
b@2486
|
501 \begin{center}
|
b@2486
|
502 \includegraphics[width=.65\textwidth]{'''+\
|
b@2946
|
503 folder_name+"ratings/"+page_name+'-preference-ratings-box.pdf'+\
|
b@2486
|
504 r'''}
|
b@2486
|
505 \caption{Box plot of ratings for page '''+\
|
b@2486
|
506 page_name+' ('+str(subject_count[real_page_names.index(page_name)])+\
|
b@2486
|
507 ''' participants).}
|
b@2486
|
508 \label{fig:boxplot'''+page_name.replace(" ", "")+'''}
|
b@2486
|
509 \end{center}
|
b@2486
|
510 \end{figure}
|
b@2486
|
511
|
b@2264
|
512 '''
|
b@2264
|
513
|
b@2264
|
514 # DEMO pie chart of gender distribution among subjects
|
b@2264
|
515 genders = ['male', 'female', 'other', 'preferNotToSay', 'UNAVAILABLE']
|
b@2264
|
516 # TODO: get the above automatically
|
b@2264
|
517 gender_distribution = ''
|
b@2264
|
518 for item in genders:
|
b@2264
|
519 number = gender.count(item)
|
b@2264
|
520 if number>0:
|
b@2264
|
521 gender_distribution += str("{:.2f}".format((100.0*number)/len(gender)))+\
|
b@2264
|
522 '/'+item.capitalize()+' ('+str(number)+'),\n'
|
b@2264
|
523
|
b@2264
|
524 body += r'''
|
b@2264
|
525 % Pie chart of gender distribution
|
b@2264
|
526 \def\angle{0}
|
b@2264
|
527 \def\radius{3}
|
b@2264
|
528 \def\cyclelist{{"orange","blue","red","green"}}
|
b@2264
|
529 \newcount\cyclecount \cyclecount=-1
|
b@2264
|
530 \newcount\ind \ind=-1
|
b@2264
|
531 \begin{figure}[htbp]
|
b@2264
|
532 \begin{center}\begin{tikzpicture}[nodes = {font=\sffamily}]
|
b@2264
|
533 \foreach \percent/\name in {'''+\
|
b@2264
|
534 gender_distribution+\
|
b@2264
|
535 r'''} {\ifx\percent\empty\else % If \percent is empty, do nothing
|
b@2264
|
536 \global\advance\cyclecount by 1 % Advance cyclecount
|
b@2264
|
537 \global\advance\ind by 1 % Advance list index
|
b@2264
|
538 \ifnum6<\cyclecount % If cyclecount is larger than list
|
b@2264
|
539 \global\cyclecount=0 % reset cyclecount and
|
b@2264
|
540 \global\ind=0 % reset list index
|
b@2264
|
541 \fi
|
b@2264
|
542 \pgfmathparse{\cyclelist[\the\ind]} % Get color from cycle list
|
b@2264
|
543 \edef\color{\pgfmathresult} % and store as \color
|
b@2264
|
544 % Draw angle and set labels
|
b@2264
|
545 \draw[fill={\color!50},draw={\color}] (0,0) -- (\angle:\radius)
|
b@2264
|
546 arc (\angle:\angle+\percent*3.6:\radius) -- cycle;
|
b@2264
|
547 \node at (\angle+0.5*\percent*3.6:0.7*\radius) {\percent\,\%};
|
b@2264
|
548 \node[pin=\angle+0.5*\percent*3.6:\name]
|
b@2264
|
549 at (\angle+0.5*\percent*3.6:\radius) {};
|
b@2264
|
550 \pgfmathparse{\angle+\percent*3.6} % Advance angle
|
b@2264
|
551 \xdef\angle{\pgfmathresult} % and store in \angle
|
b@2264
|
552 \fi
|
b@2264
|
553 };
|
b@2264
|
554 \end{tikzpicture}
|
b@2264
|
555 \caption{Representation of gender across subjects}
|
b@2264
|
556 \label{default}
|
b@2264
|
557 \end{center}
|
b@2264
|
558 \end{figure}
|
b@2264
|
559
|
b@2264
|
560 '''
|
b@2264
|
561 # problem: some people entered twice?
|
b@2264
|
562
|
b@2522
|
563
|
b@2522
|
564 # pie chart of browser usage
|
b@2522
|
565 browsers = ['Google Inc.', 'Apple Computer Inc.', 'UNAVAILABLE']
|
b@2522
|
566 # TODO: get the above automatically
|
b@2522
|
567 browser_distribution = ''
|
b@2522
|
568 for item in browsers:
|
b@2522
|
569 number = browser.count(item)
|
b@2522
|
570 if number>0:
|
b@2522
|
571 browser_distribution += str("{:.2f}".format((100.0*number)/len(browser)))+\
|
b@2522
|
572 '/'+item.capitalize()+' ('+str(number)+'),\n'
|
b@2522
|
573
|
b@2522
|
574 body += r'''
|
b@2522
|
575 % Pie chart of browser distribution
|
b@2522
|
576 \def\angle{0}
|
b@2522
|
577 \def\radius{3}
|
b@2522
|
578 \def\cyclelist{{"orange","blue","red","green"}}
|
b@2522
|
579 \newcount\cyclecount \cyclecount=-1
|
b@2522
|
580 \newcount\ind \ind=-1
|
b@2522
|
581 \begin{figure}[htbp]
|
b@2522
|
582 \begin{center}\begin{tikzpicture}[nodes = {font=\sffamily}]
|
b@2522
|
583 \foreach \percent/\name in {'''+\
|
b@2522
|
584 browser_distribution+\
|
b@2522
|
585 r'''} {\ifx\percent\empty\else % If \percent is empty, do nothing
|
b@2522
|
586 \global\advance\cyclecount by 1 % Advance cyclecount
|
b@2522
|
587 \global\advance\ind by 1 % Advance list index
|
b@2522
|
588 \ifnum6<\cyclecount % If cyclecount is larger than list
|
b@2522
|
589 \global\cyclecount=0 % reset cyclecount and
|
b@2522
|
590 \global\ind=0 % reset list index
|
b@2522
|
591 \fi
|
b@2522
|
592 \pgfmathparse{\cyclelist[\the\ind]} % Get color from cycle list
|
b@2522
|
593 \edef\color{\pgfmathresult} % and store as \color
|
b@2522
|
594 % Draw angle and set labels
|
b@2522
|
595 \draw[fill={\color!50},draw={\color}] (0,0) -- (\angle:\radius)
|
b@2522
|
596 arc (\angle:\angle+\percent*3.6:\radius) -- cycle;
|
b@2522
|
597 \node at (\angle+0.5*\percent*3.6:0.7*\radius) {\percent\,\%};
|
b@2522
|
598 \node[pin=\angle+0.5*\percent*3.6:\name]
|
b@2522
|
599 at (\angle+0.5*\percent*3.6:\radius) {};
|
b@2522
|
600 \pgfmathparse{\angle+\percent*3.6} % Advance angle
|
b@2522
|
601 \xdef\angle{\pgfmathresult} % and store in \angle
|
b@2522
|
602 \fi
|
b@2522
|
603 };
|
b@2522
|
604 \end{tikzpicture}
|
b@2522
|
605 \caption{Representation of browsers across subjects}
|
b@2522
|
606 \label{default}
|
b@2522
|
607 \end{center}
|
b@2522
|
608 \end{figure}
|
b@2522
|
609
|
b@2522
|
610 '''
|
b@2522
|
611
|
b@2522
|
612 # pie chart of platform usage
|
b@2522
|
613 platforms = ['Win32', 'Win64', 'MacIntel', 'Linux i686', 'Linux x86\_64', 'UNAVAILABLE']
|
b@2522
|
614 # TODO: get the above automatically # order alphabetically
|
b@2522
|
615 platform_distribution = ''
|
b@2522
|
616 for item in platforms:
|
b@2522
|
617 number = platform.count(item)
|
b@2522
|
618 if number>0:
|
b@2522
|
619 platform_distribution += str("{:.2f}".format((100.0*number)/len(platform)))+\
|
b@2522
|
620 '/'+item.capitalize()+' ('+str(number)+'),\n'
|
b@2522
|
621
|
b@2522
|
622 body += r'''
|
b@2522
|
623 % Pie chart of browser distribution
|
b@2522
|
624 \def\angle{0}
|
b@2522
|
625 \def\radius{3}
|
b@2522
|
626 \def\cyclelist{{"orange","blue","red","green","cyan"}}
|
b@2522
|
627 \newcount\cyclecount \cyclecount=-1
|
b@2522
|
628 \newcount\ind \ind=-1
|
b@2522
|
629 \begin{figure}[htbp]
|
b@2522
|
630 \begin{center}\begin{tikzpicture}[nodes = {font=\sffamily}]
|
b@2522
|
631 \foreach \percent/\name in {'''+\
|
b@2522
|
632 platform_distribution+\
|
b@2522
|
633 r'''} {\ifx\percent\empty\else % If \percent is empty, do nothing
|
b@2522
|
634 \global\advance\cyclecount by 1 % Advance cyclecount
|
b@2522
|
635 \global\advance\ind by 1 % Advance list index
|
b@2522
|
636 \ifnum6<\cyclecount % If cyclecount is larger than list
|
b@2522
|
637 \global\cyclecount=0 % reset cyclecount and
|
b@2522
|
638 \global\ind=0 % reset list index
|
b@2522
|
639 \fi
|
b@2522
|
640 \pgfmathparse{\cyclelist[\the\ind]} % Get color from cycle list
|
b@2522
|
641 \edef\color{\pgfmathresult} % and store as \color
|
b@2522
|
642 % Draw angle and set labels
|
b@2522
|
643 \draw[fill={\color!50},draw={\color}] (0,0) -- (\angle:\radius)
|
b@2522
|
644 arc (\angle:\angle+\percent*3.6:\radius) -- cycle;
|
b@2522
|
645 \node at (\angle+0.5*\percent*3.6:0.7*\radius) {\percent\,\%};
|
b@2522
|
646 \node[pin=\angle+0.5*\percent*3.6:\name]
|
b@2522
|
647 at (\angle+0.5*\percent*3.6:\radius) {};
|
b@2522
|
648 \pgfmathparse{\angle+\percent*3.6} % Advance angle
|
b@2522
|
649 \xdef\angle{\pgfmathresult} % and store in \angle
|
b@2522
|
650 \fi
|
b@2522
|
651 };
|
b@2522
|
652 \end{tikzpicture}
|
b@2522
|
653 \caption{Representation of platforms across subjects}
|
b@2522
|
654 \label{default}
|
b@2522
|
655 \end{center}
|
b@2522
|
656 \end{figure}
|
b@2522
|
657
|
b@2522
|
658 '''
|
b@2522
|
659
|
b@2522
|
660
|
b@2264
|
661 #TODO
|
b@2264
|
662 # time per page in function of number of fragments (plot)
|
b@2264
|
663 # time per participant in function of number of pages
|
b@2264
|
664 # plot total time for each participant
|
b@2264
|
665 # show 'count' per page (in order)
|
b@2264
|
666
|
b@2264
|
667 # clear up page_index <> page_count <> page_number confusion
|
b@2264
|
668
|
b@2264
|
669
|
b@2264
|
670 texfile = header+body+footer # add bits together
|
b@2264
|
671
|
b@2279
|
672 # print('pdflatex -output-directory="'+folder_name+'"" "'+ folder_name + 'Report.tex"')# DEBUG
|
b@2264
|
673
|
b@2264
|
674 # write TeX file
|
b@2264
|
675 with open(folder_name + 'Report.tex','w') as f:
|
b@2264
|
676 f.write(texfile)
|
b@2264
|
677 proc=subprocess.Popen(shlex.split('pdflatex -output-directory="'+folder_name+'" "'+ folder_name + 'Report.tex"'))
|
b@2264
|
678 proc.communicate()
|
b@2264
|
679 # run again
|
b@2264
|
680 proc=subprocess.Popen(shlex.split('pdflatex -output-directory="'+folder_name+'" "'+ folder_name + 'Report.tex"'))
|
b@2264
|
681 proc.communicate()
|
b@2264
|
682
|
b@2264
|
683 #TODO remove auxiliary LaTeX files
|
b@2264
|
684 try:
|
b@2264
|
685 os.remove(folder_name + 'Report.aux')
|
b@2264
|
686 os.remove(folder_name + 'Report.log')
|
b@2264
|
687 os.remove(folder_name + 'Report.out')
|
b@2264
|
688 os.remove(folder_name + 'Report.toc')
|
b@2264
|
689 except OSError:
|
b@2264
|
690 pass
|
b@2264
|
691
|