Mercurial > hg > webaudioevaluationtool
comparison scripts/score_parser.py @ 885:ba83143187d6
Scripts: score_parser.py: ignore empty rows (subject with no ratings for current song)
author | Brecht De Man <BrechtDeMan@users.noreply.github.com> |
---|---|
date | Mon, 29 Jun 2015 19:02:48 +0100 |
parents | 1dd209550560 |
children | 7a8fcf04aad3 |
comparison
equal
deleted
inserted
replaced
884:1dd209550560 | 885:ba83143187d6 |
---|---|
8 | 8 |
9 # XML results files location (modify as needed): | 9 # XML results files location (modify as needed): |
10 folder_name = "../saves" # Looks in 'saves/' folder from 'scripts/' folder | 10 folder_name = "../saves" # Looks in 'saves/' folder from 'scripts/' folder |
11 | 11 |
12 # get every XML file in folder | 12 # get every XML file in folder |
13 for file in os.listdir(folder_name): # You have to put this in folder where output XML files are. | 13 for file in os.listdir(folder_name): |
14 if file.endswith(".xml"): | 14 if file.endswith(".xml"): |
15 tree = ET.parse(folder_name + '/' + file) | 15 tree = ET.parse(folder_name + '/' + file) |
16 root = tree.getroot() | 16 root = tree.getroot() |
17 #print "DEBUG Reading " + file + "..." | 17 #print "DEBUG Reading " + file + "..." |
18 | 18 |
55 # Which of the fragmentes are in fragmentnamelist but not in headerrow? | 55 # Which of the fragmentes are in fragmentnamelist but not in headerrow? |
56 newfragments = list(set(fragmentnamelist)-set(headerrow)) | 56 newfragments = list(set(fragmentnamelist)-set(headerrow)) |
57 newfragments = sorted(newfragments) # new fragments in alphabetical order | 57 newfragments = sorted(newfragments) # new fragments in alphabetical order |
58 # If not empty, read file and rewrite adding extra columns | 58 # If not empty, read file and rewrite adding extra columns |
59 if newfragments: # if not empty | 59 if newfragments: # if not empty |
60 print ' '+page_name+','+file_name+','+subject_id | |
61 #print "DEBUG New fragments found: " + str(newfragments) | 60 #print "DEBUG New fragments found: " + str(newfragments) |
62 with open('temp.csv', 'w') as writefile: | 61 with open('temp.csv', 'w') as writefile: |
63 filewriter = csv.writer(writefile, delimiter=',') | 62 filewriter = csv.writer(writefile, delimiter=',') |
64 filewriter.writerow(headerrow + newfragments) # write new header | 63 filewriter.writerow(headerrow + newfragments) # write new header |
65 #print " "+str(headerrow + newfragments) # DEBUG | 64 #print " "+str(headerrow + newfragments) # DEBUG |
100 ratingrow.append(elementvalue.text) # add to rating row | 99 ratingrow.append(elementvalue.text) # add to rating row |
101 else: # if this subject has not rated this fragment | 100 else: # if this subject has not rated this fragment |
102 ratingrow.append('') # append empty cell | 101 ratingrow.append('') # append empty cell |
103 | 102 |
104 # write row: [subject ID, rating fragment ID 1, ..., rating fragment ID M] | 103 # write row: [subject ID, rating fragment ID 1, ..., rating fragment ID M] |
105 filewriter.writerow(ratingrow) | 104 if any(ratingrow[1:]): # append to file if row non-empty (except subject name) |
105 filewriter.writerow(ratingrow) | |
106 | 106 |