-
-
Save IgorMinar/1028816 to your computer and use it in GitHub Desktop.
Angular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="http://code.angularjs.org/angular-0.9.16.min.js" ng:autobind></script> | |
<script> | |
var SERVICE_URL = "http://blockexplorer.com/q/getdifficulty"; | |
function FormController($xhr) { | |
this.posint = /^\d+/; | |
this.fetch = function() { | |
var self = this; | |
$xhr('', SERVICE_URL, function(code, response) { | |
self.difficulty = response; | |
}); | |
}; | |
this.difficulty = 880000; | |
this.hashrate = 225000; | |
this.time = 30; | |
this.capex = 0; | |
this.electricity = 0.15; | |
this.power = 500; | |
this.rate = 20; | |
this.btcperblock = 50; | |
this.hashtime = function() { return Math.round(this.difficulty * Math.pow(2, 32) / (this.hashrate * 1000))/(3600*24) }; | |
this.opex = function() { return this.time*24 * this.electricity * this.power / 1000 }; | |
this.income = function() { return Math.round(this.rate * this.btcperblock * this.time / this.hashtime()); }; | |
} | |
</script> | |
</head> | |
<body ng:controller="FormController"> | |
<table> | |
<tr> | |
<td>Difficulty:</td> | |
<td><input type="text" size="8" name="difficulty" ng:required ng:validate="regexp:posint"/></td> | |
<td><button ng:click="fetch()">Fetch</button></td> | |
</tr> | |
<tr> | |
<td>Hash rate:</td> | |
<td><input type="text" size="8" name="hashrate" /></td> | |
<td>khash/s</td> | |
</tr> | |
<tr> | |
<td>Time frame:</td> | |
<td><input type="text" size="8" name="time" /></td> | |
<td>days</td> | |
</tr> | |
<tr> | |
<td>Cost of hardware:</td> | |
<td><input type="text" size="8" name="capex" /></td> | |
<td>USD</td> | |
</tr> | |
<tr> | |
<td>Cost of electricity:</td> | |
<td><input type="text" size="8" name="electricity" /></td> | |
<td>USD/kWh</td> | |
</tr> | |
<tr> | |
<td>Power consumption:</td> | |
<td><input type="text" size="8" name="power" /></td> | |
<td>W</td> | |
</tr> | |
<tr> | |
<td>Coins generated per block:</td> | |
<td><input type="text" size="8" name="btcperblock" /></td> | |
<td>BTC/block</td> | |
</tr> | |
<tr> | |
<td>Exchange rate:</td> | |
<td><input type="text" size="8" name="rate" /></td> | |
<td>USD/BTC</td> | |
</tr> | |
<tr> | |
<td>Operational cost:</td> | |
<td>{{opex()}}</td> | |
<td>USD/{{time}} days</td> | |
</tr> | |
<tr> | |
<td>Hash time:</td> | |
<td>{{hashtime()}}</td> | |
<td>days</td> | |
</tr> | |
<tr> | |
<td>Income:</td> | |
<td>{{income()}}</td> | |
<td>USD</td> | |
</tr> | |
<tr> | |
<td>Profit:</td> | |
<td>{{income() - opex() - capex}}</td> | |
<td>USD/{{time}} days</td> | |
</tr> | |
</table> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment