Skip to content

Commit

Permalink
websocket: enhance histo sample for 2 GPUs
Browse files Browse the repository at this point in the history
  • Loading branch information
tpruvot committed Dec 3, 2014
1 parent 543de0a commit 539a758
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions api/websocket.htm
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,23 @@
<script type="text/javascript">

var hashrates = [];
var timestamps = [];
var timeline = [];

function drawChart(ip) {

$('#container').highcharts({
chart: {
type: 'spline'
},
title: {
text: 'CCMiner WebSocket Sample - ' + ip,
text: 'ccMiner WebSocket Sample - ' + ip,
x: -20 //center
},
subtitle: {
text: 'By tpruvot@gibhub 2014',
text: 'By <a href="http://github.com/tpruvot/ccminer">tpruvot@github</a> 2014',
x: -20
},
xAxis: {
title: {
text: 'Age'
},
valueSuffix: ' s',
categories: timestamps[0]
type: 'datetime',
},
yAxis: {
title: {
Expand All @@ -39,7 +36,8 @@
value: 0,
width: 1,
color: '#808080'
}]
}],
min: 0
},
tooltip: {
valueSuffix: ' KH'
Expand All @@ -54,11 +52,11 @@
{
name: 'GPU0',
data: hashrates[0]
}/*,
},
{
name: 'GPU1',
data: hashrates[1]
}*/
}
]
});
}
Expand All @@ -67,7 +65,6 @@
if ("WebSocket" in window) {
var ws = new WebSocket('ws://'+ip+':'+port+'/histo','text');
for (var gpu=0; gpu<8; gpu++) {
timestamps[gpu] = [];
hashrates[gpu] = [];
}
ws.onmessage = function (evt) {
Expand All @@ -77,22 +74,25 @@
for (n in data) {
var map = data[n].split(';');
var gpu = 0;
var uid = 0;
var plot = {};
for (k in map) {
var kv = map[k].split('=');
if (kv.length == 1)
continue;
if (kv[0] === 'GPU')
gpu = parseInt(kv[1], 10);
else if (kv[0] === 'ID')
uid = parseInt(kv[1], 10);
else if (kv[0] === 'TS')
plot.timestamp = ts - parseInt(kv[1], 10);
plot.timestamp = parseInt(kv[1], 10);
else if (kv[0] === 'KHS')
plot.hashrate = parseInt(kv[1], 10) / 1000.0;
//console.log('Data received: #GPU'+gpu+': '+kv[0]+' = '+kv[1]);
console.log('Data received: #GPU'+gpu+': '+kv[0]+' = '+kv[1]);
}
timeline[n] = plot.timestamp;
timestamps[gpu][n] = plot.timestamp;
hashrates[gpu][n] = plot.hashrate;
if (uid == 0)
continue;
hashrates[gpu].push([+new Date(plot.timestamp*1000), plot.hashrate]);
}
drawChart(ip);
};
Expand Down

0 comments on commit 539a758

Please sign in to comment.