diff --git a/app/js/app.config.js b/app/js/app.config.js index 10c4c8a83cc391e729fe3d9a48aeddd18988cdca..58a54c88424df4d31535d3fa260b25ce4695215a 100644 --- a/app/js/app.config.js +++ b/app/js/app.config.js @@ -17,18 +17,18 @@ module.exports = () => { let homeControllers = angular.module('homeControllers', ['duniter.services']); - homeControllers.controller('MainController', require('./controllers/main/MainController')); - homeControllers.controller('HomeController', require('./controllers/main/home/HomeController')); - homeControllers.controller('IndexController', require('./controllers/IndexController')); - homeControllers.controller('IdentityController', require('./controllers/init/create/IdentityController')); - homeControllers.controller('NetworkController', require('./controllers/main/settings/tabs/NetworkController')); - homeControllers.controller('ParametersController', require('./controllers/init/create/ParametersController')); - homeControllers.controller('RootBlockController', require('./controllers/init/create/RootBlockController')); - homeControllers.controller('SyncController', require('./controllers/init/sync/SyncController')); - homeControllers.controller('SettingsController', require('./controllers/main/settings/SettingsController')); - homeControllers.controller('DataController', require('./controllers/main/settings/tabs/DataController')); - homeControllers.controller('CurrencyController', require('./controllers/main/settings/tabs/CurrencyController')); - homeControllers.controller('KeyController', require('./controllers/main/settings/tabs/KeyController')); - homeControllers.controller('GraphsController', require('./controllers/main/graphs/GraphsController')); - homeControllers.controller('BlockchainGraphsController', require('./controllers/main/graphs/BlockchainGraphsController')); + homeControllers.controller('MainController', require('./controllers/main/MainController')); + homeControllers.controller('HomeController', require('./controllers/main/home/HomeController')); + homeControllers.controller('IndexController', require('./controllers/IndexController')); + homeControllers.controller('IdentityController', require('./controllers/init/create/IdentityController')); + homeControllers.controller('NetworkController', require('./controllers/main/settings/tabs/NetworkController')); + homeControllers.controller('ParametersController', require('./controllers/init/create/ParametersController')); + homeControllers.controller('RootBlockController', require('./controllers/init/create/RootBlockController')); + homeControllers.controller('SyncController', require('./controllers/init/sync/SyncController')); + homeControllers.controller('SettingsController', require('./controllers/main/settings/SettingsController')); + homeControllers.controller('DataController', require('./controllers/main/settings/tabs/DataController')); + homeControllers.controller('CurrencyController', require('./controllers/main/settings/tabs/CurrencyController')); + homeControllers.controller('KeyController', require('./controllers/main/settings/tabs/KeyController')); + homeControllers.controller('GraphsController', require('./controllers/main/graphs/GraphsController')); + homeControllers.controller('GraphsBlockchainController', require('./controllers/main/graphs/GraphsBlockchainController')); }; diff --git a/app/js/controllers/main/graphs/BlockchainGraphsController.js b/app/js/controllers/main/graphs/BlockchainGraphsController.js deleted file mode 100644 index e066c5cfb7e0fe005fcf89baa2fe9f6020616db9..0000000000000000000000000000000000000000 --- a/app/js/controllers/main/graphs/BlockchainGraphsController.js +++ /dev/null @@ -1,60 +0,0 @@ -"use strict"; - -const BLOCKS_COUNT = 40; - -var co = require('co'); - -module.exports = ($scope, $state, BMA, UIUtils, Graph) => { - - $scope.blocksCount = $scope.blocksCount || BLOCKS_COUNT; - - $scope.updateGraphs = () => { - return co(function *() { - let summary = yield BMA.webmin.summary(); - let bmapi = BMA.instance(summary.host); - let parameters = yield bmapi.currency.parameters(); - let blocks = yield bmapi.blockchain.blocks({ - count: $scope.blocksCount, - from: Math.max(0, summary.current.number - $scope.blocksCount) - }); - let speeds = [], accelerations = [], medianTimeIncrements = [], actualDurations = []; - let BY_HOUR = 3600; - for (let i = 0, len = blocks.length; i < len; i++) { - let block = blocks[i]; - let acc = 0; - let previousPos = Math.max(0, i - parameters.dtDiffEval); - for (let j = previousPos; j < i; j++) { - acc += (blocks[j+1].medianTime - blocks[j].medianTime); - } - let availPreviousBlocks = i - 1 - previousPos; - let localAvgSpeed = acc / (availPreviousBlocks || 1); - let realDuration = !isNaN(localAvgSpeed) && localAvgSpeed != 0 ? localAvgSpeed : parameters.avgGenTime; - actualDurations.push(parseFloat((realDuration).toFixed(2))); - speeds.push(parseFloat((BY_HOUR/realDuration).toFixed(2))); - accelerations.push(block.time - block.medianTime); - medianTimeIncrements.push(block.medianTime - (i ? blocks[i-1].medianTime : block.medianTime)); - } - let minSpeeds = speeds.map(() => parseFloat((BY_HOUR/Math.ceil(parameters.avgGenTime * Math.sqrt(1.066))).toFixed(2))); - let maxSpeeds = speeds.map(() => parseFloat((BY_HOUR/Math.floor(parameters.avgGenTime / Math.sqrt(1.066))).toFixed(2))); - let minDurations = speeds.map(() => parseFloat(((parameters.avgGenTime / 1.066)).toFixed(2))); - let maxDurations = speeds.map(() => parseFloat(((parameters.avgGenTime * 1.066)).toFixed(2))); - let difficulties = blocks.map((b) => b.powMin); - - setTimeout(() => { - Graph.timeGraphs('#timeGraph', Math.max(0, summary.current.number - $scope.blocksCount + 1), accelerations, medianTimeIncrements, actualDurations, minDurations, maxDurations); - - setTimeout(() => { - Graph.speedGraph('#speedGraph', Math.max(0, summary.current.number - $scope.blocksCount), speeds, minSpeeds, maxSpeeds, (series) => { - $scope.series = series; - }); - }, 1000); - - setTimeout(() => { - Graph.difficultyGraph('#difficultyGraph', Math.max(0, summary.current.number - $scope.blocksCount), difficulties); - }, 1000); - }, 100); - }); - }; - - setTimeout(() => $scope.updateGraphs(), 300); -}; diff --git a/app/js/controllers/main/graphs/GraphsBlockchainController.js b/app/js/controllers/main/graphs/GraphsBlockchainController.js new file mode 100644 index 0000000000000000000000000000000000000000..85eacd9bc343ad2c22daee544178c2fe692058a5 --- /dev/null +++ b/app/js/controllers/main/graphs/GraphsBlockchainController.js @@ -0,0 +1,106 @@ +"use strict"; + +const BLOCKS_COUNT = 40; + +var co = require('co'); + +module.exports = ($scope, $state, $timeout, BMA, UIUtils, Graph) => { + + let data = {}; + + $scope.loading = true; + $scope.blocksCount = $scope.blocksCount || BLOCKS_COUNT; + + $scope.$watch('withTime', (newValue) => { + if (newValue) { + timeGraph(); + } + }); + + $scope.$watch('withSpeed', (newValue) => { + if (newValue) { + speedGraph(); + } + }); + + $scope.$watch('withDifficulty', (newValue) => { + if (newValue) { + diffGraph(); + } + }); + + $scope.updateGraphs = () => { + return co(function *() { + let summary = yield BMA.webmin.summary(); + let bmapi = BMA.instance(summary.host); + let parameters = yield bmapi.currency.parameters(); + let blocks = yield bmapi.blockchain.blocks({ + count: $scope.blocksCount, + from: Math.max(0, summary.current.number - $scope.blocksCount) + }); + let speeds = [], accelerations = [], medianTimeIncrements = [], actualDurations = []; + let BY_HOUR = 3600; + for (let i = 0, len = blocks.length; i < len; i++) { + let block = blocks[i]; + let acc = 0; + let previousPos = Math.max(0, i - parameters.dtDiffEval); + for (let j = previousPos; j < i; j++) { + acc += (blocks[j+1].medianTime - blocks[j].medianTime); + } + let availPreviousBlocks = i - 1 - previousPos; + let localAvgSpeed = acc / (availPreviousBlocks || 1); + let realDuration = !isNaN(localAvgSpeed) && localAvgSpeed != 0 ? localAvgSpeed : parameters.avgGenTime; + actualDurations.push(parseFloat((realDuration).toFixed(2))); + speeds.push(parseFloat((BY_HOUR/realDuration).toFixed(2))); + accelerations.push(block.time - block.medianTime); + medianTimeIncrements.push(block.medianTime - (i ? blocks[i-1].medianTime : block.medianTime)); + } + data.summary = summary; + data.speeds = speeds; + data.accelerations = accelerations; + data.medianTimeIncrements = medianTimeIncrements; + data.actualDurations = actualDurations; + data.minSpeeds = speeds.map(() => parseFloat((BY_HOUR/Math.ceil(parameters.avgGenTime * Math.sqrt(1.066))).toFixed(2))); + data.maxSpeeds = speeds.map(() => parseFloat((BY_HOUR/Math.floor(parameters.avgGenTime / Math.sqrt(1.066))).toFixed(2))); + data.minDurations = speeds.map(() => parseFloat(((parameters.avgGenTime / 1.066)).toFixed(2))); + data.maxDurations = speeds.map(() => parseFloat(((parameters.avgGenTime * 1.066)).toFixed(2))); + data.difficulties = blocks.map((b) => b.powMin); + + let graphs = []; + if ($scope.withTime) graphs.push(timeGraph); + if ($scope.withSpeed) graphs.push(speedGraph); + if ($scope.withDifficulty) graphs.push(diffGraph); + for (let i = 0, len = graphs.length; i < len; i++) { + graphs[i](); + } + $scope.loading = false; + }); + }; + + function timeGraph() { + if ($scope.withTime) { + Graph.timeGraphs('#timeGraph', Math.max(0, data.summary.current.number - $scope.blocksCount + 1), data.accelerations, data.medianTimeIncrements, data.actualDurations, data.minDurations, data.maxDurations); + } + } + + function speedGraph() { + if ($scope.withSpeed) { + Graph.speedGraph('#speedGraph', Math.max(0, data.summary.current.number - $scope.blocksCount), data.speeds, data.minSpeeds, data.maxSpeeds, (series) => { + $scope.series = series; + }); + } + } + + function diffGraph() { + if ($scope.withDifficulty) { + Graph.difficultyGraph('#difficultyGraph', Math.max(0, data.summary.current.number - $scope.blocksCount), data.difficulties); + } + } + + return co(function *() { + yield $scope.updateGraphs(); + $scope.withTime = true; + $scope.withDifficulty = true; + $scope.$apply(); + }); +}; diff --git a/app/js/lib/conf/i18n/en.json b/app/js/lib/conf/i18n/en.json index ff5caf6fa2389d28be125c36a62e7f280b382dd0..065b831a88c75cbe57214b7f0d939699104083e7 100644 --- a/app/js/lib/conf/i18n/en.json +++ b/app/js/lib/conf/i18n/en.json @@ -121,5 +121,8 @@ "settings.data.reset.experimental": "This functionality is still considered experimental. If you encounters strange behaviors, please stop the software and reset manually your node by removing all the files BUT conf.json under ~/.config/ucoin/ucoin_default, and restart the software.", "graphs.tabs.blockchain": "Blockchain", "graphs.tabs.currency": "Currency", - "graphs.blockchain.range": "Graphs for the last X blocks: (please choose X value)" + "graphs.blockchain.range": "Graphs for the last X blocks: (please choose X value)", + "graphs.blockchain.with.time": "Time variations graph", + "graphs.blockchain.with.speed": "Writing speed graph", + "graphs.blockchain.with.difficulty": "Difficulty graph" } diff --git a/app/js/lib/conf/routes.js b/app/js/lib/conf/routes.js index d9d409fa1e5b65227718ee8a3cd6e2ec534935b0..a0d2d1e382f885ba8b5343b1592f8ccd29637859 100644 --- a/app/js/lib/conf/routes.js +++ b/app/js/lib/conf/routes.js @@ -168,7 +168,7 @@ module.exports = (app) => { state('main.graphs.blockchain', { url: '/blockchain', template: require('views/main/graphs/blockchain'), - controller: 'BlockchainGraphsController' + controller: 'GraphsBlockchainController' }). //state('graphs.crypto', { diff --git a/app/views/main/graphs/blockchain.jade b/app/views/main/graphs/blockchain.jade index f53f16cae042899507da702c5d9a72bd6e1db720..e97a9fadc2d8cc394506d08f35537cec9724c1a4 100644 --- a/app/views/main/graphs/blockchain.jade +++ b/app/views/main/graphs/blockchain.jade @@ -1,22 +1,34 @@ -.row +.container + .row + .card + .card-action + .row + .col.s12 + .container + p {{ 'graphs.blockchain.range' | translate }} + .range-field + input(type="range" min="30" max="600" ng-model="blocksCount" ng-mouseup="updateGraphs()") - .col.s12 - .container - p {{ 'graphs.blockchain.range' | translate }} - .range-field - input(type="range" min="30" max="600" ng-model="blocksCount" ng-mouseup="updateGraphs()") + //.input-field.col.s6.m4 + // input#time.filled-in(type="checkbox" ng-model="withTime") + // label(for="time") {{ 'graphs.blockchain.with.time' | translate }} - .col.s12 - .card.graph - .card-content - #timeGraph + // Too heavy for now + //.input-field.col.s6.m4 + // input#speed.filled-in(type="checkbox" ng-model="withSpeed") + // label(for="speed") {{ 'graphs.blockchain.with.speed' | translate }} - .col.s12 - .card.graph - .card-content - #speedGraph - - .col.s12 - .card.graph - .card-content - #difficultyGraph + //.input-field.col.s6.m4 + // input#difficulty.filled-in(type="checkbox" ng-model="withDifficulty") + // label(for="difficulty") {{ 'graphs.blockchain.with.difficulty' | translate }} + .s12.center(ng-if="loading") + .row + .row + .preloader-wrapper.active + .spinner-layer.spinner-blue-only + .circle-clipper.left + .circle + p {{ message | translate:'{number: current_number}' }} + #timeGraph + //#speedGraph + #difficultyGraph