changeset 2431:bae25b417c2c

Tested #68 for Python 3.5
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Thu, 02 Jun 2016 10:23:31 +0100
parents ad87b0d94fa9
children aca96a5183be
files python/pythonServer.py tests/pool.xml
diffstat 2 files changed, 101 insertions(+), 75 deletions(-) [+]
line wrap: on
line diff
--- a/python/pythonServer.py	Tue May 31 12:04:31 2016 +0100
+++ b/python/pythonServer.py	Thu Jun 02 10:23:31 2016 +0100
@@ -10,6 +10,7 @@
 import datetime
 import operator
 import xml.etree.ElementTree as ET
+import copy
 
 if sys.version_info[0] == 2:
     # Version 2.x
@@ -168,27 +169,52 @@
         s.path = s.path.split("/php",1)[0]+"/tests/pool/xml"
         processFile(s)
         return
+    poolSize = int(poolSize)
     # Set up the store will all the test page key nodes
     pages = {};
     for page in root.iter("page"):
         id = page.get("id")
-        print(id)
         pages[id] = 0
-
     # Read the saves and determine the completed pages
     for filename in os.listdir("../saves/"):
         if filename.endswith(".xml"):
-            print("../saves/"+filename)
             save = ET.parse("../saves/"+filename)
             save_root = save.getroot();
-            if (save_root.get("url") == s.path):
-                for page in save_root.iter("page"):
-                    id = page.get("id")
+            if (save_root.find("waet").get("url") == "http://localhost:8000/php/pool.php"):
+                for page in save_root.findall("./page"):
+                    id = page.get("ref")
                     pages[id] = pages[id] + 1
 
     # Sort the dictionary
-    pages = sorted(pages.items(), key=operator.itemgetter(1))
+    rot_pages = {}
+    for key, value in pages.items():
+        if (value in rot_pages):
+            rot_pages[value].append(key)
+        else:
+            rot_pages[value] = [key]
+            
+    Keys = list(rot_pages)
+    print ("Current pool state:")
+    print (rot_pages)
+    
+    return_node = ET.fromstring('<waet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test-schema.xsd"/>');
+    return_node.append(copy.deepcopy(root.find("setup")))
+    page_elements = root.findall("page")
 
+    # Now append the pages
+    i = 0
+    while(len(return_node.findall("page")) < poolSize):
+        if (i > 0):
+            for page in return_node.iter("page"):
+                page.set("alwaysInclude","true")
+        for id in rot_pages[Keys[i]]:
+            return_node.append(copy.deepcopy(root.find('./page[@id="'+id+'"]')))
+        i=i+1
+    s.send_response(200)
+    s.send_header("Content-type", "text/xml")
+    s.end_headers()
+    s.wfile.write(ET.tostring(return_node))
+        
 def http_do_HEAD(s):
     s.send_response(200)
     s.send_header("Content-type", "text/html")
--- a/tests/pool.xml	Tue May 31 12:04:31 2016 +0100
+++ b/tests/pool.xml	Thu Jun 02 10:23:31 2016 +0100
@@ -1,69 +1,69 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<waet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test-schema.xsd">
-	<setup interface="likert" projectReturn="save.php" crossFade="3.0" poolSize="3">
-		<metric>
-			<metricenable>testTimer</metricenable>
-			<metricenable>elementTimer</metricenable>
-			<metricenable>elementInitialPosition</metricenable>
-			<metricenable>elementTracker</metricenable>
-			<metricenable>elementFlagListenedTo</metricenable>
-			<metricenable>elementFlagMoved</metricenable>
-			<metricenable>elementListenTracker</metricenable>
-		</metric>
-		<interface>
-			<interfaceoption type="check" name="fragmentMoved"/>
-		</interface>
-	</setup>
-	<page id='test-0' hostURL="media/example/" randomiseOrder='true' repeatCount='4' loop='true' showElementComments='true' loudness="-23">
-		<interface>
-			<scales>
-				<scalelabel position="0">(1) Very Annoying</scalelabel>
-				<scalelabel position="25">(2) Annoying</scalelabel>
-				<scalelabel position="50">(3) Slightly Annoying</scalelabel>
-				<scalelabel position="75">(4) Audible but not Annoying</scalelabel>
-				<scalelabel position="100">(5) Inaudible</scalelabel>
-			</scales>
-		</interface>
-		<audioelement url="0.wav" id="track-1" name="track-0" type="outside-reference"/>
-		<audioelement url="1.wav" id="track-2"/>
-	</page>
-    <page id='test-1' hostURL="media/example/" randomiseOrder='true' repeatCount='4' loop='true' showElementComments='true' loudness="-23">
-		<interface>
-			<scales>
-				<scalelabel position="0">(1) Very Annoying</scalelabel>
-				<scalelabel position="25">(2) Annoying</scalelabel>
-				<scalelabel position="50">(3) Slightly Annoying</scalelabel>
-				<scalelabel position="75">(4) Audible but not Annoying</scalelabel>
-				<scalelabel position="100">(5) Inaudible</scalelabel>
-			</scales>
-		</interface>
-		<audioelement url="0.wav" id="track-3" name="track-0"  type="outside-reference"/>
-		<audioelement url="2.wav" id="track-4"/>
-	</page>
-    <page id='test-2' hostURL="media/example/" randomiseOrder='true' repeatCount='4' loop='true' showElementComments='true' loudness="-23">
-		<interface>
-			<scales>
-				<scalelabel position="0">(1) Very Annoying</scalelabel>
-				<scalelabel position="25">(2) Annoying</scalelabel>
-				<scalelabel position="50">(3) Slightly Annoying</scalelabel>
-				<scalelabel position="75">(4) Audible but not Annoying</scalelabel>
-				<scalelabel position="100">(5) Inaudible</scalelabel>
-			</scales>
-		</interface>
-		<audioelement url="0.wav" id="track-5" name="track-0"  type="outside-reference"/>
-		<audioelement url="3.wav" id="track-6"/>
-	</page>
-    <page id='test-3' hostURL="media/example/" randomiseOrder='true' repeatCount='4' loop='true' showElementComments='true' loudness="-23">
-		<interface>
-			<scales>
-				<scalelabel position="0">(1) Very Annoying</scalelabel>
-				<scalelabel position="25">(2) Annoying</scalelabel>
-				<scalelabel position="50">(3) Slightly Annoying</scalelabel>
-				<scalelabel position="75">(4) Audible but not Annoying</scalelabel>
-				<scalelabel position="100">(5) Inaudible</scalelabel>
-			</scales>
-		</interface>
-		<audioelement url="0.wav" id="track-7" name="track-0"  type="outside-reference"/>
-		<audioelement url="4.wav" id="track-8"/>
-	</page>
-</waet>
+    <waet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test-schema.xsd">
+        <setup interface="likert" projectReturn="save.php" crossFade="3.0" poolSize="3">
+            <metric>
+                <metricenable>testTimer</metricenable>
+                <metricenable>elementTimer</metricenable>
+                <metricenable>elementInitialPosition</metricenable>
+                <metricenable>elementTracker</metricenable>
+                <metricenable>elementFlagListenedTo</metricenable>
+                <metricenable>elementFlagMoved</metricenable>
+                <metricenable>elementListenTracker</metricenable>
+            </metric>
+            <interface>
+                <interfaceoption type="check" name="fragmentMoved" />
+            </interface>
+        </setup>
+        <page id='test-0' hostURL="media/example/" randomiseOrder='true' repeatCount='4' loop='true' loudness="-23">
+            <interface>
+                <scales>
+                    <scalelabel position="0">(1) Very Annoying</scalelabel>
+                    <scalelabel position="25">(2) Annoying</scalelabel>
+                    <scalelabel position="50">(3) Slightly Annoying</scalelabel>
+                    <scalelabel position="75">(4) Audible but not Annoying</scalelabel>
+                    <scalelabel position="100">(5) Inaudible</scalelabel>
+                </scales>
+            </interface>
+            <audioelement url="0.wav" id="track-1" name="track-0" type="outside-reference" />
+            <audioelement url="1.wav" id="track-2" />
+        </page>
+        <page id='test-1' hostURL="media/example/" randomiseOrder='true' repeatCount='4' loop='true' loudness="-23">
+            <interface>
+                <scales>
+                    <scalelabel position="0">(1) Very Annoying</scalelabel>
+                    <scalelabel position="25">(2) Annoying</scalelabel>
+                    <scalelabel position="50">(3) Slightly Annoying</scalelabel>
+                    <scalelabel position="75">(4) Audible but not Annoying</scalelabel>
+                    <scalelabel position="100">(5) Inaudible</scalelabel>
+                </scales>
+            </interface>
+            <audioelement url="0.wav" id="track-3" name="track-0" type="outside-reference" />
+            <audioelement url="2.wav" id="track-4" />
+        </page>
+        <page id='test-2' hostURL="media/example/" randomiseOrder='true' repeatCount='4' loop='true' loudness="-23">
+            <interface>
+                <scales>
+                    <scalelabel position="0">(1) Very Annoying</scalelabel>
+                    <scalelabel position="25">(2) Annoying</scalelabel>
+                    <scalelabel position="50">(3) Slightly Annoying</scalelabel>
+                    <scalelabel position="75">(4) Audible but not Annoying</scalelabel>
+                    <scalelabel position="100">(5) Inaudible</scalelabel>
+                </scales>
+            </interface>
+            <audioelement url="0.wav" id="track-5" name="track-0" type="outside-reference" />
+            <audioelement url="3.wav" id="track-6" />
+        </page>
+        <page id='test-3' hostURL="media/example/" randomiseOrder='true' repeatCount='4' loop='true' loudness="-23">
+            <interface>
+                <scales>
+                    <scalelabel position="0">(1) Very Annoying</scalelabel>
+                    <scalelabel position="25">(2) Annoying</scalelabel>
+                    <scalelabel position="50">(3) Slightly Annoying</scalelabel>
+                    <scalelabel position="75">(4) Audible but not Annoying</scalelabel>
+                    <scalelabel position="100">(5) Inaudible</scalelabel>
+                </scales>
+            </interface>
+            <audioelement url="0.wav" id="track-7" name="track-0" type="outside-reference" />
+            <audioelement url="4.wav" id="track-8" />
+        </page>
+    </waet>