Updated hashrate graphs in dashboard
* [FEATURE] Display both pool and personal hashrate * [FEATURE] Use EnhancedLegendRendere to toggle lines in graph * [IMPROVEMENT] Unified Ajax call for graph and gauges * [IMPROVEMENT] Allow `getdashboarddata` to supply raw hashrate values
This commit is contained in:
parent
27a76509f6
commit
b533ea11a7
@ -49,16 +49,17 @@ $dPersonalSharerate = $statistics->getUserSharerate($id, $interval);
|
|||||||
$statistics->setGetCache(true);
|
$statistics->setGetCache(true);
|
||||||
|
|
||||||
// Apply pool modifiers
|
// Apply pool modifiers
|
||||||
$dPersonalHashrate = $dPersonalHashrate * $dPersonalHashrateModifier;
|
$dPersonalHashrateAdjusted = $dPersonalHashrate * $dPersonalHashrateModifier;
|
||||||
$dPoolHashrate = $dPoolHashrate * $dPoolHashrateModifier;
|
$dPoolHashrateAdjusted = $dPoolHashrate * $dPoolHashrateModifier;
|
||||||
$dNetworkHashrate = $dNetworkHashrate / 1000 * $dNetworkHashrateModifier;
|
$dNetworkHashrateAdjusted = $dNetworkHashrate / 1000 * $dNetworkHashrateModifier;
|
||||||
|
|
||||||
// Output JSON format
|
// Output JSON format
|
||||||
echo json_encode(array($_REQUEST['action'] => array(
|
echo json_encode(array($_REQUEST['action'] => array(
|
||||||
'runtime' => (microtime(true) - $dTimeStart) * 1000,
|
'runtime' => (microtime(true) - $dTimeStart) * 1000,
|
||||||
'personal' => array ( 'hashrate' => $dPersonalHashrate, 'sharerate' => $dPersonalSharerate ),
|
'raw' => array( 'personal' => array( 'hashrate' => $dPersonalHashrate ), 'pool' => array( 'hashrate' => $dPoolHashrate ), 'network' => array( 'hashrate' => $dNetworkHashrate / 1000 ) ),
|
||||||
'pool' => array( 'hashrate' => $dPoolHashrate ),
|
'personal' => array ( 'hashrate' => $dPersonalHashrateAdjusted, 'sharerate' => $dPersonalSharerate ),
|
||||||
'network' => array( 'hashrate' => $dNetworkHashrate ),
|
'pool' => array( 'hashrate' => $dPoolHashrateAdjusted ),
|
||||||
|
'network' => array( 'hashrate' => $dNetworkHashrateAdjusted ),
|
||||||
)));
|
)));
|
||||||
|
|
||||||
// Supress master template
|
// Supress master template
|
||||||
|
|||||||
@ -3,4 +3,5 @@
|
|||||||
{include file="dashboard/graph.tpl"}
|
{include file="dashboard/graph.tpl"}
|
||||||
{include file="dashboard/default_$payout_system.tpl"}
|
{include file="dashboard/default_$payout_system.tpl"}
|
||||||
{include file="dashboard/gauges.tpl"}
|
{include file="dashboard/gauges.tpl"}
|
||||||
|
{include file="dashboard/js.tpl"}
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@ -11,49 +11,3 @@
|
|||||||
</div>
|
</div>
|
||||||
<footer><p style="margin-left: 25px">Refresh interval: {$GLOBAL.config.statistics_ajax_refresh_interval|default:"10"} seconds. Hashrate based on shares submitted in the past {$INTERVAL|default:"5"} minutes.</p></footer>
|
<footer><p style="margin-left: 25px">Refresh interval: {$GLOBAL.config.statistics_ajax_refresh_interval|default:"10"} seconds. Hashrate based on shares submitted in the past {$INTERVAL|default:"5"} minutes.</p></footer>
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
<script>
|
|
||||||
{literal}
|
|
||||||
$(document).ready(function(){
|
|
||||||
var g1, g2, g3, g4, g5;
|
|
||||||
|
|
||||||
// Helper to initilize gauges
|
|
||||||
function initGauges(data) {
|
|
||||||
g1 = new JustGage({id: "nethashrate", value: parseFloat(data.getdashboarddata.network.hashrate).toFixed(2), min: 0, max: Math.round(data.getdashboarddata.network.hashrate * 2), title: "Net Hashrate", label: "{/literal}{$GLOBAL.hashunits.network}{literal}"});
|
|
||||||
g2 = new JustGage({id: "poolhashrate", value: parseFloat(data.getdashboarddata.pool.hashrate).toFixed(2), min: 0, max: Math.round(data.getdashboarddata.pool.hashrate * 2), title: "Pool Hashrate", label: "{/literal}{$GLOBAL.hashunits.pool}{literal}"});
|
|
||||||
g3 = new JustGage({id: "hashrate", value: parseFloat(data.getdashboarddata.personal.hashrate).toFixed(2), min: 0, max: Math.round(data.getdashboarddata.personal.hashrate * 2), title: "Hashrate", label: "{/literal}{$GLOBAL.hashunits.personal}{literal}"});
|
|
||||||
g4 = new JustGage({id: "sharerate", value: parseFloat(data.getdashboarddata.personal.sharerate).toFixed(2), min: 0, max: Math.round(data.getdashboarddata.personal.sharerate * 2), title: "Sharerate", label: "shares/s"});
|
|
||||||
g5 = new JustGage({id: "sharerate", value: parseFloat(data.getdashboarddata.runtime).toFixed(2), min: 0, max: Math.round(data.getdashboarddata.runtime * 3), title: "Querytime", label: "ms"});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper to refresh gauges
|
|
||||||
function refreshGauges(data) {
|
|
||||||
g1.refresh(parseFloat(data.getdashboarddata.network.hashrate).toFixed(2));
|
|
||||||
g2.refresh(parseFloat(data.getdashboarddata.pool.hashrate).toFixed(2));
|
|
||||||
g3.refresh(parseFloat(data.getdashboarddata.personal.hashrate).toFixed(2));
|
|
||||||
g4.refresh(parseFloat(data.getdashboarddata.personal.sharerate).toFixed(2));
|
|
||||||
g5.refresh(parseFloat(data.getdashboarddata.runtime).toFixed(2));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch initial data via Ajax
|
|
||||||
$.ajax({
|
|
||||||
url: '{/literal}{$smarty.server.PHP_SELF}?page=api&action=getdashboarddata&api_key={$GLOBAL.userdata.api_key}&id={$GLOBAL.userdata.id}{literal}',
|
|
||||||
async: false, // Run all others requests after this only if it's done
|
|
||||||
dataType: 'json',
|
|
||||||
success: function (data) { initGauges(data); }
|
|
||||||
});
|
|
||||||
|
|
||||||
// Our worker process to keep gauges updated
|
|
||||||
(function worker() {
|
|
||||||
$.ajax({
|
|
||||||
url: '{/literal}{$smarty.server.PHP_SELF}?page=api&action=getdashboarddata&api_key={$GLOBAL.userdata.api_key}&id={$GLOBAL.userdata.id}{literal}',
|
|
||||||
dataType: 'json',
|
|
||||||
success: function(data) { refreshGauges(data); },
|
|
||||||
complete: function() {
|
|
||||||
setTimeout(worker, {/literal}{($GLOBAL.config.statistics_ajax_refresh_interval * 1000)|default:"10000"}{literal})
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})();
|
|
||||||
});
|
|
||||||
{/literal}
|
|
||||||
</script>
|
|
||||||
|
|||||||
@ -1,70 +1,9 @@
|
|||||||
<script type="text/javascript" src="{$PATH}/js/plugins/jqplot.json2.min.js"></script>
|
|
||||||
<script type="text/javascript" src="{$PATH}/js/plugins/jqplot.dateAxisRenderer.js"></script>
|
|
||||||
<script type="text/javascript" src="{$PATH}/js/plugins/jqplot.highlighter.js"></script>
|
|
||||||
<script type="text/javascript" src="{$PATH}/js/plugins/jqplot.canvasTextRenderer.min.js"></script>
|
|
||||||
<script type="text/javascript" src="{$PATH}/js/plugins/jqplot.canvasAxisLabelRenderer.min.js"></script>
|
|
||||||
<script type="text/javascript" src="{$PATH}/js/plugins/jqplot.trendline.min.js"></script>
|
|
||||||
|
|
||||||
<article class="module width_full">
|
<article class="module width_full">
|
||||||
<header><h3>Graphs</h3></header>
|
<header><h3>Graphs</h3></header>
|
||||||
<div class="module_content">
|
<div class="module_content">
|
||||||
<div id="hashrategraph" style="height:200px; width: 100%;"></div>
|
<div id="hashrategraph" style="height:200px; width: 95%;"></div>
|
||||||
</div>
|
</div>
|
||||||
<footer>
|
<footer>
|
||||||
<p style="margin-left: 25px">Refresh interval: {$GLOBAL.config.statistics_ajax_refresh_interval|default:"10"} seconds. Hashrate based on shares submitted in the past {$INTERVAL|default:"5"} minutes.</p>
|
<p style="margin-left: 25px">Refresh interval: {$GLOBAL.config.statistics_ajax_refresh_interval|default:"10"} seconds. Hashrate based on shares submitted in the past {$INTERVAL|default:"5"} minutes.</p>
|
||||||
</footer>
|
</footer>
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
<script>{literal}
|
|
||||||
$(document).ready(function(){
|
|
||||||
$.jqplot.config.enablePlugins = true;
|
|
||||||
|
|
||||||
// Ajax API URL
|
|
||||||
var url = "{/literal}{$smarty.server.PHP_SELF}?page=api&action=getuserhashrate&api_key={$GLOBAL.userdata.api_key}&id={$GLOBAL.userdata.id}{literal}";
|
|
||||||
|
|
||||||
// jqPlit defaults
|
|
||||||
var jqPlotOptions = {
|
|
||||||
grid: { drawBorder: false, background: '#fbfbfb', shadow: false },
|
|
||||||
seriesDefaults:{
|
|
||||||
shadow: false,
|
|
||||||
fill: true,
|
|
||||||
fillAndStroke: true,
|
|
||||||
fillAlpha: 0.3,
|
|
||||||
fillColor: '#26a4ed',
|
|
||||||
label: 'hashrate',
|
|
||||||
color: '#26a4ed',
|
|
||||||
lineWidth: 4,
|
|
||||||
trendline: { color: '#d30000', lineWidth: 1.0, label: 'average', shadow: true },
|
|
||||||
markerOptions: { show: true, size: 8},
|
|
||||||
rendererOptions: { smooth: true }
|
|
||||||
},
|
|
||||||
legend: { show: true },
|
|
||||||
title: 'Hashrate',
|
|
||||||
axes: {
|
|
||||||
yaxis:{ pad: 1.05, label: '{/literal}{$GLOBAL.hashunits.personal}{literal}', labelRenderer: $.jqplot.CanvasAxisLabelRenderer},
|
|
||||||
xaxis:{ tickInterval: {/literal}{$GLOBAL.config.statistics_ajax_refresh_interval}{literal}, label: 'Time', labelRenderer: $.jqplot.CanvasAxisLabelRenderer, renderer: $.jqplot.DateAxisRenderer, tickOptions: { formatString: '%T' } }
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Init empty graph with 0 data
|
|
||||||
var plot1 = $.jqplot('hashrategraph', [[[]]], jqPlotOptions);
|
|
||||||
|
|
||||||
// Store our data globally
|
|
||||||
var storedData = Array();
|
|
||||||
|
|
||||||
// Our refresh worker process, updated at intervals
|
|
||||||
(function workerHashrateGraph() {
|
|
||||||
$.ajax({
|
|
||||||
url: url,
|
|
||||||
dataType: "json",
|
|
||||||
success: function(data) {
|
|
||||||
// Start dropping out elements
|
|
||||||
if (storedData.length > 20) { storedData.shift(); }
|
|
||||||
storedData[storedData.length] = [new Date().getTime(), data.getuserhashrate.hashrate];
|
|
||||||
if (typeof(plot1) != "undefined") plot1.replot({data: [storedData]});
|
|
||||||
},
|
|
||||||
complete: function() { setTimeout(workerHashrateGraph, {/literal}{($GLOBAL.config.statistics_ajax_refresh_interval * 1000)|default:"10000"}{literal}) }
|
|
||||||
});
|
|
||||||
})();
|
|
||||||
});
|
|
||||||
{/literal}</script>
|
|
||||||
|
|||||||
102
public/templates/test/dashboard/js.tpl
Normal file
102
public/templates/test/dashboard/js.tpl
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
<script type="text/javascript" src="{$PATH}/js/plugins/jqplot.json2.min.js"></script>
|
||||||
|
<script type="text/javascript" src="{$PATH}/js/plugins/jqplot.dateAxisRenderer.js"></script>
|
||||||
|
<script type="text/javascript" src="{$PATH}/js/plugins/jqplot.highlighter.js"></script>
|
||||||
|
<script type="text/javascript" src="{$PATH}/js/plugins/jqplot.canvasTextRenderer.min.js"></script>
|
||||||
|
<script type="text/javascript" src="{$PATH}/js/plugins/jqplot.canvasAxisLabelRenderer.min.js"></script>
|
||||||
|
<script type="text/javascript" src="{$PATH}/js/plugins/jqplot.trendline.min.js"></script>
|
||||||
|
<script type="text/javascript" src="{$PATH}/js/plugins/jqplot.enhancedLegendRenderer.min.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
{literal}
|
||||||
|
$(document).ready(function(){
|
||||||
|
var g1, g2, g3, g4, g5;
|
||||||
|
|
||||||
|
// Ajax API URL
|
||||||
|
var url = "{/literal}{$smarty.server.PHP_SELF}?page=api&action=getdashboarddata&api_key={$GLOBAL.userdata.api_key}&id={$GLOBAL.userdata.id}{literal}";
|
||||||
|
|
||||||
|
// Enable all included plugins
|
||||||
|
$.jqplot.config.enablePlugins = true;
|
||||||
|
|
||||||
|
// Store our data globally
|
||||||
|
var storedPersonalHashrate=[];
|
||||||
|
var storedPoolHashrate=[];
|
||||||
|
|
||||||
|
// jqPlit defaults
|
||||||
|
var jqPlotOptions = {
|
||||||
|
grid: { drawBorder: false, background: '#fbfbfb', shadow: false },
|
||||||
|
stackSeries: false,
|
||||||
|
seriesColors: [ '#26a4ed', '#ee8310' ],
|
||||||
|
seriesDefaults:{
|
||||||
|
lineWidth: 4, shadow: false,
|
||||||
|
lineAlpha: 0.3,
|
||||||
|
fill: false, fillAndStroke: true, fillAlpha: 0.3,
|
||||||
|
trendline: { color: '#be1e2d', lineWidth: 1.0, label: 'Your Average', shadow: true },
|
||||||
|
markerOptions: { show: true, size: 8},
|
||||||
|
rendererOptions: { smooth: true }
|
||||||
|
},
|
||||||
|
series: [ {label: 'Own', fill: true}, {label: 'Pool', trendline: { show: false } } ],
|
||||||
|
legend: { show: true, location: 'sw', renderer: $.jqplot.EnhancedLegendRenderer, rendererOptions: { seriesToggleReplot: { resetAxes: true } } },
|
||||||
|
title: 'Hashrate',
|
||||||
|
axes: {
|
||||||
|
yaxis: { padMin: 0, padMax: 1.05, label: 'Hashrate', labelRenderer: $.jqplot.CanvasAxisLabelRenderer},
|
||||||
|
xaxis: { tickInterval: {/literal}{$GLOBAL.config.statistics_ajax_refresh_interval}{literal}, label: 'Time', labelRenderer: $.jqplot.CanvasAxisLabelRenderer, renderer: $.jqplot.DateAxisRenderer, tickOptions: { angle: 30, formatString: '%T' } },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Init empty graph with 0 data
|
||||||
|
var plot1 = $.jqplot('hashrategraph', [[storedPersonalHashrate], [storedPoolHashrate]], jqPlotOptions);
|
||||||
|
|
||||||
|
// Helper to initilize gauges
|
||||||
|
function initGauges(data) {
|
||||||
|
g1 = new JustGage({id: "nethashrate", value: parseFloat(data.getdashboarddata.network.hashrate).toFixed(2), min: 0, max: Math.round(data.getdashboarddata.network.hashrate * 2), title: "Net Hashrate", label: "{/literal}{$GLOBAL.hashunits.network}{literal}"});
|
||||||
|
g2 = new JustGage({id: "poolhashrate", value: parseFloat(data.getdashboarddata.pool.hashrate).toFixed(2), min: 0, max: Math.round(data.getdashboarddata.pool.hashrate * 2), title: "Pool Hashrate", label: "{/literal}{$GLOBAL.hashunits.pool}{literal}"});
|
||||||
|
g3 = new JustGage({id: "hashrate", value: parseFloat(data.getdashboarddata.personal.hashrate).toFixed(2), min: 0, max: Math.round(data.getdashboarddata.personal.hashrate * 2), title: "Hashrate", label: "{/literal}{$GLOBAL.hashunits.personal}{literal}"});
|
||||||
|
g4 = new JustGage({id: "sharerate", value: parseFloat(data.getdashboarddata.personal.sharerate).toFixed(2), min: 0, max: Math.round(data.getdashboarddata.personal.sharerate * 2), title: "Sharerate", label: "shares/s"});
|
||||||
|
g5 = new JustGage({id: "sharerate", value: parseFloat(data.getdashboarddata.runtime).toFixed(2), min: 0, max: Math.round(data.getdashboarddata.runtime * 3), title: "Querytime", label: "ms"});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper to refresh gauges
|
||||||
|
function refreshGauges(data) {
|
||||||
|
g1.refresh(parseFloat(data.getdashboarddata.network.hashrate).toFixed(2));
|
||||||
|
g2.refresh(parseFloat(data.getdashboarddata.pool.hashrate).toFixed(2));
|
||||||
|
g3.refresh(parseFloat(data.getdashboarddata.personal.hashrate).toFixed(2));
|
||||||
|
g4.refresh(parseFloat(data.getdashboarddata.personal.sharerate).toFixed(2));
|
||||||
|
g5.refresh(parseFloat(data.getdashboarddata.runtime).toFixed(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper to refresh graphs
|
||||||
|
function refreshGraph(data) {
|
||||||
|
if (storedPersonalHashrate.length > 20) { storedPersonalHashrate.shift(); }
|
||||||
|
if (storedPoolHashrate.length > 20) { storedPoolHashrate.shift(); }
|
||||||
|
timeNow = new Date().getTime();
|
||||||
|
storedPersonalHashrate[storedPersonalHashrate.length] = [timeNow, data.getdashboarddata.raw.personal.hashrate];
|
||||||
|
storedPoolHashrate[storedPoolHashrate.length] = [timeNow, data.getdashboarddata.raw.pool.hashrate];
|
||||||
|
replotOptions = {
|
||||||
|
data: [storedPersonalHashrate, storedPoolHashrate],
|
||||||
|
series: [{show: plot1.series[0].show}, {show: plot1.series[1].show} ]
|
||||||
|
};
|
||||||
|
if (typeof(plot1) != "undefined") plot1.replot(replotOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch initial data via Ajax, starts proper gauges to display
|
||||||
|
$.ajax({
|
||||||
|
url: url,
|
||||||
|
async: false, // Run all others requests after this only if it's done
|
||||||
|
dataType: 'json',
|
||||||
|
success: function (data) { initGauges(data); }
|
||||||
|
});
|
||||||
|
|
||||||
|
// Our worker process to keep gauges and graph updated
|
||||||
|
(function worker() {
|
||||||
|
$.ajax({
|
||||||
|
url: url,
|
||||||
|
dataType: 'json',
|
||||||
|
success: function(data) { refreshGauges(data); refreshGraph(data) },
|
||||||
|
complete: function() {
|
||||||
|
setTimeout(worker, {/literal}{($GLOBAL.config.statistics_ajax_refresh_interval * 1000)|default:"10000"}{literal})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
});
|
||||||
|
{/literal}
|
||||||
|
</script>
|
||||||
Loading…
Reference in New Issue
Block a user