Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.40 KB | None | 0 0
  1. import { Component } from '@angular/core';
  2.  
  3. @Component({
  4. selector: 'app-root',
  5. templateUrl: './app.component.html',
  6. styleUrls: ['./app.component.css', './animate.css']
  7. })
  8. export class AppComponent {
  9. aboutApp = {
  10. en: {name: 'Informational technology of visual simulation of pairwise comparisons (VSPC)',
  11. sname: "Visual simulation of pairwise comparisons (VSPC)",
  12. version: 'Version',
  13. authors: 'Copyright: Kolodny V., Khokhlov A. 2018',
  14. contact: 'Contact: 16mb.com@gmail.com',
  15. process: 'The process of executing the program is as follows:',
  16. li1: 'Input names of alternatives.',
  17. li2: 'A pairwise comparison of all alternatives.',
  18. li3: 'Display the best alternative and ranking.',
  19. p1: 'The interface has the ability to select multiple languages (Ukrainian, Russian, English) and makes more easier user navigation during the comparison process from the introduction of alternatives to outputting the results of the program.',
  20. p3: 'The program has the ability to enter 4-9 alternatives.'},
  21. ru: {name: 'Информационная технология визуального моделирования попарных сравнений (ВМПС)',
  22. version: 'Версия',
  23. authors: 'Авторские права: Колодный В. В., Хохлов А. Д. 2018',
  24. contact: 'Контакты: 16mb.com@gmail.com',
  25. sname: "Визуальное моделирование попарных сравнений (ВМПС)",
  26. process: 'Процесс выполнения программы выглядит следующим образом:',
  27. li1: 'Ввод названий альтернатив.',
  28. li2: 'Попарное сравнение всех альтернатив.',
  29. li3: 'Вывод наилучшей альтернативы и результирующей ранжировки.',
  30. p1: 'Интерфейс имеет возможность выбора нескольких языков (украинский, русский, английский) и облегчает навигацию пользователя в процессе сравнения, от введения альтернатив до вывода результатов работы программы.',
  31. p3: 'Программа имеет возможность ввода 4-9 альтернатив.'},
  32. ua: {name: 'Інформаційна технологія візуального моделювання попарних порівнянь (ВМПП)',
  33. sname: "Візуальне моделювання попарних порівнянь (ВМПП)",
  34. version: 'Версія',
  35. authors: 'Авторські права: Колодний В. В., Хохлов А. Д., 2018',
  36. contact: 'Контакти: 16mb.com@gmail.com',
  37. process: `Процес виконання програми виглядає наступним чином:`,
  38. li1: 'Введення назв альтернатив.',
  39. li2: 'Попарне порівняння всіх альтернатив.',
  40. li3: 'Виведення найкращої альтернативи та результуючого ранжування.',
  41. p1: 'Інтерфейс дає можливість вибору декількох мов (Українська, Російська, Англійська) та полегшує навігацію користувача у процесі порівняння від введення альтернатив до виведення результатів роботи програми.',
  42. p3: 'Програма має можливість введення від 4 до 9 альтернатив.'}
  43. }
  44. locales = {
  45. ......
  46. };
  47. locale = this.locales.ua
  48. alternatives = [/*{name: "Файловий менеджер", rate: 0}, {name: "Браузер", rate: 0}, {name: "Сапер", rate: 0}, {name: "Поштовий клієнт", rate: 0}, {name: "Калькулятор", rate: 0}*/];
  49. alternatives2 = [];
  50. authors = false;
  51. sameAtl = false;
  52. alternativesList = [];
  53. currentCompare = [];
  54. accuracy = this.locale.acc[1];
  55. rangeNum = 25;
  56. ferror = '';
  57. isDuo = false;
  58. currentRange = Math.round(this.rangeNum/2);
  59. currentFirst = undefined;
  60. currentIteration = 0;
  61. best = '';
  62. outOfAlternatives = false;
  63. newAlternative = '';
  64. resultList = [];
  65. resultList2 = [];
  66. firstStep = true;
  67. ready = false;
  68. about = false;
  69. randoms = [];
  70. randomsCurrent = [];
  71. altNum = 4;
  72. normArray = [];
  73.  
  74. ngOnInit(){
  75. this.getRndAlternatives();
  76. }
  77. getRndAlternatives(){
  78. this.randoms = [];
  79. let num = undefined;
  80. for(let i = 0; i < 9; i++){
  81. num = this.rnd(0, 39, undefined)
  82. if(this.randoms.includes(num)){ this.getRndAlternatives(); break; }
  83. else{this.randoms.push(num);}
  84. }
  85. this.randomsCurrent = this.randoms.slice(0, this.altNum);
  86. }
  87. changeAltNum(){
  88. this.randomsCurrent = this.randoms.slice(0, this.altNum);
  89. }
  90. getCurrentCompare = function(){
  91. console.log(this.locale)
  92. if(this.alternativesList.length > 1){
  93. this.currentCompare = [];
  94. if((this.currentIteration>=this.alternativesList.length) || this.currentFirst == undefined){
  95. let num = this.rnd(0, this.alternativesList.length);
  96. this.currentFirst = this.alternativesList[num]
  97. this.alternativesList.splice(num, 1)
  98. this.currentIteration = 0
  99. }
  100. this.currentCompare[0] = this.rnd(2,4) == 3 ? this.currentFirst : this.alternativesList[this.currentIteration];
  101. this.currentCompare[1] = this.currentCompare[0] == this.currentFirst ? this.alternativesList[this.currentIteration] : this.currentFirst;
  102. this.currentIteration++
  103. }
  104. else{
  105. console.warn("Out of alternatives");
  106. this.outOfAlternatives = true
  107. this.result()
  108. }
  109. }
  110. answer = function(){
  111. console.log(this.alternatives2)
  112. if(!this.outOfAlternatives && this.firstStep){
  113. let values = [this.rangeNum-this.currentRange, this.currentRange*1];
  114. for(let i = 0; i < this.alternatives.length; i++){
  115. if(this.alternatives[i].name == this.currentCompare[0].name){
  116. this.alternatives[i].rate += values[0]-50
  117. }
  118. else if(this.alternatives[i].name == this.currentCompare[1].name){
  119. this.alternatives[i].rate += values[1]-50
  120. }
  121. }
  122. this.getCurrentCompare()
  123. this.currentRange = Math.round(this.rangeNum/2);;
  124. }
  125. if(!this.outOfAlternatives && !this.firstStep){
  126. let values = [this.rangeNum-this.currentRange, this.currentRange*1];
  127. for(let i = 0; i < this.alternatives2.length; i++){
  128. if(this.alternatives2[i].name == this.currentCompare[0].name){
  129. this.alternatives2[i].rate += values[0]-50
  130. }
  131. else if(this.alternatives2[i].name == this.currentCompare[1].name){
  132. this.alternatives2[i].rate += values[1]-50
  133. }
  134. }
  135. this.getCurrentCompare()
  136. this.currentRange = Math.round(this.rangeNum/2);;
  137. }
  138. }
  139. result = function(){
  140. if(this.firstStep){
  141. this.resultList = this.alternatives.sort(function(a,b){
  142. return a.rate - b.rate
  143. }).reverse()
  144. if(this.resultList[0].rate == this.resultList[1].rate){
  145. this.best = `${this.locale.bests} ${this.resultList[0].name} та ${this.resultList[1].name}`
  146. }
  147. else if(this.resultList[0].rate > this.resultList[1].rate){
  148. this.best = `${this.locale.best} ${this.resultList[0].name}`
  149. }
  150. let normSum = 0;
  151. for(let i = 0; i < this.alternatives.length; i ++){
  152. this.normArray[i] = Math.pow(1.02, this.alternatives[i].rate);
  153. normSum += this.normArray[i];
  154. }
  155. let normSum2 = 0;
  156. for(let i = 0; i < this.alternatives.length; i ++){
  157. this.normArray[i] = Number((this.normArray[i]/normSum).toFixed(3));
  158. normSum2 = normSum2 + this.normArray[i];
  159. this.alternatives[i].norm = this.normArray[i]
  160. }
  161. let delta = (1 - normSum2);
  162. console.log(delta.toFixed(10), normSum2)
  163. this.alternatives[0].norm += delta;
  164. this.alternatives[0].norm = this.alternatives[0].norm.toFixed(3)
  165. console.log(this.alternatives2)
  166. if(this.isDuo && this.firstStep){
  167. this.alternativesList = JSON.parse(JSON.stringify(this.alternatives));
  168. this.currentFirst = undefined;
  169. this.outOfAlternatives = false;
  170. this.getCurrentCompare();
  171. this.ready = true;
  172. this.firstStep = false;
  173. console.log(2)
  174. }
  175. }
  176. else{
  177. console.log(this.alternatives2)
  178. console.log(1)
  179. this.resultList2 = this.alternatives2.sort(function(a,b){
  180. return a.rate - b.rate
  181. }).reverse()
  182. if(this.resultList2[0].rate == this.resultList2[1].rate){
  183. this.best = `${this.locale.bests} ${this.resultList2[0].name} та ${this.resultList2[1].name}`
  184. }
  185. else if(this.resultList2[0].rate > this.resultList2[1].rate){
  186. this.best = `${this.locale.best} ${this.resultList2[0].name}`
  187. }
  188. for(let i = 0; i < this.resultList.length; i++){
  189. for(let j = 0; j < this.resultList2.length; j++){
  190. if(this.resultList[i].name == this.resultList2[j].name){
  191. this.resultList[i].secName = this.resultList2[j].name;
  192. this.resultList[i].secRate = this.resultList2[i].rate
  193. }
  194. }
  195. }
  196. console.log(this.resultList)
  197. }
  198. }
  199. rnd = function(min, max, prev) {
  200. if(prev != undefined){
  201. let num = Math.floor(Math.random() * (max - min)) + min;
  202. if(num != prev){
  203. let ret = num
  204. }else{
  205. console.log(prev)
  206. this.rnd(min, max, prev)
  207. }
  208. return num
  209. }else{
  210. return Math.floor(Math.random() * (max - min)) + min;
  211. }
  212. }
  213. getNum(){
  214. if(this.accuracy == 'normal.' || this.accuracy == 'норм.'){
  215. this.rangeNum = 100;
  216. }
  217. else if(this.accuracy == 'max.' || this.accuracy == 'макс.'){
  218. this.rangeNum = 400;
  219. }
  220. else{
  221. this.rangeNum = 30;
  222. }
  223. }
  224. addAlternative = function(){
  225. if(this.alternatives.length <9){
  226. let same = false;
  227. for(let i = 0; i < this.alternatives.length; i++){
  228. if(this.newAlternative == this.alternatives[i].name){
  229. same = true
  230. }
  231. }
  232. if(!same){
  233. this.sameAlt = false;
  234. if(this.newAlternative != "" && this.newAlternative != " " && (this.newAlternative.match(/[a-z]/i) || this.newAlternative.match(/[а-я]/i) || this.newAlternative.match(/[-!$%^&@#*()_+|~=`{}\[\]:";'<>?,.\/]/) || this.newAlternative.match(/[0-9]/))){
  235. this.ferror = '';
  236. this.alternatives.push({name: this.newAlternative, rate: 0})
  237. this.newAlternative = '';
  238. }
  239. else{
  240. this.ferror = 'ferror'
  241. }
  242. }
  243. else{
  244. this.sameAlt = true;
  245. }
  246. }
  247. }
  248. getReady = function(){
  249. if(this.rndAlts){
  250. for(let i = 0; i < this.altNum; i++){
  251. this.alternativesList.push({name: this.locale.array[this.randomsCurrent[i]], rate: 0})
  252. this.alternatives.push({name: this.locale.array[this.randomsCurrent[i]], rate: 0})
  253. console.log(this.alternativesList)
  254. }
  255. }
  256. this.getNum();
  257. this.alternativesList = JSON.parse(JSON.stringify(this.alternatives));
  258. this.alternatives2 = JSON.parse(JSON.stringify(this.alternatives));
  259. this.alternatives2.sort(function() { return 0.5 - Math.random() });
  260. this.currentRange = Math.round(this.rangeNum/2);
  261. this.getCurrentCompare();
  262. this.ready = true;
  263. console.log(this.ready)
  264. }
  265. again(){
  266. this.alternatives = [];
  267. this.currentFirst = undefined;
  268. this.currentIteration = 0;
  269. this.best = '';
  270. this.outOfAlternatives = false;
  271. this.newAlternative = '';
  272. this.resultList = [];
  273. this.ready = false;
  274. this.alternativesList = [];
  275. this.currentCompare = [];
  276. }
  277. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement