Mercurial > hg > webaudioevaluationtool
comparison scripts/timeline_view.py @ 884:1dd209550560
Scripts: merge all three plot scripts in to one (box plot, scatter plot, mean plus confidence interval plot); bug fixes
author | Brecht De Man <BrechtDeMan@users.noreply.github.com> |
---|---|
date | Mon, 29 Jun 2015 17:19:46 +0100 |
parents | ca4ae613f1dd |
children | c3f29c2b9b12 |
comparison
equal
deleted
inserted
replaced
883:cd20f076f6a3 | 884:1dd209550560 |
---|---|
1 #!/usr/bin/python | |
2 | |
1 import xml.etree.ElementTree as ET | 3 import xml.etree.ElementTree as ET |
2 import os | 4 import os |
3 import matplotlib.pyplot as plt | 5 import matplotlib.pyplot as plt |
4 | 6 |
5 colormap = ['b', 'r', 'g', 'c', 'm', 'y', 'k'] # colormap for to cycle through | 7 # CONFIGURATION |
6 | 8 |
7 timeline_folder = 'timelines/' # folder where to store timelines, e.g. 'timelines/' | 9 # XML results files location (modify as needed): |
10 folder_name = "../saves" # Looks in 'saves/' folder from 'scripts/' folder | |
8 | 11 |
12 # Folder where to store timelines | |
13 timeline_folder = folder_name + '/timelines/' # Stores in 'saves/timelines/' | |
14 | |
15 # Font settings | |
16 font = {'weight' : 'bold', | |
17 'size' : 16} | |
18 plt.rc('font', **font) | |
19 | |
20 # Colormap for to cycle through | |
21 colormap = ['b', 'r', 'g', 'c', 'm', 'y', 'k'] | |
22 | |
23 | |
24 # CODE | |
9 | 25 |
10 # create timeline_folder if not yet created | 26 # create timeline_folder if not yet created |
11 if not os.path.exists(timeline_folder): | 27 if not os.path.exists(timeline_folder): |
12 os.makedirs(timeline_folder) | 28 os.makedirs(timeline_folder) |
13 | 29 |
14 # get every XML file in folder | 30 # get every XML file in folder |
15 for file in os.listdir("."): # You have to put this script in folder where output XML files are. | 31 for file in os.listdir(folder_name): # You have to put this script in folder where output XML files are. |
16 if file.endswith(".xml"): | 32 if file.endswith(".xml"): |
17 tree = ET.parse(file) | 33 tree = ET.parse(folder_name + '/' + file) |
18 root = tree.getroot() | 34 root = tree.getroot() |
19 subject_id = file[:-4] # drop '.xml' | 35 subject_id = file[:-4] # drop '.xml' |
20 | 36 |
21 # ONE TIMELINE PER PAGE - make new plot per page | 37 # ONE TIMELINE PER PAGE - make new plot per page |
22 | 38 |
26 | 42 |
27 if page_name is None: # ignore 'empty' audio_holders | 43 if page_name is None: # ignore 'empty' audio_holders |
28 break | 44 break |
29 | 45 |
30 # SORT AUDIO ELEMENTS ALPHABETICALLY | 46 # SORT AUDIO ELEMENTS ALPHABETICALLY |
31 audioelements = root.findall("*/[@id='"+page_name+"']/audioelement") | 47 audioelements = audioholder.findall("./audioelement") |
32 | 48 |
33 data = [] | 49 data = [] |
34 for elem in audioelements: # from http://effbot.org/zone/element-sort.htm | 50 for elem in audioelements: # from http://effbot.org/zone/element-sort.htm |
35 key = elem.get("id") | 51 key = elem.get("id") |
36 data.append((key, elem)) | 52 data.append((key, elem)) |
46 if audioelement is not None: # Check it exists | 62 if audioelement is not None: # Check it exists |
47 audio_id = str(audioelement.get('id')) | 63 audio_id = str(audioelement.get('id')) |
48 audioelements_names.append(audio_id) | 64 audioelements_names.append(audio_id) |
49 | 65 |
50 # for this audioelement, loop over all listen events | 66 # for this audioelement, loop over all listen events |
51 listen_events = root.findall("*/[@id='" | 67 listen_events = audioelement.findall("./metric/metricresult/[@name='elementListenTracker']/event") |
52 + page_name | |
53 + "']/audioelement/[@id='" | |
54 + audio_id | |
55 + "']/metric/metricresult/[@name='elementListenTracker']/event") | |
56 for event in listen_events: | 68 for event in listen_events: |
57 # get testtime: start and stop | 69 # get testtime: start and stop |
58 start_time = event.find('testtime').get('start') | 70 start_time = event.find('testtime').get('start') |
59 stop_time = event.find('testtime').get('stop') | 71 stop_time = event.find('testtime').get('stop') |
60 # event lines: | 72 # event lines: |