rough ve table output w/template. This is easier than PHP.

This commit is contained in:
nearwood 2014-07-18 17:28:45 -04:00
parent bc38390836
commit 620ed64500
4 changed files with 159 additions and 12 deletions

View File

@ -140,7 +140,7 @@
</div> </div>
</div> </div>
<div id='content'> <div id='content'>
Bleh
</div> </div>
<div class="footer"> <div class="footer">
Apache PHP AngularJS<br/> Apache PHP AngularJS<br/>

113
msqParse.js Normal file
View File

@ -0,0 +1,113 @@
/**
* Tables (data, x axis, y axis)
* single constants with labels
*
*
*
*
*/
var msqApp = angular.module('msqApp', []);
msqApp.controller('msqParse', function ($scope) {
$scope.loadMsq = function(file) {
var xhr = new XMLHttpRequest();
xhr.open('GET', file);
xhr.onreadystatechange = function() {
switch (xhr.readyState)
{
case 4:
//xhr.responseXML
var xml = $($.parseXML(xhr.responseText));
$scope.msq = parseMSQ(xml);
break;
}
};
xhr.send();
};
$scope.msq = {tables: [{name: "VE TAble"}]};
});
function parseMSQ(xml)
{
var msq = {};
console.debug("Loading MSQ...");
var fileVersion = parseFloat(xml.find('versionInfo').attr('fileFormat'));
console.debug("File format: " + fileVersion);
if (fileVersion == 4.0)
{
//load 4.0 json relationships
}
msq.author = xml.find("bibliography").attr('author');
msq.date = xml.find("bibliography").attr('writeDate');
msq.format = fileVersion;
msq.sig = xml.find("versionInfo").attr('signature');
console.debug("Signature: " + msq.sig);
msq.tables = [];
var tables = msqFormat4.tables;
for (var i = 0; i < tables.length; i++)
{
var t = tables[i];
var tbl = getTable(xml, t.data, t.x, t.y);
msq.tables.push({"name": t.name, "dataRows": tbl.dataRows, "xAxis": tbl.xAxis, "yAxis": tbl.yAxis});
}
//msq.tables = [{name: "VE Table", dataRows: ["3"], xAxis: ["x1"], yAxis: ["y1"]}];
return msq;
}
/**
* create table el and <tr>s and shit
*/
function getTable(xml, data, xaxis, yaxis)
{
var tbl = {dataRows: [], xAxis: [], yAxis: []}
var d = xml.find('constant[name=' + data + ']');
var dRows = parseInt(d.attr('rows'));
var dCols = parseInt(d.attr('cols')); //TODO Check these against x,y axisses
d = d.text().trim().split(/\s+/);
if (d.length == dRows * dCols)
{
//rows seems to be the first indicator
var x = xml.find('constant[name=' + xaxis + ']');
var xCount = parseInt(x.attr('rows'));
x = x.text().trim().split(/\s+/);
var y = xml.find('constant[name=' + yaxis + ']');
var yCount = parseInt(y.attr('rows'));
y = y.text().trim().split(/\s+/);
if (xCount == dCols && yCount == dRows)
{//data and axis cell counts match
for (var r = 1; r <= yCount; r++)
{
var dr = [];
for (var c = 1; c <= xCount; c++)
{
if (r == 1)
tbl.xAxis.push(x[c]);
dr.push(d[r * c]);
}
tbl.yAxis.push(y[r]);
tbl.dataRows.push(dr);
}
}
else console.error("Data/Axis count mismatch");
}
else console.error("Error parsing table data");
return tbl;
}
msqFormat4 = {constants: [{name: "O2 Sensor Type", id: 'egoType'}],
tables: [{name: "VE Table", data: 'veTable1', x: 'frpm_table1', y: 'fmap_table1'}]
};

View File

@ -1,11 +1,28 @@
<html> <html ng-app="msqApp">
<head> <head>
<title>MSQ Viewer</title> <title>MSQ Viewer</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="view.js"></script> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.min.js"></script>
<script>window.onload=function() {view("38.msq", "#main");};</script> <script src="msqParse.js"></script>
</head> </head>
<body id="main"> <body ng-controller="msqParse">
<div><input ng-model="file" type="text" value="38.msq"/><button ng-click="loadMsq(file)">Load MSQ</button></div>
<button ng-click="loadMsq('38.msq')">Load 38.msq</button>
<div>
{{msq.author}} {{msq.date}}<br/>
{{msq.format}} {{msq.sig}}<br/>
</div>
<div ng-repeat="table in msq.tables">
{{table.name}}
<table>
<tr ng-repeat="y in table.yAxis track by $index"><th>{{y}}</th></tr>
</table>
<table>
<tr ng-repeat="row in table.dataRows track by $index"><td ng-repeat="cell in row track by $index">{{cell}}</td></tr>
</table>
<table>
<tr><th></th><th ng-repeat="x in table.xAxis track by $index">{{x}}</th></tr>
</table>
</div>
</body> </body>
</html> </html>

27
view.js
View File

@ -29,15 +29,24 @@ function view(file, targetElement)
function parseMSQ(xml, el) function parseMSQ(xml, el)
{ {
el = $(el); el = $(el);
el.text("Loading MSQ..."); console.debug("Loading MSQ...");
var author = xml.find("bibliography").attr('author'); var fileVersion = parseFloat(xml.find('versionInfo').attr('fileFormat'));
el.text(author); console.debug("File format: " + fileVersion);
if (fileVersion == 4.0)
{
//load 4.0 json relationships
} }
function parseVE(xml, el) var author = xml.find("bibliography").attr('author');
{ //el.text(author);
var tables = msqFormat4.tables;
for (var i = 0; i < tables.length; i++)
{
var t = tables[i];
var tbl = createTable(xml, t.data, t.x, t.y);
}
} }
/** /**
@ -45,5 +54,13 @@ function parseVE(xml, el)
*/ */
function createTable(xml, data, xaxis, yaxis) function createTable(xml, data, xaxis, yaxis)
{ {
var tbl = document.createElement('table');
return tbl;
} }
msqFormat4 = {constants: [{name: "O2 Sensor Type", id: 'egoType'],
tables: [{name: "VE Table", data: 'veTable1', x: 'frpm_table1', y: 'fmap_table1'}]
};