# HG changeset patch # User www-data # Date 1460636458 -3600 # Node ID 6c98ec540504cc280141602eb95b9ecc124ff9e5 # Parent 77681b87c99dcc6c9c367f37a685d52088ab227b# Parent 4d1aa94202e3de69cf72468109e21997d9e80868 Merge branch 'master' of https://github.com/BrechtDeMan/WebAudioEvaluationTool diff -r 77681b87c99d -r 6c98ec540504 core.js --- a/core.js Wed Apr 13 16:20:56 2016 +0100 +++ b/core.js Thu Apr 14 13:20:58 2016 +0100 @@ -492,10 +492,59 @@ return Math.pow(10,gain/20.0); } +function secondsToSamples(time,fs) { + return Math.round(time*fs); +} + +function samplesToSeconds(samples,fs) { + return samples / fs; +} + function randomString(length) { return Math.round((Math.pow(36, length + 1) - Math.random() * Math.pow(36, length))).toString(36).slice(1); } +function randomiseOrder(input) +{ + // This takes an array of information and randomises the order + var N = input.length; + + var inputSequence = []; // For safety purposes: keep track of randomisation + for (var counter = 0; counter < N; ++counter) + inputSequence.push(counter) // Fill array + var inputSequenceClone = inputSequence.slice(0); + + var holdArr = []; + var outputSequence = []; + for (var n=0; n array.length) { + num = array.length; + } + var ret = []; + while (num > 0) { + var index = Math.floor(Math.random() * array.length); + ret.push( array.splice(index,1)[0] ); + num--; + } + return ret; +} + function interfacePopup() { // Creates an object to manage the popup this.popup = null; @@ -556,12 +605,14 @@ }; this.hidePopup = function(){ - this.popup.style.zIndex = -1; - this.popup.style.visibility = 'hidden'; - var blank = document.getElementsByClassName('testHalt')[0]; - blank.style.zIndex = -2; - blank.style.visibility = 'hidden'; - this.buttonPrevious.style.visibility = 'inherit'; + if (this.popup) { + this.popup.style.zIndex = -1; + this.popup.style.visibility = 'hidden'; + var blank = document.getElementsByClassName('testHalt')[0]; + blank.style.zIndex = -2; + blank.style.visibility = 'hidden'; + this.buttonPrevious.style.visibility = 'inherit'; + } }; this.postNode = function() { @@ -850,43 +901,68 @@ this.currentStatePosition = null; this.currentStore = null; this.initialise = function(){ - + // Get the data from Specification - var pageHolder = []; + var pagePool = []; + var pageInclude = []; for (var page of specification.pages) { - var repeat = page.repeatCount; - while(repeat >= 0) - { - pageHolder.push(page); - repeat--; + if (page.alwaysInclude) { + pageInclude.push(page); + } else { + pagePool.push(page); } } + + // Find how many are left to get + var numPages = specification.poolSize; + if (numPages > pagePool.length) { + console.log("WARNING - You have specified more pages in than you have created!!"); + numPages = specification.pages.length; + } + if (specification.poolSize == 0) { + numPages = specification.pages.length; + } + numPages -= pageInclude.length; + + if (numPages > 0) { + // Go find the rest of the pages from the pool + var subarr = null; + if (specification.randomiseOrder) { + // Append a random sub-array + subarr = randomSubArray(pagePool,numPages); + } else { + // Append the matching number + subarr = pagePool.slice(0,numPages); + } + pageInclude = pageInclude.concat(subarr); + } + + // We now have our selected pages in pageInclude array if (specification.randomiseOrder) { - pageHolder = randomiseOrder(pageHolder); + pageInclude = randomiseOrder(pageInclude); } - for (var i=0; i - + Please enter your name. diff -r 77681b87c99d -r 6c98ec540504 example_eval/AB_example.xml --- a/example_eval/AB_example.xml Wed Apr 13 16:20:56 2016 +0100 +++ b/example_eval/AB_example.xml Thu Apr 14 13:20:58 2016 +0100 @@ -1,6 +1,6 @@ - + Please enter your name. diff -r 77681b87c99d -r 6c98ec540504 example_eval/mushra_example.xml --- a/example_eval/mushra_example.xml Wed Apr 13 16:20:56 2016 +0100 +++ b/example_eval/mushra_example.xml Thu Apr 14 13:20:58 2016 +0100 @@ -1,6 +1,6 @@ - + Thank you for looking at WAET. You can modify the successful completion text as well! diff -r 77681b87c99d -r 6c98ec540504 example_eval/project.xml --- a/example_eval/project.xml Wed Apr 13 16:20:56 2016 +0100 +++ b/example_eval/project.xml Thu Apr 14 13:20:58 2016 +0100 @@ -1,6 +1,6 @@ - + Please enter your name. diff -r 77681b87c99d -r 6c98ec540504 example_eval/radio_example.xml --- a/example_eval/radio_example.xml Wed Apr 13 16:20:56 2016 +0100 +++ b/example_eval/radio_example.xml Thu Apr 14 13:20:58 2016 +0100 @@ -1,6 +1,6 @@ - + testTimer elementTimer @@ -18,7 +18,7 @@ - + (1) Very Annoying @@ -28,8 +28,9 @@ (5) Inaudible - + + diff -r 77681b87c99d -r 6c98ec540504 scripts/pythonServer-3.py --- a/scripts/pythonServer-3.py Wed Apr 13 16:20:56 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,128 +0,0 @@ -from http.server import BaseHTTPRequestHandler, HTTPServer -from os import walk -from os import path -from os import listdir -import inspect -import os -import urllib as urllib2 -import pickle -import datetime - -# Go to right folder. -scriptdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) # script directory -os.chdir(scriptdir) # does this work? - -PSEUDO_PATH = 'example_eval/' -pseudo_files = [] -for filename in listdir(PSEUDO_PATH): - if filename.endswith('.xml'): - pseudo_files.append(filename) - -curSaveIndex = 0; -curFileName = 'test-0.xml' -while(path.isfile('saves/'+curFileName)): - curSaveIndex += 1; - curFileName = 'test-'+str(curSaveIndex)+'.xml' - -pseudo_index = curSaveIndex % len(pseudo_files) - -print('URL: http://localhost:8000/index.html') - -def send404(s): - s.send_response(404) - s.send_header("Content-type", "text/html") - s.end_headers() - -def processFile(s): - s.path = s.path.rsplit('?') - s.path = s.path[0] - s.path = s.path[1:len(s.path)] - st = s.path.rsplit(',') - lenSt = len(st) - fmt = st[lenSt-1].rsplit('.') - s.send_response(200) - if (fmt[1] == 'html'): - s.send_header("Content-type", 'text/html') - fileDump = open(urllib2.parse.unquote(s.path), encoding='utf-8') - fileBytes = bytes(fileDump.read(), "utf-8") - fileDump.close() - elif (fmt[1] == 'css'): - s.send_header("Content-type", 'text/css') - fileDump = open(urllib2.parse.unquote(s.path), encoding='utf-8') - fileBytes = bytes(fileDump.read(), "utf-8") - fileDump.close() - elif (fmt[1] == 'js'): - s.send_header("Content-type", 'application/javascript') - fileDump = open(urllib2.parse.unquote(s.path), encoding='utf-8') - fileBytes = bytes(fileDump.read(), "utf-8") - fileDump.close() - else: - s.send_header("Content-type", 'application/octet-stream') - fileDump = open(urllib2.parse.unquote(s.path), 'rb') - fileBytes = fileDump.read() - fileDump.close() - s.send_header("Content-Length", len(fileBytes)) - s.end_headers() - s.wfile.write(fileBytes) - -def saveFile(self): - global curFileName - global curSaveIndex - varLen = int(self.headers['Content-Length']) - postVars = self.rfile.read(varLen) - print(curFileName) - file = open('saves/'+curFileName,'w') - file.write(postVars.decode("utf-8")) - file.close() - try: - wbytes = os.path.getsize('saves/'+curFileName) - except OSError: - self.send_response(200) - self.send_header("Content-type", "text/xml") - self.end_headers() - self.wfile.write('Could not open file') - self.send_response(200) - self.send_header("Content-type", "text/xml") - self.end_headers() - self.wfile.write(bytes('OK"saves/'+curFileName+'"','utf-8')) - curSaveIndex += 1 - curFileName = 'test-'+str(curSaveIndex)+'.xml' - -class MyHandler(BaseHTTPRequestHandler): - def do_HEAD(s): - s.send_response(200) - s.send_header("Content-type", "text/html") - s.end_headers() - def do_GET(request): - global pseudo_index - global pseudo_files - global PSEUDO_PATH - if(request.client_address[0] == "127.0.0.1"): - if (request.path == "/favicon.ico"): - send404(request) - else: - if (request.path == '/'): - request.path = '/index.html' - elif (request.path == '/pseudo.xml'): - request.path = '/'+PSEUDO_PATH + pseudo_files[pseudo_index] - print(request.path) - pseudo_index += 1 - pseudo_index %= len(pseudo_files) - processFile(request) - else: - send404(request) - - def do_POST(request): - if(request.client_address[0] == "127.0.0.1"): - if (request.path == "/save" or request.path == "/save.php"): - saveFile(request) - else: - send404(request) - -def run(server_class=HTTPServer, - handler_class=MyHandler): - server_address = ('', 8000) - httpd = server_class(server_address, handler_class) - httpd.serve_forever() - -run() diff -r 77681b87c99d -r 6c98ec540504 scripts/pythonServer-legacy.py --- a/scripts/pythonServer-legacy.py Wed Apr 13 16:20:56 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -import SimpleHTTPServer -import SocketServer - -PORT = 8080 - -Handler = SimpleHTTPServer.SimpleHTTPRequestHandler - -httpd = SocketServer.TCPServer(("", PORT), Handler) - -print "serving at port", PORT -httpd.serve_forever() diff -r 77681b87c99d -r 6c98ec540504 scripts/pythonServer.py --- a/scripts/pythonServer.py Wed Apr 13 16:20:56 2016 +0100 +++ b/scripts/pythonServer.py Thu Apr 14 13:20:58 2016 +0100 @@ -1,21 +1,32 @@ #!/usr/bin/python -import BaseHTTPServer +# Detect the Python version to switch code between 2.x and 3.x +# http://stackoverflow.com/questions/9079036/detect-python-version-at-runtime +import sys + from os import walk from os import path from os import listdir import inspect import os -import urllib2 -import urlparse import pickle import datetime +if sys.version_info[0] == 2: + # Version 2.x + import BaseHTTPServer + import urllib2 + import urlparse +elif sys.version_info[0] == 3: + # Version 3.x + from http.server import BaseHTTPRequestHandler, HTTPServer + import urllib as urllib2 + # Go to right folder. scriptdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) # script directory os.chdir(scriptdir) # does this work? -PSEUDO_PATH = 'example_eval/' +PSEUDO_PATH = '../example_eval/' pseudo_files = [] for filename in listdir(PSEUDO_PATH): if filename.endswith('.xml'): @@ -23,42 +34,79 @@ curSaveIndex = 0; curFileName = 'test-0.xml' -while(path.isfile('saves/'+curFileName)): - curSaveIndex += 1; - curFileName = 'test-'+str(curSaveIndex)+'.xml' +while(path.isfile('../saves/'+curFileName)): + curSaveIndex += 1; + curFileName = 'test-'+str(curSaveIndex)+'.xml' pseudo_index = curSaveIndex % len(pseudo_files) -print 'URL: http://localhost:8000/index.html' +if sys.version_info[0] == 2: + print 'URL: http://localhost:8000/index.html' +elif sys.version_info[0] == 3: + print('URL: http://localhost:8000/index.html') def send404(s): - s.send_response(404) - s.send_header("Content-type", "text/html") - s.end_headers() + s.send_response(404) + s.send_header("Content-type", "text/html") + s.end_headers() def processFile(s): - s.path = s.path.rsplit('?') - s.path = s.path[0] - s.path = s.path[1:len(s.path)] - st = s.path.rsplit(',') - lenSt = len(st) - fmt = st[lenSt-1].rsplit('.') - size = path.getsize(urllib2.unquote(s.path)) - fileDump = open(urllib2.unquote(s.path)) - s.send_response(200) - - if (fmt[1] == 'html'): - s.send_header("Content-type", 'text/html') - elif (fmt[1] == 'css'): - s.send_header("Content-type", 'text/css') - elif (fmt[1] == 'js'): - s.send_header("Content-type", 'application/javascript') - else: - s.send_header("Content-type", 'application/octet-stream') - s.send_header("Content-Length", size) - s.end_headers() - s.wfile.write(fileDump.read()) - fileDump.close() + if sys.version_info[0] == 2: + s.path = s.path.rsplit('?') + s.path = s.path[0] + s.path = s.path[1:len(s.path)] + st = s.path.rsplit(',') + lenSt = len(st) + fmt = st[lenSt-1].rsplit('.') + fpath = "../"+urllib2.unquote(s.path) + size = path.getsize(fpath) + fileDump = open(fpath) + s.send_response(200) + + if (fmt[1] == 'html'): + s.send_header("Content-type", 'text/html') + elif (fmt[1] == 'css'): + s.send_header("Content-type", 'text/css') + elif (fmt[1] == 'js'): + s.send_header("Content-type", 'application/javascript') + else: + s.send_header("Content-type", 'application/octet-stream') + s.send_header("Content-Length", size) + s.end_headers() + s.wfile.write(fileDump.read()) + fileDump.close() + elif sys.version_info[0] == 3: + s.path = s.path.rsplit('?') + s.path = s.path[0] + s.path = s.path[1:len(s.path)] + st = s.path.rsplit(',') + lenSt = len(st) + fmt = st[lenSt-1].rsplit('.') + fpath = "../"+urllib2.unquote(s.path) + s.send_response(200) + if (fmt[1] == 'html'): + s.send_header("Content-type", 'text/html') + fileDump = open(fpath, encoding='utf-8') + fileBytes = bytes(fileDump.read(), "utf-8") + fileDump.close() + elif (fmt[1] == 'css'): + s.send_header("Content-type", 'text/css') + fileDump = open(fpath, encoding='utf-8') + fileBytes = bytes(fileDump.read(), "utf-8") + fileDump.close() + elif (fmt[1] == 'js'): + s.send_header("Content-type", 'application/javascript') + fileDump = open(fpath, encoding='utf-8') + fileBytes = bytes(fileDump.read(), "utf-8") + fileDump.close() + else: + s.send_header("Content-type", 'application/octet-stream') + fileDump = open(fpath, 'rb') + fileBytes = fileDump.read() + fileDump.close() + s.send_header("Content-Length", len(fileBytes)) + s.end_headers() + s.wfile.write(fileBytes) def keygen(s): reply = "" @@ -74,36 +122,39 @@ s.send_header("Content-type", "application/xml") s.end_headers() s.wfile.write(reply) - file = open("saves/save-"+key+".xml",'w') + file = open("../saves/save-"+key+".xml",'w') file.write("") file.close(); def saveFile(self): - global curFileName - global curSaveIndex - options = self.path.rsplit('?') - options = options[1].rsplit('=') - key = options[1] - print key - varLen = int(self.headers['Content-Length']) - postVars = self.rfile.read(varLen) - print "Saving file key "+key - file = open('saves/save-'+key+'.xml','w') - file.write(postVars) - file.close() - try: - wbytes = os.path.getsize('saves/save-'+key+'.xml') - except OSError: - self.send_response(200) - self.send_header("Content-type", "text/xml") - self.end_headers() - self.wfile.write('Could not open file') - self.send_response(200) - self.send_header("Content-type", "text/xml") - self.end_headers() - self.wfile.write('OK"saves/'+curFileName+'"') - curSaveIndex += 1 - curFileName = 'test-'+str(curSaveIndex)+'.xml' + global curFileName + global curSaveIndex + options = self.path.rsplit('?') + options = options[1].rsplit('=') + key = options[1] + print key + varLen = int(self.headers['Content-Length']) + postVars = self.rfile.read(varLen) + if sys.version_info[0] == 2: + print "Saving file key "+key + elif sys.version_info[0] == 3: + print("Saving file key "+key) + file = open('../saves/save-'+key+'.xml','w') + file.write(postVars) + file.close() + try: + wbytes = os.path.getsize('../saves/save-'+key+'.xml') + except OSError: + self.send_response(200) + self.send_header("Content-type", "text/xml") + self.end_headers() + self.wfile.write('Could not open file') + self.send_response(200) + self.send_header("Content-type", "text/xml") + self.end_headers() + self.wfile.write('OK"saves/'+curFileName+'"') + curSaveIndex += 1 + curFileName = 'test-'+str(curSaveIndex)+'.xml' class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler): def do_HEAD(s): @@ -137,11 +188,15 @@ saveFile(request) else: send404(request) - -def run(server_class=BaseHTTPServer.HTTPServer, - handler_class=MyHandler): - server_address = ('', 8000) - httpd = server_class(server_address, handler_class) - httpd.serve_forever() +if sys.version_info[0] == 2: + def run(server_class=BaseHTTPServer.HTTPServer,handler_class=MyHandler): + server_address = ('', 8000) + httpd = server_class(server_address, handler_class) + httpd.serve_forever() +elif sys.version_info[0] == 3: + def run(server_class=HTTPServer,handler_class=MyHandler): + server_address = ('', 8000) + httpd = server_class(server_address, handler_class) + httpd.serve_forever() run() diff -r 77681b87c99d -r 6c98ec540504 specification.js --- a/specification.js Wed Apr 13 16:20:56 2016 +0100 +++ b/specification.js Thu Apr 14 13:20:58 2016 +0100 @@ -27,7 +27,19 @@ } var dataType = schema.getAttribute('type'); if (typeof dataType == "string") { dataType = dataType.substr(3);} - else {dataType = "string";} + else { + var rest = schema.getAllElementsByTagName("xs:restriction").concat(schema.getAllElementsByTagName("xs:enumeration")); + if (rest.length > 0) { + dataType = rest[0].getAttribute("base"); + if (typeof dataType == "string") { + dataType = dataType.substr(3); + } else { + dataType = "string"; + } + } else { + dataType = "string"; + } + } if (attribute == null) { return attribute; diff -r 77681b87c99d -r 6c98ec540504 test-schema.xsd --- a/test-schema.xsd Wed Apr 13 16:20:56 2016 +0100 +++ b/test-schema.xsd Thu Apr 14 13:20:58 2016 +0100 @@ -1,263 +1,275 @@ - - - - - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +