Some new stuff
This commit is contained in:
parent
f20f9bc8fc
commit
fa6dede096
@ -1932,14 +1932,17 @@ li {
|
||||
border: solid 1px #80007e;
|
||||
background-color: #ffffff; }
|
||||
|
||||
#btc, #fx {
|
||||
font-size: 85%; }
|
||||
#btc, #fx, #trend {
|
||||
font-size: 85%;
|
||||
}
|
||||
|
||||
.up, .ontime {
|
||||
color: #4CAF50 !important; }
|
||||
.up, .ontime, .trendUp {
|
||||
color: green !important;
|
||||
}
|
||||
|
||||
.down, .delayed {
|
||||
color: #F44336 !important; }
|
||||
.down, .delayed, .trendDown {
|
||||
color: red !important;
|
||||
}
|
||||
|
||||
.nochange {
|
||||
color: #000000; }
|
||||
@ -1949,3 +1952,10 @@ li {
|
||||
background-color: #EEEEEE;
|
||||
font-family: monospace;
|
||||
white-space: pre; }
|
||||
|
||||
|
||||
.trendUp:before {
|
||||
content: "▲";
|
||||
}
|
||||
|
||||
.trendDown:before{content:'▼'}
|
||||
|
@ -44,15 +44,15 @@ li {
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
#btc, #fx {
|
||||
#btc, #fx, #trend {
|
||||
font-size: 85%;
|
||||
}
|
||||
|
||||
.up, .ontime {
|
||||
.up, .ontime, .trendUp {
|
||||
color: mui-color('green') !important;
|
||||
}
|
||||
|
||||
.down, .delayed {
|
||||
.down, .delayed, .trendDown {
|
||||
color: mui-color('red') !important;
|
||||
}
|
||||
|
||||
@ -65,3 +65,9 @@ li {
|
||||
font-family: monospace;
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
.trendUp:before {
|
||||
content: "▲";
|
||||
}
|
||||
|
||||
.trendDown:before{content:'▼'}
|
@ -12,7 +12,8 @@ let BitcoinModel = Backbone.Model.extend({
|
||||
lows: {gbp: 0, usd: 0},
|
||||
highs: {gbp: 0, usd: 0},
|
||||
eclass: '',
|
||||
balance: 0.0
|
||||
balance: 0.0,
|
||||
trend: 0
|
||||
};
|
||||
this.set('btcdata', data);
|
||||
this.set('balance', 0);
|
||||
@ -51,14 +52,18 @@ let BitcoinModel = Backbone.Model.extend({
|
||||
let highs = data.highs;
|
||||
let eclass = data.eclass;
|
||||
let balance = data.balance;
|
||||
let trend = data.trend;
|
||||
|
||||
if ((trend === undefined) || ( trend === null)) trend = 1;
|
||||
|
||||
if (g !== undefined) {
|
||||
if (data.lastGBP !== 0) {
|
||||
if (data.lastGBP !== 0)
|
||||
if (g > lastGBP) {
|
||||
eclass = 'up';
|
||||
} else {
|
||||
eclass = 'down';
|
||||
}
|
||||
} else {
|
||||
else {
|
||||
lows.gbp = g;
|
||||
lows.usd = u;
|
||||
|
||||
@ -80,7 +85,8 @@ let BitcoinModel = Backbone.Model.extend({
|
||||
lows,
|
||||
highs,
|
||||
eclass,
|
||||
balance
|
||||
balance,
|
||||
trend
|
||||
};
|
||||
}
|
||||
data.stub = Math.random(Number.MAX_SAFE_INTEGER).toString(32);
|
||||
@ -91,7 +97,6 @@ let BitcoinModel = Backbone.Model.extend({
|
||||
getBTC: function () {
|
||||
let self = this;
|
||||
let url = this.get('url');
|
||||
console.log('>> getBTC');
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: url,
|
||||
@ -107,9 +112,11 @@ let BitcoinModel = Backbone.Model.extend({
|
||||
success: function (data) {
|
||||
let gbp = data.bpi.GBP.rate_float,
|
||||
usd = data.bpi.USD.rate_float;
|
||||
let trend = data.trend;
|
||||
let btcdata = self.get('btcdata');
|
||||
btcdata.gbp = gbp;
|
||||
btcdata.usd = usd;
|
||||
btcdata.trend = trend;
|
||||
self.set('btcdata', btcdata);
|
||||
self.recalc();
|
||||
},
|
||||
@ -155,6 +162,7 @@ let Bitcoin = Backbone.View.extend({
|
||||
_.bindAll(this, 'render');
|
||||
this.model.bind('change', this.render);
|
||||
this.$btc = $('#btc');
|
||||
this.$trend = $('#trend');
|
||||
},
|
||||
render: function () {
|
||||
let btcdata = this.model.get('btcdata');
|
||||
@ -164,6 +172,17 @@ let Bitcoin = Backbone.View.extend({
|
||||
let owned = parseFloat(btcdata.lastGBP) * parseFloat(balance);
|
||||
//console.log(`owned: ${owned}`);
|
||||
let title = 'High: $' + parseFloat(btcdata.highs.usd.toFixed(2)) + ' / Low $' + parseFloat(btcdata.lows.usd.toFixed(2));
|
||||
let trendClass = '';
|
||||
|
||||
if (btcdata.trend > 1.00)
|
||||
trendClass = 'trendUp';
|
||||
else if (btcdata.trend < 1.00)
|
||||
trendClass = 'trendDown';
|
||||
else
|
||||
trendClass = '';
|
||||
|
||||
this.$trend.removeClass();
|
||||
this.$trend.addClass(trendClass);
|
||||
this.$btc.removeClass();
|
||||
this.$btc.addClass(btcdata.eclass);
|
||||
this.$btc.html(`$${parseFloat(btcdata.lastUSD.toFixed(2)) } / £${parseFloat(btcdata.lastGBP.toFixed(2))} <div>₿${balance} £${parseFloat(owned.toFixed(2))}</div>` );
|
||||
|
52
app/libs/float.js
Normal file
52
app/libs/float.js
Normal file
@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Credit: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round
|
||||
*/
|
||||
var decimalAdjust = function(type, value, exp) {
|
||||
value = value || 0;
|
||||
exp = exp === undefined ? -2 : -Math.abs(exp);
|
||||
// If the exp is undefined or zero...
|
||||
if (typeof exp === 'undefined' || +exp === 0) {
|
||||
return Math[type](value);
|
||||
}
|
||||
value = +value;
|
||||
exp = +exp;
|
||||
// If the value is not a number or the exp is not an integer...
|
||||
if (isNaN(value) || !(typeof exp === 'number' && exp % 1 === 0)) {
|
||||
return NaN;
|
||||
}
|
||||
// Shift
|
||||
value = value.toString().split('e');
|
||||
value = Math[type](+(value[0] + 'e' + (value[1] ? (+value[1] - exp) : -exp)));
|
||||
// Shift back
|
||||
value = value.toString().split('e');
|
||||
return +(value[0] + 'e' + (value[1] ? (+value[1] + exp) : exp));
|
||||
};
|
||||
|
||||
var round = function(v, d) {
|
||||
return decimalAdjust('round', v, d);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
round: round,
|
||||
floor: function(v, d) {
|
||||
return decimalAdjust('floor', v, d);
|
||||
},
|
||||
ceil: function(v, d) {
|
||||
return decimalAdjust('ceil', v, d);
|
||||
},
|
||||
equals: function(a, b, d) {
|
||||
return round(a, d) === round(b, d);
|
||||
},
|
||||
lessThan: function(a, b, d) {
|
||||
return round(a, d) < round(b, d);
|
||||
},
|
||||
lessThanOrEquals: function(a, b, d) {
|
||||
return round(a, d) <= round(b, d);
|
||||
},
|
||||
greaterThan: function(a, b, d) {
|
||||
return round(a, d) > round(b, d);
|
||||
},
|
||||
greaterThanOrEquals: function(a, b, d) {
|
||||
return round(a, d) >= round(b, d);
|
||||
}
|
||||
};
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -16,6 +16,8 @@
|
||||
"tests"
|
||||
],
|
||||
"dependencies": {
|
||||
"moment": "^2.18.1"
|
||||
"moment": "^2.18.1",
|
||||
"mui": "^0.9.21",
|
||||
"float": "^1.0.2"
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,9 @@ const http = require('http');
|
||||
const LimitedArray = require('limitedarray');
|
||||
const trend = require('trend');
|
||||
const logger = require('log4js').getLogger('fx');
|
||||
const delay = (60000 * 30);
|
||||
let fxCache = {};
|
||||
let history = new LimitedArray(96); // one days worth in 5 minute chunks
|
||||
let history = new LimitedArray(48); // one days worth in 5 minute chunks
|
||||
|
||||
function getFx() {
|
||||
logger.info('FX request');
|
||||
@ -37,17 +38,16 @@ function getFx() {
|
||||
|
||||
history.push(a.rates.GBP);
|
||||
fxCache.history = history.get();
|
||||
fxCache.trend = trend(fxCache.history, {avgPoints: 24});
|
||||
fxCache.trend = trend(fxCache.history, {avgPoints: 12});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function updateFX() {
|
||||
|
||||
logger.warn('updateBitcoin');
|
||||
getFx();
|
||||
const now = new Date();
|
||||
const mod = (60000 * 15) - (now.getTime() % (60000 * 15));
|
||||
const mod = delay - (now.getTime() % delay);
|
||||
|
||||
let fxUpdateFn = () => {
|
||||
updateFX();
|
||||
|
@ -58,7 +58,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="mui-col-md-4">
|
||||
<div class="mui--text-title mui-text-black">Bitcoin <span id="btc"></span></div>
|
||||
<div class="mui--text-title mui-text-black">Bitcoin <span id="trend"> </span><span id="btc"></span></div>
|
||||
<ul>
|
||||
<li><a href="https://www.bitstamp.net">Bitstamp</a></li>
|
||||
<li><a href="https://www.kraken.net">Kraken</a></li>
|
||||
|
@ -133,7 +133,7 @@ app.route('/poly').get(polys);
|
||||
|
||||
app.get('/slack', function(req, res) {
|
||||
res.render('pages/slackV2-min');
|
||||
//res.render('pages/slackV2');
|
||||
// res.render('pages/slackV2');
|
||||
});
|
||||
|
||||
app.get('/temp', function(req, res) {
|
||||
|
Loading…
Reference in New Issue
Block a user