arnaucube
arnaucube/blockchainIDsystemPublic Self-hosted repository
blockchainIDsystem/clientApp/GUI/views/stats/stats.js
clientApp/GUI/views/stats/stats.jsRaw
  1'use strict';
  2
  3angular.module('app.stats', ['ngRoute'])
  4
  5    .config(['$routeProvider', function($routeProvider) {
  6        $routeProvider.when('/stats', {
  7            templateUrl: 'views/stats/stats.html',
  8            controller: 'StatsCtrl'
  9        });
 10    }])
 11
 12    .controller('StatsCtrl', function($scope, $rootScope, $http, $filter) {
 13
 14        $rootScope.server = JSON.parse(localStorage.getItem("old_darkID_server"));
 15
 16        $scope.generatingID = false;
 17        $scope.ids = [];
 18        $http.get(clientapi + 'ids')
 19            .then(function(data) {
 20                console.log('data success');
 21                console.log(data);
 22                $scope.ids = data.data;
 23                $scope.idsToChart();
 24            }, function(data) {
 25                console.log('data error');
 26            });
 27
 28        $scope.newID = function() {
 29            $scope.generatingID = true;
 30            $http.get(clientapi + 'newid')
 31                .then(function(data) {
 32                    console.log('data success');
 33                    console.log(data);
 34                    $scope.ids = data.data;
 35                    $scope.generatingID = false;
 36
 37                }, function(data) {
 38                    console.log('data error');
 39                });
 40        };
 41
 42        $scope.blindAndSendToSign = function(id) {
 43            $http.get(clientapi + 'blindandsendtosign/' + id)
 44                .then(function(data) {
 45                    console.log('data success');
 46                    console.log(data);
 47                    $scope.ids = data.data;
 48
 49                }, function(data) {
 50                    console.log('data error');
 51                });
 52        };
 53        $scope.verify = function(id) {
 54            $http.get(clientapi + 'verify/' + id)
 55                .then(function(data) {
 56                    console.log('data success');
 57                    console.log(data);
 58                    $scope.ids = data.data;
 59
 60                }, function(data) {
 61                    console.log('data error');
 62                });
 63        };
 64        $scope.clientApp = function(route, param) {
 65            $http.get(clientapi + route + '/' + param)
 66                .then(function(data) {
 67                    console.log('data success');
 68                    console.log(data);
 69                    $scope.ids = data.data;
 70
 71                }, function(data) {
 72                    console.log('data error');
 73                });
 74        };
 75
 76        //chartjs
 77        $scope.chart1 = {
 78            colours: ['#4DD0E1', '#9575CD', '#F06292', '#FFF176'],
 79            labels: [],
 80            data: []
 81        };
 82        $scope.chart2 = {
 83            colours: ['#4DD0E1', '#9575CD', '#F06292', '#FFF176'],
 84            labels: [],
 85            data: []
 86        };
 87        $scope.idsToChart = function() {
 88            //chart1
 89            var dictionary = {};
 90            var ids = $scope.ids;
 91            for(var i=0; i<ids.length; i++) {
 92                var day = $filter('date')(ids[i].date, 'dd.MM.y, HH:mm');
 93                if(dictionary[day]==undefined) {
 94                    dictionary[day] = 1
 95                } else {
 96                    dictionary[day]++;
 97                }
 98            }
 99            console.log(dictionary);
100            for(var key in dictionary) {
101                $scope.chart1.labels.push(key);
102                $scope.chart1.data.push(dictionary[key]);
103            }
104
105
106            //chart2
107            var dictionary = {};
108            for(var i=0; i<ids.length; i++) {
109                if(ids[i].blockchainref) {
110                    if(dictionary['in blockchain']==undefined) {
111                        dictionary['in blockchain'] = 1
112                    } else {
113                        dictionary['in blockchain']++;
114                    }
115                } else if(ids[i].unblindedsig) {
116                    if(dictionary['signed']==undefined) {
117                        dictionary['signed'] = 1
118                    } else {
119                        dictionary['signed']++;
120                    }
121                } else {
122                    if(dictionary['unsigned']==undefined) {
123                        dictionary['unsigned'] = 1
124                    } else {
125                        dictionary['unsigned']++;
126                    }
127                }
128            }
129            console.log(dictionary);
130            for(var key in dictionary) {
131                $scope.chart2.labels.push(key);
132                $scope.chart2.data.push(dictionary[key]);
133            }
134
135        };
136    });