Skip to content

Commit 8abb71b

Browse files
authored
[WIP] scmp echo gui (#62)
* [WIP] scmp echo gui * Merge branch 'master' into echo_ui * merging echo graph progress from pingpong_ui branch * Merge branch 'master' into echo_ui * removed WIP code, keeping only echo graph * remove redundant images tag * Merge branch 'master' into echo_ui
1 parent d9a19dc commit 8abb71b

File tree

5 files changed

+179
-54
lines changed

5 files changed

+179
-54
lines changed

webapp/models/scmpecho.go

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type EchoGraph struct {
4747
func createEchoTable() error {
4848
sqlCreateTable := `
4949
CREATE TABLE IF NOT EXISTS echo(
50-
Inserted BIGINT NOT NULL PRIMARY KEY,
50+
Inserted BIGINT NOT NULL PRIMARY KEY,
5151
ActualDuration INT,
5252
CIa TEXT,
5353
CAddr TEXT,
@@ -94,21 +94,21 @@ func (echo EchoItem) ToSlice() []string {
9494
func StoreEchoItem(echo *EchoItem) error {
9595
sqlInsert := `
9696
INSERT INTO echo(
97-
Inserted,
98-
ActualDuration,
97+
Inserted,
98+
ActualDuration,
9999
CIa,
100100
CAddr,
101101
SIa,
102-
SAddr,
103-
Count,
104-
Timeout,
105-
Interval,
106-
ResponseTime,
107-
RunTime,
108-
PktLoss,
109-
CmdOutput,
110-
Error,
111-
Path
102+
SAddr,
103+
Count,
104+
Timeout,
105+
Interval,
106+
ResponseTime,
107+
RunTime,
108+
PktLoss,
109+
CmdOutput,
110+
Error,
111+
Path
112112
) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
113113
`
114114
stmt, err := db.Prepare(sqlInsert)
@@ -140,22 +140,22 @@ func StoreEchoItem(echo *EchoItem) error {
140140
func ReadEchoItemsAll() ([]EchoItem, error) {
141141
sqlReadAll := `
142142
SELECT
143-
Inserted,
144-
ActualDuration,
145-
CIa,
143+
Inserted,
144+
ActualDuration,
145+
CIa,
146146
CAddr,
147147
SIa,
148-
SAddr,
149-
Count,
150-
Timeout,
151-
Interval,
152-
ResponseTime,
153-
RunTime,
154-
PktLoss,
155-
CmdOutput,
156-
Error,
157-
Path
158-
FROM echo
148+
SAddr,
149+
Count,
150+
Timeout,
151+
Interval,
152+
ResponseTime,
153+
RunTime,
154+
PktLoss,
155+
CmdOutput,
156+
Error,
157+
Path
158+
FROM echo
159159
ORDER BY datetime(Inserted) DESC
160160
`
161161
rows, err := db.Query(sqlReadAll)
@@ -196,15 +196,15 @@ func ReadEchoItemsAll() ([]EchoItem, error) {
196196
func ReadEchoItemsSince(since string) ([]EchoGraph, error) {
197197
sqlReadSince := `
198198
SELECT
199-
Inserted,
200-
ActualDuration,
201-
ResponseTime,
202-
RunTime,
203-
PktLoss,
204-
CmdOutput,
205-
Error,
206-
Path
207-
FROM echo
199+
Inserted,
200+
ActualDuration,
201+
ResponseTime,
202+
RunTime,
203+
PktLoss,
204+
CmdOutput,
205+
Error,
206+
Path
207+
FROM echo
208208
WHERE Inserted > ?
209209
ORDER BY datetime(Inserted) DESC
210210
`

webapp/static/css/style.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ svg.svg-dials {
5757
float: left;
5858
width: 500px;
5959
height: 300px;
60+
font-size: 12px;
6061
}
6162

6263
.row:after {
@@ -66,6 +67,14 @@ svg.svg-dials {
6667
overflow: scroll;
6768
}
6869

70+
/* TAB ECHO */
71+
#echo-continuous .chart {
72+
height: 200px;
73+
width: 698px;
74+
overflow: hidden;
75+
float: left;
76+
}
77+
6978
/* TAB BWTESTER */
7079
.bwtest-dial {
7180
width: 100px;
@@ -120,6 +129,7 @@ img {
120129
float: left;
121130
width: 200px;
122131
height: 342px;
132+
font-size: 12px;
123133
}
124134

125135
.scion-ia {

webapp/static/js/webapp.js

Lines changed: 126 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var dataIntervalMs = 1000;
3030
var progIntervalMs = 500
3131
var chartCS;
3232
var chartSC;
33+
var chartSE;
3334
var lastTime;
3435
var lastTimeBwDb = new Date((new Date()).getTime() - (xAxisSec * 1000));
3536

@@ -58,6 +59,7 @@ var imageText = 'Execute camerapp to retrieve an image.';
5859
var sensorText = 'Execute sensorapp to retrieve sensor data.';
5960
var bwgraphsText = 'Click legend to hide/show data when continuous test is on.';
6061
var cont_disable_msg = 'Continuous testing disabled.'
62+
var echoText = 'Execute echo to measure response time.';
6163

6264
window.onbeforeunload = function(event) {
6365
// detect window close to end continuous test if any
@@ -103,6 +105,7 @@ function initBwGraphs() {
103105
csColAch);
104106
chartSC = drawBwtestSingleDir('sc', 'Download (mbps)', true, scColReq,
105107
scColAch);
108+
chartSE = drawPingGraph('echo-graph', 'Echo Response (ms)');
106109
// setup interval to manage smooth ticking
107110
lastTime = (new Date()).getTime() - (ticks * tickMs) + xLeftTrimMs;
108111
manageTickData();
@@ -112,6 +115,9 @@ function initBwGraphs() {
112115
function showOnlyConsoleGraphs(activeApp) {
113116
$('#bwtest-continuous').css("display",
114117
(activeApp == "bwtester") ? "block" : "none");
118+
$('#images').css("display", (activeApp == "camerapp") ? "block" : "none");
119+
$('#echo-continuous').css("display",
120+
(activeApp == "echo") ? "block" : "none");
115121
var isConsole = (activeApp == "bwtester" || activeApp == "camerapp"
116122
|| activeApp == "sensorapp" || activeApp == "echo");
117123
$('.stdout').css("display", isConsole ? "block" : "none");
@@ -192,7 +198,7 @@ function drawBwtestSingleDir(dir, yAxisLabel, legend, reqCol, achCol) {
192198
} ],
193199
tooltip : {
194200
enabled : true,
195-
formatter : formatTooltip,
201+
formatter : formatBwTooltip,
196202
},
197203
legend : {
198204
y : -15,
@@ -236,7 +242,56 @@ function drawBwtestSingleDir(dir, yAxisLabel, legend, reqCol, achCol) {
236242
return chart;
237243
}
238244

239-
function formatTooltip() {
245+
function drawPingGraph(div_id, yAxisLabel) {
246+
var chart = Highcharts.chart(div_id, {
247+
chart : {
248+
type : 'column'
249+
},
250+
title : {
251+
text : null
252+
},
253+
xAxis : {
254+
type : 'datetime',
255+
},
256+
yAxis : {
257+
min : 0,
258+
minTickInterval : 1, // keep 0.1 errors visible
259+
title : {
260+
text : yAxisLabel
261+
}
262+
},
263+
legend : {
264+
enabled : false
265+
},
266+
tooltip : {
267+
enabled : true,
268+
formatter : formatPingTooltip,
269+
},
270+
credits : {
271+
enabled : true,
272+
text : 'Download Data',
273+
href : './data/',
274+
},
275+
exporting : {
276+
enabled : false
277+
},
278+
plotOptions : {
279+
column : {
280+
pointWidth : 8
281+
}
282+
},
283+
series : [ {
284+
name : yAxisLabel,
285+
data : loadSetupData(),
286+
dataLabels : {
287+
enabled : false,
288+
}
289+
} ]
290+
});
291+
return chart;
292+
}
293+
294+
function formatBwTooltip() {
240295
var tooltip = '<b>' + this.series.name + '</b><br/>'
241296
+ Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>'
242297
+ Highcharts.numberFormat(this.y, 2) + ' mbps<br/><i>'
@@ -247,6 +302,17 @@ function formatTooltip() {
247302
return tooltip;
248303
}
249304

305+
function formatPingTooltip() {
306+
var tooltip = '<b>' + this.series.name + '</b><br/>'
307+
+ Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>'
308+
+ Highcharts.numberFormat(this.y, 3) + ' ms<br/>' + this.point.loss
309+
+ '% packet loss<br/><i>' + this.point.path + '</i>';
310+
if (this.point.error != null) {
311+
tooltip += '<br/><b>' + this.point.error + '</b>';
312+
}
313+
return tooltip;
314+
}
315+
250316
function loadSetupData() {
251317
// points are a function of timeline speed (width & seconds)
252318
// no data points on setup
@@ -269,6 +335,7 @@ function manageTickData() {
269335
var newTime = (new Date()).getTime();
270336
refreshTickData(chartCS, newTime);
271337
refreshTickData(chartSC, newTime);
338+
refreshTickData(chartSE, newTime);
272339
}, tickMs);
273340
}
274341

@@ -377,11 +444,23 @@ function requestEchoByTime(form_data) {
377444
// result returned, display it and reset progress
378445
handleEndCmdDisplay(d.graph[i].CmdOutput);
379446
}
380-
381-
console.info('continuous echo', 'duration:',
447+
var data = {
448+
'responseTime' : d.graph[i].ResponseTime,
449+
'runTime' : d.graph[i].RunTime,
450+
'loss' : d.graph[i].PktLoss,
451+
'path' : d.graph[i].Path,
452+
'error' : d.graph[i].Error,
453+
};
454+
if (data.runTime == 0) {
455+
// for other errors, use execution time
456+
data.runTime = d.graph[i].ActualDuration;
457+
}
458+
console.info(JSON.stringify(data));
459+
console.info('continous echo', 'duration:',
382460
d.graph[i].ActualDuration, 'ms');
383-
384-
// TODO (mwfarb): complete echo graph
461+
// use the time the test began
462+
var time = d.graph[i].Inserted - d.graph[i].ActualDuration;
463+
updatePingGraph(chartSE, data, time)
385464
}
386465
}
387466
}
@@ -398,19 +477,23 @@ function refreshTickData(chart, newTime) {
398477
// manually remove all left side ticks < left side time
399478
// wait for adding hidden ticks to draw
400479
var draw = false;
401-
removeOldPoints(series0, lastTime, draw);
402-
removeOldPoints(series1, lastTime, draw);
480+
if (series0)
481+
removeOldPoints(series0, lastTime, draw);
482+
if (series1)
483+
removeOldPoints(series1, lastTime, draw);
403484
// manually add hidden right side ticks, time = now
404485
// do all drawing here to avoid accordioning redraws
405486
// do not shift points since we manually remove before this
406487
draw = true;
407-
series0.addPoint([ x, y ], draw, shift);
408-
series1.addPoint([ x, y ], draw, shift);
488+
if (series0)
489+
series0.addPoint([ x, y ], draw, shift);
490+
if (series1)
491+
series1.addPoint([ x, y ], draw, shift);
409492
}
410493

411494
function removeOldPoints(series, lastTime, draw) {
412495
for (var i = 0; i < series.data.length; i++) {
413-
if (series.data[i].x < lastTime) {
496+
if (series.data[i] && series.data[i].x < lastTime) {
414497
series.removePoint(i, draw);
415498
}
416499
}
@@ -457,6 +540,36 @@ function updateBwChart(chart, dataDir, time) {
457540
}
458541
}
459542

543+
function updatePingGraph(chart, data, time) {
544+
// manually add visible right side ticks, time = now
545+
// wait for adding hidden ticks to draw, for consistancy
546+
// do not shift points since we manually remove before this
547+
var draw = false;
548+
var shift = false;
549+
if (data.error || data.loss > 0 || data.responseTime <= 0) {
550+
var error = 'An error occured.';
551+
if (data.loss > 0) {
552+
error = 'Response timeout.';
553+
}
554+
chart.series[0].addPoint({
555+
x : time,
556+
y : data.runTime,
557+
loss : data.loss,
558+
path : data.path,
559+
error : data.error ? data.error : error,
560+
color : '#f00',
561+
}, draw, shift);
562+
} else {
563+
chart.series[0].addPoint({
564+
x : time,
565+
y : data.responseTime,
566+
loss : data.loss,
567+
path : data.path,
568+
color : '#0f0',
569+
}, draw, shift);
570+
}
571+
}
572+
460573
function endProgress() {
461574
clearInterval(commandProg);
462575
commandProg = false;
@@ -524,10 +637,8 @@ function command(continuous) {
524637
// check for usable data for graphing
525638
handleContResponse(resp, continuous, startTime);
526639
} else if (activeApp == "echo") {
640+
// check for usable data for graphing
527641
handleContResponse(resp, continuous, startTime);
528-
529-
// TODO (mwfarb): implement continuous echo graph
530-
531642
} else {
532643
handleGeneralResponse();
533644
}
@@ -741,6 +852,7 @@ function setDefaults() {
741852
$('#stats_text').text(sensorText);
742853
$('#bwtest_text').text(bwText);
743854
$('#bwgraphs_text').text(bwgraphsText);
855+
$('#echo_text').text(echoText);
744856

745857
onchange_radio('cs', 'size');
746858
onchange_radio('sc', 'size');

webapp/template/index.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,16 @@ <h2>SCIONLab Apps</h2>
327327
<div id="webapp-console-graph">
328328

329329
<!-- BWTEST GRAPHING -->
330-
<div id="bwtest-continuous">
330+
<div id="bwtest-continuous" style="display: block;">
331331
<div id="cs-bwtest-graph" class="chart"></div>
332332
<div id="sc-bwtest-graph" class="chart"></div>
333333
</div>
334334

335-
<!-- COMMAND OUTPUT -->
336-
<!-- <div class="stdout" style="display: none;">-->
335+
<!-- ECHO GRAPHING -->
336+
<div id="echo-continuous" style="display: none;">
337+
<div id="echo-graph" class="chart"></div>
338+
</div>
339+
337340
<div class="stdout">
338341
<div id="results"></div>
339342
</div>

0 commit comments

Comments
 (0)