You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
4.4 KiB

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