Mercurial > hg > webaudioevaluationtool
comparison analysis/analysis.js @ 1287:d219aa5329aa
Analysis interface controls all interface objects.
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Thu, 31 Mar 2016 15:47:47 +0100 |
parents | ae57d9f618cb |
children | 760719986df3 |
comparison
equal
deleted
inserted
replaced
1286:1e2a2a9e9295 | 1287:d219aa5329aa |
---|---|
164 } | 164 } |
165 | 165 |
166 function boxplotRow(array) { | 166 function boxplotRow(array) { |
167 // Take an array of element values and return array of computed intervals | 167 // Take an array of element values and return array of computed intervals |
168 var result = { | 168 var result = { |
169 median : arrayMean(array), | 169 median : percentile(array,50), |
170 pct25 : percentile(array,25), | 170 pct25 : percentile(array,25), |
171 pct75 : percentile(array,75), | 171 pct75 : percentile(array,75), |
172 IQR : null, | 172 IQR : null, |
173 min: null, | 173 min: null, |
174 max: null, | 174 max: null, |
597 },function(error){ | 597 },function(error){ |
598 console.log("ERROR: Could not get Test Schema"); | 598 console.log("ERROR: Could not get Test Schema"); |
599 }); | 599 }); |
600 this.update = function(url) { | 600 this.update = function(url) { |
601 var self = this; | 601 var self = this; |
602 get(url).then(function(response){ | |
603 var parse = new DOMParser(); | |
604 self.specification.decode(parse.parseFromString(response,'text/xml')); | |
605 interfaceContext.generateFilters(self.specification); | |
606 return true; | |
607 },function(error){ | |
608 console.log("ERROR: Could not get"+url); | |
609 return false; | |
610 }); | |
611 } | |
612 var get_test = new XMLHttpRequest(); | |
613 get_test.parent = this; | |
614 get_test.open("GET","../scripts/get_tests.php?format=JSON",true); | |
615 get_test.onload = function() { | |
616 this.parent.testSavedDiv.innerHTML = null; | |
617 var table = document.createElement("table"); | |
618 table.innerHTML = "<tr><td>Test Filename</td><td>Count</td><td>Include</td></tr>"; | |
619 this.parent.testSaves = JSON.parse(this.responseText); | |
620 for (var test of this.parent.testSaves.tests) { | |
621 var tableRow = document.createElement("tr"); | |
622 var tableRowFilename = document.createElement("td"); | |
623 tableRowFilename.textContent = test.testName; | |
624 var tableRowCount = document.createElement("td"); | |
625 tableRowCount.textContent = test.files.length; | |
626 tableRow.appendChild(tableRowFilename); | |
627 tableRow.appendChild(tableRowCount); | |
628 var tableRowInclude = document.createElement("td"); | |
629 var tableRowIncludeInput = document.createElement("input"); | |
630 tableRowIncludeInput.type = "radio"; | |
631 tableRowIncludeInput.name = "test-include"; | |
632 tableRowIncludeInput.setAttribute("source",test.testName); | |
633 tableRowIncludeInput.addEventListener("change",this.parent); | |
634 tableRowInclude.appendChild(tableRowIncludeInput); | |
635 tableRow.appendChild(tableRowInclude); | |
636 table.appendChild(tableRow); | |
637 } | |
638 this.parent.testSavedDiv.appendChild(table); | |
639 } | |
640 get_test.send(); | |
641 this.handleEvent = function(event) { | |
642 if (event.currentTarget.nodeName == "INPUT" && event.currentTarget.name == "test-include") { | |
643 // Changed the test specification | |
644 this.selectURL = event.currentTarget.getAttribute("source"); | |
645 this.update(this.selectURL); | |
646 } | |
647 } | 602 } |
648 | 603 |
649 this.updateData = function(req_str) { | 604 this.updateData = function(req_str) { |
650 // Now go get that data | 605 // Now go get that data |
651 get(req_str).then(function(response){ | 606 get(req_str).then(function(response){ |
667 testData.updateData(req_str); | 622 testData.updateData(req_str); |
668 } | 623 } |
669 } | 624 } |
670 this.getDataButton.button.textContent = "Get Filtered Data"; | 625 this.getDataButton.button.textContent = "Get Filtered Data"; |
671 this.getDataButton.button.addEventListener("click",this.getDataButton); | 626 this.getDataButton.button.addEventListener("click",this.getDataButton); |
627 | |
628 this.testSaves = { | |
629 json: null, | |
630 selectedURL: null, | |
631 inputs: [], | |
632 parent: this | |
633 }; | |
634 this.init = function() { | |
635 var self = this; | |
636 get('../scripts/get_tests.php?format=JSON').then(function(response){ | |
637 document.getElementById("test-saved").innerHTML = null; | |
638 var table = document.createElement("table"); | |
639 table.innerHTML = "<tr><td>Test Filename</td><td>Count</td><td>Include</td></tr>"; | |
640 self.testSaves.json = JSON.parse(response); | |
641 for (var test of self.testSaves.json.tests) { | |
642 var tableRow = document.createElement("tr"); | |
643 var tableRowFilename = document.createElement("td"); | |
644 tableRowFilename.textContent = test.testName; | |
645 var tableRowCount = document.createElement("td"); | |
646 tableRowCount.textContent = test.files.length; | |
647 tableRow.appendChild(tableRowFilename); | |
648 tableRow.appendChild(tableRowCount); | |
649 var tableRowInclude = document.createElement("td"); | |
650 var obj = { | |
651 root: document.createElement("input"), | |
652 parent: self.testSaves, | |
653 handleEvent: function(event) { | |
654 this.parent.selectedURL = event.currentTarget.getAttribute("source"); | |
655 var self = this; | |
656 get(this.parent.selectedURL).then(function(response){ | |
657 var parse = new DOMParser(); | |
658 testData.specification.decode(parse.parseFromString(response,'text/xml')); | |
659 self.parent.parent.generateFilters(testData.specification); | |
660 self.parent.parent.getFileCount(); | |
661 return true; | |
662 },function(error){ | |
663 console.log("ERROR: Could not get"+url); | |
664 return false; | |
665 }); | |
666 } | |
667 } | |
668 obj.root.type = "radio"; | |
669 obj.root.name = "test-include"; | |
670 obj.root.setAttribute("source",test.testName); | |
671 obj.root.addEventListener("change",obj); | |
672 tableRowInclude.appendChild(obj.root); | |
673 tableRow.appendChild(tableRowInclude); | |
674 table.appendChild(tableRow); | |
675 self.testSaves.inputs.push(obj); | |
676 } | |
677 document.getElementById("test-saved").appendChild(table); | |
678 },function(error){console.error(error);}); | |
679 } | |
672 | 680 |
673 this.filterDOM = document.createElement("div"); | 681 this.filterDOM = document.createElement("div"); |
674 this.filterDOM.innerHTML = "<p>PreTest Filters</p><div id='filter-count'></div>"; | 682 this.filterDOM.innerHTML = "<p>PreTest Filters</p><div id='filter-count'></div>"; |
675 this.filterObjects = []; | 683 this.filterObjects = []; |
676 this.generateFilters = function(specification) { | 684 this.generateFilters = function(specification) { |
764 break; | 772 break; |
765 default: | 773 default: |
766 break; | 774 break; |
767 } | 775 } |
768 } | 776 } |
769 for (var survey_entry of specification.preTest.options) { | 777 for (var survey_entry of specification.preTest.options.concat(specification.postTest.options)) { |
770 switch(survey_entry.type) { | 778 switch(survey_entry.type) { |
771 case "number": | 779 case "number": |
772 case "radio": | 780 case "radio": |
773 case "checkbox": | 781 case "checkbox": |
774 var node = new FilterObject(this,survey_entry); | 782 var node = new FilterObject(this,survey_entry); |
777 break; | 785 break; |
778 default: | 786 default: |
779 break; | 787 break; |
780 } | 788 } |
781 } | 789 } |
782 for (var survey_entry of specification.postTest.options) { | |
783 switch(survey_entry.type) { | |
784 case "number": | |
785 case "radio": | |
786 case "checkbox": | |
787 var node = new FilterObject(this,survey_entry); | |
788 this.filterObjects.push(node); | |
789 this.filterDOM.appendChild(node.rootDOM); | |
790 break; | |
791 default: | |
792 break; | |
793 } | |
794 } | |
795 document.getElementById("test-saved").appendChild(this.filterDOM); | 790 document.getElementById("test-saved").appendChild(this.filterDOM); |
796 document.getElementById("test-saved").appendChild(this.getDataButton.button); | 791 document.getElementById("test-saved").appendChild(this.getDataButton.button); |
797 } | 792 } |
798 this.getFilterString = function() { | 793 this.getFilterString = function() { |
799 var pairs = []; | 794 var pairs = []; |
800 for (var obj of this.filterObjects) { | 795 for (var obj of this.filterObjects) { |
801 pairs = pairs.concat(obj.getFilterPairs()); | 796 pairs = pairs.concat(obj.getFilterPairs()); |
802 } | 797 } |
803 var req_str = "?url="+testData.selectURL; | 798 var req_str = "?url="+this.testSaves.selectedURL; |
804 var index = 0; | 799 var index = 0; |
805 while(pairs[index] != undefined) { | 800 while(pairs[index] != undefined) { |
806 req_str += '&'; | 801 req_str += '&'; |
807 req_str += pairs[index][0]+"="+pairs[index][1]; | 802 req_str += pairs[index][0]+"="+pairs[index][1]; |
808 index++; | 803 index++; |
828 str += "."; | 823 str += "."; |
829 } | 824 } |
830 document.getElementById("filter-count").textContent = str; | 825 document.getElementById("filter-count").textContent = str; |
831 },function(error){}); | 826 },function(error){}); |
832 } | 827 } |
833 } | 828 |
829 this.init(); | |
830 } |