Skip to content

Commit

Permalink
fixes #29: total hashrate for antminer cgminer version
Browse files Browse the repository at this point in the history
  • Loading branch information
selaux committed Feb 16, 2014
1 parent a6553a1 commit 174c4e0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/modules/miners/bfgminer.js
Expand Up @@ -122,18 +122,20 @@ module.exports = Module.extend({
var data,
calculatedHardwareErrorRate,
returnedHardwareErrorRate,
hardwareErrorRate;
hardwareErrorRate,
avgHashrate;

if (response.SUMMARY && response.SUMMARY.length > 0) {
calculatedHardwareErrorRate = (response.SUMMARY[0]['Hardware Errors'] / response.SUMMARY[0].Accepted) * 100;
returnedHardwareErrorRate = response.SUMMARY[0]['Device Hardware%'];
hardwareErrorRate = returnedHardwareErrorRate !== undefined ? returnedHardwareErrorRate : calculatedHardwareErrorRate;
avgHashrate = response.SUMMARY[0]['GHS av'] ? response.SUMMARY[0]['GHS av'] * 1000 : response.SUMMARY[0]['MHS av'];

data = _.extend({}, defaults, {
connected: true,
elapsed: response.SUMMARY[0].Elapsed,
description: response.STATUS[0].Description,
avgHashrate: response.SUMMARY[0]['MHS av'],
avgHashrate: avgHashrate,
hardwareErrors: response.SUMMARY[0]['Hardware Errors'],
hardwareErrorRate: hardwareErrorRate,
shares: {
Expand Down
14 changes: 14 additions & 0 deletions test/specs/lib/modules/miners/bfgminerSpec.js
Expand Up @@ -323,6 +323,20 @@ describe('modules/miners/bfgminer', function () {
}));
});

it('should handle a response containing GHS instead of MHS', function () {
var summary,
response,
bfgAdapter = new BfgAdapter({}, config);

summary = _.extend({}, summaryResponse.SUMMARY[0], { 'GHS av': 58 });
delete summary['MHS av'];
response = _.extend({}, summaryResponse, { SUMMARY: [ summary ] });

expect(bfgAdapter.handleSummaryResponse(response)).to.deep.equal(_.extend({}, parsedResponse, {
avgHashrate: 58000
}));
});

it('should handle a response not containing the SUMMARY property', function () {
var bfgAdapter = new BfgAdapter({}, config);
expect(bfgAdapter.handleSummaryResponse({})).to.deep.equal({
Expand Down

0 comments on commit 174c4e0

Please sign in to comment.