Mercurial > hg > webaudioevaluationtool
changeset 3018:03b0e5dc57e6
Merge branch 'vnext' into Dev_main
# Conflicts:
# python/pythonServer.py
author | Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk> |
---|---|
date | Tue, 12 Sep 2017 14:05:38 +0100 |
parents | f5bfac0557bb (current diff) 209532a650da (diff) |
children | f06405eacbe1 |
files | python/pythonServer.py tests/examples/APE_example.xml tests/examples/mushra_example.xml |
diffstat | 8 files changed, 195 insertions(+), 49 deletions(-) [+] |
line wrap: on
line diff
--- a/css/core.css Mon Sep 11 21:58:05 2017 +0100 +++ b/css/core.css Tue Sep 12 14:05:38 2017 +0100 @@ -65,9 +65,6 @@ padding: 8px; text-align: center; } -#popupTitle { - white-space: pre-line; -} div#popupResponse { width: inherit; min-height: 50px;
--- a/interfaces/ABX.js Mon Sep 11 21:58:05 2017 +0100 +++ b/interfaces/ABX.js Tue Sep 12 14:05:38 2017 +0100 @@ -271,10 +271,7 @@ }; this.updateLoading = function (progress) { // progress is a value from 0 to 100 indicating the current download state of media files - if (label == "X" || label == "x") { - this.playback.textContent = "Play"; - } - if (progress != 100) { + if (progress != 100 && label.toLowerCase() != "x") { progress = String(progress); progress = progress.split('.')[0]; this.playback.textContent = progress + '%'; @@ -301,8 +298,8 @@ }; this.stopPlayback = function () { if (this.playback.getAttribute("playstate") == "playing") { - $('.comparator-button').text('Listen'); - $('.comparator-button').removeAttr("disabled"); + $(this.playback).text('Listen'); + $(this.playback).removeAttr("disabled"); this.playback.setAttribute("playstate", "ready"); } var box = interfaceContext.commentBoxes.boxes.find(function (a) { @@ -372,15 +369,22 @@ this.boxHolders = document.getElementById('box-holders'); var node; page.audioElements.forEach(function (element, index) { - if (element.type != 'normal') { - console.log("WARNING - ABX can only have normal elements. Page " + page.id + ", Element " + element.id); + if (element.type != 'normal' && element.type != "reference") { + console.log("WARNING - ABX can only have normal or reference elements. Page " + page.id + ", Element " + element.id); element.type = "normal"; } node = buildElement.call(this, index, audioEngineContext.newTrack(element)); this.pair.push(node); this.boxHolders.appendChild(node.box); }, this); - var elementId = Math.floor(Math.random() * 2); //Randomly pick A or B to be X + // var elementId = Math.floor(Math.random() * 2); //Randomly pick A or B to be X + var elementId = page.audioElements.findIndex(function (a) { + return a.type == "reference"; + }); + if (elementId == -1) { + elementId = Math.floor(Math.random() * 2); + console.log("No defined 'X' given. Selecting element id " + page.audioElements[elementId].id); + } var element = page.addAudioElement(); for (var atr in page.audioElements[elementId]) { element[atr] = page.audioElements[elementId][atr];
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/php/test.html Tue Sep 12 14:05:38 2017 +0100 @@ -0,0 +1,105 @@ +<html lang="en"> + +<head> + <meta http-equiv="content-type" content="text/html; charset=utf-8"> + + + <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame + Remove this if you use the .htaccess --> + <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> + + <title>Web Audio Evaluation Tool</title> + <meta name="description" content="" /> + <meta name="author" content="" /> + + <!-- Load up the default core JS and CSS files--> + <link rel='stylesheet' type='text/css' href='../css/core.css'> + <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.5.2/mocha.min.css" integrity="sha256-Flo6sV8k+IPfHh6Hx97ReUJDLOwIwvhdGlKOz3UgHRE=" crossorigin="anonymous" /> + <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> + <!-- Use jQuery hosted from Google CDN --> + <!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>--> + <script type="text/javascript" src="../js/showdown.min.js"></script> + <script type="text/javascript" src="../js/jquery-2.1.4.js"></script> + <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> + <script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.1.2/chai.min.js" integrity="sha256-iP6sMGdjKeRM2DuED2Lsi/n7MNTKhGpkhuSdCHXIgYc=" crossorigin="anonymous"></script> + <script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.5.2/mocha.min.js" integrity="sha256-rw/35Nx9y5f+fLTdO7Tipm6ju+tRGwnplU1CJyPM3nE=" crossorigin="anonymous"></script> + <script> + mocha.setup('bdd'); + var expect = chai.expect; + var should = chai.should(); + var key1; + describe("requestKey.php", function() { + it("should give a key", function(done) { + var xhr = new XMLHttpRequest(); + xhr.open("GET", "requestKey.php"); + xhr.onload = function() { + var doc = xhr.response; + var state = doc.querySelector("state").textContent; + key1 = doc.querySelector("key").textContent; + expect(state).to.equal("OK"); + done(); + } + xhr.responseType = "document"; + xhr.send(); + }); + it("should create an empty file with that key", function(done) { + var xhr = new XMLHttpRequest(); + xhr.open("GET", "../saves/save-" + key1 + ".xml"); + xhr.onload = function() { + var parser = new DOMParser(); + doc = parser.parseFromString(xhr.responseText, "text/xml"); + var state = doc.querySelector("waetresult").getAttribute("key"); + expect(state).to.equal(key1); + done(); + } + xhr.responseType = ""; + xhr.send(); + }); + it("should give a different key on second request", function(done) { + var xhr = new XMLHttpRequest(); + xhr.open("GET", "requestKey.php"); + xhr.onload = function() { + var doc = xhr.response; + var state = doc.querySelector("state").textContent; + var key = doc.querySelector("key").textContent; + expect(state).to.equal("OK"); + expect(key).not.to.equal(key1); + done(); + } + xhr.responseType = "document"; + xhr.send(); + }); + }); + describe("Saves permissions", function() { + it("should write \"test-save.xml\" to saves and delete", function(done) { + var xhr = new XMLHttpRequest(); + xhr.open("GET", "test_write.php"); + xhr.onload = function() { + var doc = xhr.response; + var response = doc.querySelector("response"); + var message = doc.querySelector("message"); + expect(response.getAttribute("state")).to.equal("OK"); + done(); + } + xhr.responseType = "document"; + xhr.send(); + }); + }); + window.onload = function() { + mocha.run(); + } + + </script> +</head> + +<body class="container"> + <div> + <h1>WAET PHP Server Tests</h1> + <p class="lead">This page will test your PHP server for any implementation issues.</p> + <p>Make sure your <span>saves</span> directory is clean before testing and that you empty it afterwards as intermediary files will be made there.</p> + + </div> + <div id="mocha"></div> +</body> + +</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/php/test_write.php Tue Sep 12 14:05:38 2017 +0100 @@ -0,0 +1,10 @@ +<?php +$file = "../saves/test-save.xml"; +$state = file_put_contents($file, "<xml></xml>"); +if ($state == FALSE) { + echo "<response state=\"error\"><message>Could not open file</message></response>"; +} else { + unlink($file) or die("<response state=\"error\"><message>Could not open file</message></response>"); + echo "<response state=\"OK\"><message>OK</message></response>"; +} +?>
--- a/python/pythonServer.py Mon Sep 11 21:58:05 2017 +0100 +++ b/python/pythonServer.py Tue Sep 12 14:05:38 2017 +0100 @@ -129,7 +129,7 @@ elif sys.version_info[0] == 3: s.wfile.write(bytes(reply, "utf-8")) file = open("../saves/save-"+key+".xml",'w') - file.write("<waetresult key="+key+"/>") + file.write("<waetresult key=\""+key+"\"/>") file.close() @@ -180,6 +180,34 @@ curFileName = 'test-'+str(curSaveIndex)+'.xml' if update == False: os.remove("../saves/update-"+filename) + +def testSave(self): + self.send_response(200) + self.send_header("Content-type", "text/xml") + self.end_headers() + filename = "../saves/test-save.xml" + file = open(filename,'wb') + if sys.version_info[0] == 2: + file.write("<xml></xml>") + elif sys.version_info[0] == 3: + file.write(bytes("<xml></xml>", "utf-8")) + file.close() + message = "" + try: + wbytes = os.path.getsize(filename) + except OSError: + message = '<response state="error"><message>Could not open file</message></response>'; + if sys.version_info[0] == 2: + self.wfile.write(message) + elif sys.version_info[0] == 3: + self.wfile.write(bytes(message, "utf-8")) + return + os.remove(filename) + message = '<response state="OK"><message>OK</message></response>'; + if sys.version_info[0] == 2: + self.wfile.write(message) + elif sys.version_info[0] == 3: + self.wfile.write(bytes(message, "utf-8")) def poolXML(s): pool = ET.parse('../tests/pool.xml') @@ -250,6 +278,8 @@ requestKey(request); elif (request.path.split('?',1)[0] == "/php/pool.php"): poolXML(request); + elif (request.path.split('?',1)[0] == "/php/test_write.php"): + testSave(request); else: request.path = request.path.split('?',1)[0] if (request.path == '/'):
--- a/tests/examples/ABX_example.xml Mon Sep 11 21:58:05 2017 +0100 +++ b/tests/examples/ABX_example.xml Tue Sep 12 14:05:38 2017 +0100 @@ -2,38 +2,38 @@ <waet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test-schema.xsd"> <setup interface="ABX" projectReturn="save.php" randomiseOrder='true' poolSize="2" loudness="-23"> <survey location="before"> - <surveyentry type="question" id="sessionId" mandatory="true"> + <surveyquestion id="sessionId" mandatory="true"> <statement>Please enter your name.</statement> - </surveyentry> - <surveyentry type="checkbox" id="checkboxtest" mandatory="true"> + </surveyquestion> + <surveycheckbox id="checkboxtest" mandatory="true"> <statement>Please select with which activities you have any experience (example checkbox question)</statement> <option name="musician">Playing a musical instrument</option> <option name="soundengineer">Recording or mixing audio</option> <option name="developer">Developing audio software</option> <option name="hwdesigner">Designing or building audio hardware</option> <option name="researcher">Research in the field of audio</option> - </surveyentry> - <surveyentry type="statement" id="test-intro"> + </surveycheckbox> + <surveystatement id="test-intro"> <statement>This is an example of an 'ABX'-style test, with two pages, using the test stimuli in 'example_eval/'.</statement> - </surveyentry> + </surveystatement> </survey> <survey location="after"> - <surveyentry type="question" id="location" mandatory="true" boxsize="large"> + <surveyquestion id="location" mandatory="true" boxsize="large"> <statement>Please enter your location. (example mandatory text question)</statement> - </surveyentry> - <surveyentry type="number" id="age" min="0"> + </surveyquestion> + <surveynumber id="age" min="0"> <statement>Please enter your age (example non-mandatory number question)</statement> - </surveyentry> - <surveyentry type="radio" id="rating"> + </surveynumber> + <surveyradio id="rating"> <statement>Please rate this interface (example radio button question)</statement> <option name="bad">Bad</option> <option name="poor">Poor</option> <option name="good">Good</option> <option name="great">Great</option> - </surveyentry> - <surveyentry type="statement" id="test-thank-you"> + </surveyradio> + <surveystatement id="test-thank-you"> <statement>Thank you for taking this listening test. Please click 'submit' and your results will appear in the 'saves/' folder.</statement> - </surveyentry> + </surveystatement> </survey> <metric> <metricenable>testTimer</metricenable>
--- a/tests/examples/APE_example.xml Mon Sep 11 21:58:05 2017 +0100 +++ b/tests/examples/APE_example.xml Tue Sep 12 14:05:38 2017 +0100 @@ -22,22 +22,22 @@ </surveystatement> </survey> <survey location="after"> - <surveyentry type="question" id="location" mandatory="true" boxsize="large"> + <surveyquestion id="location" mandatory="true" boxsize="large"> <statement>Please enter your location. (example mandatory text question)</statement> - </surveyentry> - <surveyentry type="number" id="age" min="0"> + </surveyquestion> + <surveynumber id="age" min="0"> <statement>Please enter your age (example non-mandatory number question)</statement> - </surveyentry> - <surveyentry type="radio" id="rating"> + </surveynumber> + <surveyradio id="rating"> <statement>Please rate this interface (example radio button question)</statement> <option name="bad">Bad</option> <option name="poor">Poor</option> <option name="good">Good</option> <option name="great">Great</option> - </surveyentry> - <surveyentry type="statement" id="thankyou"> + </surveyradio> + <surveystatement id="thankyou"> <statement>Thank you for taking this listening test. Please click 'submit' and your results will appear in the 'saves/' folder.</statement> - </surveyentry> + </surveystatement> </survey> <metric> <metricenable>testTimer</metricenable>
--- a/tests/examples/mushra_example.xml Mon Sep 11 21:58:05 2017 +0100 +++ b/tests/examples/mushra_example.xml Tue Sep 12 14:05:38 2017 +0100 @@ -3,38 +3,38 @@ <setup interface="MUSHRA" projectReturn="save.php" randomiseOrder='true' poolSize="2" loudness="-23"> <exitText>Thank you for looking at WAET. You can modify the successful completion text as well!</exitText> <survey location="before"> - <surveyentry type="question" id="sessionId" mandatory="true"> + <surveyquestion id="sessionId" mandatory="true"> <statement>Please enter your name.</statement> - </surveyentry> - <surveyentry type="checkbox" id="checkboxtest" mandatory="true"> + </surveyquestion> + <surveycheckbox id="checkboxtest" mandatory="true"> <statement>Please select with which activities you have any experience (example checkbox question)</statement> <option name="musician">Playing a musical instrument</option> <option name="soundengineer">Recording or mixing audio</option> <option name="developer">Developing audio software</option> <option name="hwdesigner">Designing or building audio hardware</option> <option name="researcher">Research in the field of audio</option> - </surveyentry> - <surveyentry type="statement" id="test-intro"> + </surveycheckbox> + <surveystatement id="test-intro"> <statement>This is an example of an 'MUSHRA'-style test, with two pages, using the test stimuli in 'example_eval/'.</statement> - </surveyentry> + </surveystatement> </survey> <survey location="after"> - <surveyentry type="question" id="location" mandatory="true" boxsize="large"> + <surveyquestion id="location" mandatory="true" boxsize="large"> <statement>Please enter your location. (example mandatory text question)</statement> - </surveyentry> - <surveyentry type="number" id="age" min="0"> + </surveyquestion> + <surveynumber id="age" min="0"> <statement>Please enter your age (example non-mandatory number question)</statement> - </surveyentry> - <surveyentry type="radio" id="rating"> + </surveynumber> + <surveyradio id="rating"> <statement>Please rate this interface (example radio button question)</statement> <option name="bad">Bad</option> <option name="poor">Poor</option> <option name="good">Good</option> <option name="great">Great</option> - </surveyentry> - <surveyentry type="statement" id="thankyou"> + </surveyradio> + <surveystatement id="thankyou"> <statement>Thank you for taking this listening test. Please click 'submit' and your results will appear in the 'saves/' folder.</statement> - </surveyentry> + </surveystatement> </survey> <metric> <metricenable>testTimer</metricenable>