1/// <reference path="references.d.ts" /> 2/// <reference path="application.ts" /> 3var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 4 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 5 return new (P || (P = Promise))(function (resolve, reject) { 6 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 7 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 8 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 9 step((generator = generator.apply(thisArg, _arguments || [])).next()); 10 }); 11}; 12var __generator = (this && this.__generator) || function (thisArg, body) { 13 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 14 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 15 function verb(n) { return function (v) { return step([n, v]); }; } 16 function step(op) { 17 if (f) throw new TypeError("Generator is already executing."); 18 while (g && (g = 0, op[0] && (_ = 0)), _) try { 19 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 20 if (y = 0, t) op = [op[0] & 2, t.value]; 21 switch (op[0]) { 22 case 0: case 1: t = op; break; 23 case 4: _.label++; return { value: op[1], done: false }; 24 case 5: _.label++; y = op[1]; op = [0]; continue; 25 case 7: op = _.ops.pop(); _.trys.pop(); continue; 26 default: 27 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 28 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 29 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 30 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 31 if (t[2]) _.ops.pop(); 32 _.trys.pop(); continue; 33 } 34 op = body.call(thisArg, _); 35 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 36 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 37 } 38}; 39import { Distiller } from './application.js'; 40var OpenResponseViewModel = /** @class */ (function () { 41 function OpenResponseViewModel(params) { 42 var _this = this; 43 this.openResponseQuestion = ko.observable(null); 44 this.newText = ko.observable(null); 45 this.newDelta = ko.observable(null); 46 this.processingButton = ko.observable(null); 47 this.commentGettingEdited = ko.observable(null); 48 this.editOpenResponse = function (comment) { 49 if (_this.commentGettingEdited() === comment) { 50 _this.commentGettingEdited(null); 51 } 52 else { 53 var text = comment.text().replace(/<br\s*[\/]?>/gi, "\n"); 54 comment.newText(text); 55 _this.commentGettingEdited(comment); 56 } 57 }; 58 this.updateWiki = function (wikiData) { 59 var self = _this; 60 Distiller.httpSendAsync(Distiller.apiEndpoint + "/api/updateWiki/" + Distiller.currentUser().userId, JSON.stringify(wikiData), function (response) { 61 return __awaiter(this, void 0, void 0, function () { 62 return __generator(this, function (_a) { 63 response = JSON.parse(response); 64 if (response.data && !response.err) { 65 if (response.data.commentId) { 66 self.liveCommentId(response.data.commentId); 67 } 68 } 69 else if (response.err) { 70 alert("Oops! Some of your changes might not be saved. Please report this issue to [email protected]."); 71 } 72 return [2 /*return*/]; 73 }); 74 }); 75 }); 76 }; 77 this.saveEdits = function (comment) { 78 var imageURLs = null; 79 if (Distiller.pendingEditURLs().length > 0) { 80 imageURLs = encodeURIComponent(Distiller.pendingEditURLs().toString()); 81 } 82 var self = _this; 83 var textFile = {
84 newText: comment.newText(), 85 newDelta: JSON.stringify(comment.quillDelta()) 86 }; 87 Distiller.httpSendAsync(Distiller.apiEndpoint + "/api/sendUpdatedCurrentRationale/" + Distiller.currentUser().userId + "/" + self.openResponseQuestion().questionId() + "/" + comment.commentId() + "/" + comment.parentId() + "/" + imageURLs, JSON.stringify(textFile), function (response) { 88 return __awaiter(this, void 0, void 0, function () { 89 var convertedTimestamp, formattedDateTime, text, images; 90 return __generator(this, function (_a) { 91 if (self.openResponseQuestion().type() === 5) { 92 comment.quillDelta = ko.observable(JSON.stringify(comment.quillDelta())); 93 } 94 convertedTimestamp = new Date(); 95 formattedDateTime = convertedTimestamp.toLocaleDateString(); 96 text = comment.newText().replace(/\n\r?/g, '<br />'); 97 comment.text(text); 98 comment.timestamp(formattedDateTime); 99 comment.newText(null); 100 images = []; 101 if (Distiller.pendingEditURLs().length > 0) { 102 Distiller.pendingEditURLs().forEach(function (pendingUpload) { 103 var image = { 104 url: ko.observable(pendingUpload) 105 }; 106 images.push(image); 107 }); 108 } 109 comment.images(images); 110 // } 111 self.commentGettingEdited(null); 112 comment.isGettingEdited(false); 113 return [2 /*return*/]; 114 }); 115 }); 116 }); 117 }; 118 this.primaryQuestionsForListRating = ko.pureComputed(function () { 119 var _this = this; 120 var primaryQuestions = []; 121 if (this.openResponseQuestion().primaryQuestionIds().length > 0) { 122 var questions = Distiller.setOfVisibleQuestion().surveyQuestions().filter(function (element) { return _this.openResponseQuestion().primaryQuestionIds().indexOf(element.questionId()) > -1; }); 123 questions.forEach(function (question) { 124 primaryQuestions.push(question); 125 }); 126 // if (questions.length === 0) { 127 for (var z = 0; z < Distiller.setOfVisibleQuestion().surveyQuestions().length; z++) { 128 if (Distiller.setOfVisibleQuestion().surveyQuestions()[z].siblingQuestions().filter(function (element) { return _this.openResponseQuestion().primaryQuestionIds().indexOf(element.questionId()) > -1; }).length > 0) { 129 var questions_1 = Distiller.setOfVisibleQuestion().surveyQuestions()[z].siblingQuestions().filter(function (element) { return _this.openResponseQuestion().primaryQuestionIds().indexOf(element.questionId()) > -1; }); 130 questions_1.forEach(function (question) { 131 primaryQuestions.push(question); 132 }); 133 } 134 } 135 // } 136 return primaryQuestions; 137 } 138 else { 139 return primaryQuestions; 140 } 141 }, this); 142 //just for ACH 143 this.primaryQuestionForListRating = ko.pureComputed(function () { 144 var _this = this; 145 var primaryQuestion = null; 146 if (this.openResponseQuestion().primaryQuestionIds().length > 0) { 147 var questions = Distiller.setOfVisibleQuestion().surveyQuestions().filter(function (element) { return _this.openResponseQuestion().primaryQuestionIds().indexOf(element.questionId()) > -1; }); 148 if (questions.length > 0) { 149 primaryQuestion = questions[0]; 150 } 151 else { 152 for (var z = 0; z < Distiller.setOfVisibleQuestion().surveyQuestions().length; z++) { 153 if (Distiller.setOfVisibleQuestion().surveyQuestions()[z].siblingQuestions().filter(function (element) { return _this.openResponseQuestion().primaryQuestionIds().indexOf(element.questionId()) > -1; }).length > 0) { 154 var questions_2 = Distiller.setOfVisibleQuestion().surveyQuestions()[z].siblingQuestions().filter(function (element) { return _this.openResponseQuestion().primaryQuestionIds().indexOf(element.questionId()) > -1; }); 155 primaryQuestion = questions_2[0]; 156 } 157 } 158 } 159 return primaryQuestion; 160 } 161 else { 162 return primaryQuestion; 163 } 164 }, this); 165 this.consensusAuthor = ko.pureComputed(function () { 166 var consensusAuthor = { 167 userId: ko.observable(null), 168 avatarInitials: ko.observable(null), 169 avatarColor: ko.observable(null), 170 authorName: ko.observable(null), 171 timestamp: ko.observable(null) 172 }; 173 if (this.openResponseQuestion().type() === 17) { 174 if (this.openResponseQuestion().arrayOfUserForec
174asts().length > 0) { 175 var userId_1 = this.openResponseQuestion().arrayOfUserForecasts()[0].userId; 176 var authorName = ""; 177 if (Distiller.currentUser().userId === userId_1) { 178 authorName = Distiller.currentUser().name(); 179 } 180 else { 181 var potentialAuthors = Distiller.allTeammates().filter(function (element) { return element.userId() === userId_1; }); 182 if (potentialAuthors.length > 0) { 183 authorName = potentialAuthors[0].name(); 184 } 185 } 186 var avatarInitials = Distiller.avatarInitials(authorName); 187 var avatarColor = void 0; 188 if (userId_1 < Distiller.colorsArray().length) { 189 avatarColor = Distiller.colorsArray()[userId_1]; 190 } 191 else { 192 var indexOfColor = userId_1 % Distiller.colorsArray().length; 193 avatarColor = Distiller.colorsArray()[indexOfColor]; 194 } 195 var timestamp = this.openResponseQuestion().arrayOfUserForecasts()[0].forecastData[0].timestamp; 196 // let convertedTimestamp = new Date(timestamp); 197 //let formattedDateTime = convertedTimestamp.toLocaleDateString() + " " + convertedTimestamp.toLocaleTimeString(); 198 var now = new Date().getTime(); 199 var savedAt = new Date(timestamp); 200 var timezoneOffset = savedAt.getTimezoneOffset() * 60000; 201 var timeSavedAt = savedAt.getTime(); 202 var forecastAge = now - timeSavedAt; 203 var timeElapsed = Distiller.convertMilliseconds(forecastAge); 204 consensusAuthor.userId(userId_1); 205 consensusAuthor.avatarInitials(avatarInitials); 206 consensusAuthor.avatarColor(avatarColor); 207 consensusAuthor.authorName(authorName); 208 consensusAuthor.timestamp(timeElapsed); 209 // this.setTime(); 210 } 211 return consensusAuthor; 212 } 213 }, this); 214 this.setTime = function () { 215 var now = new Date().getTime(); 216 var timestamp = _this.openResponseQuestion().arrayOfUserForecasts()[0].forecastData[0].timestamp; 217 var savedAt = new Date(timestamp); 218 var timeSavedAt = savedAt.getTime(); 219 var forecastAge = now - timeSavedAt; 220 var timeElapsed = Distiller.convertMilliseconds(forecastAge); 221 _this.consensusAuthor().timestamp(timeElapsed); 222 setTimeout(function () { return _this.setTime(); }, 60000); 223 }; 224 this.showingDropdown = ko.observable({ questionId: ko.observable(null), commentId: ko.observable(null) }); 225 this.showACHDropdown = function (question, comment) { 226 if (_this.showingDropdown().questionId() === question.questionId() && _this.showingDropdown().commentId() === comment.commentId()) { 227 _this.dismissACHDropdown(); 228 } 229 else { 230 _this.showingDropdown().questionId(question.questionId()); 231 _this.showingDropdown().commentId(comment.commentId()); 232 } 233 }; 234 this.dismissACHDropdown = function () { 235 _this.showingDropdown().questionId(null); 236 _this.showingDropdown().commentId(null); 237 }; 238 this.dropdownWidth = function (questionId) { 239 var element = document.getElementById('cell' + questionId); 240 if (element) { 241 var width = element.clientWidth; 242 return width; 243 } 244 else { 245 return 60; 246 } 247 }; 248 this.achScores = ko.observableArray([]); 249 this.arrayOfAchScores = ko.pureComputed(function () { 250 var self = this; 251 self.achScores([]); 252 var hypotheses = this.openResponseQuestion().siblingQuestions().filter(function (a) { return a.type() === 13; }); 253 var evidenceQuestion = this.openResponseQuestion(); 254 var i = 0; 255 (function goAgain(i) { 256 var score = 0; 257 for (var j = 0; j < evidenceQuestion.currentUserRationales().length; j++) { 258 var comment = evidenceQuestion.currentUserRationales()[j]; 259 var commentRatingForHypothesis = {}; //DEPRECATED comment.ratings().currentUserRatings.filter(element => element.promptId === hypotheses[i].questionId())[0]; 260 var answerIds = hypotheses[i].answers().map(function (a) { return a.answerId(); }); 261 if (commentRatingForHypothesis) { 262 var commentRatingAnswerId = commentRatingForHypothesis.ratingAnswerId; 263 if (answerIds.indexOf(commentRatingAnswerId) === 3) { 264 score -= 1; 265 } 266 else if (answerIds.indexOf(commentRatingAnswerId) === 4) { 267 score -= 2; 268 } 269 } 270 if (j === evidenceQuestion.currentUserRationales().length - 1) { 271 var row = { 272 questionId: hypotheses[i].questionId(), 273 score: score 274 }; 275 self.achScores.push(row); 276 i++; 277 if (i === hypotheses.length) { 278 return true; 279 } 280 else { 281 goAgain(i); 282 } 283 } 284 } 285 })(i); 286 }, this); 287 this.myCharts = []; 288 /* public hidingChartBeforeFirstForecast = () => ko.computed(function () { 289 if (Distiller.client() === 'grossmann') { 290 let arrayOfElicitations = []; 291 let arraysOfAssociatedPointQuestions = []; 292 293 if (this.alternativeElicitations().length > 1) { 294 arrayOfElicitations = this.alternativeElicitations(); 295 arraysOfAssociatedPointQuestions = this.arraysOfAssociatedPointQuestions(); 296 } 297 else { 298 //for when there's just one elicitation 299 arrayOfElicitations.push(this.openResponseQuestion()); 300 arraysOfAssociatedPointQuestions.push(this.associatedPointQuestions()); 301 } 302 if (arrayOfElicitations.length > 0) { 303 if (arrayOfElicitations[0].savedCurrentForecast().length > 0) { 304 if (!arrayOfElicitations[0].savedCurrentForecast()[0]) { 305 return true; 306 } 307 else { 308 return false;
309 } 310 } 311 else { 312 return false; 313 } 314 } 315 else { 316 return false; 317 } 318 } else { 319 return false; 320 } 321 322 }, this); */ 323 this.scrollDragMessageIntoView = function () { 324 if (!Distiller.isInStaticTeamMode() && Distiller.currentUser().stageNumber() === 1) { 325 var scrollToElement = document.getElementById('grossmannDragInstructions'); 326 if (scrollToElement) { 327 var rect = scrollToElement.getBoundingClientRect(); 328 window.scrollTo(0, rect.top + window.scrollY - 50); 329 } 330 } 331 }; 332 this.hidingChartBeforeFirstForecast = function () { 333 if (Distiller.client() === 'grossmann') { 334 var arrayOfElicitations = _this.associatedPointQuestions(); 335 if (arrayOfElicitations.length > 0) { 336 if (arrayOfElicitations[0].savedCurrentForecast().length > 0) { 337 if (arrayOfElicitations.length > 1 && arrayOfElicitations[1].savedCurrentForecast().length > 0) { 338 if (arrayOfElicitations[1].savedCurrentForecast()[0] === null) { 339 return true; 340 } 341 else { 342 return false; 343 } 344 } 345 else { 346 if (arrayOfElicitations[0].savedCurrentForecast()[0] === null) { 347 return true; 348 } 349 else { 350 return false; 351 } 352 } 353 } 354 else { 355 return false; 356 } 357 } 358 else { 359 return false; 360 } 361 } 362 else { 363 return false; 364 } 365 }; 366 this.draggedChart = false; 367 this.drawChart = function () { 368 if (_this.inputChartType() === 'floating_bar' && _this.openResponseQuestion().answers().length > 2) { 369 _this.drawFloatingBarChart(); 370 return; 371 } 372 else { 373 _this.inputChartType(null); 374 } 375 _this.setPointChartBounds(); 376 var arrayOfElicitations = []; 377 var arraysOfAssociatedPointQuestions = []; 378 if (_this.alternativeElicitations().length > 1) { 379 arrayOfElicitations = _this.alternativeElicitations(); 380 arraysOfAssociatedPointQuestions = _this.arraysOfAssociatedPointQuestions(); 381 } 382 else { 383 //for when there's just one elicitation 384 arrayOfElicitations.push(_this.openResponseQuestion()); 385 arraysOfAssociatedPointQuestions.push(_this.associatedPointQuestions()); 386 } 387 var _loop_2 = function (z) { 388 var canvas = document.getElementById("inputChartForQ" + arrayOfElicitations[z].questionId()); 389 if (canvas) { 390 var ctx = canvas.getContext('2d'); 391 var binsArray = []; 392 for (var i = 0; i < arraysOfAssociatedPointQuestions[z].length; i++) { 393 binsArray.push(arraysOfAssociatedPointQuestions[z][i].name()); 394 } 395 var displayUnits = false; 396 if (_this.openResponseQuestion().units()) { 397 displayUnits = true; 398 } 399 var dataSetsArray_1 = []; 400 //we add these last to not screw up the indexing of draggable portions 401 var groundTruthDataSets = []; 402 for (var i = 0; i < arrayOfElicitations[z].answers().length; i++) { 403 var color = Distiller.colorsArray()[i]; 404 if (Distiller.client() === 'grossmann') { 405 color = Distiller.grossmannColorsArray()[i]; 406 } 407 var data_1 = []; 408 var groundTruthData = []; 409 var _loop_3 = function (a) { 410 var answerOption = arraysOfAssociatedPointQuestions[z][a].answers()[i];
411 if (answerOption.currentUserForecast() || answerOption.currentUserForecast() === 0) { 412 data_1.push(answerOption.currentUserForecast()); 413 } 414 else { 415 data_1.push(10000); 416 } 417 var label = answerOption.text(); 418 if (arraysOfAssociatedPointQuestions[z][a].groundTruth().length > 0) { 419 var groundTruthForAnswer = arraysOfAssociatedPointQuestions[z][a].groundTruth().filter(function (a) { return a.answerId() === answerOption.answerId(); }); 420 if (groundTruthForAnswer.length > 0) { 421 groundTruthData.push(groundTruthForAnswer[0].outcome()); 422 } 423 } 424 if (a === arraysOfAssociatedPointQuestions[z].length - 1) { 425 var dataSet = { 426 userId: Distiller.currentUser().userId, 427 timestampRow: null, 428 historicalId: null, 429 label: label, 430 fill: false, 431 lineTension: 0.4, 432 backgroundColor: color, //"rgba(225,0,0,0.4)", 433 borderColor: color, 434 borderCapStyle: color, 435 borderDashOffset: 0, 436 borderJoinStyle: color, 437 pointBorderColor: color,
438 pointBackgroundColor: color, 439 pointBorderWidth: 1, 440 pointHoverRadius: 12, 441 pointHoverBackgroundColor: color, 442 pointHoverBorderColor: 'white', 443 pointHoverBorderWidth: 1, 444 pointRadius: 8, 445 pointHitRadius: 10, 446 data: data_1, 447 spanGaps: true, 448 hidden: false, 449 dragData: true, 450 order: 2 451 }; 452 dataSetsArray_1.push(dataSet); 453 //add ground truth here 454 if (groundTruthData.length > 0) { 455 if (label.toLowerCase().indexOf('your prediction') > -1) { 456 label = 'Outcome'; 457 } 458 color = 'red'; 459 var dataSet_1 = { 460 userId: -2, 461 timestampRow: null, 462 historicalId: null, 463 label: label, 464 fill: false, 465 lineTension: 0.4, 466 backgroundColor: color, //"rgba(225,0,0,0.4)", 467 borderColor: color, 468 borderCapStyle: color, 469 borderDashOffset: 0, 470 borderJoinStyle: color, 471 pointBorderColor: color,
472 pointBackgroundColor: color, 473 pointBorderWidth: 1, 474 pointHoverRadius: 12, 475 pointHoverBackgroundColor: color, 476 pointHoverBorderColor: 'white', 477 pointHoverBorderWidth: 1, 478 pointRadius: 8, 479 pointHitRadius: 10, 480 pointStyle: 'rectRot', 481 data: groundTruthData, 482 spanGaps: true, 483 hidden: false, 484 dragData: false, 485 order: 1 486 }; 487 groundTruthDataSets.push(dataSet_1); 488 } 489 } 490 }; 491 for (var a = 0; a < arraysOfAssociatedPointQuestions[z].length; a++) { 492 _loop_3(a); 493 } 494 } 495 //adding ground truth AFTER everything 496 dataSetsArray_1.push.apply(dataSetsArray_1, groundTruthDataSets); 497 //evidently we must redraw the chart 498 //to preserve the two-way street between forecasts 499 //and graph plots; without redrawing, changes to forecast value 500 //are NOT reflected in the chart (though changes in the chart ARE still reflected in forecast value) 501 if (_this.myCharts[z]) { 502 _this.myCharts[z].destroy(); 503 } 504 if (arraysOfAssociatedPointQuestions[z].length > 0 && arraysOfAssociatedPointQuestions[z][0] !== _this.selectedGraph()) { 505 canvas.style.display = 'none'; 506 } 507 else { 508 var chartType = 'line'; 509 if (Distiller.client() === 'impact' || (_this.openResponseQuestion().answers().length === 1 && _this.associatedPointQuestions().length === 0)) { 510 chartType = 'bar'; 511 } 512 var self_1 = _this; 513 _this.myCharts[z] = new Chart(ctx, { 514 type: chartType, 515 data: { 516 labels: binsArray, 517 datasets: dataSetsArray_1 518 }, 519 options: { 520 tension: 0.4, 521 onHover: function (e, el) { 522 if (el[0]) { 523 var currentStyle = canvas.style; 524 currentStyle.cursor = canvas ? 'pointer' : 'normal'; 525 } 526 }, 527 plugins: { 528 dragData: { 529 round: _this.pointDecimalPlaces(), 530 showToolTip: true, 531 onDragStart: function (e, element) { 532 //resetting element 533 }, 534 onDrag: function (e, datasetIndex, index, value) { 535 if (arraysOfAssociatedPointQuestions[z][index].groundTruth().length > 0) { 536 return false; 537 } 538 var data = dataSetsArray_1.map(function (a) { return a.data; }); 539 var currentStyle = canvas.style; 540 self_1.draggedChart = true; 541 currentStyle.cursor = canvas ? 'grab' : 'unset'; 542 var allData = []; 543 data.forEach(function (set) { 544 allData.push.apply(allData, set); 545 }); 546 var range = self_1.myCharts[z].options.scales.y.max - self_1.myCharts[z].options.scales.y.min; 547 //if its the highest value in the chart 548 if (Math.max.apply(Math, allData) === value) { 549 /* if (value > (self.myCharts[z].options.scales.y.max * .95)) { 550 console.log("self.pointDecimalPlaces - " + self.pointDecimalPlaces()); 551 self.myCharts[z].options.scales.y.max = (self.myCharts[z].options.scales.y.max * 1.01).toFixed(self.pointDecimalPlaces()); 552 } */ 553 if (value > (self_1.myCharts[z].options.scales.y.max - (range * .05))) { 554 self_1.myCharts[z].options.scales.y.max += Math.ceil(((range) * .01)); 555 } 556 } 557 //if its the lowest value in the chart 558 else if (Math.min.apply(Math, allData) === value) { 559 if (value < (self_1.myCharts[z].options.scales.y.min * 1.1) && value > 0) { 560 self_1.myCharts[z].options.scales.y.min = Math.floor(self_1.myCharts[z].options.scales.y.min * .95); 561 //console.log("changing min on drag to " + self.myCharts[z].options.scales.y.min); 562 } 563 else if (value <= 0 && self_1.openResponseQuestion().defaultMin() < 0 && (value < (self_1.myCharts[z].options.scales.y.min * .95) || value === 0 && self_1.myCharts[z].options.scales.y.min === 0)) { 564 self_1.myCharts[z].options.scales.y.min = Math.floor(value - Math.
564ceil(range * .05)); 565 } 566 } 567 if (!arraysOfAssociatedPointQuestions[z][index].answers()[datasetIndex]) { 568 console.log("no answer option for this index "); 569 return; 570 } 571 /* else { 572 console.log("datasetIndex = " + datasetIndex); 573 } */ 574 if (data[datasetIndex + 1]) { 575 if (data[datasetIndex - 1]) { 576 //if its in the middle, check value on both ends 577 if (value >= data[datasetIndex + 1][index]) { 578 value = data[datasetIndex + 1][index]; 579 data[datasetIndex][index] = data[datasetIndex + 1][index]; 580 var elementToUpdate_1 = document.getElementById("forecastNumberBox" + arraysOfAssociatedPointQuestions[z][index].answers()[datasetIndex].answerId()); 581 elementToUpdate_1.value = Distiller.numberWithCommas(value); 582 return false; 583 } 584 else if (value <= data[datasetIndex - 1][index]) { 585 value = data[datasetIndex - 1][index]; 586 data[datasetIndex][index] = data[datasetIndex - 1][index]; 587 var elementToUpdate_2 = document.getElementById("forecastNumberBox" + arraysOfAssociatedPointQuestions[z][index].answers()[datasetIndex].answerId()); 588 elementToUpdate_2.value = Distiller.numberWithCommas(value); 589 return false; 590 } 591 } 592 else if (value >= data[datasetIndex + 1][index]) { 593 value = data[datasetIndex + 1][index]; 594 data[datasetIndex][index] = data[datasetIndex + 1][index]; 595 var elementToUpdate_3 = document.getElementById("forecastNumberBox" + arraysOfAssociatedPointQuestions[z][index].answers()[datasetIndex].answerId()); 596 elementToUpdate_3.value = Distiller.numberWithCommas(value); 597 return false; 598 } 599 var elementToUpdate = document.getElementById("forecastNumberBox" + arraysOfAssociatedPointQuestions[z][index].answers()[datasetIndex].answerId()); 600 elementToUpdate.value = Distiller.numberWithCommas(value); 601 } 602 if (data[datasetIndex - 1]) { 603 if (data[datasetIndex + 1]) { 604 if (value >= data[datasetIndex + 1][index]) { 605 value = data[datasetIndex + 1][index]; 606 data[datasetIndex][index] = data[datasetIndex + 1][index]; 607 var elementToUpdate_4 = document.getElementById("forecastNumberBox" + arraysOfAssociatedPointQuestions[z][index].answers()[datasetIndex].answerId()); 608 elementToUpdate_4.value = Distiller.numberWithCommas(value); 609 return false;
610 } 611 else if (value <= data[datasetIndex - 1][index]) { 612 value = data[datasetIndex - 1][index]; 613 data[datasetIndex][index] = data[datasetIndex - 1][index]; 614 var elementToUpdate_5 = document.getElementById("forecastNumberBox" + arraysOfAssociatedPointQuestions[z][index].answers()[datasetIndex].answerId()); 615 elementToUpdate_5.value = Distiller.numberWithCommas(value); 616 return false; 617 } 618 } 619 else if (value <= data[datasetIndex - 1][index]) { 620 value = data[datasetIndex - 1][index]; 621 data[datasetIndex][index] = data[datasetIndex - 1][index]; 622 var elementToUpdate_6 = document.getElementById("forecastNumberBox" + arraysOfAssociatedPointQuestions[z][index].answers()[datasetIndex].answerId()); 623 elementToUpdate_6.value = Distiller.numberWithCommas(value); 624 return false; 625 } 626 var elementToUpdate = document.getElementById("forecastNumberBox" + arraysOfAssociatedPointQuestions[z][index].answers()[datasetIndex].answerId()); 627 elementToUpdate.value = Distiller.numberWithCommas(value); 628 } 629 }, 630 onDragEnd: function (e, datasetIndex, index, value) { 631 if (arraysOfAssociatedPointQuestions[z][index].groundTruth().length > 0) { 632 return false; 633 } 634 var data = dataSetsArray_1.map(function (a) { return a.data; }); 635 if (data[datasetIndex + 1]) { 636 if (value >= data[datasetIndex + 1][index]) { 637 value = data[datasetIndex + 1][index]; 638 data[datasetIndex][index] = data[datasetIndex + 1][index]; 639 } 640 var elementToUpdate = document.getElementById("forecastNumberBox" + arraysOfAssociatedPointQuestions[z][index].answers()[datasetIndex].answerId()); 641 elementToUpdate.value = Distiller.numberWithCommas(value); 642 } 643 if (data[datasetIndex - 1]) { 644 if (value <= data[datasetIndex - 1][index]) { 645 value = data[datasetIndex - 1][index]; 646 data[datasetIndex][index] = data[datasetIndex - 1][index]; 647 } 648 var elementToUpdate = document.getElementById("forecastNumberBox" + arraysOfAssociatedPointQuestions[z][index].answers()[datasetIndex].answerId()); 649 elementToUpdate.value = Distiller.numberWithCommas(value); 650 } 651 arraysOfAssociatedPointQuestions[z][index].answers()[datasetIndex].currentUserForecast(value); 652 if (value > (self_1.maxValueForCE() * .95)) { 653 self_1.maxValueForCE(Math.round(value * 1.2)); 654 } 655 var allData = []; 656 data.forEach(function (set) { 657 allData.push.apply(allData, set); 658 }); 659 if (Math.max.apply(Math, allData) < (self_1.myCharts[z].options.scales.y.max * .6)) { 660 self_1.myCharts[z].options.scales.y.max = (self_1.myCharts[z].options.scales.y.max * .8).toFixed(self_1.pointDecimalPlaces()); 661 self_1.maxValueForCE(self_
6611.myCharts[z].options.scales.y.max); 662 } 663 else if (Math.min.apply(Math, allData) < (self_1.myCharts[z].options.scales.y.min * 1.1) && Math.min.apply(Math, allData) > 0) { 664 self_1.myCharts[z].options.scales.y.min = Math.floor(Math.min.apply(Math, allData) * .95); 665 self_1.yMin(self_1.myCharts[z].options.scales.y.min); 666 } 667 self_1.updateForecastTotal(arraysOfAssociatedPointQuestions[z][index]); 668 } 669 }, 670 legend: { 671 display: true, 672 labels: { 673 font: 'Montserrat' 674 } 675 }, 676 zoom: { 677 limits: { 678 y: { min: self_1.yMin(), max: _this.yMax(), minRange: _this.minZoomRange() } 679 }, 680 pan: { 681 enabled: false, 682 mode: 'y', 683 }, 684 zoom: { 685 wheel: { 686 enabled: _this.zoomEnabled(), 687 }, 688 pinch: { 689 enabled: true 690 }, 691 mode: 'y', 692 onZoom: function () { 693 self_1.setToZero(); 694 } 695 } 696 }, 697 }, 698 responsive: true, 699 animation: false, 700 maintainAspectRatio: false, 701 scales: { 702 y: { 703 title: { 704 display: displayUnits, 705 text: _this.openResponseQuestion().units() 706 }, 707 beginAtZero: true, 708 min: _this.yMin(), 709 max: _this.maxValueForCE(), 710 type: _this.scale(), 711 ticks: { 712 stepSize: _this.pointStepValue(), 713 precision: 0 714 } 715 }, 716 x: { 717 ticks: { 718 display: true /*false */ 719 } 720 } 721 } 722 } 723 }); 724 } 725 } 726 }; 727 for (var z = 0; z < arrayOfElicitations.length; z++) { 728 _loop_2(z); 729 } 730 }; 731 this.drawFloatingBarChart = function () { return __awaiter(_this, void 0, void 0, function () { 732 var arrayOfElicitations, arraysOfAssociatedPointQuestions, displayUnits, _loop_4, this_2, z; 733 return __generator(this, function (_a) { 734 switch (_a.label) { 735 case 0: 736 this.setPointChartBounds(); 737 arrayOfElicitations = []; 738 arraysOfAssociatedPointQuestions = []; 739 if (this.alternativeElicitations().length > 1) { 740 arrayOfElicitations = this.alternativeElicitations(); 741 arraysOfAssociatedPointQuestions = this.arraysOfAssociatedPointQuestions(); 742 } 743 else { 744 //for when there's just one elicitation 745 arrayOfElicitations.push(this.openResponseQuestion()); 746 arraysOfAssociatedPointQuestions.push(this.associatedPointQuestions()); 747 } 748 displayUnits = false;
749 if (this.openResponseQuestion().units()) { 750 displayUnits = true; 751 } 752 _loop_4 = function (z) { 753 var canvas, ctx, binsArray, i, dataSetsArray_2, forecastData, formattedDataSetsArray, labelTooltip, self_2; 754 return __generator(this, function (_b) { 755 switch (_b.label) { 756 case 0: 757 canvas = document.getElementById("inputChartForQ" + arrayOfElicitations[z].questionId()); 758 if (!canvas) return [3 /*break*/, 2]; 759 ctx = canvas.getContext('2d'); 760 binsArray = []; 761 for (i = 0; i < arraysOfAssociatedPointQuestions[z].length; i++) { 762 binsArray.push(arraysOfAssociatedPointQuestions[z][i].name()); 763 } 764 dataSetsArray_2 = []; 765 return [4 /*yield*/, this_2.buildPlaceholderForecasts(arraysOfAssociatedPointQuestions[z])]; 766 case 1: 767 forecastData = _b.sent(); 768 dataSetsArray_2.push.apply(dataSetsArray_2, forecastData); 769 formattedDataSetsArray = this_2.formatDataForBars(dataSetsArray_2); 770 dataSetsArray_2 = formattedDataSetsArray; 771 //evidently we must redraw the chart 772 //to preserve the two-way street between forecasts 773 //and graph plots; without redrawing, changes to forecast value 774 //are NOT reflected in the chart (though changes in the chart ARE still reflected in forecast value) 775 if (this_2.myCharts[z]) { 776 this_2.myCharts[z].destroy(); 777 } 778 labelTooltip = function (tooltipItems) { 779 var label = null; 780 if (tooltipItems.dataset.label.indexOf('_range_') > -1) { 781 label = tooltipItems.dataset.label.slice(0, tooltipItems.dataset.label.indexOf(':')) + ' - Drag the dark blue lines to adjust your forecast.'; 782 } 783 else { 784 label = tooltipItems.dataset.label + ": " + tooltipItems.raw[0]; 785 if (label.indexOf('_endpoint_') > -1) { 786 label = label.slice(0, label.indexOf('_endpoint_')) + label.slice(label.indexOf('_endpoint_') + 10, label.length); 787 } 788 } 789 return label; 790 }; 791 self_2 = this_2; 792 this_2.myCharts[z] = new Chart(ctx, { 793 type: 'bar', 794 data: { 795 labels: binsArray, 796 datasets: dataSetsArray_2 797 }, 798 options: { 799 tension: 0.4, 800 onHover: function (e, el) { 801 if (el[0]) { 802 var currentStyle = canvas.style; 803 currentStyle.cursor = canvas ? 'pointer' : 'normal'; 804 } 805 }, 806 plugins: { 807 tooltip: { 808 yAlign: 'to
808p', 809 callbacks: { 810 label: labelTooltip 811 } 812 }, 813 dragData: { 814 round: 0, //this.pointDecimalPlaces(), 815 showToolTip: true, 816 onDragStart: function (e, element) { 817 //resetting element 818 }, 819 onDrag: function (e, datasetIndex, index, value) { 820 if (value[0] < .0001) { 821 return false; 822 } 823 if (self_2.scale() === 'logarithmic' && value[0] < 1) { 824 return false; 825 } 826 var data = dataSetsArray_2.map(function (a) { return a.data; }); 827 var currentStyle = canvas.style; 828 self_2.draggedChart = true; 829 currentStyle.cursor = canvas ? 'grab' : 'unset'; 830 var range = self_2.myCharts[z].options.scales.y.max - self_2.myCharts[z].options.scales.y.min; 831 var allData = []; 832 data.forEach(function (set) { 833 allData.push.apply(allData, set[0]); 834 allData.push.apply(allData, set[1]); 835 }); 836 var increment = parseFloat(((self_2.yMax() - self_2.yMin()) / 100).toFixed(3)); 837 // if (self.scale() === 'logarithmic') { 838 // let K = Distiller.getK(Math.min(...allData), self.myCharts[z].options.scales.y.max); 839 // let newUpperBound = Distiller.getUpperBound(K, chart.data.datasets[i].data[a][0]); 840 // } 841 // let range = self.myCharts[z].options.scales.y.max - self.myCharts[z].options.scales.y.min; 842 // if (value[1] > (self.myCharts[z].options.scales.y.max * .95)) { 843 if (value[1] > (self_2.myCharts[z].options.scales.y.max - (range * .05))) { 844 self_2.myCharts[z].options.scales.y.max += Math.ceil(((range) * .01)); 845 } 846 //if its the lowest value in the chart 847 if (Math.min.apply(Math, allData) === value[0] || Math.min.apply(Math, allData) === value[1]) { 848 // console.log("updating min! "); 849 if (value[0] < (self_2.myCharts[z].options.scales.y.min + Math.ceil(range * .01)) || value[1] < (self_2.myCharts[z].options.scales.y.min + Math.
849ceil(range * .01)) && value[0] > 0 && value[1] > 0) { 850 if (self_2.scale() === 'linear') { 851 self_2.myCharts[z].options.scales.y.min -= Math.ceil(range * .01); 852 } 853 else { 854 var ordersOfMagnitude = Distiller.getOrdersOfMagnitude(Math.min.apply(Math, allData), Math.max.apply(Math, allData)); 855 if (ordersOfMagnitude < 1) { 856 ordersOfMagnitude = 1; 857 } 858 // let decrement = Math.ceil(range * Math.pow(.01, ordersOfMagnitude)); 859 // self.myCharts[z].options.scales.y.min -= decrement; 860 // console.log("min = " + Math.min(...allData)); 861 // console.log("max = " + Math.max(...allData)); 862 // console.log("ordersOfMagnitude = " + ordersOfMagnitude); 863 // console.log("decrement = " + decrement); 864 } 865 } 866 } 867 var isEndpoint = false; 868 if (dataSetsArray_2[datasetIndex].label.indexOf('_endpoint_') > -1) { 869 isEndpoint = true; 870 } 871 //index is the question 872 var question = arraysOfAssociatedPointQuestions[z][index]; 873 var answerIds = []; 874 //datasetindex is the answer 875 if (isEndpoint) { 876 answerIds.push(question.answers()[datasetIndex / 2].answerId()); 877 if (self_2.scale() === 'logarithmic') { 878 var K = Distiller.getK(Math.min.apply(Math, allData), self_2.yMax()); 879 var newUpperBound = Distiller.getUpperBound(K, value[0]); 880 value[1] = newUpperBound; 881 } 882 } 883 else { 884 var firstIndex = Math.floor(datasetIndex / 2); 885 answerIds.push(question.answers()[firstIndex].answerId()); 886 answerIds.push(question.answers()[firstIndex + 1].answerId()); 887 } 888 var valueArray = data[datasetIndex][index]; 889 /* if (self.scale() === 'logarithmic' && isEndpoint) { 890 console.log("Original " + JSON.stringify(valueArray)); 891 let lowerBound = valueArray[0]; 892 let upperBound = 1.03 * valueArray[0]; 893 let newEndpoint = []; 894 newEndpoint.push(lowerBound); 895 newEndpoint.push(upperBound) 896 data[datasetIndex][index] = newEndpoint; 897 valueArray = data[datasetIndex][index]; 898 console.log("UPDATING " + JSON.stringify(valueArray)); 899 900 } */ 901 //for some reason 902 //value defaults to a bigger range 903 //than it should; so we correct it here... 904 if (isEndpoint && self_2.scale() === 'linear') { 905 value[1] = value[0] + increment; 906 } 907 if (data[datasetIndex + 1]) { 908 if (!isEndpoint) { 909 var newValueAbove = []; 910 //push upper bound of current value for one above 911 newValueAbove.push(valueArray[1]); 912 var upperBound = valueArray[1] + increment; 913 newValueAbove.push(upperBound); 914 data[datasetIndex + 1][index] = newValueAbove; 915 } 916 else { 917 // console.log("is endpoint and has one above"); 918 //adjust the range above 919 data[datasetIndex + 1][index][0] = valueArray[0]; 920 } 921 } 922 if (data[datasetIndex + 2]) { 923 if (valueArray[1] >= data[datasetIndex + 2][index][1]) { 924 return false;
925 } 926 if (!isEndpoint) { 927 data[datasetIndex + 2][index][0] = valueArray[1]; 928 } 929 } 930 if (data[datasetIndex - 1]) { 931 if (!isEndpoint) { 932 var newValueBelow = []; 933 //push upper bound of current value for one above 934 newValueBelow.push(valueArray[0]); 935 var upperBound = valueArray[0] + increment; 936 newValueBelow.push(upperBound); 937 data[datasetIndex - 1][index] = newValueBelow; 938 } 939 else { 940 //adjust the range below 941 data[datasetIndex - 1][index][1] = valueArray[0]; 942 } 943 } 944 if (data[datasetIndex - 2]) { 945 if (valueArray[1] <= data[datasetIndex - 2][index][1]) { 946 return false; 947 } 948 if (!isEndpoint) { 949 data[datasetIndex - 2][index][1] = valueArray[0]; 950 } 951 } 952 for (var i = 0; i < answerIds.length; i++) { 953 var elementToUpdate = document.getElementById("forecastNumberBox" + answerIds[i]); 954 elementToUpdate.value = Distiller.numberWithCommas(valueArray[i]); 955 // console.log("valueAray[i] " + valueArray[i]); 956 // console.log("numberWithCommas = " + Distiller.numberWithCommas(valueArray[i])); 957 } 958 if (self_2.scale() === 'logarithmic') { 959 self_2.updateFloatingBordersForLog(z); 960 } 961 else { 962 self_2.updateFloatingBordersOnZoom(z); 963 } 964 }, 965 onDragEnd: function (e, datasetIndex, index, value) { 966 var data = dataSetsArray_2.map(function (a) { return a.data; }); 967 var increment = parseFloat(((self_2.yMax() - self_2.yMin()) / 100).toFixed(3)); 968 var allData = []; 969 data.forEach(function (set) { 970 allData.push.apply(allData, set[0]); 971 allData.push.apply(allData, set[1]); 972 }); 973 var valueArray = data[datasetIndex][index]; 974 var isEndpoint = false;
975 if (dataSetsArray_2[datasetIndex].label.indexOf('_endpoint_') > -1) { 976 isEndpoint = true; 977 } 978 //index is the question 979 var question = arraysOfAssociatedPointQuestions[z][index]; 980 var answerOptionsToUpdate = []; 981 //datasetindex is the answer 982 if (isEndpoint) { 983 answerOptionsToUpdate.push(question.answers()[datasetIndex / 2]); 984 } 985 else { 986 var firstIndex = Math.floor(datasetIndex / 2); 987 answerOptionsToUpdate.push(question.answers()[firstIndex]); 988 answerOptionsToUpdate.push(question.answers()[firstIndex + 1]); 989 } 990 var range = self_2.myCharts[z].options.scales.y.max - self_2.myCharts[z].options.scales.y.min; 991 if (Math.max.apply(Math, allData) === value[1] || Math.max.apply(Math, allData) === value[1] + increment) { 992 if (value[1] < (self_2.myCharts[z].options.scales.y.max * .6)) { 993 self_2.myCharts[z].options.scales.y.max = Math.floor(self_2.myCharts[z].options.scales.y.max * .8); 994 self_2.maxValueForCE(self_2.myCharts[z].options.scales.y.max); 995 self_2.myCharts[z].update(); 996 } 997 } 998 // else if (Math.min(...allData) < (self.myCharts[z].options.scales.y.min * 1.1) && Math.min(...allData) > 0) { 999 else if (Math.min.apply(Math, allData) < ((range * 1.1) + self_2.myCharts[z].options.scales.y.min) && Math.min.apply(Math, allData) > 0) { 1000 // self.myCharts[z].options.scales.y.min = Math.floor(Math.min(...allData) * .95); 1001 // COME BACK TO THIS JUNE 14 self.myCharts[z].options.scales.y.min -= Math.ceil(range * .05); 1002 // self.yMin(self.myCharts[z].options.scales.y.min); 1003 } 1004 for (var i = 0; i < answerOptionsToUpdate.length; i++) { 1005 answerOptionsToUpdate[i].currentUserForecast(valueArray[i]); 1006 } 1007 self_2.updateForecastTotal(arraysOfAssociatedPointQuestions[z][index]); 1008 if (self_2.scale() === 'logarithmic') { 1009 self_2.updateFloatingBordersForLog(z); 1010 } 1011 else { 1012 self_2.updateFloatingBordersOnZoom(z); 1013 } 1014 } 1015 }, 1016 legend: { 1017 display: false, 1018 }, 1019 zoom: { 1020 limits: { 1021 y: { min: self_2.yMin(), max: this_2.yMax(), minRange: this_2.minZoomRange() } 1022 }, 1023 pan: { 1024 enabled: false, 1025 mode: 'y', 1026 }, 1027 zoom: { 1028 wheel: { 1029 enabled: this_2.zoomEnabled(), 1030 }, 1031 pinch: { 1032 enabled: true 1033 }, 1034 mode: 'y', 1035 onZoom: function () { 1036 self_2.setToZero(); 1037 } 1038 } 1039 }, 1040 }, 1041 responsive: true, 1042 animation: false, 1043 maintainAspectRatio: false, 1044 scales: { 1045 y: { 1046 title: { 1047 display: displayUnits, 1048 text: this_2.openResponseQuestion().units() 1049 }, 1050 stacked: fal
1050se, 1051 beginAtZero: true, 1052 min: this_2.yMin(), 1053 max: this_2.maxValueForCE(), 1054 type: this_2.scale(), 1055 ticks: { 1056 stepSize: this_2.pointStepValue(), 1057 precision: 0 1058 } 1059 }, 1060 x: { 1061 stacked: true, 1062 ticks: { 1063 display: true 1064 } 1065 } 1066 } 1067 } 1068 }); 1069 if (this_2.scale() === 'logarithmic') { 1070 this_2.updateFloatingBordersForLog(z); 1071 } 1072 else { 1073 self_2.updateFloatingBordersOnZoom(z); 1074 } 1075 //when we redraw the chart, we lose the binding I guess 1076 //so we must remind the DOM about this value. 1077 this_2.selectedGraph.valueHasMutated(); 1078 _b.label = 2; 1079 case 2: return [2 /*return*/]; 1080 } 1081 }); 1082 }; 1083 this_2 = this; 1084 z = 0; 1085 _a.label = 1; 1086 case 1: 1087 if (!(z < arrayOfElicitations.length)) return [3 /*break*/, 4]; 1088 return [5 /*yield**/, _loop_4(z)]; 1089 case 2: 1090 _a.sent(); 1091 _a.label = 3; 1092 case 3: 1093 z++; 1094 return [3 /*break*/, 1]; 1095 case 4: return [2 /*return*/]; 1096 } 1097 }); 1098 }); }; 1099 this.formatDataForBars = function (forecasts) { 1100 var dataSetsArray = []; 1101 var userForecasts = forecasts; 1102 if (userForecasts.length > 0) { 1103 var _loop_5 = function (a) { 1104 var userName = userForecasts[0].label; 1105 var userId = userForecasts[0].userId; 1106 var combinedAnswerText = '_range_'; 1107 if (a < userForecasts[0].data.length - 1) { 1108 combinedAnswerText = userName + ": " + userForecasts[0].forecastData[a].answerText + " - " + userForecasts[0].forecastData[a + 1].answerText + "_range_"; 1109 } 1110 var answerText = userName + ": " + userForecasts[0].forecastData[a].answerText; 1111 var pointRadius = 3; 1112 var lineWidth = 1; 1113 var pointHoverRadius = 5; 1114 if (userId == Distiller.currentUser().userId) { 1115 pointRadius = 8; 1116 lineWidth = 3; 1117 pointHoverRadius = 12; 1118 } 1119 var data_2 = []; 1120 var pointData = [];
1121 userForecasts.forEach(function (userQuestionForecast) { 1122 if (a < userForecasts[0].data.length - 1) { 1123 var range = []; 1124 var lowerBound = userQuestionForecast.data[a]; 1125 var upperBound = userQuestionForecast.data[a + 1]; 1126 range.push(lowerBound); 1127 range.push(upperBound); 1128 data_2.push(range); 1129 } 1130 var pointRange = []; 1131 var pointLowerBound = userQuestionForecast.data[a]; 1132 var increment = parseFloat(((_this.yMax() - _this.yMin()) / 100).toFixed(3)); 1133 var pointUpperBound = userQuestionForecast.data[a] + increment; 1134 pointRange.push(pointLowerBound); 1135 pointRange.push(pointUpperBound); 1136 pointData.push(pointRange); 1137 }); 1138 var color = 'rgba(54, 162, 235, .5)'; 1139 if (userForecasts[0].userId !== Distiller.currentUser().userId) { 1140 if (a > 0 && a < userForecasts[0].data.length - 2) { 1141 //leave as is 1142 } 1143 else { 1144 color = 'rgba(54, 162, 235, .3)'; 1145 } 1146 } 1147 else { 1148 color = 'rgba(255,0,0, .5)'; 1149 if (a > 0 && a < userForecasts[0].data.length - 2) { 1150 //leave as is 1151 } 1152 else { 1153 color = 'rgba(255,0,0, .3)'; 1154 } 1155 } 1156 var borderWidth = { 1157 top: 0, 1158 right: 0, 1159 bottom: 0, 1160 left: 0 1161 }; 1162 var pointBorderWidth = { 1163 top: 0, 1164 right: 0, 1165 bottom: 0, 1166 left: 0 1167 }; 1168 var barPercentage = .8; 1169 if (a === 0 || a === userForecasts[0].data.length - 2) { 1170 barPercentage = .2; 1171 } 1172 var rangeLabel = combinedAnswerText; 1173 var endPointLabel = answerText; 1174 var dataSet = { 1175 type: 'bar', 1176 barPercentage: barPercentage, 1177 userId: userId, 1178 timestampRow: userForecasts[0].timestampRow, 1179 historicalId: userForecasts[0].historicalId, 1180 label: rangeLabel, 1181 fill: false, 1182 lineTension: 0.4, 1183 backgroundColor: color, //"rgba(225,0,0,0.4)", 1184 borderColor: 'rgba(54, 162, 235, 1)', 1185 borderCapStyle: 'transparent', 1186 borderDashOffset: 0, 1187 borderJoinStyle: 'transparent', 1188 borderWidth: borderWidth, 1189 pointBorderColor: 'transparent',
1190 pointBackgroundColor: 'transparent', 1191 pointBorderWidth: 0, 1192 pointHoverRadius: pointHoverRadius, 1193 pointHoverBackgroundColor: color, 1194 pointHoverBorderColor: 'white', 1195 pointHoverBorderWidth: 1, 1196 pointRadius: pointRadius, 1197 pointHitRadius: 10, 1198 data: data_2, 1199 spanGaps: true, 1200 hidden: false, 1201 dragData: true, 1202 stack: userId.toString(), 1203 order: 2, 1204 }; 1205 var pointForecastDataSet = { 1206 type: 'bar', 1207 barPercentage: .8, 1208 userId: userId, 1209 timestampRow: userForecasts[0].timestampRow, 1210 historicalId: userForecasts[0].historicalId, 1211 label: endPointLabel + '_endpoint_', 1212 fill: false, 1213 lineTension: 0.4, 1214 backgroundColor: '#003366', //color,//"rgba(225,0,0,0.4)", 1215 borderColor: '#003366', 1216 borderCapStyle: 'transparent', 1217 borderDashOffset: 0, 1218 borderJoinStyle: 'transparent', 1219 borderWidth: pointBorderWidth, 1220 pointBorderColor: 'transparent',
1221 pointBackgroundColor: 'transparent', 1222 pointBorderWidth: 0, 1223 pointHoverRadius: pointHoverRadius, 1224 pointHoverBackgroundColor: color, 1225 pointHoverBorderColor: 'white', 1226 pointHoverBorderWidth: 1, 1227 pointRadius: pointRadius, 1228 pointHitRadius: 10, 1229 data: pointData, 1230 spanGaps: true, 1231 hidden: false, 1232 dragData: true, 1233 stack: userId.toString(), 1234 order: 1, 1235 }; 1236 //first push point in, so the order (from bottom to top) 1237 // will be point, range, point, range, etc. 1238 dataSetsArray.push(pointForecastDataSet); 1239 if (a < userForecasts[0].data.length - 1) { 1240 dataSetsArray.push(dataSet); 1241 } 1242 }; 1243 for (var a = 0; a < userForecasts[0].data.length; a++) { 1244 _loop_5(a); 1245 } 1246 } 1247 return dataSetsArray; 1248 }; 1249 this.pointDecimalPlaces = function () { 1250 if (_this.numberOfDecimalPlaces() > 0 || _this.yMax() < 10) { 1251 if (_this.yMax() < 10 && _this.numberOfDecimalPlaces() > 2) { 1252 return _this.numberOfDecimalPlaces(); 1253 } 1254 else if (_this.yMax() > 10 && _this.numberOfDecimalPlaces() < 2) { 1255 return 2; 1256 } 1257 else { 1258 return _this.numberOfDecimalPlaces(); 1259 } 1260 } 1261 else if (_this.yMax() < 10) { 1262 return 2; 1263 } 1264 else { 1265 return 0; 1266 } 1267 }; 1268 this.pointStepValue = function () { 1269 if (_this.yMax() < 10) { 1270 return .01; 1271 } 1272 else { 1273 // return 1; 1274 var stepSizeUnrounded = Math.round(_this.yMax() / 100); 1275 var numberOfZeros = Distiller.numberOfDigitsInInt(stepSizeUnrounded) - 1; 1276 stepSizeUnrounded = stepSizeUnrounded / (Math.pow(10, numberOfZeros)); 1277 stepSizeUnrounded = Math.round(stepSizeUnrounded); 1278 var stepSizeRounded = stepSizeUnrounded * (Math.pow(10, numberOfZeros)); 1279 return stepSizeRounded; //Math.round(this.yMax() / 100); 1280 } 1281 }; 1282 this.yMin = ko.observable(0); 1283 this.yMax = ko.observable(100); 1284 this.scale = ko.observable("linear"); 1285 this.zoomEnabled = ko.observable(false); 1286 this.minZoomRange = ko.observable(1); 1287 this.toggleLogScale = function () { 1288 if (_this.zoomEnabled()) { 1289 _this.zoomEnabled(false); 1290 } 1291 if (_this.scale() === 'linear') { 1292 _this.scale('logarithmic'); 1293 // this.yMin(0); 1294 _this.drawChart(); 1295 } 1296 else { 1297 _this.scale('linear'); 1298 _this.drawChart(); 1299 } 1300 }; 1301 this.updateFloatingBordersForLog = function (z) { 1302 if (_this.myCharts[z]) { 1303 var chart = _this.myCharts[z]; 1304 // chart.options.scales.y.min = 0; 1305 var actualYMax = chart.options.scales.y.max; 1306 // let actualYMin = 1307 var allData = []; 1308 var arrays = chart.data.datasets.map(function (a) { return a.data; }); 1309 for (var i = 0; i < arrays.length; i++) { 1310 for (var a = 0; a < arrays[i].length; a++) { 1311 allData.push(parseFloat(arrays[i][a])); 1312 } 1313 } 1314 var actualYMin = Math.min.apply(Math, allData); 1315 var K = Distiller.getK(actualYMin, actualYMax); 1316 for (var i = 0; i < chart.data.datasets.length; i++) { 1317 if (chart.data.datasets[i].label.indexOf('_endpoint_') > -1) { 1318 for (var a = 0; a < chart.data.datasets[i].data.length; a++) { 1319 var newEndpoint = []; 1320 var newUpperBound = Distiller.getUpperBound(K, chart.data.datasets[i].data[a][0]); 1321 newEndpoint.push(chart.data.datasets[i].data[a][0]); 1322 newEndpoint.push(newUpperBound); 1323 chart.data.datasets[i].data[a] = newEndpoint; 1324 } 1325 } 1326 }
1327 chart.update(); 1328 } 1329 }; 1330 this.updateFloatingBordersOnZoom = function (z) { 1331 if (_this.myCharts[z]) { 1332 var chart = _this.myCharts[z]; 1333 var actualYMax = chart.options.scales.y.max; 1334 var actualYMin = chart.options.scales.y.min; 1335 var newIncrement = parseFloat(((actualYMax - actualYMin) / 100).toFixed(3)); 1336 for (var i = 0; i < chart.data.datasets.length; i++) { 1337 if (chart.data.datasets[i].label.indexOf('_endpoint_') > -1) { 1338 for (var a = 0; a < chart.data.datasets[i].data.length; a++) { 1339 var newEndpoint = []; 1340 var newUpperBound = chart.data.datasets[i].data[a][0] + newIncrement; 1341 newEndpoint.push(chart.data.datasets[i].data[a][0]); 1342 newEndpoint.push(newUpperBound); 1343 chart.data.datasets[i].data[a] = newEndpoint; 1344 } 1345 } 1346 } 1347 chart.update(); 1348 } 1349 }; 1350 this.toggleZoom = function () { 1351 var index = 0; 1352 if (_this.alternativeElicitations().length > 0) { 1353 index = _this.alternativeElicitations().indexOf(_this.selectedGraph()); 1354 } 1355 var chart = _this.myCharts[index]; 1356 if (chart) { 1357 if (_this.zoomEnabled()) { 1358 _this.zoomEnabled(false); 1359 } 1360 else { 1361 _this.zoomEnabled(true); 1362 } 1363 chart.options.plugins.zoom.zoom.wheel.enabled = !chart.options.plugins.zoom.zoom.wheel.enabled; 1364 chart.options.plugins.zoom.zoom.pinch.enabled = !chart.options.plugins.zoom.zoom.pinch.enabled; 1365 chart.update(); 1366 } 1367 }; 1368 this.setToZero = function () { 1369 var index = 0; 1370 if (_this.alternativeElicitations().length > 0) { 1371 index = _this.alternativeElicitations().indexOf(_this.selectedGraph()); 1372 } 1373 if (_this.myCharts[index]) { 1374 _this.myCharts[index].pan((-1 * _this.yMax())); 1375 } 1376 }; 1377 this.allSims = ko.observableArray([ 1378 "Critter World", 1379 "AB Street", 1380 "Goofspiel", 1381 "Hanabi", 1382 "Othello", 1383 "Pathwayz", 1384 "Skylines", 1385 "Stratego" 1386 ]); 1387 this.selectedRating = function (question, comment) { 1388 for (var i = 0; i < question.answers().length; i++) { 1389 var ratingIsSelected = _this.ratingIsSelected(question, comment, question.answers()[i])(); 1390 if (ratingIsSelected) { 1391 return question.answers()[i]; 1392 } 1393 else if (i === question.answers().length - 1) { 1394 return null; 1395 } 1396 } 1397 }; 1398 this.showingSimDropdownFor = ko.observable(null); 1399 this.toggleSimDropdown = function () { 1400 if (_this.showingSimDropdownFor() === _this.openResponseQuestion().questionId()) { 1401 _this.showingSimDropdownFor(null); 1402 } 1403 else { 1404 _this.showingSimDropdownFor(_this.openResponseQuestion().questionId()); 1405 } 1406 }; 1407 this.selectedSim = ko.observable(null); 1408 this.selectSim = function (sim) { 1409 _this.selectedSim(sim); 1410 if (sim === 'Critter World') { 1411 Distiller.addStyle('/style/css/sim_critterworld.css'); 1412 } 1413 if (sim === 'AB Street') { 1414 Distiller.addStyle('/style/css/sim_abstreet.css'); 1415 } 1416 if (sim === 'Goofspiel') { 1417 Distiller.addStyle('/style/css/sim_goofspiel.css'); 1418 } 1419 if (sim === 'Hanabi') { 1420 Distiller.addStyle('/style/css/sim_hanabi.css'); 1421 } 1422 if (sim === 'Othello') { 1423 Distiller.addStyle('/style/css/sim_othello.css'); 1424 } 1425 if (sim === 'Pathwayz') { 1426 Distiller.addStyle('/style/css/sim_pathwayz.css'); 1427 } 1428 if (sim === 'Skylines') { 1429 Distiller.addStyle('/style/css/sim_skylines.css'); 1430 } 1431 if (sim === 'Stratego') { 1432 Distiller.addStyle('/style/css/sim_stratego.css'); 1433 } 1434 _this.toggleSimDropdown(); 1435 }; 1436 this.ratingIsSelected = function (question, comment, answer) { return ko.pureComputed(function () { 1437 if (comment.ratings()) { 1438 //get all the promptIds of current user ratings for this comment 1439 var currentUserRatingForComment = null; // DEPRECATED comment.ratings().currentUserRatings.filter(element => element.promptId === question.questionId())[0]; 1440 if (currentUserRatingForComment) { 1441 if (currentUserRatingForComment.ratingAnswerId === answer.answerId()) { 1442 return true; 1443 } 1444 else { 1445 return false;
1446 } 1447 } 1448 else { 1449 return false; 1450 } 1451 } 1452 }, _this); }; 1453 this.submitWithEnterKey = function (data, event) { 1454 if (event.which == 13) { 1455 _this.sendCurrentUserRationale(); 1456 } 1457 }; 1458 this.checkAllQuestions = function () { 1459 var finalResponse = { 1460 incomplete: [] 1461 }; 1462 //time series and alternative elicitations 1463 if (_this.arraysOfAssociatedPointQuestions().length > 0) { 1464 _this.arraysOfAssociatedPointQuestions().forEach(function (array) { 1465 array.forEach(function (question) { 1466 if (question.groundTruth().length === 0) { 1467 if (question.type() === 1 || question.type() === 18) { 1468 if (Distiller.sumArray(question.answers().map(function (a) { return a.currentUserForecast(); })) !== 100 && question.answers().length > 1) { 1469 finalResponse.incomplete.push(question.name()); 1470 } 1471 } 1472 else { 1473 if (question.answers().filter(function (a) { return a.currentUserForecast() === null; }).length > 0 && question.answers().length > 1) { 1474 finalResponse.incomplete.push(question.name()); 1475 } 1476 } 1477 } 1478 }); 1479 }); 1480 } 1481 //alternative elicitations but no timeseries 1482 else if (_this.alternativeElicitations().length > 0) { 1483 _this.alternativeElicitations().forEach(function (question) { 1484 if (question.groundTruth().length === 0) { 1485 if (question.type() === 1 || question.type() === 18) { 1486 if (Distiller.sumArray(question.answers().map(function (a) { return a.currentUserForecast(); })) !== 100 && question.answers().length > 1) { 1487 finalResponse.incomplete.push(question.name()); 1488 } 1489 } 1490 else { 1491 if (question.answers().filter(function (a) { return a.currentUserForecast() === null; }).length > 0 && question.answers().length > 1) { 1492 finalResponse.incomplete.push(question.name()); 1493 } 1494 } 1495 } 1496 }); 1497 } 1498 //time series but not alternative elicitations 1499 else if (_this.associatedPointQuestions().length > 0) { 1500 _this.associatedPointQuestions().forEach(function (question) { 1501 if (question.groundTruth().length === 0) { 1502 if (question.type() === 1 || question.type() === 18) { 1503 if (Distiller.sumArray(question.answers().map(function (a) { return a.currentUserForecast(); })) !== 100 && question.answers().length > 1) { 1504 finalResponse.incomplete.push(question.name()); 1505 } 1506 } 1507 else { 1508 if (question.answers().filter(function (a) { return a.currentUserForecast() === null; }).length > 0 && question.answers().length > 1) { 1509 finalResponse.incomplete.push(question.name()); 1510 } 1511 } 1512 } 1513 }); 1514 } 1515 // no time series and no alternative elicitations 1516 else { 1517 if (_this.openResponseQuestion().type() === 1 || _this.openResponseQuestion().type() === 18 && _this.openResponseQuestion().groundTruth().length === 0) { 1518 if (Distiller.sumArray(_this.openResponseQuestion().answers().map(function (a) { return a.currentUserForecast(); })) !== 100 && _this.openResponseQuestion().answers().length > 1) { 1519 finalResponse.incomplete.push(_this.openResponseQuestion().name()); 1520 } 1521 } 1522 else { 1523 if (_this.openResponseQuestion().answers().filter(function (a) { return a.currentUserForec
1523ast() === null; }).length > 0 && _this.openResponseQuestion().answers().length > 1 && _this.openResponseQuestion().groundTruth().length === 0) { 1524 finalResponse.incomplete.push(_this.openResponseQuestion().name()); 1525 } 1526 } 1527 } 1528 return finalResponse; 1529 }; 1530 this.checkIfQuestionsTouched = function () { 1531 var finalResponse = { 1532 noForecast: [] 1533 }; 1534 //time series and alternative elicitations 1535 if (_this.arraysOfAssociatedPointQuestions().length > 0) { 1536 _this.arraysOfAssociatedPointQuestions().forEach(function (array) { 1537 array.forEach(function (question) { 1538 var currentForecasts = question.answers().map(function (a) { return a.currentUserForecast(); }); 1539 if (question.savedCurrentForecast()[0] === null) { 1540 finalResponse.noForecast.push(question); 1541 } 1542 else if (Distiller.arraysAreEqual(currentForecasts, question.savedCurrentForecast())) { 1543 //this is where we can detect if they are not touched but HAVE a saved forecast 1544 } 1545 }); 1546 }); 1547 } 1548 //alternative elicitations but no timeseries 1549 /*else if (this.alternativeElicitations().length > 0) { 1550 this.alternativeElicitations().forEach(question => { 1551 let currentForecasts = question.answers().map(a => a.currentUserForecast()); 1552 if (question.savedCurrentForecast()[0] === null) { 1553 finalResponse.noForecast.push(question); 1554 1555 } 1556 }); 1557 } 1558 //time series but not alternative elicitations 1559 else if (this.associatedPointQuestions().length > 0) { 1560 this.associatedPointQuestions().forEach(question => { 1561 if (Distiller.sumArray(question.answers().map(a => a.currentUserForecast())) !== 100) { 1562 finalResponse.notOneHundred.push(question.name()) 1563 } 1564 }); 1565 } 1566 // no time series and no alternative elicitations 1567 else { 1568 if (Distiller.sumArray(this.openResponseQuestion().answers().map(a => a.currentUserForecast())) !== 100) { 1569 finalResponse.notOneHundred.push(this.openResponseQuestion().name()) 1570 } 1571 } 1572 */ 1573 return finalResponse; 1574 }; 1575 this.saveForecastAndRationale = function (question) { return __awaiter(_this, void 0, void 0, function () { 1576 var questionTotalData, textForTeamQuestion_1, questions, index, i, defaultCount, q, defaultCount, i, i, relatedTeamQuestionSets, relatedTeamQuestion_1, i, imageURLs, self_3, incompleteQuestionsString_1; 1577 return __generator(this, function (_a) { 1578 switch (_a.label) { 1579 case 0: 1580 this.processingButton(question.questionId()); 1581 questionTotalData = { 1582 incomplete: [] 1583 }; 1584 if (question.type() === 1 || question.type() === 18 || question.type() === 11) { 1585 questionTotalData = this.checkAllQuestions(); 1586 } 1587 if ((Distiller.client() === 'grossmann' && this.customGrossmannError()() && this.customGrossmannError()() !== '') || !this.pointsAreOrderedCorrectly()()) { 1588 this.processingButton(null); 1589 alert("Oops! You must address the errors in red before you may save this entry."); 1590 return [2 /*return*/]; 1591 } 1592 if (!(questionTotalData.incomplete.length === 0)) return [3 /*break*/, 16]; 1593 textForTeamQuestion_1 = this.newText(); 1594 questions = []; 1595 if (!(this.arraysOfAssociatedPointQuestions().length > 0)) return [3 /*break*/, 5]; 1596 index = this.alternativeElicitations().indexOf(this.selectedGraph()); 1597 i = 0; 1598 _a.label = 1; 1599 case 1: 1600 if (!(i < this.arraysOfAssociatedPointQuestions().length)) return [3 /*break*/, 4]; 1601 defaultCount = 0; 1602 for (q = 0; q < this.arraysOfAssociatedPointQuestions()[i].length; q++) { 1603 if (Distiller.arraysAreEqual(Distiller.defaultForecast(this.arraysOfAssociatedPointQuestions()[i][q]), this.arraysOfAssociatedPointQuestions()[i][q].answers().map(function (a) { return a.currentUserForec
1603ast(); }))) { 1604 defaultCount++; 1605 } 1606 if (defaultCount === this.arraysOfAssociatedPointQuestions()[i].length) { 1607 alert("Oops! It looks like you haven't inputted a forecast for one of the prompts. Click through the tabs at the top of the input graph to make sure you've forecasted on all prompts before proceeding."); 1608 this.processingButton(null); 1609 return [2 /*return*/]; 1610 } 1611 // this.saveForecastAsync(this.arraysOfAssociatedPointQuestions()[i][q]); 1612 questions.push(this.arraysOfAssociatedPointQuestions()[i][q]); 1613 } 1614 if (!(i === this.arraysOfAssociatedPointQuestions().length - 1)) return [3 /*break*/, 3]; 1615 return [4 /*yield*/, this.saveForecastsAndRationalesAsync(questions)]; 1616 case 2: 1617 _a.sent(); 1618 _a.label = 3; 1619 case 3: 1620 i++; 1621 return [3 /*break*/, 1]; 1622 case 4: return [3 /*break*/, 11]; 1623 case 5: 1624 if (!(this.associatedPointQuestions().length > 0)) return [3 /*break*/, 7]; 1625 defaultCount = 0; 1626 for (i = 0; i < this.associatedPointQuestions().length; i++) { 1627 if (Distiller.arraysAreEqual(Distiller.defaultForecast(this.associatedPointQuestions()[i]), this.associatedPointQuestions()[i].answers().map(function (a) { return a.currentUserForecast(); }))) { 1628 defaultCount++; 1629 } 1630 if (defaultCount === this.associatedPointQuestions().length) { 1631 alert("Oops! It looks like you haven't inputted a forecast. Please input a forecast before saving."); 1632 this.processingButton(null); 1633 return [2 /*return*/]; 1634 } 1635 questions.push(this.associatedPointQuestions()[i]); 1636 } 1637 return [4 /*yield*/, this.saveForecastsAndRationalesAsync(questions)]; 1638 case 6: 1639 _a.sent(); 1640 return [3 /*break*/, 11]; 1641 case 7: 1642 if (!(this.alternativeElicitations().length > 0)) return [3 /*break*/, 9]; 1643 for (i = 0; i < this.alternativeElicitations().length; i++) { 1644 if (Distiller.arraysAreEqual(Distiller.defaultForecast(this.alternativeElicitations()[i]), this.alternativeElicitations()[i].answers().map(function (a) { return a.currentUserForecast(); }))) { 1645 alert("Oops! It looks like you haven't inputted a forecast. Please input a forecast before saving."); 1646 this.processingButton(null); 1647 return [2 /*return*/]; 1648 } 1649 questions.push(this.alternativeElicitations()[i]); 1650 } 1651 return [4 /*yield*/, this.saveForecastsAndRationalesAsync(questions)]; 1652 case 8: 1653 _a.sent(); 1654 return [3 /*break*/, 11]; 1655 case 9: 1656 if (Distiller.arraysAreEqual(Distiller.defaultForecast(question), question.answers().map(function (a) { return a.currentUserForecast(); }))) { 1657 alert("Oops! It looks like you haven't inputted a forecast. Please input a forecast before saving."); 1658 this.processingButton(null); 1659 return [2 /*return*/]; 1660 } 1661 return [4 /*yield*/, this.saveForecastAsync(question)]; 1662 case 10: 1663 _a.sent(); 1664 _a.label = 11; 1665 case 11: 1666 if (textForTeamQuestion_1) { 1667 console.log("doiing this separately "); 1668 this.sendCurrentUserRationale(); 1669 } 1670 relatedTeamQuestionSets = Distiller.questionSets().filter(function (a) { return a.parentId() === question.questionId(); }); 1671 if (!(relatedTeamQuestionSets.length > 0)) return [3 /*break*/, 15]; 1672 relatedTeamQuestion_1 = relatedTeamQuestionSets[
16720].surveyQuestions()[0]; 1673 i = 0; 1674 _a.label = 12; 1675 case 12: 1676 if (!(i < relatedTeamQuestion_1.answers().length)) return [3 /*break*/, 15]; 1677 relatedTeamQuestion_1.answers()[i].currentUserForecast(question.answers()[i].currentUserForecast()); 1678 if (!(i === relatedTeamQuestion_1.answers().length - 1)) return [3 /*break*/, 14]; 1679 return [4 /*yield*/, this.saveForecastAsync(relatedTeamQuestion_1)]; 1680 case 13: 1681 _a.sent(); 1682 imageURLs = null; 1683 self_3 = this; 1684 if (textForTeamQuestion_1) { 1685 Distiller.httpSendAsync(Distiller.apiEndpoint + "/api/sendCurrentRationale/" + Distiller.currentUser().userId + "/" + relatedTeamQuestion_1.questionId() + "/" + imageURLs + "/" + '1', textForTeamQuestion_1, function (response) { 1686 return __awaiter(this, void 0, void 0, function () { 1687 var parsedResponse, newComment; 1688 return __generator(this, function (_a) { 1689 parsedResponse = JSON.parse(response); 1690 if (parsedResponse.commentId) { 1691 newComment = Distiller.buildNewComment(relatedTeamQuestion_1, parsedResponse.commentId, textForTeamQuestion_1, null); 1692 if (relatedTeamQuestion_1.currentUserRationales().map(function (a) { return a.commentId(); }).indexOf(newComment.commentId()) < 0) { 1693 relatedTeamQuestion_1.currentUserRationales.push(newComment); 1694 } 1695 relatedTeamQuestion_1.teammateComments.push(newComment); 1696 } 1697 else { 1698 alert("Oops! Something went wrong. Please email [email protected] to report this issue. Include a screenshot if you can. Many thanks in advance."); 1699 } 1700 return [2 /*return*/]; 1701 }); 1702 }); 1703 }); 1704 } 1705 _a.label = 14; 1706 case 14: 1707 i++; 1708 return [3 /*break*/, 12]; 1709 case 15: return [3 /*break*/, 17]; 1710 case 16: 1711 incompleteQuestionsString_1 = ''; 1712 questionTotalData.incomplete.forEach(function (questionName) { 1713 incompleteQuestionsString_1 += questionName; 1714 incompleteQuestionsString_1 += '\n\n'; 1715 }); 1716 this.processingButton(null); 1717 if (question.type() === 1 || question.type() === 18) { 1718 alert("Oops! Your forecast does not sum to 100% on the following question(s):\n\n" + incompleteQuestionsString_1); 1719 } 1720 else { 1721 alert("Oops! You have not submitted a forecast for the following questions:\n\n" + incompleteQuestionsString_1); 1722 } 1723 _a.label = 17; 1724 case 17: return [2 /*return*/]; 1725 } 1726 }); 1727 }); }; 1728 this.saveForecastAndRationaleConsensus = function (question) { return __awaiter(_this, void 0, void 0, function () { 1729 var textForTeamQuestion; 1730 return __generator(this, function (_a) { 1731 switch (_a.label) { 1732 case 0: 1733 textForTeamQuestion = this.newText(); 1734 return [4 /*yield*/, this.saveForecastConsensusAsync(question)]; 1735 case 1: 1736 _a.sent(); 1737 if (textForTeamQuestion) { 1738 this.sendCurrentUserRationale(); 1739 } 1740 return [2 /*return*/]; 1741 } 1742 }); 1743 }); }; 1744 this.sendCurrentUserRationale = function () { 1745 _this.processingButton(_this.openResponseQuestion().questionId()); 1746 var imageURLs = null; 1747 if (Distiller.pendingUploadURLs().length > 0) { 1748 imageURLs = encodeURIComponent(Distiller.pendingUploadURLs().toString()); 1749 } 1750 else if (Distiller.pendingTopURLs().length > 0) { 1751 imageURLs = encodeURIComponent(Distiller.pendingTopURLs().toString()); 1752 } 1753 var self = _this; 1754 if (!self.newText()) { 1755 return; 1756 } 1757 var textFile = { 1758 newText: self.newText(), 1759 newDelta: JSON.stringify(self.newDelta()) 1760 }; 1761 var type = 1; 1762 if (_this.openResponseQuestion().type() === 5) { 1763 type = 2; 1764 } 1765 Distiller.httpSendAsync(Distiller.apiEndpoint + "/api/sendCurrentRationale/" + Distiller.currentUser().userId + "/" + self.openResponseQuestion().questionId() + "/" + imageURLs + "/" + type, JSON.stringify(textFile), function (response) { 1766 return __awaiter(this, void 0, void 0, function () { 1767 var parsedResponse, newComment; 1768 return __generator(this, function (_a) { 1769 self.processingButton(null); 1770 if (self.openResponseQuestion().type() === 12 && document.getElementById("listInput_" + self.openResponseQuestion().questionId())) { 1771 document.getElementById("listInput_" + self.openResponseQuestion().questionId()).focus(); 1772 } 1773 parsedResponse = JSON.parse(response); 1774 if (parsedResponse.commentId) { 1775 newComment = Distiller.buildNewComment(self.openResponseQuestion(), parsedResponse.commentId, self.newText(), self.newDelta()); 1776 self.newText(null); 1777 self.newDelta(null); 1778 self.openResponseQuestion().currentUserRationales.unshift(newComment); 1779 self.openResponseQuestion().teammateComments.unshift(newComment); 1780 if (self.openResponseQuestion().type() === 5) { 1781 self.allWikis.push(newComment); 1782 self.myVisibleWiki(self.allWikis()[self.allWikis().length - 1]); 1783 } 1784 } 1785 else { 1786 alert("Oops! Something went wrong. Please email [email protected] to report this issue. Include a screenshot if you can. Many thanks in advance."); 1787 } 1788 return [2 /*return*/]; 1789 }); 1790 }); 1791 }); 1792 }; 1793 this.combinedQuestions = ko.observableArray([]); 1794 this.relatedRatingQuestions = function (questionId) { 1795 // let relatedRatingQuestions = this.combinedQuestions().filter(element => element.primaryQuestionIds().indexOf(questionId) > -1); 1796 //new april 11 2021 only one rating prompt per list 1797 var relatedRatingQuestions = _this.combinedQuestions().filter(function (element) { return element.primaryQuestionIds().indexOf(questionId) > -1 && element.name() === _this.openResponseQuestion().name(); }); 1798 return relatedRatingQuestions; 1799 }; 1800 this.relatedACHQuestions = function (questionId) { 1801 var relatedRatingQuestions = _this.combinedQuestions().filter(function (element) { return element.primaryQuestionIds().indexOf(questionId) > -1; }); 1802 return relatedRatingQuestions; 1803 }; 1804 /* DEPRECATED public submitRating = (question: IQuestion, answer: IAnswerOption, comment: IQuestionComment) => { 1805 1806 //update UI 1807 let currentUserRatingForComment = comment.ratings().currentUserRatings.filter(element => element.promptId === question.questionId())[0]; 1808 1809 let newRating = { 1810 userId: Distiller.currentUser().userId, 1811 promptId: question.questionId(), 1812 ratingAnswerId: answer.answerId(), 1813 commentId: comment.commentId() 1814 } 1815 1816 if (currentUserRatingForComment) { 1817 let indexToSplice = comment.ratings().currentUserRatings.indexOf(currentUserRatingForComment); 1818 comment.ratings().currentUserRatings.splice(indexToSplice, 1, newRating); 1819 } 1820 else {
1821 comment.ratings().currentUserRatings.push(newRating); 1822 comment.ratings().teammateRatings.push(newRating); 1823 } 1824 1825 //force our isSelected computed to reevaluate. 1826 //we need this unfortunately because the values within ratings are not 1827 //ko observables 1828 comment.ratings.valueHasMutated(); 1829 1830 let self = this; 1831 let rating = answer.answerId(); 1832 let commentId = comment.commentId(); 1833 1834 Distiller.httpPostAsync(Distiller.apiEndpoint + "/api/submitRating/" + Distiller.currentUser().userId + "/" + question.questionId() + "/" + commentId + "/" + rating, async function (response) { 1835 // submit rating response? 1836 self.dismissACHDropdown(); 1837 }); 1838 1839 } */ 1840 //below this line relates to forecasting stuff... we could break it out into its own ViewModel.. 1841 this.selectMCAnswerOption = function (question, answerOption) { return __awaiter(_this, void 0, void 0, function () { 1842 var i; 1843 return __generator(this, function (_a) { 1844 switch (_a.label) { 1845 case 0: 1846 if (question.text().indexOf('all that apply') < 0) { 1847 i = 0; 1848 question.answers().forEach(function (answer) { 1849 if (answer.currentUserForecast() > 0 && answer != answerOption) { 1850 answer.currentUserForecast(0); 1851 } 1852 }); 1853 } 1854 if (answerOption.currentUserForecast() === 0 || answerOption.currentUserForecast() === null) { 1855 answerOption.currentUserForecast(1); 1856 } 1857 else { 1858 answerOption.currentUserForecast(0); 1859 } 1860 return [4 /*yield*/, this.saveForecastAsync(question)]; 1861 case 1: 1862 _a.sent(); 1863 return [2 /*return*/]; 1864 } 1865 }); 1866 }); }; 1867 this.mcAttempts = ko.observableArray([]); 1868 //assigns 1 of 4 potential statuses to a question: 1869 //1) incomplete, 2) not applicable (if there is no ground truth) 1870 //3) correct, or 4) incorrect 1871 this.questionStatus = function (question) { return ko.pureComputed(function () { 1872 var userSelections = question.answers().filter(function (a) { return a.currentUserForecast() > 0; }); 1873 var currentUserForecast = question.answers().map(function (a) { return a.currentUserForecast(); }); 1874 var savedCurrentForecast = question.savedCurrentForecast(); 1875 if (Distiller.arraysAreEqual(currentUserForecast, savedCurrentForecast)) { 1876 if (question.type() === 14) { 1877 if (question.groundTruth().length > 0) { 1878 if (question.savedCurrentForecast().length > 0) { 1879 if (question.savedCurrentForecast()[0] === question.groundTruth()[0].outcome()) { 1880 return 'correct'; 1881 } 1882 else { 1883 return 'incorrect'; 1884 } 1885 } 1886 else { 1887 return 'incomplete'; 1888 } 1889 } 1890 else { 1891 return 'not applicable'; 1892 } 1893 } 1894 else { 1895 if (userSelections.length < question.groundTruth().length) { 1896 return 'incomplete'; 1897 } 1898 else if (question.groundTruth().length === 0) { 1899 return 'not applicable'; 1900 } 1901 else { 1902 var correctSubmissions = []; 1903 var correctAnswers = question.groundTruth().filter(function (a) { return a.outcome() > 0; }); 1904 var _loop_6 = function (i) { 1905 var userSelection = question.answers().filter(function (a) { return a.answerId() === question.groundTruth()[i].answerId(); }); 1906 if (userSelection.length > 0) { 1907 if (userSelection[0].currentUserForec
1907ast() === question.groundTruth()[i].outcome()) { 1908 correctSubmissions.push(userSelection[0].answerId); 1909 } 1910 if (i === question.groundTruth().length - 1) { 1911 if (correctAnswers.length === correctSubmissions.length && userSelections.length === correctAnswers.length) { 1912 return { value: 'correct' }; 1913 } 1914 else { 1915 return { value: 'incorrect' }; 1916 } 1917 } 1918 } 1919 else { 1920 if (i === question.groundTruth().length - 1) { 1921 if (correctAnswers.length === correctSubmissions.length && userSelections.length === correctAnswers.length) { 1922 return { value: 'correct' }; 1923 } 1924 else { 1925 return { value: 'incorrect' }; 1926 } 1927 } 1928 } 1929 }; 1930 for (var i = 0; i < question.groundTruth().length; i++) { 1931 var state_1 = _loop_6(i); 1932 if (typeof state_1 === "object") 1933 return state_1.value; 1934 } 1935 } 1936 } 1937 } 1938 else { 1939 return 'not applicable'; 1940 } 1941 }, _this); }; 1942 //THIS IS RAYTHEON-SPECIFIC. NEED TO BLOCK IT FOR OTHER USE CASES 1943 this.addPlaceholderComment = function (question, userId) { 1944 Distiller.httpPostAsync(Distiller.apiEndpoint + "/api/addPlaceholderComment/" + Distiller.currentUser().userId + "/" + question.questionId(), function (response) { 1945 return __awaiter(this, void 0, void 0, function () { 1946 var parsedResponse, newText, newComment; 1947 return __generator(this, function (_a) { 1948 parsedResponse = JSON.parse(response); 1949 if (parsedResponse.insertId) { 1950 newText = 'placeholder_for_numeric_question'; 1951 newComment = Distiller.buildNewComment(question, parsedResponse.insertId, newText, null); 1952 question.currentUserRationales.push(newComment); 1953 question.teammateComments.push(newComment); 1954 } 1955 return [2 /*return*/]; 1956 }); 1957 }); 1958 }); 1959 }; 1960 this.toggleEditView = function () { 1961 if (Distiller.editingQuestion()) { 1962 if (Distiller.editingQuestion().questionId() === _this.openResponseQuestion().questionId()) { 1963 Distiller.editingQuestion(null); 1964 } 1965 else { 1966 Distiller.editingQuestion(_this.openResponseQuestion()); 1967 } 1968 } 1969 else { 1970 Distiller.editingQuestion(_this.openResponseQuestion()); 1971 } 1972 }; 1973 this.saveForecastCheckTotal = function (question) { return __awaiter(_this, void 0, void 0, function () { 1974 return __generator(this, function (_a) { 1975 switch (_a.label) { 1976 case 0: 1977 if (!(question.forecastTotal() === 100 || question.answers().length === 1 || question.type() === 11)) return [3 /*break*/, 2]; 1978 return [4 /*yield*/, this.saveForecastAndRationale(question)]; 1979 case 1: 1980 _a.sent(); 1981 return [3 /*break*/, 3]; 1982 case 2: 1983 alert("Oops! It looks like your forecast does not sum to 100%. Please ensure your forecast sums to 100% before saving it."); 1984 _a.label = 3; 1985 case 3: return [2 /*return*/]; 1986 } 1987 }); 1988 }); }; 1989 this.binWidth = function (question) { 1990 var denominator = question.answers().length; 1991 if (_this.associatedPointQuestions().length > 0) { 1992 denominator = _this.associatedPointQuestions().length; 1993 } 1994 var width = 100 / denominator - 1.2; 1995 if (denominator > 10) { 1996 width = (100 / denominator) * .78; 1997 // width = (100 / denominator) * .95; 1998 } 1999 _this.updateForecastTotal(question); 2000 return width; 2001 }; 2002 this.observableProbBinContainerWidth = ko.observable(null); 2003 this.observableProbBinWidth = ko.observable(null); 2004 this.setProbBinWidth = function () { 2005 var width = 100; 2006 if ((_this.openResponseQuestion().type() === 1 || _this.openResponseQuestion().type() === 18) && _this.openResponseQuestion().answers().length > 0) { 2007 var label = document.getElementById('pointForecastLabel' + _this.openResponseQuestion().questionId()); 2008 var labelWidth = 115; 2009 if (label) { 2010 labelWidth = label.offsetWidth + 10; 2011 } 2012 width = _this.observableProbBinContainerWidth() - labelWidth; 2013 if (width <= 60) { 2014 width = 60; 2015 } 2016 _this.observableProbBinWidth(width); 2017 } 2018 else { 2019 _this.observableProbBinWidth(width); 2020 } 2021 }; 2022 this.setProbBinContainerWidth = function () { 2023 var width = 100; 2024 if ((_this.openResponseQuestion().type() === 1 || _this.openResponseQuestion().type() === 18) && _this.openResponseQuestion().answers().length > 0) { 2025 var element = document.getElementById('graphSliderContainer' + _this.openResponseQuestion().questionId()); 2026 if (element) { 2027 width = element.offsetWidth - 40; 2028 width = width * .01 * _this.binWidth(_this.openResponseQuestion()); 2029 } 2030 _this.observableProbBinContainerWidth(width); 2031 } 2032 else { 2033 _this.observableProbBinContainerWidth(width); 2034 } 2035 }; 2036 this.observablePointBinContainerWidth = ko.observable(100); 2037 this.labelWidth = ko.observable(90); 2038 this.setPointBinContainerWidth = function () { 2039 //trying to fix it here so I can apply EVERYWHERE soon 2040 if (Distiller.client() === 'grossmann') { 2041 var numberOfContainers = _this.associatedPointQuestions().length; 2042 if (_this.arraysOfAssociatedPointQuestions().length > 0) { 2043 numberOfContainers = _this.arraysOfAssociatedPointQuestions()[0].length; 2044 } 2045 var element = document.getElementById('graphSliderContainer' + _this.openResponseQuestion().questionId()); 2046 var label = document.getElementById('pointForecastLabel' + _this.openResponseQuestion().questionId()); 2047 if (element && label) { 2048 var marginTotal = 20 * (numberOfContainers + 1); 2049 var width = (element.offsetWidth - label.offsetWidth - marginTotal) / numberOfContainers; 2050 _this.labelWidth(label.offsetWidth); 2051 _this.observablePointBinContainerWidth(width); 2052 } 2053 } 2054 else { 2055 // console.log("setting point bin container width"); 2056 var width = 100; 2057 if ((_this.openResponseQuestion().type() === 1 || _this.openResponseQuestion().type() === 18 || _this.openResponseQuestion().type() === 11) 2058 && _this.openResponseQuestion().answers().length > 0) { 2059 var element = document.getElementById('graphSliderContainer' + _this.openResponseQuestion().questionId()); 2060 if (element) { 2061 width = element.offsetWidth - 40; 2062 width = width * .01 * _this.binWidth(_this.openResponseQuestion()); 2063 } 2064 _this.observablePointBinContainerWidth(width); 2065 } 2066 else { 2067 _this.observablePointBinContainerWidth(width); 2068 } 2069 } 2070 }; 2071 this.observablePointBinWidth = ko.observable(100); 2072 this.setPointBinWidth = function () { 2073 var width = 100; 2074 if ((_this.openResponseQuestion().type() === 1 || _this.openResponseQuestion().type() === 18 || _this.openResponseQuestion().type() === 11) 2075 && _this.openResponseQuestion().answers().length > 0) { 2076 var label = document.getElementById('pointForecastLabel' + _this.openResponseQuestion().questionId()); 2077 var labelWidth = 115; 2078 if (label) { 2079 labelWidth = label.offsetWidth + 10; 2080 } 2081 if (labelWidth > 160) { 2082 labelWidth = 160; 2083 } 2084 width = _this.observablePointBinContainerWidth() - labelWidth;
2085 //weird edge case when there are 2 bins, we want to make the min width bigger (?) 2086 if (_this.arraysOfAssociatedPointQuestions().length === 0 && _this.associatedPointQuestions().length === 0) { 2087 if (_this.openResponseQuestion().answers().length < 3) { 2088 if (width <= 120) { //was 60 and 60 below too 2089 width = 120; //should set this as a function of the number of bins 2090 } 2091 } 2092 } 2093 _this.observablePointBinWidth(width); 2094 } 2095 else { 2096 _this.observablePointBinWidth(width); 2097 } 2098 }; 2099 /* public pointChartBinWidth = (question: IQuestion) => { 2100 2101 let denominator = question.answers().length; 2102 if (this.associatedPointQuestions().length > 0) { 2103 denominator = this.associatedPointQuestions().length; 2104 } 2105 2106 let width = 100 / denominator - 1.2; 2107 if (denominator > 10) { 2108 width = (100 / denominator) * .78; 2109 } 2110 2111 this.updateForecastTotal(question); 2112 return width; 2113 } */ 2114 /* public isOrderedCorrectly = (question: IQuestion) => ko.pureComputed(function () { 2115 2116 let nullForecasts = question.answers().filter(a => a.currentUserForecast() === null); 2117 if (nullForecasts.length > 0) { 2118 return true; 2119 } 2120 let forecasts = question.answers().map(a => parseInt(a.currentUserForecast().toString())); 2121 2122 //check for ascending order 2123 if (forecasts[0] <= forecasts[forecasts.length - 1]) { 2124 for (let i = 0; i < forecasts.length; i++) { 2125 if (i < forecasts.length - 1) { 2126 if (forecasts[i + 1] >= forecasts[i]) { 2127 //all good 2128 } 2129 else { 2130 return false; 2131 } 2132 } 2133 else { 2134 //we've been through all of them and it's all good 2135 return true; 2136 } 2137 } 2138 } 2139 2140 else { 2141 return false; 2142 } 2143 2144 2145 }, this); */ 2146 this.hasTouchedSliders = ko.observable(false); 2147 //for numeric input 2148 this.updateNumericQuestion = function (question) { 2149 var answers = question.answers(); 2150 answers.forEach(function (answer) { 2151 if (!answer.currentUserForecast()) { 2152 answer.currentUserForecast(0); 2153 } 2154 if (answer.currentUserForecast().toString().length > 1 && answer.currentUserForecast().toString().indexOf('0') === 0) { 2155 answer.currentUserForecast(parseInt(answer.currentUserForecast().toString())); 2156 } 2157 }); 2158 var currentForecasts = question.answers().map(function (a) { return a.currentUserForecast(); }); 2159 if (Distiller.arraysAreEqual(currentForecasts, question.savedCurrentForecast()) || Distiller.arraysAreEqual(currentForecasts, _this.defaultForecasts())) { 2160 _this.hasTouchedSliders(false); 2161 } 2162 else { 2163 _this.hasTouchedSliders(true); 2164 } 2165 }; 2166 this.preventForecastUpdate = ko.observable(false); 2167 this.reenableSliders = function () { 2168 _this.preventForecastUpdate(false); 2169 }; 2170 this.lastMaxForecast = ko.observable(0); 2171 this.currentMaxForecast = function (question) { 2172 var forecastArray = question.answers().map(function (a) { return a.currentUserForecast(); }); 2173 if (_this.arraysOfAssociatedPointQuestions().length > 0) { 2174 _this.arraysOfAssociatedPointQuestions().forEach(function (arrayOfQuestions) { 2175 arrayOfQuestions.forEach(function (associatedQuestion) { 2176 if (associatedQuestion !== question) { 2177 forecastArray.push.apply(forecastArray, associatedQuestion.answers().map(function (a) { return a.currentUserForec
2177ast(); })); 2178 } 2179 }); 2180 }); 2181 } 2182 else if (_this.associatedPointQuestions().length > 0) { 2183 _this.associatedPointQuestions().forEach(function (pointQuestion) { 2184 forecastArray.push.apply(forecastArray, pointQuestion.answers().map(function (a) { return a.currentUserForecast(); })); 2185 }); 2186 } 2187 return forecastArray.reduce(function (previousLargestNumber, currentLargestNumber) { 2188 return (currentLargestNumber > previousLargestNumber) ? currentLargestNumber : previousLargestNumber; 2189 }, 0); 2190 }; 2191 this.isOrderedCorrectly = function (question) { return ko.pureComputed(function () { 2192 var nullForecasts = question.answers().filter(function (a) { return a.currentUserForecast() === null; }); 2193 if (nullForecasts.length > 0) { 2194 return true; 2195 } 2196 var forecasts = question.answers().map(function (a) { return parseInt(a.currentUserForecast().toString()); }); 2197 //check for ascending order 2198 if (forecasts[0] <= forecasts[forecasts.length - 1]) { 2199 for (var i = 0; i < forecasts.length; i++) { 2200 if (i < forecasts.length - 1) { 2201 if (forecasts[i + 1] >= forecasts[i]) { 2202 //all good 2203 } 2204 else { 2205 return false; 2206 } 2207 } 2208 else { 2209 //we've been through all of them and it's all good 2210 return true; 2211 } 2212 } 2213 } 2214 else { 2215 return false; 2216 } 2217 }, _this); }; 2218 this.isOrderedCorrectlyNonComputed = function (question) { 2219 var nullForecasts = question.answers().filter(function (a) { return a.currentUserForecast() === null; }); 2220 if (nullForecasts.length > 0) { 2221 return true; 2222 } 2223 var forecasts = question.answers().map(function (a) { return parseInt(a.currentUserForecast().toString()); }); 2224 //check for ascending order 2225 if (forecasts[0] <= forecasts[forecasts.length - 1] && forecasts[forecasts.length - 1] > 0) { 2226 for (var i = 0; i < forecasts.length; i++) { 2227 if (i < forecasts.length - 1) { 2228 if (forecasts[i + 1] >= forecasts[i]) { 2229 //all good 2230 } 2231 else { 2232 return false; 2233 } 2234 } 2235 else { 2236 //we've been through all of them and it's all good 2237 return true; 2238 } 2239 } 2240 } 2241 else { 2242 return false; 2243 } 2244 }; 2245 this.pointsAreOrderedCorrectly = function () { return ko.pureComputed(function () { 2246 var arrayOfElicitations = []; 2247 var arraysOfAssociatedPointQuestions = []; 2248 if (this.alternativeElicitations().length > 1) { 2249 arrayOfElicitations = this.alternativeElicitations(); 2250 arraysOfAssociatedPointQuestions = this.arraysOfAssociatedPointQuestions(); 2251 } 2252 else { 2253 //for when there's just one elicitation 2254 arrayOfElicitations.push(this.openResponseQuestion()); 2255 arraysOfAssociatedPointQuestions.push(this.associatedPointQuestions()); 2256 } 2257 if (this.openResponseQuestion().type() === 11) { 2258 if (arraysOfAssociatedPointQuestions.length > 0) { 2259 for (var i = 0; i < arraysOfAssociatedPointQuestions.length; i++) { 2260 for (var q = 0; q < arraysOfAssociatedPointQuestions[i].length; q++) { 2261 var question = arraysOfAssociatedPointQuestions[i][q]; 2262 var nullForecasts = question.answers().filter(function (a) { return a.currentUserForec
2262ast() === null; }); 2263 if (nullForecasts.length > 0) { 2264 return true; 2265 } 2266 var forecasts = question.answers().map(function (a) { return parseFloat(a.currentUserForecast().toString()); }); 2267 //check for ascending order 2268 if (forecasts[0] <= forecasts[forecasts.length - 1]) { 2269 for (var f = 0; f < forecasts.length; f++) { 2270 if (f < forecasts.length - 1) { 2271 if (forecasts[f + 1] >= forecasts[f]) { 2272 //all good 2273 } 2274 else { 2275 return false; 2276 } 2277 } 2278 else { 2279 //we've been through all of them and it's all good 2280 if (q === arraysOfAssociatedPointQuestions[i].length - 1 && i === arraysOfAssociatedPointQuestions.length - 1) { 2281 return true; 2282 } 2283 } 2284 } 2285 } 2286 else { 2287 return false; 2288 } 2289 } 2290 } 2291 } 2292 else { 2293 return true; 2294 } 2295 } 2296 else { 2297 return true; 2298 } 2299 }, _this); }; 2300 this.customGrossmannError = function () { return ko.pureComputed(function () { 2301 var setIds = [266, 267, 268, 269]; 2302 var errorMessage = ''; 2303 var negativeMessage = ' The outcome cannot be negative. '; 2304 var hundredMessage = ' The outcome cannot exceed 100. '; 2305 var thousandMessage = ' The outcome cannot exceed 1,000. '; 2306 var millionMessage = ' The outcome cannot exceed 1,000,000. '; 2307 if (this.associatedPointQuestions() && Distiller.setOfVisibleQuestion() && setIds.indexOf(Distiller.setOfVisibleQuestion().setId()) > -1) { 2308 var setId = Distiller.setOfVisibleQuestion().setId(); 2309 var currentUserForecasts_1 = []; 2310 this.associatedPointQuestions().forEach(function (question) { 2311 var forecasts = question.answers().filter(function (a) { return a.currentUserForecast() !== null; }).map(function (a) { return a.currentUserForecast(); }); 2312 currentUserForecasts_1.push.apply(currentUserForecasts_1, forecasts); 2313 }); 2314 if (currentUserForecasts_1.length > 0) { 2315 for (var i = 0; i < currentUserForecasts_1.length; i++) { 2316 if (currentUserForecasts_1[i] < 0 && errorMessage.indexOf(negativeMessage) < 0) { 2317 errorMessage += negativeMessage; 2318 } 2319 //poverty 2320 if (setId === 267) { 2321 if (currentUserForecasts_1[i] > 100 && errorMessage.indexOf(hundredMessage) < 0) { 2322 errorMessage += hundredMessage; 2323 } 2324 } 2325 //infant mortality 2326 else if (setId === 268) { 2327 if (currentUserForecasts_1[i] > 1000 && errorMessage.indexOf(thousandMessage) < 0) { 2328 errorMessage += thousandMessage; 2329 } 2330 } 2331 //co2 2332 else if (setId === 269) { 2333 if (currentUserForecasts_1[i] > 1000000 && errorMessage.indexOf(millionMessage) < 0) { 2334 errorMessage += millionMessage; 2335 } 2336 } 2337 } 2338 } 2339 if (errorMessage !== '') { 2340 errorMessage = 'Please consider the following error(s) before submitting your predictions: ' + errorMessage; 2341 return errorMessage; 2342 } 2343 else { 2344 return null; 2345 } 2346 } 2347 else { 2348 return null; 2349 } 2350 }, _this); }; 2351 this.zoomRangeIn = function () { 2352 /* 2353 if (this.yMax() > 10) { 2354 //find next number divisible by 10 2355 let nextNumber = this.yMax() - 10; 2356 this.yMax(nextNumber); 2357 } 2358 else */ if (_this.numberOfDecimalPlaces() <= 8) { 2359 var nextNumber = (_this.yMax() / 10).toFixed(_this.numberOfDecimalPlaces() + 1); 2360 _this.yMax(parseFloat(nextNumber)); 2361 } 2362 else { 2363 alert("You can't zoom in any further, but you can put whatever numebr you'd like in the number input box."); 2364 } 2365 }; 2366 this.zoomRangeOut = function () { 2367 if (_this.yMax() >= 10) { 2368 //find next number divisible by 10 2369 var nextNumber = _this.yMax() + 10; 2370 if (nextNumber <= 100) { 2371 _this.yMax(nextNumber); 2372 } 2373 else { 2374 _this.yMax(100); 2375 } 2376 } 2377 else { 2378 var nextNumber = (_this.yMax() * 10).toFixed(_this.numberOfDecimalPlaces() - 1); 2379 _this.yMax(parseFloat(nextNumber)); 2380 } 2381 }; 2382 this.computeRangeTicks = function () { return ko.pureComputed(function () { 2383 var numberOfTicks = 10; 2384 //linear 2385 var min = this.yMin(); 2386 var max = this.yMax(); 2387 var range = max - min; 2388 var tickIncrement = range / numberOfTicks; 2389 var tickValues = []; 2390 var rangeTicks = []; 2391 var labelDecimals = 0; 2392 //log scale 2393 if (this.openResponseQuestion().type() === 24) { 2394 for (var i = 0; i < numberOfTicks; i++) { 2395 tickValues.push((max / 10) / Math.pow(10, i)); 2396 } 2397 for (var i = 0; i < tickValues.length; i++) { 2398 if (i === tickValues.length - 1) { 2399 tickValues[i] = 0; 2400 } 2401 var tick = { 2402 percentWidth: ko.observable(10), 2403 label1: ko.observable(Distiller.numberAsExponent(tickValues[i])), 2404 label2: ko.observable(Distiller.numberAsExponent((tickValues[i] * 10))) 2405 }; 2406 rangeTicks.push(tick); 2407 } 2408 rangeTicks.reverse(); 2409 } 2410 else { //linear scale 2411 for (var i = 0; i < numberOfTicks; i++) { 2412 tickValues.push(min + (tickIncrement * i)); 2413 } 2414 if (this.numberOfDecimalPlaces() > 0) { 2415 labelDecimals = this.numberOfDecimalPlaces(); 2416 if (labelDecimals > 2) { 2417 labelDecimals -= 2; 2418 } 2419 } 2420 for (var i = 0; i < tickValues.length; i++) { 2421 var tick = { 2422 percentWidth: ko.observable(10), 2423 label1: ko.observable(Distiller.numberAsExponent(tickValues[i].toFixed(labelDecimals))), 2424 label2: ko.observable(Distiller.numberAsExponent((tickValues[i] + tickIncrement).toFixed(labelDecimals))) 2425 }; 2426 rangeTicks.push(tick); 2427 } 2428 } 2429 // return rangeTicks; 2430 this.rangeTicks(rangeTicks); 2431 }, _this); }; 2432 this.rangeTicks = ko.observableArray([]); 2433 /* 2434 public rangeTicks: KnockoutObservableArray<any> = ko.observableArray([ 2435 {percentWidth: ko.observable(10), 2436 label1: ko.observable(0), 2437 label2: ko.observable(null)}, 2438 {percentWidth: ko.observable(10), 2439 label1: ko.observable(10), 2440 label2: ko.observable(null)}, 2441 {percentWidth: ko.observable(10), 2442 label1: ko.observable(20), 2443 label2: ko.observable(null)}, 2444 {percentWidth: ko.observable(10), 2445 label1: ko.observable(30), 2446 label2: ko.observable(null)}, 2447 {percentWidth: ko.observable(10), 2448 label1: ko.observable(40), 2449 label2: ko.observable(null)}, 2450 {percentWidth: ko.observable(10), 2451 label1: ko.observable(50), 2452 label2: ko.observable(null)}, 2453 {percentWidth: ko.observable(10), 2454 label1: ko.observable(60), 2455 label2: ko.observable(null)}, 2456 {percentWidth: ko.observable(10), 2457 label1: ko.observable(70), 2458 label2: ko.observable(null)}, 2459 {percentWidth: ko.observable(10), 2460 label1: ko.observable(80), 2461 label2: ko.observable(null)}, 2462 {percentWidth: ko.observable(10), 2463 label1: ko.observable(90), 2464 label2: ko.observable(100)}, 2465 ]); */ 2466 this.updateCallCount = 0; 2467 //for probability forecasting questions and point estimates 2468 this.updateForecastTotal = function (question, answer) { 2469 //this auto updates the other bin when its a binary probability 2470 if ((question.type() === 1 || question.type() === 18) && question.answers().length === 2 && answer) {
2471 if (answer.currentUserForecast) { 2472 var indexOfAnswer = question.answers().indexOf(answer); 2473 var indexOfOtherAnswer = 0; 2474 if (indexOfAnswer === 0) { 2475 indexOfOtherAnswer = 1; 2476 } 2477 var newNumberOfDecimalPlaces = 0; 2478 if (answer.currentUserForecast() === null) { 2479 return; 2480 } 2481 var stringifiedForecast = answer.currentUserForecast().toString(); 2482 var indexOfDecimal = stringifiedForecast.indexOf('.'); 2483 if (indexOfDecimal > -1) { 2484 newNumberOfDecimalPlaces = stringifiedForecast.length - indexOfDecimal; 2485 } 2486 question.answers()[indexOfOtherAnswer].currentUserForecast(parseFloat((100 - answer.currentUserForecast()).toFixed(newNumberOfDecimalPlaces))); 2487 } 2488 } 2489 _this.updateCallCount++; 2490 //why is this called SO MUCH console.log("updateCallCount = " + this.updateCallCount); 2491 var total = 0; 2492 var answers = question.answers(); 2493 answers.forEach(function (answer) { 2494 if (!answer.currentUserForecast()) { 2495 if (answer.currentUserForecast() !== 0) { 2496 answer.currentUserForecast(null); 2497 } 2498 } 2499 if ((question.type() === 1 || question.type() === 18) && answer.currentUserForecast() && answer.currentUserForecast().toString().length > 1 /* && answer.currentUserForecast().toString().indexOf('.') !== 1 */) { 2500 var stringForecast = answer.currentUserForecast().toString(); 2501 var numberOfDecimals = _this.numberOfDecimalPlaces(); 2502 if (stringForecast.indexOf('.') > -1) { 2503 var decimalsInForecast = stringForecast.slice(stringForecast.indexOf('.') + 1, str
2503ingForecast.length).length; 2504 if (decimalsInForecast > numberOfDecimals) { 2505 numberOfDecimals = decimalsInForecast; 2506 } 2507 } 2508 //THIS STANDARDIZES SIG FIGS. WE COULD DO THIS ELSEWHERE SO IT DOESN'T INTERFERE WITH TYPING DECIMALS 2509 // answer.currentUserForecast(<any>parseFloat(answer.currentUserForecast().toString()).toFixed(numberOfDecimals)); 2510 } 2511 if (question.type() === 1 || question.type() === 18) { 2512 if (answer.currentUserForecast() < 0) { 2513 answer.currentUserForecast(0); 2514 } 2515 } 2516 else if (question.type() === 11) { 2517 if (_this.inputChartType() !== 'floating_bar') { 2518 if (answer.currentUserForecast() > (_this.maxValueForCE() * .95)) { 2519 _this.maxValueForCE(parseFloat((answer.currentUserForecast() * 1.05).toFixed(_this.pointDecimalPlaces()))); 2520 } 2521 } 2522 } 2523 //question type 18 is probability slider question type with the option for <1% forecasts 2524 //but we're now going to run this REGARDLESS of question type and just trust the question type interface 2525 //will have or not have the interface for granular forecasts 2526 if ((answer.currentUserForecast() && answer.currentUserForecast().toString().indexOf('.') > -1 || answer.currentUserForecast() < 6) && Distiller.answerShowingGranularInterface().indexOf(answer.answerId()) < 0) { 2527 Distiller.answerShowingGranularInterface.push(answer.answerId()); 2528 } 2529 else if (Distiller.answerShowingGranularInterface().indexOf(answer.answerId()) > -1 && /*answer.currentUserForecast() > 5 */ (answer.currentUserForecast() && answer.currentUserForecast().toString().indexOf('.') < 0 && answer.currentUserForecast() > 6)) { 2530 Distiller.answerShowingGranularInterface.splice(Distiller.answerShowingGranularInterface().indexOf(answer.answerId()), 1); 2531 } 2532 if (answer.currentUserForecast() == 1) { 2533 _this.stopSlider(answer); 2534 } 2535 if (answer.currentUserForecast()) { 2536 var currentUserForecast = parseFloat(answer.currentUserForecast().toString()); 2537 total = parseFloat((total + currentUserForecast).toFixed(_this.numberOfDecimalPlaces())); 2538 } 2539 }); 2540 var currentForecasts = question.answers().map(function (a) { return a.currentUserForecast(); }); 2541 if (Distiller.arraysAreEqual(currentForecasts, question.savedCurrentForecast()) || Distiller.arraysAreEqual(currentForecasts, _this.defaultForecasts())) { 2542 _this.hasTouchedSliders(false); 2543 } 2544 else { 2545 _this.hasTouchedSliders(true); 2546 } 2547 question.forecastTotal(total); 2548 //last check 2549 if (_this.numberOfDecimalPlaces() === 0) { 2550 if (question.forecastTotal() == parseFloat((100).toFixed(_this.numberOfDecimalPlaces())) && question.type() != 11 && question.answers().length !== 2) { 2551 _this.stopAllSliders(); 2552 } 2553 } 2554 else { 2555 var forecast = _this.openResponseQuestion().answers().map(function (a) { return parseFloat(a.currentUserForecast()); }); 2556 var largestForecast = Math.max.apply(Math, forecast); 2557 var largestForecastAnswer = _this.openResponseQuestion().answers()[forecast.indexOf(largestForecast)]; 2558 var maxToStopOn = 100 + ((Math.pow(.1, _this.numberOfDecimalPlaces())) * 9); 2559 if (question.forecastTotal() > 100 && question.forecastTotal() < maxToStopOn && !_this.preventForecastUpdate() && question.answers().length !== 2) { 2560 _this.preventForecastUpdate(true); 2561 _this.stopAllSliders();
2562 //I don't know why I did this before...? added the number of decimals 2563 var extra = parseFloat((question.forecastTotal() - 100).toFixed(_this.numberOfDecimalPlaces())); 2564 largestForecastAnswer.currentUserForecast((largestForecastAnswer.currentUserForecast() - extra).toFixed(_this.numberOfDecimalPlaces())); 2565 setTimeout(function () { return _this.reenableSliders(); }, 100); 2566 } 2567 } 2568 //point slider questions 2569 if (question.type() === 11) { 2570 if (_this.currentMaxForecast(question) < (_this.maxValueForCE() * .5) && _this.currentMaxForecast(question) > 0 && _this.isOrderedCorrectlyNonComputed(question)) { 2571 if (_this.inputChartType() !== 'floating_bar') { 2572 _this.maxValueForCE(_this.maxValueForCE() * .6); 2573 } 2574 } 2575 _this.lastMaxForecast(_this.currentMaxForecast(question)); 2576 var allQuestions_1 = []; 2577 if (_this.alternativeElicitations().length > 1) { 2578 allQuestions_1.push.apply(allQuestions_1, _this.alternativeElicitations()); 2579 _this.arraysOfAssociatedPointQuestions().forEach(function (arrayOfPointQuestions) { 2580 allQuestions_1.push.apply(allQuestions_1, arrayOfPointQuestions); 2581 }); 2582 } 2583 else { 2584 //for when there's just one elicitation 2585 //it already has this.openResponseQuestion() 2586 allQuestions_1.push.apply(allQuestions_1, _this.associatedPointQuestions()); 2587 } 2588 if (allQuestions_1.length > 0) { 2589 for (var q = 0; q < allQuestions_1.length; q++) { 2590 var forecasts = allQuestions_1[q].answers().map(function (a) { return a.currentUserForecast(); }); 2591 if (Distiller.arraysAreEqual(forecasts, allQuestions_1[q].savedCurrentForecast()) || Distiller.arraysAreEqual(currentForecasts, _this.defaultForecasts())) { 2592 _this.hasTouchedSliders(false); 2593 } 2594 else { 2595 _this.hasTouchedSliders(true); 2596 return; 2597 } 2598 } 2599 } 2600 } 2601 }; 2602 this.stopSlider = function (answer) { 2603 var slider = document.getElementById("slider" + answer.answerId()); 2604 if (slider) { 2605 slider.disabled = true; 2606 _this.triggerMouseUp(slider); 2607 slider.disabled = false; 2608 } 2609 }; 2610 this.stopAllSliders = function () { 2611 var inputs = document.getElementsByClassName("forecastSlider"); 2612 if (inputs.length > 0) { 2613 for (var i = 0; i < inputs.length; i++) { 2614 var element = inputs[i]; 2615 element.disabled = true; 2616 _this.triggerMouseUp(element); 2617 } 2618 for (var i = 0; i < inputs.length; i++) { 2619 var element = inputs[i]; 2620 element.disabled = false; 2621 } 2622 } 2623 }; 2624 this.convertDecimalIntoFraction = function (answer) { 2625 var numerator = answer.currentUserForecast(); 2626 var denominator = 100; 2627 var stringifiedForecast = answer.currentUserForecast().toString(); 2628 var indexOfDecimal = stringifiedForecast.indexOf("."); 2629 var indexOfE = stringifiedForecast.indexOf("e-"); 2630 if (indexOfDecimal > -1) { 2631 var decimalPlaces = stringifiedForecast.length - (indexOfDecimal - 1); 2632 if (indexOfE > -1) { 2633 decimalPlaces = parseInt(stringifiedForecast.substring(indexOfE + 2)) + 4; 2634 } 2635 if (_this.numberOfDecimalPlaces() > decimalPlaces) { 2636 decimalPlaces = _this.numberOfDecimalPlaces(); 2637 }
2638 var decimal = (answer.currentUserForecast() * .01).toFixed(decimalPlaces); 2639 var length_1 = decimal.toString().length - 2; 2640 if (indexOfE > -1) { 2641 length_1 = decimalPlaces; 2642 } 2643 denominator = Math.round(Math.pow(10, length_1)); //these should ALWAYS be whole numbers 2644 numerator = Math.round(decimal * denominator); //whenever they are not whole numbers, its the computer's fault (base 2 stuff) 2645 } 2646 for (var i = 0; i < length; i++) { 2647 if ((numerator % 10) === 0 && (denominator % 10) === 0) { 2648 numerator /= 10; 2649 denominator /= 10; 2650 } 2651 } 2652 // return Math.floor(numerator).toString() + " / " + Distiller.numberWithCommas(Math.floor(denominator)); 2653 return Distiller.numberWithCommas(Math.floor(numerator)) + " / " + Distiller.numberWithCommas(Math.floor(denominator)); 2654 }; 2655 this.greatestCommonDivisor = function (a, b) { 2656 if (b < .0000001) { 2657 return a; 2658 } 2659 else { 2660 return _this.greatestCommonDivisor(b, Math.floor(a % b)); 2661 } 2662 }; 2663 this.factorOfTenFraction = function (a, b) { 2664 console.log("a % b" + (a % b)); 2665 }; 2666 this.convertForecastToLog = function (answer, event) { 2667 var linearValue = (parseFloat(event.target.value) * .9) + 10; //we convert the linear value to 2668 // the new scale, which is 90% of the tick mark scale 2669 //and has a minimum of 10 2670 var maxExponent = Math.log10(_this.yMax()); //was just 2 before 2671 var exponent = maxExponent - ((_this.yMax() - linearValue) / 10); 2672 var logScaleNumber = Math.pow(10, exponent); 2673 var decimalPlaces = 0; 2674 if (exponent < 0) { 2675 decimalPlaces = Math.abs(exponent) + 1; 2676 } 2677 logScaleNumber = parseFloat(logScaleNumber.toFixed(decimalPlaces)); 2678 if (linearValue === 10) { 2679 logScaleNumber = 0; 2680 } 2681 answer.currentUserForecast(logScaleNumber); 2682 }; 2683 this.hasUnfinishedCalculation = ko.observable(false); 2684 this.currentForecastWithCommas = function (answer) { return ko.pureComputed({ 2685 read: function () { 2686 var cleanedCurrentForecast = '0'; 2687 if (answer.currentUserForecast() || answer.currentUserForecast() === 0) { 2688 cleanedCurrentForecast = answer.currentUserForecast().toString().replace(/,/g, ""); 2689 } 2690 else { 2691 return null; 2692 } 2693 if (cleanedCurrentForecast.indexOf('e+') < 0) { 2694 var currentForecastWithCommas = cleanedCurrentForecast.replace(/\B(?=(\d{3})+(?!\d))/g, ","); 2695 if (cleanedCurrentForecast.indexOf('.') > -1) { 2696 var nonDecimalPortion = cleanedCurrentForecast.substring(0, cleanedCurrentForecast.indexOf('.')); 2697 nonDecimalPortion = nonDecimalPortion.replace(/\B(?=(\d{3})+(?!\d))/g, ","); 2698 var decimalPortion = cleanedCurrentForecast.substring(cleanedCurrentForecast.indexOf('.')); 2699 currentForecastWithCommas = nonDecimalPortion + decimalPortion; 2700 } 2701 answer.currentUserForecast(parseFloat(cleanedCurrentForecast)); 2702 return currentForecastWithCommas; 2703 } 2704 else { 2705 cleanedCurrentForecast = answer.currentUserForecast().toString().replace(/e\+/g, "*10^"); 2706 // return answer.currentUserForecast(); 2707 return cleanedCurrentForecast; 2708 } 2709 }, 2710 write: function (value) { 2711 this.hasUnfinishedCalculation(false); 2712 if (value === null || value === '') { 2713 console.log("IS NAN"); 2714 return; 2715 } 2716 var forecastNumberBox = document.getElementById("forecastNumberBox" + answer.answerId()); 2717 var cleanedCurrentForecast = forecastNumberBox.value.toString().replace(/,/g, ""); 2718 if (cleanedCurrentForecast.indexOf('e+') > -1) { 2719 this.hasUnfinishedCalculation(true); 2720 } 2721 var total = 0; 2722 if (cleanedCurrentForecast.indexOf('*') > -1 || cleanedCurrentForecast.indexOf('^') > -1) { 2723 this.hasUnfinishedCalculation(true); 2724 // console.log("hasUnfinishedCalculation() " + this.hasUnfinishedCalculation()); 2725 var arrayOfNumberStrings = cleanedCurrentForecast.split('*'); 2726 var arrayOfNumbers = []; 2727 if (arrayOfNumberStrings.length > 0) { 2728 for (var i = 0; i < arrayOfNumberStrings.length; i++) { 2729 var number = 0; 2730 if (arrayOfNumberStrings[i].indexOf('^') > -1) { 2731 var exponentArray = arrayOfNumberStrings[i].split('^'); 2732 if (parseFloat(exponentArray[0]) && parseFloat(exponentArray[1])) 2733 number = Math.pow(parseFloat(exponentArray[0]), parseFloat(exponentArray[1])); 2734 } 2735 else { 2736 number = parseFloat(arrayOfNumberStrings[i]); 2737 } 2738 arrayOfNumbers.push(number); 2739 } 2740 } 2741 if (arrayOfNumbers.length > 0) { 2742 total = arrayOfNumbers.reduce(function (a, b) { return a * b; }); 2743 } 2744 } 2745 else { 2746 this.hasUnfinishedCalculation(false); 2747 } 2748 if (!this.hasUnfinishedCalculation()) { 2749 if (cleanedCurrentForecast.indexOf('e+') < 0) { 2750 if (isNaN(parseFloat(cleanedCurrentForecast))) { 2751 return; 2752 } 2753 else {
2754 answer.currentUserForecast(parseFloat(cleanedCurrentForecast)); 2755 } 2756 } 2757 else { 2758 if (parseFloat(cleanedCurrentForecast) === Infinity) { 2759 cleanedCurrentForecast = '1.7976931348623158e+307'; 2760 } 2761 answer.currentUserForecast(parseFloat(cleanedCurrentForecast)); 2762 } 2763 } 2764 else { 2765 var self_4 = this; 2766 forecastNumberBox.onblur = function () { 2767 if (total === Infinity) { 2768 alert("Oops! That number is too big. The upper limit is ~10^300."); 2769 } 2770 else if (!isNaN(total)) { 2771 cleanedCurrentForecast = total.toString(); 2772 answer.currentUserForecast(parseFloat(cleanedCurrentForecast)); 2773 self_4.hasUnfinishedCalculation(false); 2774 } 2775 else { 2776 alert("Oops! We couldn't calculate that expression. Contact us via the help widget in the lower right if you think we should be able to calculate it."); 2777 } 2778 }; 2779 } 2780 }, 2781 owner: _this 2782 }); }; 2783 this.sumBinaryToOne = function (answer, question) { 2784 var otherBinForecast = 100 - answer.currentUserForecast(); 2785 var indexOfCurrentAnswer = question.answers().indexOf(answer); 2786 if (indexOfCurrentAnswer === 0) { 2787 question.answers()[1].currentUserForecast(otherBinForecast); 2788 } 2789 else { 2790 question.answers()[0].currentUserForecast(otherBinForecast); 2791 } 2792 }; 2793 this.incrementDenominator = function (answer, question) { 2794 var stringifiedForecast = answer.currentUserForecast().toString(); 2795 var indexOfDecimal = stringifiedForecast.indexOf('.'); 2796 if (indexOfDecimal > -1) { 2797 var newNumberOfDecimalPlaces = stringifiedForecast.length - indexOfDecimal; 2798 var newForecast = (answer.currentUserForecast() / 10).toFixed(newNumberOfDecimalPlaces); 2799 answer.currentUserForecast(newForecast); 2800 } 2801 else { 2802 answer.currentUserForecast(answer.currentUserForecast() / 10); 2803 } 2804 if (_this.openResponseQuestion().answers().length === 2) { 2805 _this.sumBinaryToOne(answer, question); 2806 } 2807 }; 2808 this.decrementDenominator = function (answer, question) { 2809 var stringifiedForecast = answer.currentUserForecast().toString(); 2810 var indexOfDecimal = stringifiedForecast.indexOf('.'); 2811 if (indexOfDecimal > -1) { 2812 var newNumberOfDecimalPlaces = stringifiedForecast.length - (indexOfDecimal + 1) - 1; 2813 var newForecast = (answer.currentUserForecast() * 10).toFixed(newNumberOfDecimalPlaces); 2814 answer.currentUserForecast(newForecast); 2815 } 2816 else { 2817 answer.currentUserForecast(answer.currentUserForecast() * 10); 2818 } 2819 if (_this.openResponseQuestion().answers().length === 2) { 2820 _this.sumBinaryToOne(answer, question); 2821 } 2822 }; 2823 this.incrementNumerator = function (answer, question) { 2824 if (!answer.currentUserForecast()) { 2825 answer.currentUserForecast(0); 2826 } 2827 var stringifiedForecast = answer.currentUserForecast().toString(); 2828 var indexOfDecimal = stringifiedForecast.indexOf('.'); 2829 if (indexOfDecimal > -1) { 2830 var numberOfDecimalPlaces = stringifiedForecast.length - (indexOfDecimal + 1); 2831 var incrementValue = "0."; 2832 for (var i = 0; i < numberOfDecimalPlaces - 1; i++) { 2833 incrementValue += "0"; 2834 } 2835 incrementValue += "1"; 2836 var newForecast = (parseFloat(answer.currentUserForec
2836ast()) + parseFloat(incrementValue)).toFixed(numberOfDecimalPlaces); 2837 answer.currentUserForecast(newForecast); 2838 } 2839 else { 2840 answer.currentUserForecast(parseFloat(answer.currentUserForecast()) + 1); 2841 } 2842 if (_this.openResponseQuestion().answers().length === 2) { 2843 _this.sumBinaryToOne(answer, question); 2844 } 2845 }; 2846 this.decrementNumerator = function (answer, question) { 2847 var stringifiedForecast = answer.currentUserForecast().toString(); 2848 var indexOfDecimal = stringifiedForecast.indexOf('.'); 2849 var numberOfDecimalPlaces = stringifiedForecast.length - (indexOfDecimal + 1); 2850 if (indexOfDecimal > -1) { 2851 var decrementValue = "0."; 2852 for (var i = 0; i < numberOfDecimalPlaces - 1; i++) { 2853 decrementValue += "0"; 2854 } 2855 decrementValue += "1"; 2856 var newForecast = (parseFloat(answer.currentUserForecast()) - parseFloat(decrementValue)).toFixed(numberOfDecimalPlaces); 2857 answer.currentUserForecast(newForecast); 2858 } 2859 else { 2860 answer.currentUserForecast(answer.currentUserForecast() - 1); 2861 } 2862 if (_this.openResponseQuestion().answers().length === 2) { 2863 _this.sumBinaryToOne(answer, question); 2864 } 2865 }; 2866 this.sliderStepValue = ko.pureComputed(function () { 2867 var stepValue = "1"; 2868 var forecast = this.openResponseQuestion().answers().map(function (a) { return parseFloat(a.currentUserForecast()); }); 2869 // console.log("parsed forecast = " + JSON.stringify(forecast)); 2870 //console.log("raw forecast = " + JSON.stringify(this.openResponseQuestion().answers().map(a => a.currentUserForecast()))); 2871 if (this.alternativeElicitations().length > 0) { 2872 var indexOfSelectedGraph = this.alternativeElicitations().indexOf(this.selectedGraph()); 2873 if (indexOfSelectedGraph < 0) { 2874 console.log("THERE IS NO SELECTED GRAPH?"); 2875 } 2876 else { 2877 if (this.arraysOfAssociatedPointQuestions().length > 0) { 2878 var questions = this.arraysOfAssociatedPointQuestions()[indexOfSelectedGraph]; 2879 questions.forEach(function (question) { 2880 var forecastsForQuestion = question.answers().map(function (a) { return parseFloat(a.currentUserForecast()); }); 2881 forecast.push.apply(forecast, forecastsForQuestion); 2882 }); 2883 } 2884 } 2885 } 2886 else if (this.associatedPointQuestions().length > 0) { 2887 var questions = this.associatedPointQuestions(); 2888 questions.forEach(function (question) { 2889 var forecastsForQuestion = question.answers().map(function (a) { return parseFloat(a.currentUserForecast()); }); 2890 forecast.push.apply(forecast, forecastsForQuestion); 2891 }); 2892 } 2893 //let smallestForecast = Math.min(...forecast); 2894 var indexOfForecastWithMostDecimals = -1; 2895 var maxDecimalLength = 0; 2896 // console.log("forecasts = " + JSON.stringify(forecast)); 2897 forecast.forEach(function (row) { 2898 var stringifiedForecast = row.toString(); 2899 if (stringifiedForecast.indexOf('.') > -1) { 2900 var numberOfDecimalPlaces = stringifiedForecast.length - (stringifiedForecast.indexOf('.') + 1); 2901 if (numberOfDecimalPlaces > maxDecimalLength) { 2902 maxDecimalLength = numberOfDecimalPlaces; 2903 indexOfForecastWithMostDecimals = forecast.indexOf(row); 2904 } 2905 } 2906 }); 2907 // console.log("indexOfForecastWithMostDecimals = " + indexOfForecastWithMostDecimals); 2908 var forecastWithMostDecimals = Math.min.apply(Math, forecast);
2909 if (indexOfForecastWithMostDecimals > -1) { 2910 forecastWithMostDecimals = forecast[indexOfForecastWithMostDecimals]; 2911 } 2912 //console.log("forecastWithMostDecimals = " + forecastWithMostDecimals); 2913 var stringifiedForecast = forecastWithMostDecimals.toString(); 2914 var indexOfDecimal = stringifiedForecast.indexOf("."); 2915 if (indexOfDecimal > -1) { 2916 var decimalPlaces = stringifiedForecast.length - (indexOfDecimal + 1); 2917 stepValue = (1 * Math.pow(.1, decimalPlaces)).toFixed(decimalPlaces); 2918 } 2919 //adjusting based on yMax, which overrides stepValue based on forecasts IF its smaller 2920 var decimalsBasedOnYMax = 0; 2921 var stepValueBasedOnYMax = "1"; 2922 if (this.yMax() <= 1) { 2923 decimalsBasedOnYMax = 1; 2924 if (this.yMax() < 1) { 2925 var stringifiedYMax = this.yMax().toString(); 2926 var indexOfDecimal_1 = stringifiedYMax.indexOf('.'); 2927 if (indexOfDecimal_1 > -1) { 2928 decimalsBasedOnYMax = stringifiedYMax.length - (indexOfDecimal_1 + 1); 2929 } 2930 decimalsBasedOnYMax += 3; //because yMax will have one LESS decimal than the rest 2931 } 2932 } 2933 stepValueBasedOnYMax = (1 * Math.pow(.1, decimalsBasedOnYMax)).toFixed(decimalsBasedOnYMax); 2934 if (parseFloat(stepValueBasedOnYMax) < parseFloat(stepValue)) { 2935 stepValue = stepValueBasedOnYMax; 2936 } 2937 if (Distiller.client() === 'grossmann' && Distiller.setOfVisibleQuestion()) { 2938 if (Distiller.setOfVisibleQuestion().setName().indexOf('Poverty') > -1 2939 || Distiller.setOfVisibleQuestion().setName().indexOf('Mortality') > -1 2940 || Distiller.setOfVisibleQuestion().setName().indexOf('Concentration') > -1) { 2941 stepValue = '.1'; 2942 } 2943 } 2944 return stepValue; 2945 }, this); 2946 this.numberOfDecimalPlaces = ko.pureComputed(function () { 2947 var numberOfDecimalPlaces = 0; 2948 var stringifiedStepValue = this.sliderStepValue().toString(); 2949 if (stringifiedStepValue.indexOf('.') > -1) { 2950 numberOfDecimalPlaces = stringifiedStepValue.length - (1 + stringifiedStepValue.indexOf('.')); 2951 } 2952 return numberOfDecimalPlaces; 2953 }, this); 2954 this.maxValueForCE = ko.observable(150000); 2955 this.arrayOfCompletedSiblings = ko.pureComputed(function () { 2956 var completedSiblings = []; 2957 Distiller.setOfVisibleQuestion().surveyQuestions().forEach(function (surveyQuestion) { 2958 //forecast sliders 2959 if (surveyQuestion.type() === 1) { 2960 if (surveyQuestion.savedCurrentForecast().length === surveyQuestion.answers().length) { 2961 if (completedSiblings.indexOf(surveyQuestion.questionId() === -1)) { 2962 completedSiblings.push(surveyQuestion.questionId()); 2963 } 2964 } 2965 } 2966 //plain multiple choice 2967 if (surveyQuestion.type() === 6) { 2968 if (surveyQuestion.forecastTotal() > 0) { 2969 if (completedSiblings.indexOf(surveyQuestion.questionId() === -1)) { 2970 completedSiblings.push(surveyQuestion.questionId()); 2971 } 2972 } 2973 } 2974 //plain open response 2975 if (surveyQuestion.type() === 8) { 2976 if (surveyQuestion.currentUserRationales().length > 0) { 2977 if (completedSiblings.indexOf(surveyQuestion.questionId() === -1)) { 2978 completedSiblings.push(surveyQuestion.questionId()); 2979 } 2980 } 2981 } 2982 //list -- we can decide how many list items they should have here 2983 if (surveyQuestion.type() === 12) { 2984 if (surveyQuestion.currentUserRationales().length >= 5) { 2985 if (completedSiblings.indexOf(surveyQuestion.questionId() === -1)) { 2986 completedSiblings.push(surveyQuestion.questionId()); 2987 } 2988 } 2989 } 2990 //rate items in the list 2991 /* DEPRECATED if (surveyQuestion.type() === 13) { 2992 if (surveyQuestion.primaryQuestionIds().length > 0) { 2993 let primaryQuestion = Distiller.setOfVisibleQuestion().surveyQuestions().filter(element => surveyQuestion.primaryQuestionIds().indexOf(element.questionId()) > -1)[0]; 2994 let commentRatings = []; 2995 let j = 0; 2996 primaryQuestion.currentUserRationales().forEac
2996h(comment => { 2997 let currentUserRatingsForComment = comment.ratings().currentUserRatings.filter(element => element.promptId === surveyQuestion.questionId()); 2998 if (currentUserRatingsForComment.length > 0) { 2999 commentRatings.push(currentUserRatingsForComment[0]); 3000 } 3001 j++; 3002 if (j === primaryQuestion.currentUserRationales().length) { 3003 //this forces them to rate every list item 3004 if (commentRatings.length === primaryQuestion.currentUserRationales().length) { 3005 if (completedSiblings.indexOf(surveyQuestion.questionId() === -1)) { 3006 completedSiblings.push(surveyQuestion.questionId()); 3007 } 3008 } 3009 } 3010 3011 }); 3012 } 3013 } */ 3014 //numeric input 3015 if (surveyQuestion.type() === 14) { 3016 if (surveyQuestion.savedCurrentForecast().length > 0) { 3017 if (completedSiblings.indexOf(surveyQuestion.questionId() === -1)) { 3018 completedSiblings.push(surveyQuestion.questionId()); 3019 } 3020 } 3021 } 3022 //range input 3023 if (surveyQuestion.type() === 15) { 3024 if (surveyQuestion.savedCurrentForecast().length > 0) { 3025 if (completedSiblings.indexOf(surveyQuestion.questionId() === -1)) { 3026 completedSiblings.push(surveyQuestion.questionId()); 3027 } 3028 } 3029 } 3030 if (surveyQuestion.siblingQuestions().length > 0) { 3031 var i_1 = 0; 3032 surveyQuestion.siblingQuestions().forEach(function (siblingQuestion) { 3033 i_1++; 3034 //forecast sliders 3035 if (siblingQuestion.type() === 1) { 3036 if (siblingQuestion.savedCurrentForecast().length === siblingQuestion.answers().length) { 3037 if (completedSiblings.indexOf(siblingQuestion.questionId() === -1)) { 3038 completedSiblings.push(siblingQuestion.questionId()); 3039 } 3040 } 3041 } 3042 //plain multiple choice 3043 if (siblingQuestion.type() === 6) { 3044 if (siblingQuestion.savedCurrentForecast().length === siblingQuestion.answers().length) { 3045 if (completedSiblings.indexOf(siblingQuestion.questionId() === -1)) { 3046 completedSiblings.push(siblingQuestion.questionId()); 3047 } 3048 } 3049 } 3050 //plain open response 3051 if (siblingQuestion.type() === 8) { 3052 if (siblingQuestion.currentUserRationales().length > 0) { 3053 if (completedSiblings.indexOf(siblingQuestion.questionId() === -1)) { 3054 completedSiblings.push(siblingQuestion.questionId()); 3055 } 3056 } 3057 } 3058 //list -- we can decide how many list items they should have here 3059 if (siblingQuestion.type() === 12) { 3060 if (siblingQuestion.currentUserRationales().length >= 5) { 3061 if (completedSiblings.indexOf(siblingQuestion.questionId() === -1)) { 3062 completedSiblings.push(siblingQuestion.questionId()); 3063 } 3064 } 3065 } 3066 //rate items in the list 3067 if (siblingQuestion.type() === 13) { 3068 if (siblingQuestion.primaryQuestionIds().length > 0) { 3069 var primaryQuestion_1 = Distiller.setOfVisibleQuestion().surveyQuestions().filter(function (element) { return siblingQuestion.primaryQuestionIds().indexOf(element.questionId()) > -1; })[0]; 3070 if (!primaryQuestion_1) { 3071 for (var z = 0; z < Distiller.setOfVisibleQuestion().surveyQuestions().length; z++) { 3072 if (Distiller.setOfVisibleQuestion().surveyQuestions()[z].siblingQuestions().filter(function (element) { return siblingQuestion.primaryQuestionIds().indexOf(element.questionId()) > -1; }).length > 0) { 3073 primaryQuestion_1 = Distiller.setOfVisibleQuestion().surveyQuestions()[z].siblingQuestions().filter(function (element) { return siblingQuestion.primaryQuestionIds().indexOf(element.questionId()) > -1; })[0]; 3074 } 3075 } 3076 } 3077 var commentRatings_1 = []; 3078 var j_1 = 0; 3079 primaryQuestion_1.currentUserRationales().forEac
3079h(function (comment) { 3080 var currentUserRatingsForComment = []; //DEPRECATED comment.ratings().currentUserRatings.filter(element => element.promptId === siblingQuestion.questionId()); 3081 if (currentUserRatingsForComment.length > 0) { 3082 commentRatings_1.push(currentUserRatingsForComment[0]); 3083 } 3084 j_1++; 3085 if (j_1 === primaryQuestion_1.currentUserRationales().length) { 3086 //this forces them to rate every list item 3087 if (commentRatings_1.length === primaryQuestion_1.currentUserRationales().length) { 3088 if (completedSiblings.indexOf(siblingQuestion.questionId() === -1)) { 3089 completedSiblings.push(siblingQuestion.questionId()); 3090 } 3091 } 3092 } 3093 }); 3094 } 3095 } 3096 //numeric input 3097 if (siblingQuestion.type() === 14) { 3098 if (siblingQuestion.savedCurrentForecast().length > 0) { 3099 if (completedSiblings.indexOf(siblingQuestion.questionId() === -1)) { 3100 completedSiblings.push(siblingQuestion.questionId()); 3101 } 3102 } 3103 } 3104 //range input 3105 if (siblingQuestion.type() === 15) { 3106 if (siblingQuestion.savedCurrentForecast()[0] > 0 || siblingQuestion.savedCurrentForecast()[0] === 0) { 3107 if (completedSiblings.indexOf(siblingQuestion.questionId() === -1)) { 3108 completedSiblings.push(siblingQuestion.questionId()); 3109 } 3110 } 3111 } 3112 //update forecast slider - always include it 3113 // because it comes after required steps (?) 3114 if (siblingQuestion.type() === 16) { 3115 if (completedSiblings.indexOf(siblingQuestion.questionId() === -1)) { 3116 completedSiblings.push(siblingQuestion.questionId()); 3117 } 3118 } 3119 }); 3120 } 3121 }); 3122 return completedSiblings; 3123 }, this); 3124 this.listRateCompleted = function () { 3125 var primaryQuestions = _this.primaryQuestionsForListRating(); 3126 if (primaryQuestions.length > 0) { 3127 var f_1 = 0; 3128 primaryQuestions.forEach(function (primaryQuestion) { 3129 f_1++; 3130 if (_this.arrayOfCompletedSiblings().indexOf(primaryQuestion.questionId()) > -1) { 3131 var i_2 = 0; 3132 _this.relatedRatingQuestions(primaryQuestion.questionId()).forEach(function (relatedQuestion) { 3133 if (_this.arrayOfCompletedSiblings().indexOf(relatedQuestion.questionId()) < 0) { 3134 return false; 3135 } 3136 i_2++; 3137 if (i_2 === _this.relatedRatingQuestions(primaryQuestion.questionId()).length && f_1 === primaryQuestions.length) { 3138 return true; 3139 } 3140 }); 3141 } 3142 else { 3143 return false; 3144 } 3145 }); 3146 } 3147 else { 3148 return false; 3149 } 3150 }; 3151 this.affirmConsensus = function () { 3152 var self = _this; 3153 _this.processingButton(_this.openResponseQuestion().questionId()); 3154 Distiller.httpPostAsync(Distiller.apiEndpoint + "/api/affirmConsensus/" + Distiller.currentUser().userId + "/" + _this.openResponseQuestion().questionId(), function (response) { 3155 return __awaiter(this, void 0, void 0, function () { 3156 return __generator(this, function (_a) { 3157 Distiller.getAffirmations(self.openResponseQuestion()); 3158 self.processingButton(null); 3159 return [2 /*return*/]; 3160 }); 3161 }); 3162 }); 3163 }; 3164 this.revertSliders = function () { 3165 if (_this.openResponseQuestion().answers().length > 0) { 3166 for (var i = 0; i < _this.openResponseQuestion().answers().length; i++) { 3167 _this.openResponseQuestion().answers()[i].currentUserForec
3167ast(_this.openResponseQuestion().savedCurrentForecast()[i]); 3168 } 3169 } 3170 }; 3171 this.showingPastRationales = ko.observable(false); 3172 this.toggleAllCurrentUserRationales = function () { 3173 if (_this.showingPastRationales()) { 3174 _this.showingPastRationales(false); 3175 } 3176 else { 3177 _this.showingPastRationales(true); 3178 } 3179 }; 3180 this.hasRationaleInput = ko.observable(true); 3181 this.description = ko.observable(null); 3182 this.textPlaceholder = ko.observable("Please explain your thinking here"); 3183 this.selectedGraph = ko.observable(null); 3184 this.selectAssociatedQuestion = function (associatedQuestion) { 3185 _this.selectedGraph(associatedQuestion); 3186 }; 3187 this.switchGraph = function (associatedQuestion) { 3188 if (_this.alternativeElicitations().length > 0) { 3189 _this.selectAssociatedQuestion(associatedQuestion); 3190 } 3191 }; 3192 this.associatedPointQuestions = ko.observableArray([]); 3193 this.alternativeElicitations = ko.observableArray([]); 3194 this.arraysOfAssociatedPointQuestions = ko.observableArray([]); 3195 this.loadingPointChart = ko.observable(false); 3196 this.setPointDefaults = function (question) { 3197 if (question.name().toLowerCase().indexOf("life expectancy") > -1) { 3198 _this.yMax(120); 3199 _this.maxValueForCE(120); 3200 } 3201 else if (question.name().toLowerCase().indexOf("poverty rate") > -1) { 3202 _this.yMax(100); 3203 _this.maxValueForCE(100); 3204 } 3205 else { 3206 if (question.defaultMin()) { 3207 _this.yMin(question.defaultMin()); 3208 } 3209 else { 3210 _this.yMin(0); 3211 } 3212 if (question.defaultMax()) { 3213 _this.yMax(question.defaultMax()); 3214 } 3215 else { 3216 _this.yMax(100); 3217 } 3218 _this.minZoomRange(1000); 3219 if (!_this.draggedChart) { 3220 _this.maxValueForCE(_this.yMax()); 3221 } 3222 } 3223 //do this server side maybe? 3224 var self = _this; 3225 _this.loadingPointChart(true); 3226 var total = 0; 3227 question.answers().forEach(function (answer) { 3228 total += answer.currentUserForecast(); 3229 }); 3230 if (total === 0 && !_this.hidingChartBeforeFirstForecast()) { 3231 var range = _this.yMax() - _this.yMin(); 3232 var defaultMiddle = Math.round((range / 2) + _this.yMin()); 3233 var spacerValue_1 = Math.round(range / 10); 3234 var startingValue_1 = defaultMiddle - (spacerValue_1 * Math.floor(question.answers().length / 2)); 3235 for (var i = 0; i < question.answers().length; i++) { 3236 var forecast = null; 3237 if (question.answers()[i].defaultValue()) { 3238 if (question.answers()[i].defaultValue() === 'blank') { 3239 forecast = null; 3240 } 3241 else { 3242 forecast = question.answers()[i].defaultValue(); 3243 } 3244 } 3245 else { 3246 forecast = startingValue_1 + (i * spacerValue_1); 3247 } 3248 question.answers()[i].currentUserForecast(forecast); 3249 } 3250 if (_this.arraysOfAssociatedPointQuestions().length > 0) { 3251 var p_1 = 0; 3252 _this.arraysOfAssociatedPointQuestions().forEach(function (pointQuestionArray) { 3253 p_1++; 3254 pointQuestionArray.forEach(function (pointQuestion) { 3255 for (var i = 0; i < pointQuestion.answers().length; i++) { 3256 var forecast = null; 3257 if (pointQuestion.answers()[i].defaultValue()) { 3258 if (pointQuestion.answers()[i].defaultValue() === 'blank') { 3259 forecast = null; 3260 } 3261 else { 3262 forecast = pointQuestion.answers()[i].defaultValue(); 3263 } 3264 } 3265 else { 3266 forecast = startingValue_1 + (i * spacerValue_1); 3267 } 3268 pointQuestion.answers()[i].currentUserForec
3268ast(forecast); 3269 if (i === pointQuestion.answers().length - 1 && p_1 === self.arraysOfAssociatedPointQuestions().length) { 3270 self.loadingPointChart(false); 3271 } 3272 } 3273 }); 3274 }); 3275 } 3276 else { 3277 _this.associatedPointQuestions().forEach(function (pointQuestion) { 3278 for (var i = 0; i < pointQuestion.answers().length; i++) { 3279 var forecast = null; 3280 if (pointQuestion.answers()[i].defaultValue()) { 3281 if (pointQuestion.answers()[i].defaultValue() === 'blank') { 3282 forecast = null; 3283 } 3284 else { 3285 forecast = pointQuestion.answers()[i].defaultValue(); 3286 } 3287 } 3288 else { 3289 forecast = startingValue_1 + (i * spacerValue_1); 3290 } 3291 pointQuestion.answers()[i].currentUserForecast(forecast); 3292 } 3293 }); 3294 self.loadingPointChart(false); 3295 } 3296 } 3297 else { 3298 // console.log("total is NOT zero"); 3299 } 3300 _this.defaultForecasts([]); 3301 question.answers().forEach(function (answer) { 3302 _this.defaultForecasts.push(answer.currentUserForecast()); 3303 }); 3304 if (Distiller.getOrdersOfMagnitude(question.defaultMin(), question.defaultMax()) > 3) { 3305 if (_this.scale() === 'linear') { 3306 _this.toggleLogScale(); 3307 } 3308 } 3309 }; 3310 this.setPointChartBounds = function () { 3311 var allForecasts = []; 3312 var hasForecasts = false; 3313 if (_this.arraysOfAssociatedPointQuestions().length > 0) { 3314 _this.arraysOfAssociatedPointQuestions().forEach(function (associatedPointQuestionArray) { 3315 associatedPointQuestionArray.forEach(function (pointQuestion) { 3316 pointQuestion.answers().forEach(function (answer) { 3317 if (answer.currentUserForecast() || answer.currentUserForecast() === 0) { 3318 if (answer.currentUserForecast() > 0 || answer.currentUserForecast() < 0 || answer.currentUserForecast() === 0) { 3319 hasForecasts = true; 3320 } 3321 if (answer.outcome() || answer.outcome() === 0) { 3322 hasForecasts = true; 3323 allForecasts.push(answer.outcome()); 3324 } 3325 allForecasts.push(answer.currentUserForecast()); 3326 } 3327 }); 3328 }); 3329 }); 3330 } 3331 else if (_this.associatedPointQuestions().length > 0) { 3332 _this.associatedPointQuestions().forEach(function (pointQuestion) { 3333 pointQuestion.answers().forEach(function (answer) { 3334 if (answer.currentUserForecast() > 0 || answer.currentUserForecast() < 0 || answer.currentUserForecast() === 0) { 3335 hasForecasts = true; 3336 } 3337 if (answer.outcome() || answer.outcome() === 0) { 3338 hasForecasts = true; 3339 allForecasts.push(answer.outcome()); 3340 } 3341 allForecasts.push(answer.currentUserForecast()); 3342 }); 3343 }); 3344 } 3345 else { 3346 _this.openResponseQuestion().answers().forEach(function (answer) {
3347 if (answer.currentUserForecast() || answer.currentUserForecast() === 0) { 3348 if (answer.currentUserForecast() > 0 || answer.currentUserForecast() < 0 || answer.currentUserForecast() === 0) { 3349 hasForecasts = true; 3350 } 3351 if (answer.outcome() || answer.outcome() === 0) { 3352 hasForecasts = true; 3353 allForecasts.push(answer.outcome()); 3354 } 3355 allForecasts.push(answer.currentUserForecast()); 3356 } 3357 }); 3358 } 3359 if ((hasForecasts || (!hasForecasts && _this.hasTouchedSliders())) && _this.openResponseQuestion().type() !== 1 && _this.openResponseQuestion().type() !== 18 && !Distiller.arraysAreEqual(allForecasts, _this.openResponseQuestion().answers().map(function (a) { return a.defaultValue(); }))) { 3360 var min = Math.min.apply(Math, allForecasts); 3361 var max = Math.max.apply(Math, allForecasts); 3362 var range = max - min; 3363 var decrement = Math.floor(.1 * range); 3364 var increment = Math.floor(.1 * range); 3365 if (increment < 1) { 3366 increment = 1; 3367 } 3368 if (Distiller.client() === 'grossmann') { 3369 _this.yMin(Math.floor(.8 * min)); 3370 } 3371 // else if (this.inputChartType() === 'floating_bar') { 3372 else { 3373 var newYMin = min - decrement; 3374 if ((min - decrement) === 0) { 3375 newYMin = 0; 3376 } 3377 _this.yMin(newYMin); 3378 } 3379 var newYMax = max + increment; 3380 _this.yMax(newYMax); 3381 // if (!this.draggedChart) { 3382 _this.maxValueForCE(_this.yMax()); 3383 // } 3384 _this.minZoomRange(Math.round(min * 1.2)); 3385 if (Distiller.getOrdersOfMagnitude(min, max) > 3) { 3386 if (_this.scale() === 'linear') { 3387 _this.toggleLogScale(); 3388 } 3389 } 3390 } 3391 else { 3392 _this.setPointDefaults(_this.openResponseQuestion()); 3393 } 3394 }; 3395 this.commentHidingParams = ko.observable(null); 3396 this.quillOptions = ko.observable(null); 3397 this.rationaleLimit = ko.observable(null); 3398 this.readOnlyQuillOptions = ko.observable({ 3399 isReadOnly: true 3400 }); 3401 this.editOrReplyQuillOptions = ko.observable({ 3402 placeholder: 'Use this space to provide feedback, ask questions, etc', 3403 isReadOnly: false, 3404 toolbarOptions: [ 3405 ['bold', 'italic', 'underline', 'strike', 'blockquote'], // toggled buttons 3406 // ['blockquote', 'code-block'], 3407 // [{ 'header': 1 }, { 'header': 2 }], // custom button values 3408 [{ 'list': 'ordered' }, { 'list': 'bullet' }], 3409 [{ 'script': 'sub' }, { 'script': 'super' }], // superscript/subscript 3410 [{ 'indent': '-1' }, { 'indent': '+1' }], // outdent/indent 3411 [{ 'size': ['small', false, 'large', 'huge'] }], // custom dropdown 3412 // [{ 'header': [1, 2, 3, 4, 5, 6, false] }], 3413 [{ 'color': [] }, { 'background': [] }], // dropdown with defaults from theme 3414 [{ 'font': ['montserrat', 'arvo'] }], 3415 [{ 'align': [] }], 3416 ['clean', 'link', 'image'] 3417 ] 3418 }); 3419 this.allWikis = ko.observableArray([]); 3420 this.otherTeamWikis = ko.observableArray([]); 3421 this.teamIdOfVisibleWiki = ko.observable(null); 3422 this.wikiTeamIds = ko.observableArray([]); 3423 this.myVisibleWiki = ko.observable(null); 3424 this.goToWiki = function (wiki) { 3425 if (!wiki) { 3426 return; 3427 } 3428 _this.myVisibleWiki(wiki); 3429 }; 3430 this.toggleEdit = function (comment) { 3431 if (comment.isGettingEdited()) { 3432 comment.isGettingEdited(false); 3433 } 3434 else {
3435 comment.newText(comment.text().replace(/<br \/>/g, '\r\n')); 3436 comment.isGettingEdited(true); 3437 } 3438 }; 3439 this.toggleWikiEdit = function (comment) { return __awaiter(_this, void 0, void 0, function () { 3440 var newComment; 3441 return __generator(this, function (_a) { 3442 if (comment.isGettingEdited()) { 3443 comment.isGettingEdited(false); 3444 this.myVisibleWiki(this.allWikis()[this.allWikis().length - 2]); 3445 this.allWikis.splice(this.allWikis().length - 1, 1); 3446 } 3447 else { 3448 newComment = Distiller.buildNewComment(this.openResponseQuestion(), comment.commentId(), comment.text(), JSON.parse(comment.quillDelta())); 3449 this.openResponseQuestion().currentUserRationales.unshift(newComment); 3450 this.openResponseQuestion().teammateComments.unshift(newComment); 3451 newComment.newText(comment.text().replace(/<br \/>/g, '\r\n')); 3452 newComment.isGettingEdited(true); 3453 this.allWikis.push(newComment); 3454 this.myVisibleWiki(this.allWikis()[this.allWikis().length - 1]); 3455 } 3456 return [2 /*return*/]; 3457 }); 3458 }); }; 3459 this.socket = ko.observable(null); 3460 this.outgoingDelta = ko.observable(null); 3461 this.incomingDelta = ko.observable(null); 3462 this.outgoingCursor = ko.observable(null); 3463 this.incomingCursors = ko.observableArray([]); 3464 this.liveCommentId = ko.observable(null); 3465 this.yDoc = ko.observable(null); 3466 this.yText = ko.observable(null); 3467 this.quillInstance = ko.observable(null); 3468 this.inputChartType = ko.observable(null); 3469 this.defaultForecasts = ko.observableArray([]); 3470 this.loadMoreManually = ko.observable(false); 3471 this.isReadOnly = ko.observable(false); 3472 this.hideQuestionText = ko.observable(false); 3473 this.showFractionalInterface = ko.observable(null); 3474 this.answer = ko.observable(null); 3475 this.grossmannLastYearComments = ko.pureComputed(function () { 3476 var commentsOldestToNewest = _this.openResponseQuestion().currentUserRationales().filter(function (a) { return a.text() != 'placeholder_for_numeric_question'; }).slice(0).sort(function (a, b) { return a.commentId() - b.commentId(); }); 3477 var comments = []; 3478 if (Distiller.currentUser().stageNumber() === 3) { 3479 commentsOldestToNewest = commentsOldestToNewest.filter(function (a) { return a.timestamp().indexOf('2022') > -1; }); 3480 if (commentsOldestToNewest[0]) { 3481 comments.push(commentsOldestToNewest[0]); 3482 } 3483 if (commentsOldestToNewest[1]) { 3484 comments.push(commentsOldestToNewest[1]); 3485 } 3486 } 3487 else if (Distiller.currentUser().stageNumber() === 5) { 3488 commentsOldestToNewest = commentsOldestToNewest.filter(function (a) { return a.timestamp().indexOf('2023') > -1; }); 3489 if (commentsOldestToNewest[0]) { 3490 comments.push(commentsOldestToNewest[0]); 3491 } 3492 // ONLY block NSC FOR SUPERSMES if (Distiller.visibleQuestion().questionId() !== 1290) { 3493 if (commentsOldestToNewest[1]) { 3494 comments.push(commentsOldestToNewest[1]); 3495 } 3496 // } 3497 } 3498 return comments; 3499 }); 3500 var hidingParams = { 3501 showRespondButton: ko.observable(true), 3502 showEditButton: ko.observable(true), 3503 showCopyLink: ko.observable(false) 3504 }; 3505 if (Distiller.client() === 'grossmann') { 3506 hidingParams.showRespondButton(false); 3507 hidingParams.showEditButton(true); 3508 } 3509 if (params.isReadOnly) { 3510 this.isReadOnly(params.isReadOnly); 3511 hidingParams.showRespondButton(false); 3512 hidingParams.showEditButton(false); 3513 } 3514 if (params.showCopyLink) { 3515 hidingParams.showCopyLink(true); 3516 } 3517 if (params.showFractionalInterface) {
3518 this.showFractionalInterface(params.showFractionalInterface); 3519 } 3520 this.commentHidingParams(hidingParams); 3521 //this restricts interface to just ONE 3522 //answer that we've passed in. No labels no nothing 3523 if (params.answer) { 3524 this.answer(params.answer); 3525 } 3526 var question = params.question; 3527 var description = null; 3528 if (params.description) { 3529 this.description(params.description); 3530 } 3531 if (params.hideQuestionText) { 3532 this.hideQuestionText(true); 3533 } 3534 if (params.inputChartType) { 3535 this.inputChartType(params.inputChartType); 3536 } 3537 if (typeof params.hasRationaleInput !== 'undefined') { 3538 this.hasRationaleInput(params.hasRationaleInput); 3539 } 3540 if (params.textPlaceholder) { 3541 this.textPlaceholder(params.textPlaceholder); 3542 } 3543 if (params.quillOptions) { 3544 this.quillOptions(params.quillOptions); 3545 } 3546 if (params.rationaleLimit) { 3547 this.rationaleLimit(params.rationaleLimit); 3548 } 3549 if (params.loadMoreManually) { 3550 this.loadMoreManually(params.loadMoreManually); 3551 } 3552 if (params.wikis) { 3553 this.allWikis([]); 3554 if (params.wikis.length > 0) { 3555 var i_3 = 0; 3556 params.wikis.forEach(function (wiki) { 3557 i_3++; 3558 if (i_3 < params.wikis.length) { 3559 wiki.isGettingEdited(false); 3560 } 3561 _this.allWikis.push(wiki); 3562 }); 3563 this.myVisibleWiki(this.allWikis()[this.allWikis().length - 1]); 3564 // console.log("allWikis.map commentId " + JSON.stringify(this.allWikis().map(a => a.commentId()))); 3565 this.liveCommentId(this.myVisibleWiki().commentId()); 3566 if ((Distiller.currentUser().stageNumber() === 3 && Distiller.client() === 'xrisk') || Distiller.client() !== 'xrisk') { 3567 this.myVisibleWiki().isGettingEdited(true); 3568 } 3569 setTimeout(function () { 3570 //this is SO BAD. patch for hiding toolbars 3571 //because otherwise they show up a million times in a row 3572 _this.goToWiki(_this.myVisibleWiki()); 3573 }, 1000); 3574 } 3575 } 3576 this.openResponseQuestion(question); 3577 var self = this; 3578 /* if (this.openResponseQuestion().defaultMax()) { 3579 let defaultMin = this.openResponseQuestion().defaultMin(); 3580 if (this.openResponseQuestion().defaultMin() === 0) { 3581 defaultMin = 1; 3582 } 3583 } */ 3584 //if (this.openResponseQuestion().primaryQuestionIds()) 3585 //this is karger specific 3586 if (this.openResponseQuestion().type() === 5 && ((Distiller.currentUser().stageNumber() === 3 && Distiller.client() === 'xrisk') || Distiller.client() !== 'xrisk')) { 3587 var yDoc = new Y.Doc(); 3588 self.yDoc(yDoc); 3589 var socketHost_1 = Distiller.host(); 3590 if (socketHost_1.indexOf('quorumapp.com') < 0) { 3591 socketHost_1 = 'http://localhost:5001'; 3592 } 3593 if (socketHost_1.indexOf('http://') > -1) { 3594 socketHost_1 = 'ws://' + socketHost_1.slice(7, socketHost_1.length); 3595 } 3596 else if (socketHost_1.indexOf('https://') > -1) { 3597 socketHost_1 = 'wss://' + socketHost_1.slice(8, socketHost_1.length); 3598 } 3599 //disconnect if it has a connection already 3600 //otherwise they accumulate! 3601 if (Distiller.wsProvider()) { 3602 Distiller.wsProvider().disconnect(); 3603 } 3604 var roomData = { 3605 userName: Distiller.currentUser().name(), 3606 userId: Distiller.currentUser().userId, 3607 teamId: Distiller.currentUser().team().teamId(), 3608 questionId: self.openResponseQuestion().questionId(),
3609 host: socketHost_1 3610 }; 3611 var roomName = "question" + roomData.questionId + "_team" + roomData.teamId; 3612 //THIS TRIGGERS ON('CONNECTION' SERVER SIDE 3613 var wsProvider = new WebsocketProvider(socketHost_1, roomName, self.yDoc()); 3614 wsProvider.awareness.setLocalStateField('user', { 3615 name: Distiller.currentUser().name(), 3616 color: Distiller.userColor(Distiller.currentUser().userId) 3617 }); 3618 Distiller.wsProvider(wsProvider); 3619 self.socket(wsProvider); 3620 wsProvider.on('connection-close', function (closeEvent) { 3621 // console.log("closing connectioN! "); 3622 }); 3623 var timeout_1 = null; 3624 this.outgoingDelta.subscribe(function (delta) { 3625 if (timeout_1) { 3626 clearTimeout(timeout_1); 3627 } 3628 timeout_1 = setTimeout(function () { 3629 var text = self.newText(); 3630 var delta = JSON.stringify(self.newDelta()); 3631 if (self.myVisibleWiki()) { 3632 text = self.myVisibleWiki().newText(), 3633 delta = JSON.stringify(self.myVisibleWiki().quillDelta()); 3634 } 3635 var wikiData = { 3636 text: text, 3637 delta: delta, 3638 userId: Distiller.currentUser().userId, 3639 questionId: self.openResponseQuestion().questionId(), 3640 commentId: self.liveCommentId(), 3641 host: socketHost_1 //window.location.href 3642 }; 3643 self.updateWiki(wikiData); 3644 }, 2000); 3645 }); 3646 } 3647 this.combinedQuestions.push(this.openResponseQuestion()); 3648 if (question.type() === 17) { 3649 Distiller.getAffirmations(question); 3650 if (question.arrayOfUserForecasts().length > 0) { 3651 this.setTime(); 3652 } 3653 question.arrayOfUserForecasts.subscribe(function (userForecasts) { 3654 if (userForecasts.length > 0) { 3655 _this.setTime(); 3656 } 3657 }); 3658 } 3659 for (var i = 0; i < this.openResponseQuestion().siblingQuestions().length; i++) { 3660 var siblingQuestion = this.openResponseQuestion().siblingQuestions()[i]; 3661 self.combinedQuestions.push(siblingQuestion); 3662 /* DEPRECATED OCTOBER 31 2022 let userSubmissions = siblingQuestion.answers().filter(a => a.currentUserForecast() > 0); 3663 if (userSubmissions.length > 0) { 3664 this.getGroundTruth(siblingQuestion); 3665 } */ 3666 } 3667 //this is where we build the associated questions 3668 //with question pairs data 3669 this.associatedPointQuestions([]); 3670 var associatedQuestions = this.combinedQuestions().filter(function (a) { return a.primaryQuestionIds().indexOf(_this.openResponseQuestion().questionId()) > -1; }); 3671 if (associatedQuestions.length > 0) { 3672 this.selectedGraph(this.openResponseQuestion()); 3673 this.associatedPointQuestions.push(this.openResponseQuestion()); 3674 for (var i = 0; i < associatedQuestions.length; i++) { 3675 this.associatedPointQuestions.push(associatedQuestions[i]); 3676 } 3677 } 3678 else if (this.openResponseQuestion().type() === 11) { 3679 this.selectedGraph(this.openResponseQuestion()); 3680 this.associatedPointQuestions.push(this.openResponseQuestion()); 3681 } 3682 else { 3683 this.selectedGraph(this.openResponseQuestion()); 3684 } 3685 //HACK FOR NOW 3686 this.alternativeElicitations([]); 3687 //alternative elicitations are those where altId is NOT null 3688 //and is equal to the altId of the question we're constructing. 3689 var alternativeElicitions = this.combinedQuestions().filter(function (a) { return a.primaryQuestionIds().length === 0 && a.altId() && a.altId() === question.altId(); }); 3690 if (alternativeElicitions.length > 1) { 3691 for (var i = 0; i < alternativeElicitions.length; i++) { 3692 this.alternativeElicitations.push(alternativeElicitions[i]); 3693 } 3694 } 3695 this.arraysOfAssociatedPointQuestions([]); 3696 if (this.alternativeElicitations().length > 1) { 3697 var _loop_1 = function (i) { 3698 var associatedQuestions_1 = this_1.combinedQuestions().filter(function (a) { return a.primaryQuestionIds().indexOf(_this.alternativeElicitations()[i].questionId()) > -1 && (a.type() === 11 || a.type() === 18); }); 3699 if (associatedQuestions_1.length > 0) { 3700 var row = []; 3701 row.push(this_1.alternativeElicitations()[i]); 3702 for (var a = 0; a < associatedQuestions_1.length; a++) { 3703 row.push(associatedQuestions_1[a]); 3704 } 3705 this_1.arraysOfAssociatedPointQuestions.push(row); 3706 } 3707 }; 3708 var this_1 = this; 3709 for (var i = 0; i < this.alternativeElicitations().length; i++) { 3710 _loop_1(i); 3711 } 3712 } 3713 //if its a probability slider and there is no forecast, 3714 //set default position to ignorance prior 3715 if (question.type() === 1 || question.type() === 18) { 3716 var total_1 = 0;
3717 question.answers().forEach(function (answer) { 3718 total_1 += answer.currentUserForecast(); 3719 }); 3720 if (total_1 === 0) { 3721 var ignorancePrior_1 = Math.round(100 / question.answers().length); 3722 if (question.answers().length === 1) { 3723 ignorancePrior_1 = 50; 3724 } 3725 question.answers().forEach(function (answer) { 3726 if (answer.defaultValue() === null) { 3727 answer.currentUserForecast(ignorancePrior_1); 3728 } 3729 else if (answer.defaultValue() === 'blank') { 3730 answer.currentUserForecast(null); 3731 } 3732 else { 3733 answer.currentUserForecast(answer.defaultValue()); 3734 } 3735 }); 3736 if (this.alternativeElicitations().length > 0 && this.arraysOfAssociatedPointQuestions().length === 0) { 3737 this.alternativeElicitations().forEach(function (altElicitation) { 3738 altElicitation.answers().forEach(function (answer) { 3739 if (answer.defaultValue() === null) { 3740 answer.currentUserForecast(ignorancePrior_1); 3741 } 3742 else if (answer.defaultValue() === 'blank') { 3743 answer.currentUserForecast(null); 3744 } 3745 else { 3746 answer.currentUserForecast(answer.defaultValue()); 3747 } 3748 }); 3749 }); 3750 } 3751 else if (this.arraysOfAssociatedPointQuestions().length > 0) { 3752 this.arraysOfAssociatedPointQuestions().forEach(function (arrayOfQuestions) { 3753 arrayOfQuestions.forEach(function (row) { 3754 row.answers().forEach(function (answer) { 3755 if (answer.defaultValue() === null) { 3756 answer.currentUserForecast(ignorancePrior_1); 3757 } 3758 else if (answer.defaultValue() === 'blank') { 3759 answer.currentUserForecast(null); 3760 } 3761 else { 3762 answer.currentUserForecast(answer.defaultValue()); 3763 } 3764 }); 3765 }); 3766 }); 3767 } 3768 else if (this.associatedPointQuestions().length > 0) { 3769 this.associatedPointQuestions().forEach(function (associatedQuestion) { 3770 associatedQuestion.answers().forEach(function (answer) { 3771 if (answer.defaultValue() === null) { 3772 answer.currentUserForecast(ignorancePrior_1); 3773 } 3774 else if (answer.defaultValue() === 'blank') { 3775 answer.currentUserForecast(null); 3776 } 3777 else { 3778 answer.currentUserForecast(answer.defaultValue()); 3779 } 3780 }); 3781 }); 3782 } 3783 } 3784 } 3785 var currentForecasts = question.answers().map(function (a) { return a.currentUserForecast(); }); 3786 self.defaultForecasts([]); 3787 question.answers().forEach(function (answer) { 3788 self.defaultForecasts.push(answer.currentUserForecast()); 3789 }); 3790 if (question.type() === 11 || ((question.type() === 18 || question.type() === 1) && (this.arraysOfAssociatedPointQuestions().length > 0 || this.associatedPointQuestions().length > 0))) { 3791 Distiller.windowResizeEvents.subscribe(function () { 3792 self.setPointBinContainerWidth(); 3793 self.setPointBinWidth(); 3794 }); 3795 //set these to start 3796 setTimeout(function () { return self.setPointBinContainerWidth(); }, 100); 3797 setTimeout(function () { return self.setPointBinWidth(); }, 100); 3798 } 3799 //if its a probability question 3800 else if ((question.type() === 1 || question.type() === 18) && this.arraysOfAssociatedPointQuestions().length === 0) { 3801 Distiller.windowResizeEvents.subscribe(function () { 3802 self.setProbBinContainerWidth(); 3803 self.setProbBinWidth(); 3804 }); 3805 //set these to start 3806 setTimeout(function () { return self.setProbBinContainerWidth(); }, 100); 3807 setTimeout(function () { return self.setProbBinWidth(); }, 100); 3808 } 3809 if (window.location.href.indexOf("comment") > -1) { 3810 Distiller.scrollIntoView(); 3811 } 3812 self.hasTouchedSliders.subscribe(function (touchedSliders) { 3813 if (touchedSliders && !Distiller.expandedNodeQuestion()) { //expanded node questions autosave.. 3814 Distiller.hasUnsavedForecast(true); 3815 } 3816 else { 3817 Distiller.hasUnsavedForecast(false); 3818 } 3819 }); 3820 if (question.type() !== 5) 3821 self.newText.subscribe(function (newText) { 3822 if (newText) { 3823 Distiller.hasUnsavedText(true); 3824 } 3825 else { 3826 Distiller.hasUnsavedText(false); 3827 } 3828 }); 3829 //need to unsubscribe here because its a GLOBAL variable 3830 //and the subscriptions accumulate. For local variables, subscriptions are disposed 3831 //with disposal of the view (I *think*) 3832 if (Distiller.tabSubscription()) { 3833 // Distiller.tabSubscription().dispose(); 3834 } 3835 /* Distiller.tabSubscription( */ Distiller.selectedSubtab.subscribe(function (tag) { 3836 if (tag) { 3837 if (tag.toLowerCase().indexOf('my forecast') > -1) { 3838 if (question.type() === 11 || ((question.type() === 18 || question.type() === 1) && (_this.arraysOfAssociatedPointQuestions().length > 0 || _this.associatedPointQuestions().length > 0))) { 3839 self.setPointBinContainerWidth(); 3840 self.setPointBinWidth(); 3841 } 3842 else if ((question.type() === 1 || question.type() === 18) && _this.arraysOfAssociatedPointQuestions().length === 0) { 3843 self.setProbBinContainerWidth(); 3844 self.setProbBinWidth(); 3845 } 3846 } 3847 } 3848 }) /*)*/; 3849 }
3850 OpenResponseViewModel.prototype.buildPlaceholderForecasts = function (questions) { 3851 return __awaiter(this, void 0, void 0, function () { 3852 var _this = this; 3853 return __generator(this, function (_a) { 3854 return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () { 3855 var arrayOfPlaceholderForecasts, _loop_7, i; 3856 return __generator(this, function (_a) { 3857 arrayOfPlaceholderForecasts = []; 3858 _loop_7 = function (i) { 3859 var question = questions[i]; 3860 var color = 'rgba(255, 0, 0, .5)'; 3861 var pointRadius = 3; 3862 var lineWidth = 1; 3863 var pointHoverRadius = 5; 3864 var userForecast = []; 3865 var forecastData = []; 3866 question.answers().forEach(function (answer) { 3867 userForecast.push(answer.currentUserForecast()); 3868 var forecastDataRow = { 3869 message: "successful response", 3870 ID: null, 3871 userId: Distiller.currentUser().userId, 3872 forecast: answer.currentUserForecast(), 3873 answerId: answer.answerId(), 3874 answerText: answer.text(), 3875 timestamp: null, 3876 name: Distiller.currentUser().name() 3877 }; 3878 forecastData.push(forecastDataRow); 3879 }); 3880 var timestampRow = null; 3881 var userId = Distiller.currentUser().userId; 3882 var userForecastData = { 3883 userId: userId, 3884 timestampRow: timestampRow, 3885 label: Distiller.currentUser().name(), 3886 historicalId: null, 3887 fill: false, 3888 lineTension: 0, 3889 backgroundColor: color, 3890 borderColor: color, 3891 borderCapStyle: 'square', 3892 borderWidth: lineWidth, 3893 borderDashOffset: 0, 3894 borderJoinStyle: 'miter', 3895 pointBorderColor: color,
3896 pointBackgroundColor: color, 3897 pointBorderWidth: 1, 3898 pointHoverRadius: pointHoverRadius, 3899 pointHoverBackgroundColor: color, 3900 pointHoverBorderColor: 'brown', 3901 pointHoverBorderWidth: 1, 3902 pointRadius: pointRadius, 3903 pointHitRadius: 10, 3904 data: userForecast, 3905 forecastData: forecastData, 3906 spanGaps: true, 3907 }; 3908 arrayOfPlaceholderForecasts.push(userForecastData); 3909 }; 3910 for (i = 0; i < questions.length; i++) { 3911 _loop_7(i); 3912 } 3913 resolve(arrayOfPlaceholderForecasts); 3914 return [2 /*return*/]; 3915 }); 3916 }); })]; 3917 }); 3918 }); 3919 }; 3920 OpenResponseViewModel.prototype.getGroundTruth = function (question) { 3921 return __awaiter(this, void 0, void 0, function () { 3922 var _this = this; 3923 return __generator(this, function (_a) { 3924 return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () { 3925 return __generator(this, function (_a) { 3926 Distiller.httpPostAsync(Distiller.apiEndpoint + "/api/getGroundTruth/" + Distiller.currentUser().userId + "/" + question.questionId(), function (response) { 3927 var groundTruth = JSON.parse(response); 3928 question.groundTruth([]); 3929 if (groundTruth.length > 0) { 3930 groundTruth.forEach(function (groundTruthRow) { 3931 var row = { 3932 answerId: ko.observable(groundTruthRow.answerId), 3933 outcome: ko.observable(groundTruthRow.outcome) 3934 }; 3935 question.groundTruth.push(row); 3936 }); 3937 } 3938 resolve(response); 3939 }); 3940 return [2 /*return*/]; 3941 }); 3942 }); })]; 3943 }); 3944 }); 3945 }; 3946 OpenResponseViewModel.prototype.addToTeamForecastArray = function (question) { 3947 return __awaiter(this, void 0, void 0, function () { 3948 var _this = this; 3949 return __generator(this, function (_a) { 3950 return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () { 3951 var teammateForecast, color, indexOfColor, timestamp, isoTimestamp, timestampRow, userForecastData, existingForecastForUser, index; 3952 return __generator(this, function (_a) { 3953 teammateForecast = []; 3954 if (Distiller.currentUser().userId < Distiller.colorsArray().length) { 3955 color = Distiller.colorsArray()[Distiller.currentUser().userId]; 3956 } 3957 else { 3958 indexOfColor = Distiller.currentUser().userId % Distiller.colorsArray().length; 3959 color = Distiller.colorsArray()[indexOfColor]; 3960 } 3961 question.savedCurrentForecast([]); 3962 timestamp = new Date(); 3963 isoTimestamp = timestamp.toISOString(); 3964 question.answers().forEach(function (answer) { 3965 //come back here!!! 3966 var teammateForecastRow = { 3967 name: Distiller.currentUser().name(), 3968 userId: Distiller.currentUser().userId, 3969 forecast: parseInt(answer.currentUserForec
3969ast()), 3970 answerId: answer.answerId(), 3971 answerText: answer.text(), 3972 timestamp: isoTimestamp 3973 }; 3974 if (!answer.currentUserForecast()) { 3975 answer.currentUserForecast(0); 3976 } 3977 question.savedCurrentForecast.push(parseFloat(answer.currentUserForecast())); 3978 teammateForecast.push(teammateForecastRow); 3979 }); 3980 timestampRow = Distiller.buildTimestampRow(teammateForecast); 3981 userForecastData = { 3982 userId: Distiller.currentUser().userId, 3983 timestampRow: timestampRow, 3984 label: Distiller.currentUser().name(), 3985 fill: false, 3986 lineTension: 0, 3987 backgroundColor: color, 3988 borderColor: color, 3989 borderCapStyle: 'square', 3990 borderWidth: 2, 3991 borderDashOffset: 0, 3992 borderJoinStyle: 'miter', 3993 pointBorderColor: 'black',
3994 pointBackgroundColor: 'white', 3995 pointBorderWidth: 1, 3996 pointHoverRadius: 2, 3997 pointHoverBackgroundColor: color, 3998 pointHoverBorderColor: 'brown', 3999 pointHoverBorderWidth: 1, 4000 pointRadius: 4, 4001 pointHitRadius: 10, 4002 data: question.savedCurrentForecast(), 4003 forecastData: teammateForecast, 4004 spanGaps: true, 4005 }; 4006 existingForecastForUser = question.arrayOfUserForecasts().filter(function (a) { return a.userId === Distiller.currentUser().userId; }); 4007 if (existingForecastForUser.length > 0) { 4008 index = question.arrayOfUserForecasts().indexOf(existingForecastForUser[0], 1); 4009 question.arrayOfUserForecasts.splice(index, 1, userForecastData); 4010 } 4011 //if it is a consensus question, but current user didn't save the last one, replace it anyway 4012 else if (question.type() === 17) { 4013 question.arrayOfUserForecasts.splice(0, 1, userForecastData); 4014 } 4015 else { 4016 question.arrayOfUserForecasts.push(userForecastData); 4017 } 4018 resolve("done"); 4019 return [2 /*return*/]; 4020 }); 4021 }); })]; 4022 }); 4023 }); 4024 }; 4025 OpenResponseViewModel.prototype.saveForecastAsync = function (question) { 4026 return __awaiter(this, void 0, void 0, function () { 4027 var _this = this; 4028 return __generator(this, function (_a) { 4029 this.processingButton(question.questionId()); 4030 return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () { 4031 var forecast, stringifiedForecast, self; 4032 return __generator(this, function (_a) { 4033 forecast = []; 4034 question.answers().forEach(function (answer) { 4035 var binForecast = { answerId: answer.answerId(), forecast: answer.currentUserForecast() }; 4036 forecast.push(binForecast); 4037 }); 4038 stringifiedForecast = JSON.stringify(forecast); 4039 self = this; 4040 Distiller.httpPostAsync(Distiller.apiEndpoint + "/api/saveCurrentForecast/" + Distiller.currentUser().userId + "/" + question.questionId() + "/" + stringifiedForecast, function (response) { 4041 return __awaiter(this, void 0, void 0, function () { 4042 return __generator(this, function (_a) { 4043 switch (_a.label) { 4044 case 0: 4045 if (!(response === "error posting individual forecast")) return [3 /*break*/, 1]; 4046 alert("Oops! There's been an error saving your forecast. Please contact [email protected]."); 4047 return [3 /*break*/, 3]; 4048 case 1: 4049 self.mcAttempts.push(question.questionId()); 4050 return [4 /*yield*/, self.addToTeamForecastArray(question)]; 4051 case 2: 4052 _a.sent(); 4053 self.processingButton(null); 4054 self.updateForecastTotal(question); 4055 //if it's not the linked team question 4056 if (question.setId() === Distiller.setOfVisibleQuestion().setId() /* && this.openResponseQuestion().questionId() === question.questionId()*/) { 4057 if (question.currentUserRationales().length < 1) { 4058 self.addPlaceholderComment(question, Distiller.currentUser().userId); 4059 } 4060 } 4061 //DEPRECATED 10/31/22 await self.getGroundTruth(question); 4062 if ((Distiller.client() === 'gjp' && question.name().toLowerCase().indexOf("baseline") > -1) || (Distiller.client() === 'impact' && (question.name().toLowerCase().indexOf("submission 1.3") > -1 || question.name().toLowerCase().indexOf("submission 2.10") > -1))) { 4063 Distiller.checkForBaselineDisagreements(); 4064 } 4065 resolve("done"); 4066 _a.label = 3; 4067 case 3: return [2 /*return*/]; 4068 } 4069 }); 4070 }); 4071 }); 4072 return [2 /*return*/]; 4073 }); 4074 }); })]; 4075 }); 4076 }); 4077 }; 4078 OpenResponseViewModel.prototype.saveForecastsAndRationalesAsync = function (questions) { 4079 return __awaiter(this, void 0, void 0, function () { 4080 var self, forecasts, rationales; 4081 var _this = this; 4082 return __generator(this, function (_a) { 4083 self = this; 4084 this.processingButton(questions[0].questionId()); 4085 forecasts = []; 4086 rationales = []; 4087 if (this.newText()) { 4088 rationales.push(this.newText()); 4089 } 4090 return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () { 4091 var objectToSend, stringifiedObject, self; 4092 return __generator(this, function (_a) { 4093 questions.forEach(function (question) { 4094 var forecast = [];
4095 question.answers().forEach(function (answer) { 4096 var binForecast = { userId: Distiller.currentUser().userId, questionId: question.questionId(), answerId: answer.answerId(), forecast: answer.currentUserForecast() }; 4097 forecast.push(binForecast); 4098 }); 4099 forecasts.push(forecast); 4100 }); 4101 objectToSend = { 4102 forecasts: forecasts, 4103 rationales: rationales 4104 }; 4105 stringifiedObject = JSON.stringify(objectToSend); 4106 self = this; 4107 Distiller.httpSendAsync(Distiller.apiEndpoint + "/api/saveCurrentForecastsAndRationales/" + Distiller.currentUser().userId, stringifiedObject, function (response) { 4108 return __awaiter(this, void 0, void 0, function () { 4109 return __generator(this, function (_a) { 4110 if (response === "error posting individual forecast") { 4111 alert("Oops! There's been an error saving your forecast. Please contact [email protected]."); 4112 } 4113 else { 4114 questions.forEach(function (question) { 4115 self.mcAttempts.push(question.questionId()); 4116 self.addToTeamForecastArray(question); 4117 self.processingButton(null); 4118 self.updateForecastTotal(question); 4119 //if it's not the linked team question 4120 if (question.setId() === Distiller.setOfVisibleQuestion().setId() /* && this.openResponseQuestion().questionId() === question.questionId()*/) { 4121 if (question.currentUserRationales().length < 1 && !self.newText()) { 4122 self.addPlaceholderComment(question, Distiller.currentUser().userId); 4123 } 4124 } 4125 // await self.getGroundTruth(question); 4126 if ((Distiller.client() === 'gjp' && question.name().toLowerCase().indexOf("baseline") > -1) || (Distiller.client() === 'impact' && (question.name().toLowerCase().indexOf("submission 1.3") > -1 || question.name().toLowerCase().indexOf("submission 2.10") > -1))) { 4127 Distiller.checkForBaselineDisagreements(); 4128 } 4129 }); 4130 resolve("done"); 4131 } 4132 return [2 /*return*/]; 4133 }); 4134 }); 4135 }); 4136 return [2 /*return*/]; 4137 }); 4138 }); })]; 4139 }); 4140 }); 4141 }; 4142 OpenResponseViewModel.prototype.saveForecastConsensusAsync = function (question) { 4143 return __awaiter(this, void 0, void 0, function () { 4144 var _this = this; 4145 return __generator(this, function (_a) { 4146 this.processingButton(question.questionId()); 4147 return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () { 4148 var currentForecasts, self, forecast_1, stringifiedForecast; 4149 return __generator(this, function (_a) { 4150 currentForecasts = question.answers().map(function (a) { return a.currentUserForec
4150ast(); }); 4151 self = this; 4152 if (Distiller.arraysAreEqual(currentForecasts, question.savedCurrentForecast())) { 4153 self.affirmConsensus(); 4154 resolve("done"); 4155 } 4156 else { 4157 forecast_1 = []; 4158 question.answers().forEach(function (answer) { 4159 var binForecast = { answerId: answer.answerId(), forecast: parseInt(answer.currentUserForecast()) }; 4160 forecast_1.push(binForecast); 4161 }); 4162 stringifiedForecast = JSON.stringify(forecast_1); 4163 Distiller.httpPostAsync(Distiller.apiEndpoint + "/api/saveCurrentConsensus/" + Distiller.currentUser().userId + "/" + question.questionId() + "/" + stringifiedForecast, function (response) { 4164 return __awaiter(this, void 0, void 0, function () { 4165 return __generator(this, function (_a) { 4166 switch (_a.label) { 4167 case 0: 4168 if (!(response === "error posting individual forecast")) return [3 /*break*/, 1]; 4169 alert("Oops! There's been an error saving your forecast. Please contact [email protected]."); 4170 return [3 /*break*/, 3]; 4171 case 1: 4172 self.mcAttempts.push(question.questionId()); 4173 return [4 /*yield*/, self.addToTeamForecastArray(question)]; 4174 case 2: 4175 _a.sent(); 4176 self.processingButton(null); 4177 self.updateForecastTotal(question); 4178 Distiller.forecastAffirmations([]); 4179 Distiller.getAffirmations(question); 4180 resolve("done"); 4181 _a.label = 3; 4182 case 3: return [2 /*return*/]; 4183 } 4184 }); 4185 }); 4186 }); 4187 } 4188 return [2 /*return*/]; 4189 }); 4190 }); })]; 4191 }); 4192 }); 4193 }; 4194 OpenResponseViewModel.prototype.triggerMouseUp = function (node) { 4195 var clickEvent = document.createEvent('MouseEvents'); 4196 clickEvent.initEvent("mouseup", true, true); 4197 node.dispatchEvent(clickEvent); 4198 }; 4199 return OpenResponseViewModel; 4200}()); 4201/* 4202Distiller.registerComponent("open-response-view", OpenResponseViewModel, "OpenResponse"); 4203Distiller.registerComponent("list-input-view", OpenResponseViewModel, "ListInput"); 4204Distiller.registerComponent("list-rate-view", OpenResponseViewModel, "ListRate"); 4205Distiller.registerComponent("list-rate-ach", OpenResponseViewModel, "ListRateACH"); 4206Distiller.registerComponent("multiple-choice-view", OpenResponseViewModel, "MultipleChoice"); 4207Distiller.registerComponent("probability-input-view", OpenResponseViewModel, "ProbabilityInput"); 4208Distiller.registerComponent("probability-input-rationale", OpenResponseViewModel, "ProbabilityInputRationale"); 4209Distiller.registerComponent("probability-update-rationale", OpenResponseViewModel, "ProbabilityUpdate");
4210Distiller.registerComponent("probability-consensus-input", OpenResponseViewModel, "ProbabilityConsensusInput"); 4211Distiller.registerComponent("numeric-input-view", OpenResponseViewModel, "NumericInput"); 4212Distiller.registerComponent("range-input-view", OpenResponseViewModel, "RangeInput"); 4213Distiller.registerComponent("question-icon", OpenResponseViewModel, "QuestionIcon"); 4214Distiller.registerComponent("quill-wiki-view", OpenResponseViewModel, "QuillWikiView"); 4215Distiller.registerComponent("probability-rationale-granular", OpenResponseViewModel, "ProbabilityRationaleGranular"); 4216Distiller.registerComponent("point-forecast-sliders", OpenResponseViewModel, "PointForecastSliders"); 4217Distiller.registerComponent("point-forecast-graph-input", OpenResponseViewModel, "PointForecastGraphInput"); 4218*/ 4219export default OpenResponseViewModel;
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.