controllers.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. angular.module('starter.controllers', [])
  2. .controller('AppCtrl', function($scope, $ionicModal, $timeout) {
  3. // With the new view caching in Ionic, Controllers are only called
  4. // when they are recreated or on app start, instead of every page change.
  5. // To listen for when this page is active (for example, to refresh data),
  6. // listen for the $ionicView.enter event:
  7. //$scope.$on('$ionicView.enter', function(e) {
  8. //});
  9. })
  10. .controller('SettingsCtrl', function($scope) {
  11. })
  12. .controller('CategoriesCtrl', function($scope) {
  13. $scope.categories = [
  14. { title: 'Game', name: "GAME" },
  15. { title: 'Entertainment', name: "ENTER" },
  16. { title: 'Lifestyle', name: "GAME" },
  17. { title: 'Shopping', name: "GAME" },
  18. { title: 'Weather', name: "GAME" },
  19. { title: 'Health and Fitness', name: "GAME" },
  20. { title: 'Productivity', name: "GAME" },
  21. ];
  22. })
  23. .controller('AppsCtrl', function($scope, $stateParams, $http, $ionicLoading, $state) {
  24. $scope.loadingShow = function() {
  25. $ionicLoading.show({
  26. template: 'Loading...',
  27. duration: 3000
  28. }).then(function(){
  29. console.log("The loading indicator is now displayed");
  30. });
  31. };
  32. $scope.loadingHide = function(){
  33. $ionicLoading.hide().then(function(){
  34. console.log("The loading indicator is now hidden");
  35. });
  36. };
  37. $scope.catId = $stateParams.catId;
  38. var query = "";
  39. if($scope.catId) {
  40. query += "/?genre=" + $scope.catId;
  41. }
  42. $scope.loadingShow();
  43. $http.get('https://trust4app.herokuapp.com/crawler/downloadedapps' + query).then(function(response){
  44. $scope.apps = response.data;
  45. $scope.loadingHide();
  46. });
  47. $scope.showApp = function(app) {
  48. $state.go('app.single', { appId : app.appId });
  49. }
  50. })
  51. .controller('SingleCtrl', function($scope, $stateParams, $http, $ionicLoading) {
  52. $scope.loadingShow = function() {
  53. $ionicLoading.show({
  54. template: 'Loading...',
  55. duration: 1000
  56. }).then(function(){
  57. console.log("The loading indicator is now displayed");
  58. });
  59. };
  60. $scope.loadingHide = function(){
  61. $ionicLoading.hide().then(function(){
  62. console.log("The loading indicator is now hidden");
  63. });
  64. };
  65. $scope.app = {};
  66. $scope.reputationHTI = false;
  67. $scope.spHTI = false;
  68. $scope.finalHTI = false;
  69. $scope.appId = $stateParams.appId;
  70. $scope.loadingShow();
  71. $http.get('https://trust4app.herokuapp.com/crawler/downloadedapps/' + $scope.appId).then(function(response){
  72. $scope.app = response.data;
  73. $scope.loadingShow();
  74. });
  75. $scope.$watch('app', function (newValue, oldValue, scope) {
  76. if(newValue.appId) {
  77. $scope.showCertainTrust();
  78. }
  79. });
  80. $scope.showCertainTrust = function () { //this will just calculate the expectation of the Reputaion and SP QUality category considering the sub categories
  81. var f = 0.0;
  82. var CT_objects = [];
  83. var CT_names = ['ratingsCT', 'reviewsCT', 'securityRisksCT', 'privacyRisksCT'];
  84. var app = $scope.app;
  85. for (var i = 0, element; element = CT_names[i]; ++i) {
  86. var CT_object;
  87. if (-1 !== element.indexOf('ratings')) {
  88. CT_object = new CertainTrust(Number(app.averageRatingTrustValue.toFixed(2)), Number(app.averageRatingConfidenceValue.toFixed(2)), f, 3);
  89. }
  90. if (-1 !== element.indexOf('reviews')) {
  91. CT_object = new CertainTrust(Number(app.reviewsTrustValue.toFixed(2)), Number(app.reviewsConfidenceValue.toFixed(2)), f, 3);
  92. }
  93. if (-1 !== element.indexOf('security')) {
  94. CT_object = new CertainTrust(Number(app.sTrustValue.toFixed(2)), Number(app.sConfidenceValue.toFixed(2)), f, 3);
  95. }
  96. if (-1 !== element.indexOf('privacy')) {
  97. CT_object = new CertainTrust(Number(app.pTrustValue.toFixed(2)), Number(app.pConfidenceValue.toFixed(2)), f, 3);
  98. }
  99. // the result HTIs should be read-only
  100. var HTI = new CertainTrustHTI(CT_object, { domParent: element, readonly: true });
  101. CT_objects[element] = CT_object;
  102. }
  103. // ANDObserver.update();
  104. f = 0.9;
  105. var spQualityCT_result = CT_objects['securityRisksCT'].AND(CT_objects['privacyRisksCT']);
  106. spQualityCT_result.setF(f);
  107. var HTI2 = new CertainTrustHTI(spQualityCT_result, { domParent: "spQualityAndResult", readonly: true });
  108. var wFusionArr = new Array();
  109. wFusionArr.push(CT_objects['ratingsCT']);
  110. wFusionArr.push(CT_objects['reviewsCT']);
  111. var wFusionWeightArr = new Array();
  112. wFusionWeightArr.push(1/3);
  113. wFusionWeightArr.push(2/3);
  114. var repuatationWFusionCT_result = CT_objects['ratingsCT'].wFusion(wFusionArr,wFusionWeightArr);
  115. repuatationWFusionCT_result.setF(f);
  116. var HTI1 = new CertainTrustHTI(repuatationWFusionCT_result, { domParent: "reputationWFusionResult", readonly: true });
  117. var finalAndCT_result = repuatationWFusionCT_result.AND(spQualityCT_result);
  118. var HTI3 = new CertainTrustHTI(finalAndCT_result, { domParent: "finalAndResult", readonly: true });
  119. var ct1 = new CertainTrust("Reputation",repuatationWFusionCT_result.getT(), repuatationWFusionCT_result.getC(),repuatationWFusionCT_result.getF(),3);
  120. var ct2 = new CertainTrust("S&p Quality",spQualityCT_result.getT(), spQualityCT_result.getC(),spQualityCT_result.getF(),3);
  121. new CertainTrustTViz([ct1,ct2], { id: "tvizAnd", middle: "AND", canvas: { height: 300, width: 300 },
  122. onClick: function(certainTrust) {
  123. if (certainTrust.getName() === "Reputation") $scope.reputationHTI = true;
  124. else $scope.spHTI = true;
  125. $scope.$apply();
  126. },
  127. onMiddleClick: function(certainTrust) {
  128. $scope.finalHTI = true;
  129. $scope.$apply();
  130. }
  131. });
  132. }
  133. });