var containerOver = document.getElementById(json.name + "Big");
// if (containerOver != null) {
// containerOver.update();
// } TODO: reenable if textsize of overlays can be changed
var viewerContainer = document.getElementById("viewerContainer");
var tip = "Tip: Scroll to zoom the graph. Click and drag to pan the graph.<br/>";
json.jsonBig = jQuery.extend(true, {}, json);
var ref = prepopulateContainerOver(containerOver, viewerContainer, tip, [ json ], containerOver.updateData, 'graph', true);
var containerContent = ref.containerContent;
var containerChart = ref.containerChart;
var containerOptions = ref.options;
var error = ref.error;
var vmode = json.type.I.verticalLines.trim();
var hmodeh = json.type.I.horizontalLinesHeader.trim();
var hmode = json.type.I.horizontalLinesBody.trim();
var count = 0;
for ( var key in results[0]) {
++count;
}
if (count === 0) {
alert("Query \"" + json.type.I.query + "\" returns no columns!");
return;
}
// vertical lines
var c = 0;
var tmp = "\\begin{tabular}[t]{";
if (vmode === "a" || vmode === "o" || vmode === "i" || vmode === "n") {
for ( var key in results[0]) {
if (vmode === "n") {
tmp += "c";
} else if (c === 0) {
if (vmode === "a" || vmode === "o") {
tmp += "|c";
} else {
tmp += "c";
}
} else {
if (vmode === "a" || vmode === "i") {
tmp += "|c";
} else {
tmp += "c";
}
}
++c;
}
if (vmode === "a" || vmode === "o") {
tmp += "|}";
} else {
tmp += "}";
}
} else {
tmp += vmode + "}";
}
// header
if (hmodeh === "a" || hmodeh === "o" || hmodeh === "i" || hmodeh === "n") {
if (hmodeh === "a" || hmodeh === "o") {
tmp += "\\firsthline ";
}
} else {
var pattern = hmodeh.split(" ");
if (pattern.length != 2) {
alert("Format string is too short! Must contain exactly 2 format specifications. Format string was: " + hmodeh);
return;
}
var first = pattern[0].split('');
var firsth = true;
for (var i = 0; i < first.length; ++i) {
switch (first[i]) {
case 'h':
if (firsth) {
tmp += "\\firsthline";
firsth = false;
} else {
tmp += "\\hline"
}
break;
case 'b':
break;
default:
alert("Unknown format character found! Format string was: " + hmodeh);
return;
}
}
tmp += " ";
}
for ( var key in results[0]) {
tmp += "\\textbf{" + key + "}&";
}
tmp = tmp.substring(0, tmp.length - 1) + "\\\\";
if (hmodeh === "a" || hmodeh === "o" || hmodeh === "i" || hmodeh === "n") {
if (hmodeh === "a" || hmodeh === "i") {
tmp += "\\hline ";
}
} else {
var pattern = hmodeh.split(" ");
var second = pattern[1].split('');
for (var i = 0; i < second.length; ++i) {
switch (second[i]) {
case 'h':
tmp += "\\hline";
break;
case 'b':
break;
default:
alert("Unknown format character found! Format string was: " + hmodeh);
return;
}
}
tmp += " ";
}
// body
var pattern = hmode.split(" ");
var i = 0;
c = 0;
for ( var r in results) {
for ( var key in results[r]) {
tmp += results[r][key] + "&";
}
tmp = tmp.substring(0, tmp.length - 1) + "\\\\";
if (hmode === "a" || (hmode === "i" && c !== results.length - 1) || (hmode === "o" && c === results.length - 1)) {
tmp += "\\hline ";
} else if (hmode !== "a" && hmode !== "i" && hmode !== "o" && hmode !== "n") {
var format = pattern[i++ % pattern.length].split('');
for (var j = 0; j < format.length; ++j) {
switch (format[j]) {
case 'h':
tmp += "\\hline";
break;
case 'b':
break;
default:
alert("Unknown format character found! Format string was: " + hmodeh);
return;
}
}
tmp += " ";
}
++c;
}
tmp += "\\end{tabular}";
return tmp;
}
function buildContainerPivotBig(json, containerOver, initial) {
var basetextsize = 8;
var viewerContainer = document.getElementById("viewerContainer");
json.jsonBig = jQuery.extend(true, {}, json);
var tip = "Tip: Drag and drop attributes to the row/column area.<br/>";
var ref = prepopulateContainerOver(containerOver, viewerContainer, tip, [ json ], updateData, 'pivot table', false);
var containerContent = ref.containerContent;
var containerControl = ref.containerControl;
var containerChart = ref.containerChart;
var containerOptions = ref.options;
var editor = ref.editor;
var error = ref.error;
editor.setValue(prettifySQL(json.jsonBig.type.I.queryB));
var viewerContainer = document.getElementById("viewerContainer");
var tip = 'Tip: Click on the attributes to change the sorting.';
json.jsonBig = jQuery.extend(true, {}, json);
var ref = prepopulateContainerOver(containerOver, viewerContainer, tip, [ json ], update, 'table', false);
var containerContent = ref.containerContent;
var containerOptions = ref.options;
var containerChart = ref.containerChart;
var error = ref.error;
var overlay = container;
var xCount = json.type.I.xCount;
var yCount = json.type.I.yCount;
var xValues;
try {
xValues = JSON.parse(json.type.I.xValues);
} catch (e) {
alert("Parsing of xValues for " + json.name + " failed!\nError: " + e.message + "\nValue: " + json.type.I.xValues);
}
var yValues;
try {
yValues = JSON.parse(json.type.I.yValues);
} catch (e) {
alert("Parsing of yValues for " + json.name + " failed!\nError: " + e.message + "\nValue: " + json.type.I.yValues);
}
var leftArr;
if (json.type.I.leftArr === "auto") {
if (json.type.I.yUnitName != "") {
leftArr = [ {
text : json.type.I.yUnitName,
c : yCount
} ];
} else {
leftArr = [];
}
} else {
try {
leftArr = JSON.parse(json.type.I.leftArr);
} catch (e) {
alert("Parsing of leftArr for " + json.name + " failed!\nError: " + e.message + "\nValue: " + json.type.I.leftArr);
}
}
var rightArr;
if (json.type.I.rightArr === "auto") {
rightArr = [];
for (var i = 0; i < yValues.length; ++i) {
rightArr[rightArr.length] = {
text : yValues[i],
c : 1
};
}
} else {
try {
rightArr = JSON.parse(json.type.I.rightArr);
} catch (e) {
alert("Parsing of rightArr for " + json.name + " failed!\nError: " + e.message + "\nValue: " + json.type.I.rightArr);
}
}
var topArr;
if (json.type.I.topArr === "auto") {
topArr = [];
for (var i = 0; i < xValues.length; ++i) {
topArr[topArr.length] = {
text : xValues[i],
c : 1
};
}
} else {
try {
topArr = JSON.parse(json.type.I.topArr);
} catch (e) {
alert("Parsing of topArr for " + json.name + " failed!\nError: " + e.message + "\nValue: " + json.type.I.topArr);
}
}
var bottomArr;
if (json.type.I.bottomArr === "auto") {
if (json.type.I.xUnitName != "") {
bottomArr = [ {
text : json.type.I.xUnitName,
c : xCount
} ];
} else {
bottomArr = [];
}
} else {
try {
bottomArr = JSON.parse(json.type.I.bottomArr);
} catch (e) {
alert("Parsing of bottomArr for " + json.name + " failed!\nError: " + e.message + "\nValue: " + json.type.I.bottomArr);
}
}
var queryBackup = json.type.I.query;
var yFirst = json.type.I.yFirst;
var forceXequal = json.type.I.forceXequal;
var forceYequal = json.type.I.forceYequal;
if (xValues.length != xCount) {
alert("Length of xValues array does not match xCount!\nxValues has length " + xCount.length + " but xCount is " + xCount);
}
if (yValues.length != yCount) {
alert("Length of yValues array does not match yCount!\nyValues has length " + yCount.length + " but yCount is " + yCount);
}
if (((queryBackup.match(/\?/g) || []).length) != 2) {
alert("Query for multiplot must contain exactly 2 occurrences of \"?\"\nQuery was: " + queryBackup);
}
// TODO: right now only labels of one line height are supported!
var fontbasesize = 15;
var left = leftArr.length != 0 ? fontbasesize * zoomFactor * 1.6 : 0;
var right = rightArr.length != 0 ? fontbasesize * zoomFactor * 1.6 : 0;
var top = topArr.length != 0 ? fontbasesize * zoomFactor * 1.6 : 0;
var bottom = bottomArr.length != 0 ? fontbasesize * zoomFactor * 1.6 : 0;
var options = getChartOptions(json, zoomFactor, {});
var legend = options.legend.show ? fontbasesize * zoomFactor * 1.6 : 0;
var inner = document.createElement('table');
var charts = [];
inner.setAttribute('style', 'height: 100%; width: 100%; border-collapse: collapse; text-align:center;');
overlay.appendChild(inner);
inner.className = 'multiplot';
var overlaywidth = $(overlay).width();
var overlayheight = $(overlay).height();
var nextLeft = 0;
var nextRight = 0;
var h = Math.floor((overlayheight - top - bottom - legend - 1) / yCount);
var w = Math.floor((overlaywidth - left - right - 1) / xCount);
var style = 'width: ' + w + 'px;' + 'height: ' + h + 'px;';
var yExtent;
var xExtent = [];
var legendItems = [];
var colors = {};
// Calculate size of axis labels
var div = document.createElement('div');
div.setAttribute('style', style);
overlay.appendChild(div);
var cellquery = queryBackup;
if (yFirst) {
cellquery = cellquery.replace("?", yValues[0]);
cellquery = cellquery.replace("?", xValues[0]);
} else {
cellquery = cellquery.replace("?", xValues[0]);
cellquery = cellquery.replace("?", yValues[0]);
}
json.type.I.query = cellquery;
defaultChartOptions.noyticks = true;
defaultChartOptions.noxticks = true;
var chartdata;
if (json.result == undefined) {
json.result = [];
}
var chartdata = getChartData(json);
if (chartdata.error != undefined) {
alert(json.name + " has error:\n" + chartdata.error);
}
var options = getChartOptions(json, zoomFactor, chartdata.values, div);
delete options.axis.y.label;
delete options.axis.x.label;
options.legend.show = false;
var chart = c3.generate(options);
var pl = chart.pl();
var pb = chart.pb();
overlay.removeChild(div);
var options = getChartOptions(json, zoomFactor, chartdata, div);
delete options.axis.y.label;
delete options.axis.x.label;
options.legend.show = false;
var chart = c3.generate(options);
var pl = chart.pl() - pl;
var pb = chart.pb() - pb;
overlay.removeChild(div);
// /////////////////////////////
var h = Math.floor((overlayheight - top - bottom - legend - pb - 1) / yCount);
var w = Math.floor((overlaywidth - left - right - pl - 1) / xCount);
if (top != 0) {
var tr = document.createElement('tr');
inner.appendChild(tr);
if (left != 0) {
var td = document.createElement('td');
tr.appendChild(td);
}
var cur = topArr.shift();
var td = document.createElement('td');
tr.appendChild(td);
getTop(cur, json, td);
$(td).css("padding-left", pl);
while (topArr.length != 0) {
var cur = topArr.shift();
var td = document.createElement('td');
tr.appendChild(td);
getTop(cur, json, td);
}
if (right != 0) {
var td = document.createElement('td');
tr.appendChild(td);
}
}
for (var y = 0; y < yCount; ++y) {
var tr = document.createElement('tr');
inner.appendChild(tr);
if (left != 0 && y == nextLeft) {
var cur = leftArr.shift();
var td = document.createElement('td');
tr.appendChild(td);
nextLeft += getLeft(cur, json, td);
if (y == yCount - 1) {
$(td).css("padding-bottom", pb);
}
}
for (var x = 0; x < xCount; ++x) {
var td = document.createElement('td');
tr.appendChild(td);
var cellInner = document.createElement('div');
td.appendChild(cellInner);
var chart = c3.generate(options);
charts[charts.length] = chart;
if (legend != 0) {
var a = options.data.keys.value;
for (var i = 1; i < a.length; ++i) {
if (legendItems.indexOf(a[i]) === -1) {
legendItems[legendItems.length] = a[i];
colors[a[i]] = chart.color(a[i]);
}
}
}
if (forceYequal) {
if (x == 0) {
// save y extent
yExtent = chart.yd();
}
}
if (forceXequal) {
if (y == 0) {
// save x extent
xExtent[x] = chart.xd();
}
}
}
if (right != 0 && y == nextRight) {
var cur = rightArr.shift();
var td = document.createElement('td');
tr.appendChild(td);
nextRight += getRight(cur, json, td);
if (y == yCount - 1) {
$(td).css("padding-bottom", pb);
}
}
}
if (bottom != 0) {
var tr = document.createElement('tr');
inner.appendChild(tr);
if (left != 0) {
var td = document.createElement('td');
tr.appendChild(td);
}
while (bottomArr.length != 0) {
var cur = bottomArr.shift();
var td = document.createElement('td');
tr.appendChild(td);
getBottom(cur, json, td);
}
if (right != 0) {
var td = document.createElement('td');
tr.appendChild(td);
}
}
if (legend != 0) {
var tr = document.createElement('tr');
inner.appendChild(tr);
if (left != 0) {
var td = document.createElement('td');
tr.appendChild(td);
}
var td = document.createElement('td');
tr.appendChild(td);
td.setAttribute('colspan', xCount);
try {
var addOpt = JSON.parse(json.type.I.options);
} catch (e) {
alert('Parsing of options for ' + json.name + ' failed. \nDid you forgot to enclose every field and value by ", or did your TeX program replace " by \'\'?\nRemember that the correct JSON String syntax is: "key": "value"\n JSON String was:\n' + json.type.I.options);
}
jQuery.extend(true, options, addOpt);
if (options.axis.x.label == '') {
delete options.axis.x.label;
}
if (options.axis.y.label == '') {
delete options.axis.y.label;
}
if (json.type.I.includeZero) {
options.axis.y.min = 0;
}
var defaultformat = function(v) {
return (v || v === 0) ? +v : "";
};
var funcsave = options.axis.y.tick.format;
funcsave = typeof funcsave == "function" ? optionsBig.axis.y.tick.format : defaultformat;
if (json.type.I.logScale) {
options.axis.y.tick.format = function(d) {
return funcsave(+Math.exp(d).toFixed(2));
};
}
switch (json.type.I.chartType) {
case 'Line':
case 'line':
if (json.type.I.fillGraph) {
options.data.type = 'area';
} else {
options.data.type = 'line';
}
break;
case 'Bar':
case 'bar':
options.data.type = 'bar';
break;
case 'SignaturePlot':
case 'signatureplot':
case 'compareToBest':
case 'comparetobest':
try {
options.data = compareToBest([ options.data ]);
options.axis.x.tick.format = function(x) {
return '' + (Math.round(x * 10000) / 100) + '%';
};
options.axis.y.tick.format = function(y) {
return '' + (Math.round(y * 10000) / 100) + '%';
};
} catch (e) {
alert(e);
}
break;
default:
alert('Unknown chart type. Type was: "' + json.type.I.chartType + '"');
}
var header = document.createElement('span');
header.innerHTML = '<span style="text-decoration:underline;">SQL Query for ' + f + ':</span><br />Tip: Press CTRL-Space for autocomplete.<br />Tip: Click outside of the editor area to execute a query.';
containerControl.appendChild(header);
while (containerOver.firstChild) {
containerOver.removeChild(containerOver.firstChild);
}
switch (json.type.C) {
case "pdbf.json.MultiplotChart":
case "pdbf.json.Chart":
buildContainerChartBig(json, containerOver, true);
break;
case "pdbf.json.Text":
case "pdbf.json.DataText":
case "pdbf.json.DataTable":
buildContainerTableBig(json, containerOver);
break;
case "pdbf.json.Pivot":
buildContainerPivotBig(json, containerOver, true);
break;
}
});
containerControl.appendChild(def);
var error = document.createElement('span');
containerControl.appendChild(error);
error.innerHTML = 'Query status: OK';
containerControl.appendChild(getSpacer());
var options = document.createElement('div');
containerControl.appendChild(options);
var download = document.createElement('input');
download.type = 'button';
download.value = 'Download query result as CSV';
download.setAttribute('style', 'font-size:inherit; white-space: normal;');
download.addEventListener('click', function() {
var cols = [];
for ( var key in json.resultBig[0]) {
cols[cols.length] = {
columnid : key
};
}
alasql.into.CSV('result.csv', {
headers : true
}, json.resultBig, cols);
});
options.appendChild(download);
options.appendChild(getSpacer());
options.appendChild(getSpacer());
if (fixed) {
var containerChartSub = document.createElement('div');
containerChartSub.setAttribute('style', 'width:100%; height:100%; max-height:100%; z-index:9999');
containerChart.appendChild(containerChartSub);
}
var containerClose = document.createElement('div');
containerClose.innerHTML = 'Click here to close this window (or press Escape) [X]';
containerClose.setAttribute('style', 'float:right; cursor: pointer; font-weight: bold;');
addClickCloseHandler(containerClose, containerOver);
containerOver.appendChild(containerClose);
var containerLabel = document.createElement('span');
containerLabel.innerHTML = 'Switch representation:<br />';
containerSwitch.appendChild(containerLabel);
var center = document.createElement('center');
center.appendChild(containerControl);
center.appendChild(containerChart);
containerOver.appendChild(center);
viewerContainer.appendChild(containerOver);
var selectArr = [];
for (var x = 0; x < json.type.I.xCount; ++x) {
selectArr[xValues[x]] = [];
for (var y = 0; y < json.type.I.yCount; ++y) {
var cellquery = json.type.I.query;
var yFirst = json.type.I.yFirst;
if (yFirst) {
cellquery = cellquery.replace("?", yValues[y]);
cellquery = cellquery.replace("?", xValues[x]);
} else {
cellquery = cellquery.replace("?", xValues[x]);
cellquery = cellquery.replace("?", yValues[y]);
}
selectArr[xValues[x]][yValues[y]] = cellquery;
}
}
$(selectX).change(function() {
var x = $(selectX).val();
var y = $(selectY).val();
json.jsonBig.type.I.query = selectArr[x][y];
json.jsonBig.type.I.queryB = selectArr[x][y];
editor.setValue(prettifySQL(json.jsonBig.type.I.query));
containerOver.updateData();
});
$(selectY).change(function() {
var x = $(selectX).val();
var y = $(selectY).val();
json.jsonBig.type.I.query = selectArr[x][y];
json.jsonBig.type.I.queryB = selectArr[x][y];
editor.setValue(prettifySQL(json.jsonBig.type.I.query));
containerOver.updateData();
});
var x = $(selectX).val();
var y = $(selectY).val();
json.jsonBig.type.I.query = selectArr[x][y];
json.jsonBig.type.I.queryB = selectArr[x][y];
editor.setValue(prettifySQL(json.jsonBig.type.I.query));
}
}
if (results[0] instanceof Array) {
return {
error : "Query \"" + json.type.I.query + "\" contains multiple statements!"
};
}
var columns = [];
for ( var key in results[0]) {
columns[columns.length] = key;
}
var ret = {
values : {
x : columns[0],
json : results,
keys : {
value : columns
}
},
error : error,
res : results
};
// logscale
if (json.type.I.logScale == true) {
for (var i = 0; i < ret.values.json.length; i++) {
var logscaleValues = ret.values.json[i];
for (var series = 0; series < ret.values.keys.value.length; ++series) {
var logId = ret.values.keys.value[series];
if (logId == ret.values.x) {
continue;
}
var logVal = logscaleValues[logId];
if (isNaN(logVal)) {
throw "Error! Logscale is active and chart contains negative values!";
}
function GRUBBS_FILTER(arr, alpha) {
var arr = arr.slice();
if (!Array.isArray(arr)) {
throw new Error("Argument of GRUBBS_FILTER is not an array!");
}
if (alpha == undefined) {
var alpha = 0.05;
}
while (true) {
var N = arr.length;
var t = jStat.studentt.inv((alpha) / (2 * N), N - 2);
var ZCrit = (N - 1) / Math.sqrt(N) * Math.sqrt((t * t) / (N - 2 + t * t));
var M = jStat.mean(arr);
var SD = jStat.stdev(arr, true);
var Z = undefined;
var Zindex = -1;
arr.forEach(function(e, i) {
var tmp = Math.abs(e - M) / SD;
if (Z == undefined || tmp > Z) {
Z = tmp;
Zindex = i;
}
});
var margin_of_error = MARGIN_OF_ERROR(arr);
var avg = MEAN(arr);
if (Z > ZCrit && margin_of_error / avg > 0.025) {
arr.splice(Zindex, 1);
} else {
break;
}
}
return arr;
}
alasql.fn.GRUBBS_FILTER = GRUBBS_FILTER;
function MEAN(arr) {
if (!Array.isArray(arr)) {
throw new Error("Argument of MEAN is not an array!");
}
return jStat.mean(arr);
}
alasql.fn.MEAN = MEAN;
function STDDEV_SAMP(arr) {
if (!Array.isArray(arr)) {
throw new Error("Argument of STDDEV_SAMP is not an array!");
}
return jStat.stdev(arr, true);
}
alasql.fn.STDDEV_SAMP = STDDEV_SAMP;
function MARGIN_OF_ERROR(arr, alpha) {
if (!Array.isArray(arr)) {
throw new Error("Argument of MARGIN_OF_ERROR is not an array!");
}
var stdev = jStat.stdev(arr, true);
if (alpha == undefined) {
var alpha = 0.05;
}
var n = arr.length;
return jStat.studentt.inv(1 - alpha / 2, n - 1) * stdev * Math.sqrt(n);
}
alasql.fn.MARGIN_OF_ERROR = MARGIN_OF_ERROR;
function CONF_INT(arr, alpha) {
if (!Array.isArray(arr)) {
throw new Error("Argument of CONF_INT is not an array!");
}
var MOE = alasql.fn.MARGIN_OF_ERROR(arr, alpha); // TODO: maybe remove
// null/undefined values?
var MEAN = alasql.fn.MEAN(arr); // TODO: maybe remove null/undefined values?
return [ MEAN - MOE, MEAN + MOE ]
}
alasql.fn.CONF_INT = CONF_INT;
function T_TEST(arr1, arr2, alpha) {
if (!Array.isArray(arr1)) {
throw new Error("Argument 1 of T_TEST is not an array!");
}
if (!Array.isArray(arr2)) {
throw new Error("Argument 2 of T_TEST is not an array!");
}
if (alpha == undefined) {
var alpha = 0.05;
}
if (arr1 == arr2)
return true;
var m1 = jStat.mean(arr1);
var m2 = jStat.mean(arr2);
var n1 = arr1.length;
var n2 = arr2.length;
var s1 = jStat.stdev(arr1, true);
var s2 = jStat.stdev(arr2, true);
var sp = Math.sqrt(((n1 - 1) * (s1 * s1) + (n2 - 1) * (s2 * s2)) / (n1 + n2 - 2));
var t = Math.abs((m1 - m2) / (sp * Math.sqrt(1 / n1 + 1 / n2)));
var df = n1 + n2 - 2;
var p = 2 - jStat.studentt.cdf(t, df) * 2;
return p >= alpha;
}
alasql.fn.T_TEST = T_TEST;
function WELCH_TEST(arr1, arr2, alpha) {
if (!Array.isArray(arr1)) {
throw new Error("Argument 1 of WELCH_TEST is not an array!");
}
if (!Array.isArray(arr2)) {
throw new Error("Argument 2 of WELCH_TEST is not an array!");
}
if (alpha == undefined) {
var alpha = 0.05;
}
if (arr1 == arr2)
return true;
var m1 = jStat.mean(arr1);
var m2 = jStat.mean(arr2);
var n1 = arr1.length;
var n2 = arr2.length;
var s1 = jStat.stdev(arr1, true);
var s2 = jStat.stdev(arr2, true);
var s1s1n1 = s1 * s1 / n1;
var s2s2n2 = s2 * s2 / n2;
var t = Math.abs((m1 - m2) / Math.sqrt(s1s1n1 + s2s2n2));
var df = ((s1s1n1 + s2s2n2) * (s1s1n1 + s2s2n2)) / (((s1s1n1 * s1s1n1) / (n1 - 1)) + ((s2s2n2 * s2s2n2) / (n2 - 1)));
var p = 2 - jStat.studentt.cdf(t, df) * 2;
return p >= alpha;
}
alasql.fn.WELCH_TEST = WELCH_TEST;
function compareToBest(valuesArr) {
var values = valuesArr[0]; // Call by reference
if (values.keys == undefined)
return values;
var keys = values.keys.value;
if (values.finished) {
return values;
}
if (keys.length > 1) {
throw new Error("compareToBest does only support one attribute");
}
values.x = "x";
var aname = keys[0];
keys[keys.length] = "x";
var runtimes = values.json;
if (Array.isArray(runtimes[0][aname])) {
var runtime_count = runtimes.length;
var means = [];
var min;
var min_int;
// calculate mean of each experiment, search minimum of conf. int. lower
// bounds
for (var i = 0; i < runtime_count; ++i) {
var cur = runtimes[i][aname];
means[i] = alasql.fn.MEAN(cur);
var ci = alasql.fn.CONF_INT(cur);
if (min_int == undefined || ci[0] < min_int[0]) {
min = i;
min_int = ci;
}
}
var distance = []; // distance from best experiment
for (var i = 0; i < runtime_count; ++i) {
// for t_bests the distance is set to 0
if (alasql.fn.WELCH_TEST(runtimes[min][aname], runtimes[i][aname])) {
distance[i] = 0;
} else {
distance[i] = means[i] - min_int[1];
if (distance[i] < 0) {
distance[i] = 0;
}
}
}
var res = [];
slowDown.forEach(function(v, i) {
res[i] = {
x : i / (runtime_count - 1)
};
res[i][aname] = slowDown[i];
});
values.json = res;
values.finished = true;
return values;
} else {
var runtime_count = runtimes.length;
var means = [];
var min;
var min_int;
// calculate mean of each experiment, search minimum of conf. int. lower
// bounds
for (var i = 0; i < runtime_count; ++i) {
var cur = runtimes[i][aname];
means[i] = cur;
var ci = [ cur, cur ];
if (min_int == undefined || ci[0] < min_int[0]) {
min = i;
min_int = ci;
}
}
var distance = []; // distance from best experiment
for (var i = 0; i < runtime_count; ++i) {
distance[i] = means[i] - min_int[1];
}
function alasqlQuery(q) {
var results = alasql(q);
return results;
}
function isInt(x) {
var y = parseInt(x, 10);
return !isNaN(y) && x == y && x.toString() == y.toString();
}
function prettifySQL(sql) {
return sql; // TODO: Currently we dont support pretty printing sql because
// pretty printing of alasql breaks quoted literals
}