-
Notifications
You must be signed in to change notification settings - Fork 10
/
plot-stress.html
235 lines (231 loc) · 5.89 KB
/
plot-stress.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<!DOCTYPE HTML>
<html>
<head>
<style>
#radioButtons ul li{
height: 30px;;
}
</style>
<script>
/////////////////////////////// Code for all task////////////////////////
function allGraph(data){
var keysAll = new Set();
for (var key in data) {
for (graphName in data[key]) {
//alert(graphName);
keysAll.add(graphName);
}
}
console.log(keysAll);
return keysAll;
}
function graph(data, graphName){
var lines = [];
var names = [];
for (var key in data) {
line = [];
if (key in data && graphName in data[key]) {
for (var i = 0; i < data[key][graphName].length; i++) {
if (data[key][graphName][i] != -1) {
line.push({
x: i*2,
y: data[key][graphName][i]
});
}
}
names.push(key)
}
lines.push(line)
}
return [lines, names];
}
function taskGraph(data, graphName, start, end){
var lines = [];
var names = [];
for (var key in data) {
line = [];
if (key in data && graphName in data[key]) {
var firstValue = null
for (var i = 0; i < data[key][graphName].length; i++) {
if (data[key][graphName][i] != -1) {
if (end == -1 || i*2>=start && i*2<=end) {
if (firstValue == null) {
firstValue = data[key][graphName][i];
if (graphName.startsWith("sum_"))
console.log(graphName+"'s first value is: "+firstValue);
}
line.push({
x: i*2,
y: graphName.startsWith("sum_")? data[key][graphName][i] - firstValue: data[key][graphName][i]
});
}
}
}
names.push(key)
}
lines.push(line)
}
return [lines, names];
}
Object.size = function(obj) {
var size = 0,
key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
function newrender(linesSize, lines, names){
var options = {
animationEnabled: false,
theme: "light2",
title: {
text: "graphName"
},
axisX: {
//valueFormatString: "DD MMM YYYY",
},
axisY: {
title: "graphName",
titleFontSize: 18
},
toolTip:{
content: "{name}: {y}"
},
data: []
};
for (i=0; i<linesSize; i++) {
if (names[i] != undefined) {
var leg = true
} else {
var leg = false
}
options['data'].push({
type: "line",
showInLegend: leg,
name: names[i],
yValueFormatString: "#.##",
dataPoints: lines[i]
});
}
return options;
}
function addData(data, start, end) {
var graphs = Array.from(allGraph(data));
var totalGraph = graphs.length;
for(var x=0; x < totalGraph; x++){
var graphName = graphs[x];
if(start && end){
var ret = taskGraph(data, graphName, start, end);//for tasks
var lines = ret[0]
var names = ret[1]
} else {
var ret = graph(data, graphName);
var lines = ret[0]
var names = ret[1]
}
var linesSize = Object.size(lines);
var options = "options"+x;
options = newrender(linesSize, lines, names);
options.title.text = graphName;
options.axisY.title = graphName;
var idName = "chartContainer" + x;
$("#graph").append('<div id='+idName+' style="height: 370px; width: 100%; margin-bottom: 15px; padding-bottom: 15px;"></div>');
$("#"+idName).CanvasJSChart(options);
}
}
///////////////////////// Code for addTaskUI ///////////////////////
function addTaskUI(task){
$("#liAll").css('display','block');
for (var key in task) {
var keyUpperCase = key.toUpperCase();
if(task[key].length!=0){
$("#radioButtons ul").append('<li><label for="'+key+'"><input type="radio" name="task" id="'+key+'" class="radioClass" value="'+key+'">'+keyUpperCase+'</label></li>');
}
}
}
//////////////////////Code for tasks/////////////////////////
function findStartEnd(data, taskNum){
var start, end, obj;
for(key in data){
if(taskNum==key){
var tasksSize = Object.size(data[key]);
for(var key in data[taskNum]){
if(key==0){
obj = data[taskNum][key];
start = obj["start-time"];
}
if(key==tasksSize-1){
obj = data[taskNum][key];
end = obj["end-time"];
break;
}
}
}
}
return [start, end];
}
////////////////load file///////////////////
window.onload = function() {
//////////////////////////////////////
var results_stress, metrics_stress;
$("#clickMe").click(function(){
$.ajax({
type: 'GET',
url: 'results-stress.json',
dataType: 'json',
async: false,
success: function (data) {
results_stress = data;
}
});
addTaskUI(results_stress);
//////////////////////////////////////
$.ajax({
type: 'GET',
url: 'metrics-stress.json',
dataType: 'json',
async: false,
success: function (data) {
metrics_stress = data;
}
});
addData(metrics_stress);
});
//////////////////////////////////////////
document.getElementById("all").checked = true; //This is only for firefox issue
$(document).on('change', '.radioClass', function () {
var startEnd = findStartEnd(results_stress, this.value);
var start = startEnd[0];
var end = startEnd[1];
addData(metrics_stress, start, end);
});
}
</script>
</head>
<body>
<div style="height: 30px;margin: 20px 0;">
<label for="file1">Choose first file:</label>
<select name="file1" id="file1">
<option value="metrics-stress.json">metrics-stress.json</option>
</select>
<label for="file2">Choose second file:</label>
<select name="file2" id="file2">
<option value="results-stress.json">results-stress.json</option>
</select>
<button id="clickMe">Click me</button>
</div>
<div id="graph" style="width: 80%;float: left;"></div>
<div id="rightSide" style="width: 20%;float: right;">
<div id="radioButtons" style="margin: 15px 0 0 0;padding-left: 25px;">
<ul style="list-style-type: none;">
<li id="liAll" style="display: none;">
<label for="all"><input type="radio" name="task" id="all" class="radioClass" value="all" checked="checked">ALL</label>
</li>
</ul>
</div>
</div>
<script src="https://canvasjs.com/assets/script/jquery-1.11.1.min.js"></script>
<script src="https://canvasjs.com/assets/script/jquery.canvasjs.min.js"></script>
</body>
</html>