# HG changeset patch # User Nicholas Jillings # Date 1459430692 -3600 # Node ID afa7f88e44a936d65fa1b33f504413d95ec65647 # Parent 788a9af36b660fe10406e11c2ac6b2113f1f78f9 Analysis: Get filtered score values. Download filtered data. diff -r 788a9af36b66 -r afa7f88e44a9 analysis/analysis.js --- a/analysis/analysis.js Thu Mar 31 13:31:42 2016 +0100 +++ b/analysis/analysis.js Thu Mar 31 14:24:52 2016 +0100 @@ -589,7 +589,7 @@ this.testSavedDiv = document.getElementById("test-saved"); this.testSaves = null; this.selectURL = null; - + this.specification = new Specification(); get("../test-schema.xsd").then(function(response){ var parse = new DOMParser(); @@ -645,11 +645,31 @@ this.update(this.selectURL); } } + + this.updateData = function(req_str) { + // Now go get that data + get(req_str).then(function(response){ + // Returns the data + chartContext.valueData = JSON.parse(response); + },function(error){console.error(error);}); + } } var interfaceContext = new function() { // This creates the interface for the user to connect with the dynamic back-end to retrieve data this.rootDOM = document.createElement("div"); + this.getDataButton = { + button: document.createElement("button"), + parent: this, + handleEvent: function(event) { + // Get the list of files: + var req_str = "../scripts/get_filtered_score.php"+this.parent.getFilterString(); + testData.updateData(req_str); + } + } + this.getDataButton.button.textContent = "Get Filtered Data"; + this.getDataButton.button.addEventListener("click",this.getDataButton); + this.filterDOM = document.createElement("div"); this.filterDOM.innerHTML = "

PreTest Filters

"; this.filterObjects = []; @@ -773,31 +793,41 @@ } } document.getElementById("test-saved").appendChild(this.filterDOM); + document.getElementById("test-saved").appendChild(this.getDataButton.button); } - this.getFileCount = function() { - // First we must get the filter pairs + this.getFilterString = function() { var pairs = []; for (var obj of this.filterObjects) { pairs = pairs.concat(obj.getFilterPairs()); } - var req_str = "../scripts/get_filtered_count.php?url="+testData.selectURL; + var req_str = "?url="+testData.selectURL; var index = 0; while(pairs[index] != undefined) { req_str += '&'; req_str += pairs[index][0]+"="+pairs[index][1]; index++; } - get(req_str).then(function(response){ + return req_str; + } + this.getFilteredUrlArray = function() { + var req_str = "../scripts/get_filtered_count.php"+this.getFilterString(); + return get(req_str).then(function(response){ var urls = JSON.parse(response); - var str = "Filtered to "+urls.urls.length+" file"; - if (urls.urls.length != 1) { + return urls.urls; + },function(error){ + console.error(error); + }); + } + this.getFileCount = function() { + // First we must get the filter pairs + this.getFilteredUrlArray().then(function(response){ + var str = "Filtered to "+response.length+" file"; + if (response.length != 1) { str += "s."; } else { str += "."; } document.getElementById("filter-count").textContent = str; - },function(error){ - console.error(error); - }); + },function(error){}); } } \ No newline at end of file diff -r 788a9af36b66 -r afa7f88e44a9 scripts/get_filtered_score.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/get_filtered_score.php Thu Mar 31 14:24:52 2016 +0100 @@ -0,0 +1,146 @@ +id = $id; + $this->nest = array(); + $this->type = null; + $this->num = 0; + } + function addNewChild($id) { + if ($this->type == null) { + $this->type = "nest"; + } + if ($this->type == "nest") { + $obj = new nestedObject($id); + array_push($this->nest,$obj); + $this->num = count($this->nest); + return $this->nest[$this->num-1]; + } + return null; + } + function findChild($checkId) { + if ($this->type == "nest"){ + foreach($this->nest as $child) + { + if (strcmp($checkId,$child->id) == 0) { + return $child; + } + } + } + return null; + } + function addValue($val) { + if ($this->type == null) { + $this->type = "value"; + } + if ($this->type == "value") { + array_push($this->nest,$val); + $this->num = count($this->nest); + return $this->nest[$this->num-1]; + } + return null; + } +} + + +$request = "http://".$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; +$request = explode("get_filtered_score.php",$request); +$request = implode("get_filtered_count.php",$request); +$json = json_decode(file_get_contents($request),true); +$saves = $json["urls"]; +// Now we have the filtered save file URLs + +// Build the root nest object to hold the testPages +$root = new nestedObject("root"); +foreach($saves as $url) { + $xml_object = simplexml_load_string(file_get_contents($url)); + if ($xml_object == false) { + echo "

FATAL

could not parse file ".$url.": "; + foreach(libxml_get_errors() as $error) { + echo "
", $error->message; + } + } else { + foreach($xml_object->page as $pageInstance) + { + // Find in the nest + $pageInstanceId = $pageInstance['ref']; + $page_nest = $root->findChild($pageInstanceId); + if ($page_nest == null) { + $page_nest = $root->addNewChild($pageInstanceId); + } + + // Iterate over each $element node + foreach($pageInstance->audioelement as $element) { + // Find our specific element tag + $elementId = null; + if (isset($element['name'])) { + $elementId = $element['name']; + } else { + $elementId = $element['ref']; + } + $element_nest = $page_nest->findChild($elementId); + if ($element_nest == null) { + $element_nest = $page_nest->addNewChild($elementId); + } + // Now get the tags + foreach($element->value as $value) { + $axis_nest = null; + $axisName = "default"; + if (isset($value['interface-name'])) + { + // Find the axis nest + $axisName = $value['interface-name']; + } + + $axis_nest = $element_nest->findChild($axisName); + if ($axis_nest == null) { + $axis_nest = $element_nest->addNewChild($axisName); + } + // Now push our value + $axis_nest->addValue($value); + } + } + } + } +} +$doc_root = '{ "pages": ['; +for ($pageIndex = 0; $pageIndex < $root->num; $pageIndex++) +{ + $page = $root->nest[$pageIndex]; + $doc_page = '{ "id": "'.$page->id.'", "elements": ['; + for($elementIndex = 0; $elementIndex < $page->num; $elementIndex++) + { + $element = $page->nest[$elementIndex]; + $doc_element = '{ "id": "'.$element->id.'", "axis": ['; + for($axisIndex = 0; $axisIndex < $element->num; $axisIndex++) + { + $axis = $element->nest[$axisIndex]; + $doc_axis = '{ "name": "'.$axis->id.'", "values": ['; + for ($valueIndex = 0; $valueIndex < $axis->num; $valueIndex++) + { + $doc_axis = $doc_axis."".strval($axis->nest[$valueIndex]); + if ($valueIndex < $axis->num-1) { + $doc_axis = $doc_axis.', '; + } + } + $doc_axis = $doc_axis.']}'; + if ($axisIndex < $element->num-1) { + $doc_axis = $doc_axis.', '; + } + $doc_element = $doc_element.$doc_axis; + } + $doc_element = $doc_element.']}'; + if ($elementIndex < $page->num-1) { + $doc_element = $doc_element.', '; + } + $doc_page = $doc_page.$doc_element; + } + $doc_page = $doc_page.']}'; + if ($pageIndex < $root->num-1) { + $doc_page = $doc_page.', '; + } + $doc_root = $doc_root.$doc_page; +} +$doc_root = $doc_root.']}'; +echo $doc_root; +?> \ No newline at end of file