diff scripts/comment_parser.py @ 2228:3358d04605db

Updated scripts to work with latest results document specification
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Thu, 14 Apr 2016 17:16:20 +0100
parents 03b2ff7308fa
children 5bf0555905de
line wrap: on
line diff
--- a/scripts/comment_parser.py	Thu Apr 14 15:58:52 2016 +0100
+++ b/scripts/comment_parser.py	Thu Apr 14 17:16:20 2016 +0100
@@ -42,43 +42,46 @@
         
         # get list of all page names
         for audioholder in root.findall("./page"):   # iterate over pages
-            page_name = audioholder.get('id')               # get page name
+            page_name = audioholder.get('ref')               # get page name
             
             if page_name is None: # ignore 'empty' audio_holders
                 print "WARNING: " + file + " contains empty page. (comment_parser.py)"
                 break
+                
+            if audioholder.get("state") != "complete":
+                print "WARNING: " + file + "test page " + page_name + " is not complete, skipping."
+            else :
+                # create folder [page_name] if not yet created
+                if not os.path.exists(folder_name + "/" + page_name):
+                    os.makedirs(folder_name + "/" + page_name)
 
-            # create folder [page_name] if not yet created
-            if not os.path.exists(folder_name + "/" + page_name):
-                os.makedirs(folder_name + "/" + page_name)
+                # for page [page_name], print comments related to fragment [id]
+                for audioelement in audioholder.findall("./audioelement"):
+                    if audioelement is not None: # Check it exists
+                        audio_id = str(audioelement.get('ref'))
 
-            # for page [page_name], print comments related to fragment [id]
-            for audioelement in audioholder.findall("./audioelement"):
-                if audioelement is not None: # Check it exists
-                    audio_id = str(audioelement.get('id'))
-                    
-                    csv_name = folder_name +'/' + page_name+'/'+page_name+'-comments-'+audio_id+'.csv'
+                        csv_name = folder_name +'/' + page_name+'/'+page_name+'-comments-'+audio_id+'.csv'
 
-                    # If file hasn't been opened yet this time, empty
-                    if csv_name not in file_history:
-                        csvfile = open(csv_name, 'w')
-                        file_history.append(csv_name) # remember this file has been written to this time around
-                    else: 
-                        # append (!) to file [page_name]/[page_name]-comments-[id].csv
-                        csvfile = open(csv_name, 'a')
-                    writer = csv.writer(csvfile, 
-                                        delimiter=',', 
-                                        dialect="excel",
-                                        quoting=csv.QUOTE_ALL)
-                    commentstr = audioelement.find("./comment/response").text
-                        
-                    if commentstr is None:
-                       commentstr = ''
-                        
-                    # anonymous comments:
-                    #writer.writerow([commentstr.encode("utf-8")]) 
-                    # comments with (file) name:
-                    writer.writerow([file[:-4]] + [commentstr.encode("utf-8")]) 
+                        # If file hasn't been opened yet this time, empty
+                        if csv_name not in file_history:
+                            csvfile = open(csv_name, 'w')
+                            file_history.append(csv_name) # remember this file has been written to this time around
+                        else: 
+                            # append (!) to file [page_name]/[page_name]-comments-[id].csv
+                            csvfile = open(csv_name, 'a')
+                        writer = csv.writer(csvfile, 
+                                            delimiter=',', 
+                                            dialect="excel",
+                                            quoting=csv.QUOTE_ALL)
+                        commentstr = audioelement.find("./comment/response").text
+
+                        if commentstr is None:
+                           commentstr = ''
+
+                        # anonymous comments:
+                        #writer.writerow([commentstr.encode("utf-8")]) 
+                        # comments with (file) name:
+                        writer.writerow([file[:-4]] + [commentstr.encode("utf-8")]) 
 
                     #TODO Replace 'new line' in comment with something else?